Skip to content

Commit

Permalink
New Function: UserPath view
Browse files Browse the repository at this point in the history
  • Loading branch information
WunderJacob committed Dec 15, 2023
1 parent 7e5feb3 commit 7c65e1f
Show file tree
Hide file tree
Showing 21 changed files with 808 additions and 86 deletions.
269 changes: 249 additions & 20 deletions amd/src/app-lazy.js

Large diffs are not rendered by default.

107 changes: 107 additions & 0 deletions classes/course_completion/conditions/manual.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Base class for a single booking option availability condition.
*
* All bo condition types must extend this class.
*
* @package local_adele
* @author Jacob Viertel
* @copyright 2023 Wunderbyte GmbH
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace local_adele\course_completion\conditions;

use local_adele\course_completion\course_completion;


defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot . '/local/adele/lib.php');

/**
* Class for a single learning path course condition.
*
* @package local_adele
* @author Jacob Viertel
* @copyright 2023 Wunderbyte GmbH
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class manual implements course_completion {

/** @var int $id Standard Conditions have hardcoded ids. */
public $id = COURSES_COND_MANUALLY;
/** @var string $type of the redered condition in frontend. */
public $type = 'manual';
/**
* Obtains a string describing this restriction (whether or not
* it actually applies). Used to obtain information that is displayed to
* students if the activity is not available to them, and for staff to see
* what conditions are.
*
* The $full parameter can be used to distinguish between 'staff' cases
* (when displaying all information about the activity) and 'student' cases
* (when displaying only conditions they don't meet).
*
* @return array availability and Information string (for admin) about all restrictions on
* this item
*/
public function get_description():array {
$description = $this->get_description_string();
$name = $this->get_name_string();
$label = $this->type;

return [
'id' => $this->id,
'name' => $name,
'description' => $description,
'label' => $label,
'type' => $this->type,
];
}

/**
* Helper function to return localized description strings.
*
* @return string
*/
private function get_description_string() {
$description = get_string('course_description_condition_manually', 'local_adele');
return $description;
}

/**
* Helper function to return localized description strings.
*
* @return string
*/
private function get_name_string() {
$description = get_string('course_name_condition_manually', 'local_adele');
return $description;
}

/**
* Helper function to return localized description strings.
*
* @return string
*/
private function get_label_string() {
$label = get_string('course_label_condition_manually', 'local_adele');
return $label;
}
}
106 changes: 106 additions & 0 deletions classes/external/get_lp_user_path_relation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* This class contains a list of webservice functions related to the adele Module by Wunderbyte.
*
* @package local_adele
* @author Jacob Viertel
* @copyright 2023 Wunderbyte GmbH
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

declare(strict_types=1);

namespace local_adele\external;

use context_system;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_value;
use core_external\external_single_structure;
use local_adele\learning_paths;
use moodle_exception;

defined('MOODLE_INTERNAL') || die();

require_once($CFG->libdir . '/externallib.php');

/**
* External Service for local adele.
*
* @package local_adele
* @author Jacob Viertel
* @copyright 2023 Wunderbyte GmbH
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class get_lp_user_path_relation extends external_api {

/**
* Describes the parameters for get_next_question webservice.
*
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters([
'learningpathid' => new external_value(PARAM_INT, 'userid', VALUE_REQUIRED),
'userid' => new external_value(PARAM_INT, 'userid', VALUE_REQUIRED),
'learninggoalid' => new external_value(PARAM_INT, 'learninggoalid', VALUE_REQUIRED),
'userpathid' => new external_value(PARAM_INT, 'userpathid', VALUE_REQUIRED),
]
);
}

/**
* Webservice for the local catquiz plugin to get next question.
*
* @param int $learningpathid
* @return array
*/
public static function execute($learningpathid, $userid, $learninggoalid, $userpathid): array {
$params = self::validate_parameters(self::execute_parameters(), [
'userid' => $userid,
'learninggoalid' => $learninggoalid,
'learningpathid' => $learningpathid,
'userpathid' => $userpathid,
]);

require_login();

$context = context_system::instance();
if (!has_capability('local/adele:canmanage', $context)) {
throw new moodle_exception('norighttoaccess', 'local_adele');
}
return learning_paths::get_learning_user_relation($params);
}

