Skip to content

Commit

Permalink
Merge pull request #47 from Wunderbyte-GmbH/issue_gh46_restriction_cr…
Browse files Browse the repository at this point in the history
…iteria

New Feature: Restriction overview and calculation GH-46
  • Loading branch information
WunderJacob authored Jan 9, 2024
2 parents 231b85a + 96d183b commit 4a8f500
Show file tree
Hide file tree
Showing 18 changed files with 183 additions and 48 deletions.
2 changes: 1 addition & 1 deletion amd/build/app-lazy.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amd/build/app-lazy.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions amd/src/app-lazy.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions classes/course_completion/conditions/manual.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function get_description():array {
* @return string
*/
private function get_description_string() {
$description = get_string('course_description_condition_manually', 'local_adele');
$description = get_string('course_description_condition_completion_manual', 'local_adele');
return $description;
}

Expand All @@ -90,7 +90,7 @@ private function get_description_string() {
* @return string
*/
private function get_name_string() {
$description = get_string('course_name_condition_manually', 'local_adele');
$description = get_string('course_name_condition_completion_manual', 'local_adele');
return $description;
}

Expand All @@ -101,8 +101,8 @@ private function get_name_string() {
* @return boolean
*/
public function get_completion_status($node, $userid) {
if (isset($node['data']['manual'] ) && $node['data']['manual']
&& $node['data']['value']) {
if (isset($node['data']['manualcompletion'] ) && $node['data']['manualcompletion']
&& $node['data']['manualcompletionvalue']) {
return true;
}
return false;
Expand Down
8 changes: 4 additions & 4 deletions classes/course_restriction/conditions/manual.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function get_description():array {
* @return string
*/
private function get_description_string() {
$description = get_string('course_description_condition_manually', 'local_adele');
$description = get_string('course_description_condition_restriction_manual', 'local_adele');
return $description;
}

Expand All @@ -89,7 +89,7 @@ private function get_description_string() {
* @return string
*/
private function get_name_string() {
$description = get_string('course_name_condition_manually', 'local_adele');
$description = get_string('course_name_condition_restriction_manual', 'local_adele');
return $description;
}

Expand All @@ -100,8 +100,8 @@ private function get_name_string() {
* @return boolean
*/
public function get_restriction_status($node, $userid) {
if (isset($node['data']['manual'] ) && $node['data']['manual']
&& $node['data']['value']) {
if (isset($node['data']['manualrestriction'] ) && $node['data']['manualrestriction']
&& $node['data']['manualrestrictionvalue']) {
return true;
}
return false;
Expand Down
14 changes: 13 additions & 1 deletion classes/course_restriction/conditions/timed.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ private function get_name_string() {
* @return boolean
*/
public function get_restriction_status($node, $userid) {
return true;
$timed = [];
foreach ($node['restriction']['nodes'] as $restrictionnode) {
if ($restrictionnode['data']['label'] == 'timed') {
$validtime = false;
$datetimestamp = strtotime($restrictionnode['data']['value']);
$currenttimestamp = strtotime(date('Y-m-d'));
if ($datetimestamp <= $currenttimestamp) {
$validtime = true;
}
$timed[$restrictionnode['id']] = $validtime;
}
}
return $timed;
}
}
27 changes: 22 additions & 5 deletions classes/learning_paths.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,32 @@ public static function addnodemanualcondition($json) {
$node->deletable = false;
$node->data->completion = $json->user_path_relation->{$node->id} ?? false;
$node->data->manual = false;
if ($node->completion && $node->completion->nodes) {
foreach ($node->completion->nodes as $completionnode) {
if ($completionnode->data->label == 'manual') {
$node->data->manual = true;
$node = self::checkmanualcondition($node);
}
return json_encode($json);
}

/**
* Get user path relation.
*
* @param object $node
* @return array
*/
public static function checkmanualcondition($node) {
$conditions = [
'completion',
'restriction',
];
foreach ($conditions as $condition) {
if ($node->{$condition} && $node->{$condition}->nodes) {
foreach ($node->{$condition}->nodes as $conditionnode) {
if ($conditionnode->data->label == 'manual') {
$node->data->{ 'manual' . $condition} = true;
}
}
}
}
return json_encode($json);
return $node;
}


Expand Down
52 changes: 47 additions & 5 deletions classes/relation_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
namespace local_adele;

use local_adele\course_completion\course_completion_status;
use local_adele\course_restriction\course_restriction_status;
use local_adele\helper\user_path_relation;

defined('MOODLE_INTERNAL') || die();
Expand All @@ -54,8 +55,11 @@ public static function updated_single($event) {
if ($userpath) {
foreach ($userpath->json['tree']['nodes'] as $node) {
$completioncriteria = course_completion_status::get_condition_status($node, $userpath->user_id);
$restrictioncriteria = course_restriction_status::get_restriction_status($node, $userpath->user_id);
$completionnodepaths = [];
$restrictionnodepaths = [];
$singlecompletionnode = [];
$singlerestrictionnode = [];
if (isset($node['completion'])) {
foreach ($node['completion']['nodes'] as $completionnode) {
$failedcompletion = false;
Expand Down Expand Up @@ -91,11 +95,49 @@ public static function updated_single($event) {
}
}
}
$completionnode = self::getcompletionnode($completionnodepaths);
if (isset($node['restriction'])) {
foreach ($node['restriction']['nodes'] as $restrictionnnode) {
$failedrestriction = false;
$validationconditionstring = [];
if ($restrictionnnode['parentCondition'][0] == 'starting_condition') {
$currentcondition = $restrictionnnode;
$validationcondition = false;
while ( $currentcondition ) {
if ($currentcondition['data']['label'] == 'timed' ) {
$validationcondition =
$restrictioncriteria[$currentcondition['data']['label']][$currentcondition['id']];
$singlerestrictionnode[$currentcondition['data']['label']
. '_' . $currentcondition['id']] = $validationcondition;
$validationconditionstring[] = $currentcondition['data']['label']
. '_' . $currentcondition['id'];
} else {
$validationcondition = $restrictioncriteria[$currentcondition['data']['label']];
$singlerestrictionnode[$currentcondition['data']['label']] = $validationcondition;
$validationconditionstring[] = $currentcondition['data']['label'];
}
// Check if the conditon is true and break if one condition is not met.
if (!$validationcondition) {
$failedrestriction = true;
}
// Get next Condition and return null if no child node exsists.
$currentcondition = self::searchnestedarray($node['restriction']['nodes'],
$currentcondition['childCondition'], 'id');
}
if ($validationcondition && !$failedrestriction) {
$restrictionnodepaths[] = $validationconditionstring;
}
}
}
}
$completionnode = self::getconditionnode($completionnodepaths);
$restrictionnode = self::getconditionnode($restrictionnodepaths);
$userpath->json['user_path_relation'][$node['id']] = [
'completioncriteria' => $completioncriteria,
'completionnode' => $completionnode,
'singlecompletionnode' => $singlecompletionnode,
'restrictioncriteria' => $restrictioncriteria,
'restrictionnode' => $restrictionnode,
'singlerestrictionnode' => $singlerestrictionnode,
];
// Match completions.
}
Expand All @@ -107,15 +149,15 @@ public static function updated_single($event) {
/**
* Observer for course completed
*
* @param array $completionnodepaths
* @param array $conditionnodepaths
* @return array
*/
public static function getcompletionnode($completionnodepaths) {
public static function getconditionnode($conditionnodepaths) {
// TODO sort the valid completion paths.
$valid = count($completionnodepaths) ? true : false;
$valid = count($conditionnodepaths) ? true : false;
return [
'valid' => $valid,
'conditions' => $completionnodepaths,
'conditions' => $conditionnodepaths,
];
}

Expand Down
6 changes: 4 additions & 2 deletions lang/en/local_adele.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@
$string['node_courseshortname'] = 'Short Coursename:';

// Conditions description.
$string['course_description_condition_manually'] = 'Course will be completed manually';
$string['course_name_condition_manually'] = 'Course completion checkbox';
$string['course_description_condition_completion_manual'] = 'Course will be completed manually';
$string['course_name_condition_completion_manual'] = 'Course completion checkbox';
$string['course_description_condition_restriction_manual'] = 'Access will be granted manually';
$string['course_name_condition_restriction_manual'] = 'Course restriction checkbox';
$string['course_description_condition_timed'] = 'Course has to be completed due to a given date ';
$string['course_name_condition_timed'] = 'Course determination date';
$string['course_description_condition_course_completed'] = 'Course has been completed by student';
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'local_adele';
$plugin->release = '0.1.3';
$plugin->version = 2024010308;
$plugin->release = '0.1.4';
$plugin->version = 2024010908;
$plugin->requires = 2022112800;
$plugin->maturity = MATURITY_ALPHA;
$plugin->dependencies = [
Expand Down
3 changes: 0 additions & 3 deletions vue3/components/completion/CompletionItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import course_completed from './conditions/course_completed.vue'
import manual from '../completion/conditions/manual.vue'
import catquiz from './conditions/catquiz.vue'
import modquiz from './conditions/modquiz.vue'
import manual_output from './conditions_output/manual_output.vue'
const props = defineProps(['completion']);
Expand All @@ -18,8 +17,6 @@ const dynamicComponent = computed(() => {
return course_completed;
case 'manual':
return manual;
case 'manual_output':
return manual_output;
case 'catquiz':
return catquiz;
case 'modquiz':
Expand Down
6 changes: 3 additions & 3 deletions vue3/components/completion/CompletionOutPutItem.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template>
<div v-for="output_item in output_items">
<component :is="getOutputLabel(output_item)" v-model="completion.value" :completion="completion"/>
<component :is="getOutputLabel(output_item)" v-model="data.manualcompletionvalue" :data="data"/>
</div>
</template>

<script setup>
import manual_output from './conditions_output/manual_output.vue'
const props = defineProps(['completion']);
const props = defineProps(['data']);
const output_items = ['manual'];
const dynamicComponent = (output_item) => {
Expand All @@ -20,7 +20,7 @@ const dynamicComponent = (output_item) => {
};
const getOutputLabel = (output_item) => {
if (props.completion) {
if (props.data) {
return dynamicComponent(output_item)
}else{
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<template>
<div class="form-check">
<input
:id="completion.node_id"
:id="data.node_id"
class="form-check-input"
type="checkbox"
:checked="modelValue"
@change="$emit('update:modelValue', $event.target.checked)"
/>
<label :for="completion.node_id">Finish course manual</label>
<label :for="data.node_id">Finish course manually</label>
</div>
</template>

<script setup>
const props = defineProps(['modelValue', 'completion']);
const props = defineProps(['modelValue', 'data']);
</script>
50 changes: 41 additions & 9 deletions vue3/components/nodes/CustomNodeEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { Handle, Position } from '@vue-flow/core'
import { defineProps, computed, ref } from 'vue';
import { useStore } from 'vuex';
import CompletionOutPutItem from '../completion/CompletionOutPutItem.vue'
import RestrictionOutPutItem from '../restriction/RestrictionOutPutItem.vue'

// Load Store
const store = useStore();
Expand All @@ -49,10 +50,15 @@ const nodeBackgroundColor = computed(() => {
const sourceHandleStyle = computed(() => ({ backgroundColor: props.data.color, filter: 'invert(100%)', width: '10px', height: '10px'}))
const targetHandleStyle = computed(() => ({ backgroundColor: props.data.color, filter: 'invert(100%)', width: '10px', height: '10px'}))

const isTableVisible = ref(false);
const isCompletionVisible = ref(false);
const isRestrictionVisible = ref(false);

const toggleTable = () => {
isTableVisible.value = !isTableVisible.value;
const toggleTable = (condition) => {
const otherCondition = condition == 'Completion' ? 'Restriction' : 'Completion';
const conditionRef = eval(`is${condition}Visible`);
conditionRef.value = !conditionRef.value;
const otherconditionRef = eval(`is${otherCondition}Visible`);
otherconditionRef.value = false;
};

</script>
Expand All @@ -61,15 +67,17 @@ const toggleTable = () => {
<div class="custom-node text-center rounded p-3"
:style="[nodeBackgroundColor, { height: '200px', width: '400px' }]">
<div class="mb-2"><b>{{ store.state.strings.node_coursefullname }}</b> {{ data.fullname }}</div>
<div class="mb-2"><b>{{ store.state.strings.node_courseshortname }}</b> {{ data.shortname }}</div>
<div v-if="data.manual">
<CompletionOutPutItem :completion="data" />
<div v-if="data.manualrestriction">
<RestrictionOutPutItem :data="data" />
</div>
<div v-if="data.manualcompletion">
<CompletionOutPutItem :data="data" />
</div>
<div v-if="data.completion.singlecompletionnode">
<button class="btn btn-link" @click="toggleTable" aria-expanded="false" aria-controls="collapseTable">
{{ isTableVisible ? 'Hide Completion Criteria' : 'Show Completion Criteria' }}
<button class="btn btn-link" @click="toggleTable('Completion')" aria-expanded="false" aria-controls="collapseTable">
{{ isCompletionVisible ? 'Hide Completion Criteria' : 'Show Completion Criteria' }}
</button>
<div v-show="isTableVisible" class="table-container">
<div v-show="isCompletionVisible" class="table-container">
<table class="table table-bordered table-hover fancy-table">
<thead class="thead-light">
<tr>
Expand All @@ -89,6 +97,30 @@ const toggleTable = () => {
</table>
</div>
</div>
<div v-if="data.completion.singlerestrictionnode">
<button class="btn btn-link" @click="toggleTable('Restriction')" aria-expanded="false" aria-controls="collapseTable">
{{ isRestrictionVisible ? 'Hide Restriction Criteria' : 'Show Restriction Criteria' }}
</button>
<div v-show="isRestrictionVisible" class="table-container">
<table class="table table-bordered table-hover fancy-table">
<thead class="thead-light">
<tr>
<th>Key</th>
<th>Checkmark</th>
</tr>
</thead>
<tbody>
<tr v-for="(value, key) in data.completion.singlerestrictionnode" :key="key">
<td>{{ key }}</td>
<td>
{{ value }}
<span v-if="value" class="text-success">&#10004;</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions vue3/components/restriction/RestrictionItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<script setup>
import { computed } from 'vue';
import manual from '../restriction/conditions/manual.vue'
import manual_output from '../restriction/conditions_output/manual_output.vue'
import timed from '../restriction/conditions/timed.vue'
const props = defineProps(['restriction']);
Expand All @@ -15,6 +16,8 @@ const dynamicComponent = computed(() => {
return manual;
case 'timed':
return timed;
case 'manual_output':
return manual_output;
default:
return null;
}
Expand Down
Loading

0 comments on commit 4a8f500

Please sign in to comment.