/**
* Returns description of method result value.
*
* @return external_single_structure
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'user_id' => new external_value(PARAM_INT, 'Item id'),
'username' => new external_value(PARAM_TEXT, 'Username'),
'firstname' => new external_value(PARAM_TEXT, 'Firstname'),
'lastname' => new external_value(PARAM_TEXT, 'Lastname'),
'email' => new external_value(PARAM_RAW, 'email'),
'json' => new external_value(PARAM_RAW, 'Flow Chart'),
]
);
}
}
10 changes: 5 additions & 5 deletions classes/external/get_lp_user_path_relations.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class get_lp_user_path_relations extends external_api {
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters([
'learningpathid' => new external_value(PARAM_INT, 'userid', VALUE_REQUIRED),
'userid' => new external_value(PARAM_INT, 'userid', VALUE_REQUIRED),
'learninggoalid' => new external_value(PARAM_INT, 'learninggoalid', VALUE_REQUIRED),
]
Expand All @@ -70,9 +69,8 @@ public static function execute_parameters(): external_function_parameters {
* @param int $learningpathid
* @return array
*/
public static function execute($learningpathid, $userid, $learninggoalid): array {
public static function execute($userid, $learninggoalid): array {
$params = self::validate_parameters(self::execute_parameters(), [
'learningpathid' => $learningpathid,
'userid' => $userid,
'learninggoalid' => $learninggoalid,
]);
Expand All @@ -96,8 +94,10 @@ public static function execute_returns(): external_multiple_structure {
return new external_multiple_structure(
new external_single_structure([
'id' => new external_value(PARAM_INT, 'Item id'),
'user_id' => new external_value(PARAM_TEXT, 'Historyid id'),
'json' => new external_value(PARAM_TEXT, 'Item name'),
'username' => new external_value(PARAM_TEXT, 'Username'),
'firstname' => new external_value(PARAM_TEXT, 'Firstname'),
'lastname' => new external_value(PARAM_TEXT, 'Lastname'),
'progress' => new external_value(PARAM_INT, 'Item name'),
]
)
);
Expand Down
8 changes: 4 additions & 4 deletions classes/external/observer_course_completed.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public static function observe($event) {
foreach ($learningpaths as $learningpath) {
$learningpath->json = json_decode($learningpath->json, true);
$userpath = $userpathrelation->get_user_path_relation($learningpath, $params->relateduserid);
if (!$userpath) {
if ($userpath) {
$userpath->json = json_decode($userpath->json, true);
foreach ($learningpath->json['tree']->nodes as $node) {
if ($node['course_node_id'] == $params->courseid) {
$learningpath->json['user_path_relaction'][$params->courseid] = true;
foreach ($learningpath->json['tree']['nodes'] as $node) {
if ($node['data']['course_node_id'] == $params->courseid) {
$learningpath->json['user_path_relaction'][$node['id']] = true;
// Revision old user path relation.
$data = [
'id' => $userpath->id,
Expand Down
20 changes: 9 additions & 11 deletions classes/external/observer_course_enrolled.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static function observe($event) {
$learningpath->json = json_decode($learningpath->json, true);
$userpath = self::buildsqlqueryuserpath($learningpath->id, $params->relateduserid);
if (!$userpath) {
$userpathrelation = self::getuserpathrelation($learningpath, $params->relateduserid, $DB);
$userpathrelation = self::getuserpathrelation($learningpath);
$DB->insert_record('local_adele_path_user', [
'user_id' => $params->relateduserid,
'learning_path_id' => $learningpath->id,
Expand All @@ -80,20 +80,18 @@ public static function observe($event) {
*/
public static function getuserpathrelation($learningpath) {
// Using named parameter :courseid in the SQL query.
$completioncriteria = false;
if (!$completioncriteria) {
foreach ($learningpath->json['tree']->nodes as $node) {
if ($node['completion'] && count($node['completion']['nodes'])) {
$test = $node['completion']['nodes'];
foreach ($node['completion']['nodes'] as $complitionnode) {
if ($complitionnode['type'] == 'feedback') {
self::loopcriteria();
}
$userpathrelation = [];
foreach ($learningpath->json['tree']['nodes'] as $node) {
if ($node['completion'] && count($node['completion']['nodes'])) {
foreach ($node['completion']['nodes'] as $complitionnode) {
if ($complitionnode['type'] == 'feedback') {
self::loopcriteria();
}
}
}
$userpathrelation[$node['id']] = false;
}
return 'tbd';
return $userpathrelation;
}

/**
Expand Down
Loading

0 comments on commit 7c65e1f

Please sign in to comment.