MDL-53700 competency: Migrating the competency API to core
authorFrederic Massart <fred@moodle.com>
Tue, 5 Apr 2016 04:45:37 +0000 (12:45 +0800)
committerFrederic Massart <fred@moodle.com>
Mon, 18 Apr 2016 03:05:59 +0000 (11:05 +0800)
51 files changed:
admin/tool/lp/classes/course_competencies_form_element.php
admin/tool/lp/classes/course_competency_rule_form_element.php
admin/tool/lp/classes/external.php
admin/tool/lp/classes/external/user_competency_summary_in_course_exporter.php
admin/tool/lp/classes/output/competency_summary.php
admin/tool/lp/classes/output/course_competencies_page.php
admin/tool/lp/classes/output/manage_competencies_page.php
admin/tool/lp/classes/output/manage_competency_frameworks_page.php
admin/tool/lp/classes/output/manage_templates_page.php
admin/tool/lp/classes/output/plan_page.php
admin/tool/lp/classes/output/plans_page.php
admin/tool/lp/classes/output/related_competencies.php
admin/tool/lp/classes/output/template_competencies_page.php
admin/tool/lp/classes/output/user_competency_course_navigation.php
admin/tool/lp/classes/output/user_competency_summary.php
admin/tool/lp/classes/output/user_competency_summary_in_course.php
admin/tool/lp/classes/output/user_competency_summary_in_plan.php
admin/tool/lp/classes/output/user_evidence_list_page.php
admin/tool/lp/classes/output/user_evidence_page.php
admin/tool/lp/competencies.php
admin/tool/lp/competencyframeworks.php
admin/tool/lp/coursecompetencies.php
admin/tool/lp/editcompetency.php
admin/tool/lp/editcompetencyframework.php
admin/tool/lp/editplan.php
admin/tool/lp/edittemplate.php
admin/tool/lp/learningplans.php
admin/tool/lp/lib.php
admin/tool/lp/plan.php
admin/tool/lp/plans.php
admin/tool/lp/settings.php
admin/tool/lp/template_cohorts.php
admin/tool/lp/template_plans.php
admin/tool/lp/templatecompetencies.php
admin/tool/lp/tests/api_test.php
admin/tool/lp/tests/course_competency_settings_test.php
admin/tool/lp/tests/event_test.php
admin/tool/lp/tests/externallib_test.php
admin/tool/lp/tests/plan_persistent_test.php
admin/tool/lp/tests/plan_test.php
admin/tool/lp/tests/task_test.php
admin/tool/lp/user_competency.php
admin/tool/lp/user_competency_in_course.php
admin/tool/lp/user_competency_in_plan.php
admin/tool/lp/user_evidence.php
admin/tool/lp/user_evidence_edit.php
admin/tool/lp/user_evidence_list.php
competency/classes/api.php [moved from admin/tool/lp/classes/api.php with 99% similarity]
competency/classes/external/competency_framework_exporter.php
lib/classes/task/complete_plans_task.php
lib/classes/task/sync_plans_from_template_cohorts_task.php

index b61f201..035d2cd 100644 (file)
@@ -27,7 +27,7 @@ defined('MOODLE_INTERNAL') || die();
 
 global $CFG;
 
-use tool_lp\api;
+use core_competency\api;
 use core_competency\external\competency_exporter;
 require_once($CFG->libdir . '/form/autocomplete.php');
 
@@ -62,7 +62,7 @@ class tool_lp_course_competencies_form_element extends MoodleQuickForm_autocompl
         $courseid = $options['courseid'];
 
         if (!empty($options['cmid'])) {
-            $current = \tool_lp\api::list_course_module_competencies_in_course_module($options['cmid']);
+            $current = \core_competency\api::list_course_module_competencies_in_course_module($options['cmid']);
             $ids = array();
             foreach ($current as $coursemodulecompetency) {
                 array_push($ids, $coursemodulecompetency->get_competencyid());
index 724a715..29fc72f 100644 (file)
@@ -27,7 +27,7 @@ defined('MOODLE_INTERNAL') || die();
 
 global $CFG;
 
-use tool_lp\api;
+use core_competency\api;
 use core_competency\external\competency_exporter;
 use core_competency\course_module_competency;
 
@@ -59,7 +59,7 @@ class tool_lp_course_competency_rule_form_element extends MoodleQuickForm_select
         if (!empty($options['cmid'])) {
             $cmid = $options['cmid'];
 
-            $current = \tool_lp\api::list_course_module_competencies_in_course_module($cmid);
+            $current = \core_competency\api::list_course_module_competencies_in_course_module($cmid);
 
             // Note: We just pick the outcome set on the first course_module_competency - because in our UI are are
             // forcing them to be all the same for each activity.
index 56269d1..4b2ae2e 100644 (file)
@@ -42,6 +42,7 @@ use external_multiple_structure;
 use invalid_parameter_exception;
 use required_capability_exception;
 use grade_scale;
+use core_competency\api;
 use core_competency\competency;
 use core_competency\competency_framework;
 use core_competency\course_competency;
index 25a6d06..0548002 100644 (file)
@@ -28,7 +28,7 @@ use renderable;
 use templatable;
 use renderer_base;
 use stdClass;
-use tool_lp\api;
+use core_competency\api;
 use tool_lp\external\competency_summary_exporter;
 
 /**
index 27e94f2..45c5cbf 100644 (file)
@@ -31,7 +31,7 @@ use stdClass;
 use moodle_url;
 use context_system;
 use context_course;
-use tool_lp\api;
+use core_competency\api;
 use tool_lp\course_competency_statistics;
 use core_competency\competency;
 use core_competency\course_competency;
index fd6d9a2..28cf66e 100644 (file)
@@ -31,7 +31,7 @@ use single_button;
 use stdClass;
 use moodle_url;
 use context_system;
-use tool_lp\api;
+use core_competency\api;
 use core_competency\competency;
 use core_competency\competency_framework;
 use core_competency\external\competency_framework_exporter;
index 11213c5..3864cbf 100644 (file)
@@ -32,7 +32,7 @@ use stdClass;
 use moodle_url;
 use context;
 use context_system;
-use tool_lp\api;
+use core_competency\api;
 use core_competency\competency_framework;
 use core_competency\external\competency_framework_exporter;
 
index 400145d..36130ff 100644 (file)
@@ -32,7 +32,7 @@ use single_button;
 use stdClass;
 use moodle_url;
 use context_system;
-use tool_lp\api;
+use core_competency\api;
 use core_competency\template;
 use core_competency\external\template_exporter;
 
index 031cc98..e156a97 100644 (file)
@@ -28,7 +28,7 @@ use renderable;
 use templatable;
 use stdClass;
 use moodle_url;
-use tool_lp\api;
+use core_competency\api;
 use core_competency\plan;
 use core_competency\external\competency_exporter;
 use core_competency\external\plan_exporter;
index f94e13a..c0ac23f 100644 (file)
@@ -30,7 +30,7 @@ use renderer_base;
 use stdClass;
 use single_button;
 use moodle_url;
-use tool_lp\api;
+use core_competency\api;
 use core_competency\external\plan_exporter;
 use core_competency\plan;
 use core_competency\user_evidence;
index 436e9e9..cd753fc 100644 (file)
@@ -29,7 +29,7 @@ use templatable;
 use renderer_base;
 use stdClass;
 use moodle_url;
-use tool_lp\api;
+use core_competency\api;
 use core_competency\external\competency_exporter;
 
 /**
index 96e23ca..e51b13d 100644 (file)
@@ -33,7 +33,7 @@ use context_system;
 use moodle_url;
 use core_competency\external\template_exporter;
 use core_competency\template;
-use tool_lp\api;
+use core_competency\api;
 use tool_lp\external\competency_summary_exporter;
 use tool_lp\external\template_statistics_exporter;
 use tool_lp\template_statistics;
index 954ed5e..ef40ba4 100644 (file)
@@ -115,7 +115,7 @@ class user_competency_course_navigation implements renderable, templatable {
             $data->hasusers = false;
         }
 
-        $coursecompetencies = \tool_lp\api::list_course_competencies($this->courseid);
+        $coursecompetencies = \core_competency\api::list_course_competencies($this->courseid);
         $data->competencies = array();
         $contextcache = array();
         foreach ($coursecompetencies as $coursecompetency) {
index a0a9244..a4c56ed 100644 (file)
@@ -28,7 +28,7 @@ use core_user;
 use renderer_base;
 use renderable;
 use templatable;
-use tool_lp\api;
+use core_competency\api;
 use core_competency\user_competency;
 use tool_lp\external\user_competency_summary_exporter;
 
index a0e82b8..2abc6f9 100644 (file)
@@ -26,7 +26,7 @@ namespace tool_lp\output;
 use renderable;
 use renderer_base;
 use templatable;
-use tool_lp\api;
+use core_competency\api;
 use core_competency\user_competency;
 use tool_lp\external\user_competency_summary_in_course_exporter;
 
index e4f5479..e650aa1 100644 (file)
@@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die();
 
 use renderable;
 use templatable;
-use tool_lp\api;
+use core_competency\api;
 use tool_lp\external\user_competency_summary_in_plan_exporter;
 
 /**
index 8ccdaec..9ea1db8 100644 (file)
@@ -29,7 +29,7 @@ use renderer_base;
 use stdClass;
 use single_button;
 use moodle_url;
-use tool_lp\api;
+use core_competency\api;
 use tool_lp\external\user_evidence_summary_exporter;
 use core_competency\user_evidence;
 use context_user;
index 1ba5347..96f7165 100644 (file)
@@ -27,7 +27,7 @@ use moodle_url;
 use renderable;
 use templatable;
 use stdClass;
-use tool_lp\api;
+use core_competency\api;
 use tool_lp\external\user_evidence_summary_exporter;
 
 /**
index ebc9d95..1e4e552 100644 (file)
@@ -30,10 +30,10 @@ $pagecontextid = required_param('pagecontextid', PARAM_INT);  // Reference to th
 $search = optional_param('search', '', PARAM_RAW);
 
 require_login();
-\tool_lp\api::require_enabled();
+\core_competency\api::require_enabled();
 
 $pagecontext = context::instance_by_id($pagecontextid);
-$framework = \tool_lp\api::read_framework($id);
+$framework = \core_competency\api::read_framework($id);
 $context = $framework->get_context();
 
 if (!\core_competency\competency_framework::can_read_context($context)) {
@@ -62,6 +62,6 @@ $page = new \tool_lp\output\manage_competencies_page($framework, $search, $pagec
 echo $output->render($page);
 
 // Log the framework viewed event after rendering the page.
-\tool_lp\api::competency_framework_viewed($framework);
+\core_competency\api::competency_framework_viewed($framework);
 
 echo $output->footer();
index 9a9a0a4..13edbb3 100644 (file)
@@ -32,7 +32,7 @@ $url = new moodle_url("/admin/tool/lp/competencyframeworks.php");
 $url->param('pagecontextid', $pagecontextid);
 
 require_login();
-\tool_lp\api::require_enabled();
+\core_competency\api::require_enabled();
 
 if (!\core_competency\competency_framework::can_read_context($context)) {
     throw new required_capability_exception($context, 'moodle/competency:competencyview', 'nopermissions', '');
index 2073536..4beab69 100644 (file)
@@ -30,7 +30,7 @@ $params = array('id' => $id);
 $course = $DB->get_record('course', $params, '*', MUST_EXIST);
 
 require_login($course);
-\tool_lp\api::require_enabled();
+\core_competency\api::require_enabled();
 
 $context = context_course::instance($course->id);
 $urlparams = array('courseid' => $id);
index 24c0593..0cde794 100644 (file)
@@ -31,7 +31,7 @@ $pagecontextid = required_param('pagecontextid', PARAM_INT);  // Reference to th
 $parentid = optional_param('parentid', 0, PARAM_INT);
 
 require_login();
-\tool_lp\api::require_enabled();
+\core_competency\api::require_enabled();
 
 if (empty($competencyframeworkid) && empty($id)) {
     throw new coding_exception('Competencyframeworkid param is required');
@@ -40,13 +40,13 @@ if (empty($competencyframeworkid) && empty($id)) {
 // Get competency framework.
 $competencyframework = null;
 if (!empty($competencyframeworkid)) {
-    $competencyframework = \tool_lp\api::read_framework($competencyframeworkid);
+    $competencyframework = \core_competency\api::read_framework($competencyframeworkid);
 }
 
 // Get competency.
 $competency = null;
 if (!empty($id)) {
-    $competency = \tool_lp\api::read_competency($id);
+    $competency = \core_competency\api::read_competency($id);
     if (empty($competencyframework)) {
         $competencyframework = $competency->get_framework();
     }
@@ -57,7 +57,7 @@ $parent = null;
 if ($competency) {
     $parent = $competency->get_parent();
 } else if ($parentid) {
-    $parent = \tool_lp\api::read_competency($parentid);
+    $parent = \core_competency\api::read_competency($parentid);
 }
 
 // Get page URL.
@@ -90,10 +90,10 @@ if ($form->is_cancelled()) {
 $data = $form->get_data();
 if ($data) {
     if (empty($competency)) {
-        \tool_lp\api::create_competency($data);
+        \core_competency\api::create_competency($data);
         $returnmsg = get_string('competencycreated', 'tool_lp');
     } else {
-        \tool_lp\api::update_competency($data);
+        \core_competency\api::update_competency($data);
         $returnmsg = get_string('competencyupdated', 'tool_lp');
     }
     redirect($returnurl, $returnmsg, null, \core\output\notification::NOTIFY_SUCCESS);
index 7d4d38e..5ae6cd8 100644 (file)
@@ -40,7 +40,7 @@ if (!empty($id)) {
 
 // We check that we have the permission to edit this framework, in its own context.
 require_login();
-\tool_lp\api::require_enabled();
+\core_competency\api::require_enabled();
 require_capability('moodle/competency:competencymanage', $context);
 
 // Set up the framework page.
@@ -55,7 +55,7 @@ if ($form->is_cancelled()) {
     if (empty($data->id)) {
         // Create new framework.
         $data->contextid = $context->id;
-        $framework = \tool_lp\api::create_framework($data);
+        $framework = \core_competency\api::create_framework($data);
         $frameworkmanageurl = new moodle_url('/admin/tool/lp/competencies.php', array(
             'pagecontextid' => $pagecontextid,
             'competencyframeworkid' => $framework->get_id()
@@ -63,7 +63,7 @@ if ($form->is_cancelled()) {
         $messagesuccess = get_string('competencyframeworkcreated', 'tool_lp');
         redirect($frameworkmanageurl, $messagesuccess, 0, \core\output\notification::NOTIFY_SUCCESS);
     } else {
-        \tool_lp\api::update_framework($data);
+        \core_competency\api::update_framework($data);
         $messagesuccess = get_string('competencyframeworkupdated', 'tool_lp');
         redirect($frameworksurl, $messagesuccess, 0, \core\output\notification::NOTIFY_SUCCESS);
     }
index d77d146..7f8faa9 100644 (file)
@@ -30,7 +30,7 @@ $id = optional_param('id', false, PARAM_INT);
 $returntype = optional_param('return', null, PARAM_ALPHA);
 
 require_login(0, false);
-\tool_lp\api::require_enabled();
+\core_competency\api::require_enabled();
 
 $url = new moodle_url('/admin/tool/lp/editplan.php', array('id' => $id, 'userid' => $userid, 'return' => $returntype));
 
@@ -39,7 +39,7 @@ if (empty($id)) {
     $pagetitle = get_string('addnewplan', 'tool_lp');
     list($title, $subtitle, $returnurl) = \tool_lp\page_helper::setup_for_plan($userid, $url, null, $pagetitle, $returntype);
 } else {
-    $plan = \tool_lp\api::read_plan($id);
+    $plan = \core_competency\api::read_plan($id);
 
     // The userid parameter must be the same as the owner of the plan.
     if ($userid != $plan->get_userid()) {
@@ -80,11 +80,11 @@ $data = $form->get_data();
 
 if ($data) {
     if (empty($data->id)) {
-        $plan = \tool_lp\api::create_plan($data);
+        $plan = \core_competency\api::create_plan($data);
         $returnurl = new moodle_url('/admin/tool/lp/plan.php', ['id' => $plan->get_id()]);
         $returnmsg = get_string('plancreated', 'tool_lp');
     } else {
-        \tool_lp\api::update_plan($data);
+        \core_competency\api::update_plan($data);
         $returnmsg = get_string('planupdated', 'tool_lp');
     }
     redirect($returnurl, $returnmsg, null, \core\output\notification::NOTIFY_SUCCESS);
index f5eaaba..d596f30 100644 (file)
@@ -40,7 +40,7 @@ if (!empty($id)) {
 
 // We check that we have the permission to edit this framework, in its own context.
 require_login(0, false);
-\tool_lp\api::require_enabled();
+\core_competency\api::require_enabled();
 require_capability('moodle/competency:templatemanage', $context);
 
 // We keep the original context in the URLs, so that we remain in the same context.
@@ -55,7 +55,7 @@ if (empty($id)) {
     list($title, $subtitle, $returnurl) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, null, $pagetitle,
         $returntype);
 } else {
-    $template = \tool_lp\api::read_template($id);
+    $template = \core_competency\api::read_template($id);
     $pagetitle = get_string('edittemplate', 'tool_lp');
     list($title, $subtitle, $returnurl) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, $template,
         $pagetitle, $returntype);
@@ -69,14 +69,14 @@ if ($form->is_cancelled()) {
 $data = $form->get_data();
 if ($data) {
     if (empty($data->id)) {
-        $template = \tool_lp\api::create_template($data);
+        $template = \core_competency\api::create_template($data);
         $returnurl = new moodle_url('/admin/tool/lp/templatecompetencies.php', [
             'templateid' => $template->get_id(),
             'pagecontextid' => $pagecontextid
         ]);
         $returnmsg = get_string('templatecreated', 'tool_lp');
     } else {
-        \tool_lp\api::update_template($data);
+        \core_competency\api::update_template($data);
         $returnmsg = get_string('templateupdated', 'tool_lp');
     }
     redirect($returnurl, $returnmsg, null, \core\output\notification::NOTIFY_SUCCESS);
index bdacec4..cc16639 100644 (file)
@@ -29,7 +29,7 @@ $pagecontextid = required_param('pagecontextid', PARAM_INT);
 $context = context::instance_by_id($pagecontextid);
 
 require_login(0, false);
-\tool_lp\api::require_enabled();
+\core_competency\api::require_enabled();
 if (!\core_competency\template::can_read_context($context)) {
     throw new required_capability_exception($context, 'moodle/competency:templateview', 'nopermissions', '');
 }
index ecacd04..3542e17 100644 (file)
@@ -33,7 +33,7 @@ require_once($CFG->libdir . '/externallib.php');
  * @param context $coursecontext The context of the course
  */
 function tool_lp_extend_navigation_course($navigation, $course, $coursecontext) {
-    if (!\tool_lp\api::is_enabled()) {
+    if (!\core_competency\api::is_enabled()) {
         return;
     }
 
@@ -62,7 +62,7 @@ function tool_lp_extend_navigation_course($navigation, $course, $coursecontext)
  * @param context_course $coursecontext The context of the course
  */
 function tool_lp_extend_navigation_user($navigation, $user, $usercontext, $course, $coursecontext) {
-    if (!\tool_lp\api::is_enabled()) {
+    if (!\core_competency\api::is_enabled()) {
         return;
     }
 
@@ -89,7 +89,7 @@ function tool_lp_extend_navigation_user($navigation, $user, $usercontext, $cours
  * @return bool
  */
 function tool_lp_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course) {
-    if (!\tool_lp\api::is_enabled()) {
+    if (!\core_competency\api::is_enabled()) {
         return false;
     } else if (!\core_competency\plan::can_read_user($user->id)) {
         return false;
@@ -110,7 +110,7 @@ function tool_lp_myprofile_navigation(core_user\output\myprofile\tree $tree, $us
  * @param context $coursecategorycontext The context of the course category
  */
 function tool_lp_extend_navigation_category_settings($navigation, $coursecategorycontext) {
-    if (!\tool_lp\api::is_enabled()) {
+    if (!\core_competency\api::is_enabled()) {
         return false;
     }
 
@@ -168,7 +168,7 @@ function tool_lp_extend_navigation_category_settings($navigation, $coursecategor
 function tool_lp_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
     global $CFG;
 
-    if (!\tool_lp\api::is_enabled()) {
+    if (!\core_competency\api::is_enabled()) {
         return false;
     }
 
@@ -202,7 +202,7 @@ function tool_lp_pluginfile($course, $cm, $context, $filearea, $args, $forcedown
 function tool_lp_comment_add($comment, $params) {
     global $USER;
 
-    if (!\tool_lp\api::is_enabled()) {
+    if (!\core_competency\api::is_enabled()) {
         return;
     }
 
@@ -383,7 +383,7 @@ function tool_lp_comment_add($comment, $params) {
  * @return array
  */
 function tool_lp_comment_permissions($params) {
-    if (!\tool_lp\api::is_enabled()) {
+    if (!\core_competency\api::is_enabled()) {
         return array('post' => false, 'view' => false);
     }
 
@@ -409,7 +409,7 @@ function tool_lp_comment_permissions($params) {
  * @return bool
  */
 function tool_lp_comment_validate($params) {
-    if (!\tool_lp\api::is_enabled()) {
+    if (!\core_competency\api::is_enabled()) {
         return false;
     }
 
@@ -436,7 +436,7 @@ function tool_lp_comment_validate($params) {
 function tool_lp_coursemodule_standard_elements($formwrapper, $mform) {
     global $CFG, $COURSE;
 
-    if (!\tool_lp\api::is_enabled()) {
+    if (!\core_competency\api::is_enabled()) {
         return;
     } else if (!has_capability('moodle/competency:coursecompetencymanage', $formwrapper->get_context())) {
         return;
@@ -471,7 +471,7 @@ function tool_lp_coursemodule_standard_elements($formwrapper, $mform) {
  * @param stdClass $course The course.
  */
 function tool_lp_coursemodule_edit_post_actions($data, $course) {
-    if (!\tool_lp\api::is_enabled()) {
+    if (!\core_competency\api::is_enabled()) {
         return $data;
     }
 
@@ -495,17 +495,17 @@ function tool_lp_coursemodule_edit_post_actions($data, $course) {
     $added = array_diff($newids, $existingids);
 
     foreach ($removed as $removedid) {
-        \tool_lp\api::remove_competency_from_course_module($data->coursemodule, $removedid);
+        \core_competency\api::remove_competency_from_course_module($data->coursemodule, $removedid);
     }
     foreach ($added as $addedid) {
-        \tool_lp\api::add_competency_to_course_module($data->coursemodule, $addedid);
+        \core_competency\api::add_competency_to_course_module($data->coursemodule, $addedid);
     }
 
     if (isset($data->competency_rule)) {
         // Now update the rules for each course_module_competency.
-        $current = \tool_lp\api::list_course_module_competencies_in_course_module($data->coursemodule);
+        $current = \core_competency\api::list_course_module_competencies_in_course_module($data->coursemodule);
         foreach ($current as $coursemodulecompetency) {
-            \tool_lp\api::set_course_module_competency_ruleoutcome($coursemodulecompetency, $data->competency_rule);
+            \core_competency\api::set_course_module_competency_ruleoutcome($coursemodulecompetency, $data->competency_rule);
         }
     }
 
@@ -519,5 +519,5 @@ function tool_lp_coursemodule_edit_post_actions($data, $course) {
  * @return bool
  */
 function tool_lp_scale_used_anywhere($scaleid) {
-    return \tool_lp\api::is_scale_used_anywhere($scaleid);
+    return \core_competency\api::is_scale_used_anywhere($scaleid);
 }
index 0b2baaa..fded203 100644 (file)
@@ -30,9 +30,9 @@ require_login(null, false);
 if (isguestuser()) {
     throw new require_login_exception('Guests are not allowed here.');
 }
-\tool_lp\api::require_enabled();
+\core_competency\api::require_enabled();
 
-$plan = \tool_lp\api::read_plan($id);
+$plan = \core_competency\api::read_plan($id);
 $url = new moodle_url('/admin/tool/lp/plan.php', array('id' => $id));
 
 list($title, $subtitle) = \tool_lp\page_helper::setup_for_plan($plan->get_userid(), $url, $plan);
@@ -44,6 +44,6 @@ $page = new \tool_lp\output\plan_page($plan);
 echo $output->render($page);
 
 // Trigger viewed event.
-\tool_lp\api::plan_viewed($plan);
+\core_competency\api::plan_viewed($plan);
 
 echo $output->footer();
index fedeef5..7ac1418 100644 (file)
@@ -28,7 +28,7 @@ require_login(null, false);
 if (isguestuser()) {
     throw new require_login_exception('Guests are not allowed here.');
 }
-\tool_lp\api::require_enabled();
+\core_competency\api::require_enabled();
 
 $userid = optional_param('userid', $USER->id, PARAM_INT);
 
index 00dcf38..09a7fb8 100644 (file)
@@ -30,7 +30,7 @@ $category = new admin_category($parentname, get_string('competencies', 'tool_lp'
 $ADMIN->add('root', $category, 'badges');
 
 // If the plugin is enabled we add the pages.
-if (\tool_lp\api::is_enabled()) {
+if (\core_competency\api::is_enabled()) {
 
     // Manage competency frameworks page.
     $temp = new admin_externalpage(
index 424be32..b92dcd0 100644 (file)
@@ -28,9 +28,9 @@ $id = required_param('id', PARAM_INT);
 $pagecontextid = required_param('pagecontextid', PARAM_INT);  // Reference to the context we came from.
 
 require_login(0, false);
-\tool_lp\api::require_enabled();
+\core_competency\api::require_enabled();
 
-$template = \tool_lp\api::read_template($id);
+$template = \core_competency\api::read_template($id);
 $context = $template->get_context();
 $canreadtemplate = $template->can_read();
 $canmanagetemplate = $template->can_manage();
@@ -50,7 +50,7 @@ list($title, $subtitle) = \tool_lp\page_helper::setup_for_template($pagecontexti
 
 // Remove cohort.
 if ($canmanagetemplate && ($removecohort = optional_param('removecohort', false, PARAM_INT)) !== false && confirm_sesskey()) {
-    \tool_lp\api::delete_template_cohort($template, $removecohort);
+    \core_competency\api::delete_template_cohort($template, $removecohort);
 }
 
 // Capture the form submission.
@@ -62,7 +62,7 @@ if ($canmanagetemplate && ($data = $form->get_data()) && !empty($data->cohorts))
     foreach ($data->cohorts as $cohortid) {
 
         // Create the template/cohort relationship.
-        $relation = \tool_lp\api::create_template_cohort($template, $cohortid);
+        $relation = \core_competency\api::create_template_cohort($template, $cohortid);
 
         // Create a plan for each member if template visible, and the due date is not reached, and we didn't reach our limit yet.
         if ($template->get_visible() && $i < $maxtocreate && !$duedatereached) {
@@ -70,7 +70,7 @@ if ($canmanagetemplate && ($data = $form->get_data()) && !empty($data->cohorts))
             // Only create a few plans right now.
             $tocreate = \core_competency\template_cohort::get_missing_plans($template->get_id(), $cohortid);
             if ($i + count($tocreate) <= $maxtocreate) {
-                $i += \tool_lp\api::create_plans_from_template_cohort($template, $cohortid);
+                $i += \core_competency\api::create_plans_from_template_cohort($template, $cohortid);
             } else {
                 $maxreached = true;
             }
index 4c11837..87374cb 100644 (file)
@@ -28,9 +28,9 @@ $id = required_param('id', PARAM_INT);
 $pagecontextid = required_param('pagecontextid', PARAM_INT);  // Reference to the context we came from.
 
 require_login(0, false);
-\tool_lp\api::require_enabled();
+\core_competency\api::require_enabled();
 
-$template = \tool_lp\api::read_template($id);
+$template = \core_competency\api::read_template($id);
 $context = $template->get_context();
 $canreadtemplate = $template->can_read();
 $canmanagetemplate = $template->can_manage();
@@ -51,7 +51,7 @@ $form = new \tool_lp\form\template_plans($url->out(false));
 if ($canmanagetemplate && ($data = $form->get_data()) && !empty($data->users)) {
     $i = 0;
     foreach ($data->users as $userid) {
-        $result = \tool_lp\api::create_plan_from_template($template->get_id(), $userid);
+        $result = \core_competency\api::create_plan_from_template($template->get_id(), $userid);
         if ($result) {
             $i++;
         }
index 64225e4..a18f216 100644 (file)
@@ -29,17 +29,17 @@ $templateid = required_param('templateid', PARAM_INT);
 $pagecontextid = required_param('pagecontextid', PARAM_INT);  // Reference to the context we came from.
 
 require_login(0, false);
-\tool_lp\api::require_enabled();
+\core_competency\api::require_enabled();
 
 $pagecontext = context::instance_by_id($pagecontextid);
-$template = \tool_lp\api::read_template($templateid);
+$template = \core_competency\api::read_template($templateid);
 $context = $template->get_context();
 if (!$template->can_read()) {
     throw new required_capability_exception($context, 'moodle/competency:templateview', 'nopermissions', '');
 }
 
 // Trigger a template viewed event.
-\tool_lp\api::template_viewed($template);
+\core_competency\api::template_viewed($template);
 
 // Set up the page.
 $url = new moodle_url('/admin/tool/lp/templatecompetencies.php', array('templateid' => $template->get_id(),
index b6bc8e9..dcf6fb9 100644 (file)
@@ -25,7 +25,7 @@
 defined('MOODLE_INTERNAL') || die();
 global $CFG;
 
-use tool_lp\api;
+use core_competency\api;
 use core_competency\competency;
 use core_competency\competency_framework;
 use core_competency\course_competency_settings;
index bea1f33..4b8a371 100644 (file)
@@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die();
 global $CFG;
 
 use core_competency\course_competency;
-use tool_lp\api;
+use core_competency\api;
 use core_competency\course_competency_settings;
 
 /**
index bf8334e..435b923 100644 (file)
@@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die();
 global $CFG;
 require_once($CFG->dirroot . '/comment/lib.php');
 
-use tool_lp\api;
+use core_competency\api;
 
 /**
  * Event tests.
index 825e871..3f7c671 100644 (file)
@@ -27,7 +27,7 @@ global $CFG;
 
 require_once($CFG->dirroot . '/webservice/tests/helpers.php');
 
-use tool_lp\api;
+use core_competency\api;
 use tool_lp\external;
 use core_competency\invalid_persistent_exception;
 use core_competency\plan;
index 02f6eeb..859ec11 100644 (file)
@@ -25,7 +25,7 @@
 defined('MOODLE_INTERNAL') || die();
 global $CFG;
 
-use tool_lp\api;
+use core_competency\api;
 use core_competency\plan;
 
 /**
index cb96ff6..d51101d 100644 (file)
@@ -373,7 +373,7 @@ class tool_lp_plan_testcase extends advanced_testcase {
         $record->duedate = time() - 200;
         $DB->update_record(core_competency\plan::TABLE, $record);
 
-        $success = tool_lp\api::complete_plan($plan->get_id());
+        $success = core_competency\api::complete_plan($plan->get_id());
         $this->assertTrue($success);
 
         // Completing plan: with due date too soon (pass).
@@ -382,7 +382,7 @@ class tool_lp_plan_testcase extends advanced_testcase {
         $record->duedate = time() + 200;
         $DB->update_record(core_competency\plan::TABLE, $record);
 
-        $success = tool_lp\api::complete_plan($plan->get_id());
+        $success = core_competency\api::complete_plan($plan->get_id());
         $this->assertTrue($success);
 
         // Completing plan: with due date in the future (pass).
@@ -391,7 +391,7 @@ class tool_lp_plan_testcase extends advanced_testcase {
         $record->duedate = time() + core_competency\plan::DUEDATE_THRESHOLD + 10;
         $DB->update_record(core_competency\plan::TABLE, $record);
 
-        $success = tool_lp\api::complete_plan($plan->get_id());
+        $success = core_competency\api::complete_plan($plan->get_id());
         $this->assertTrue($success);
 
         // Completing plan: with due date unset (pass).
@@ -400,7 +400,7 @@ class tool_lp_plan_testcase extends advanced_testcase {
         $record->duedate = 0;
         $DB->update_record(core_competency\plan::TABLE, $record);
 
-        $success = tool_lp\api::complete_plan($plan->get_id());
+        $success = core_competency\api::complete_plan($plan->get_id());
         $this->assertTrue($success);
 
         // Reopening plan: with due date in the past => duedate unset.
@@ -409,7 +409,7 @@ class tool_lp_plan_testcase extends advanced_testcase {
         $record->duedate = time() - 200;
         $DB->update_record(core_competency\plan::TABLE, $record);
 
-        $success = tool_lp\api::reopen_plan($plan->get_id());
+        $success = core_competency\api::reopen_plan($plan->get_id());
         $this->assertTrue($success);
         $plan->read();
         $this->assertEquals(0, $plan->get_duedate());
@@ -420,7 +420,7 @@ class tool_lp_plan_testcase extends advanced_testcase {
         $record->duedate = time() + 100;
         $DB->update_record(core_competency\plan::TABLE, $record);
 
-        $success = tool_lp\api::reopen_plan($plan->get_id());
+        $success = core_competency\api::reopen_plan($plan->get_id());
         $this->assertTrue($success);
         $plan->read();
         $this->assertEquals(0, $plan->get_duedate());
@@ -431,7 +431,7 @@ class tool_lp_plan_testcase extends advanced_testcase {
         $record->duedate = time() + core_competency\plan::DUEDATE_THRESHOLD + 10;
         $DB->update_record(core_competency\plan::TABLE, $record);
 
-        $success = tool_lp\api::reopen_plan($plan->get_id());
+        $success = core_competency\api::reopen_plan($plan->get_id());
         $this->assertTrue($success);
         $plan->read();
 
index 15e3de9..9377d1a 100644 (file)
@@ -24,7 +24,7 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-use tool_lp\api;
+use core_competency\api;
 use core_competency\plan;
 
 /**
@@ -122,7 +122,7 @@ class tool_lp_task_testcase extends advanced_testcase {
         // Let's unlink the plan and run the task again, it should not be recreated.
         $currenttime = $currenttime + 1;
         $plan = plan::get_record(array('userid' => $user5->id, 'templateid' => $tpl->get_id()));
-        \tool_lp\api::unlink_plan_from_template($plan);
+        \core_competency\api::unlink_plan_from_template($plan);
         $DB->execute($plansql, array('currenttime' => $currenttime, 'planid' => $plan->get_id()));
         $this->assertTrue(plan::record_exists_select('userid = ?', array($user5->id)));
         $this->assertFalse(plan::record_exists_select('userid = ? AND templateid = ?', array($user5->id, $tpl->get_id())));
@@ -149,7 +149,7 @@ class tool_lp_task_testcase extends advanced_testcase {
         // Test a user plan deleted will not be recreated.
         $currenttime = $currenttime + 1;
         $plan = plan::get_record(array('userid' => $user4->id, 'templateid' => $tpl->get_id()));
-        \tool_lp\api::delete_plan($plan->get_id());
+        \core_competency\api::delete_plan($plan->get_id());
         $currenttime = $currenttime + 1;
         $task->execute();
         $task->set_last_run_time($currenttime);
@@ -218,7 +218,7 @@ class tool_lp_task_testcase extends advanced_testcase {
 
         // Let's unlink the plan and run the task again, it should not be recreated.
         $plan = plan::get_record(array('userid' => $user5->id, 'templateid' => $tpl->get_id()));
-        \tool_lp\api::unlink_plan_from_template($plan);
+        \core_competency\api::unlink_plan_from_template($plan);
         $this->assertTrue(plan::record_exists_select('userid = ?', array($user5->id)));
         $this->assertFalse(plan::record_exists_select('userid = ? AND templateid = ?', array($user5->id, $tpl->get_id())));
         $this->assertEquals(4, plan::count_records(array('templateid' => $tpl->get_id())));
index 890422d..51933c1 100644 (file)
@@ -30,9 +30,9 @@ require_login(null, false);
 if (isguestuser()) {
     throw new require_login_exception('Guests are not allowed here.');
 }
-\tool_lp\api::require_enabled();
+\core_competency\api::require_enabled();
 
-$uc = \tool_lp\api::get_user_competency_by_id($id);
+$uc = \core_competency\api::get_user_competency_by_id($id);
 $params = array('id' => $id);
 $url = new moodle_url('/admin/tool/lp/user_competency.php', $params);
 
@@ -63,6 +63,6 @@ echo $output->header();
 $page = new \tool_lp\output\user_competency_summary($uc);
 echo $output->render($page);
 // Trigger viewed event.
-\tool_lp\api::user_competency_viewed($uc);
+\core_competency\api::user_competency_viewed($uc);
 
 echo $output->footer();
index ba2f079..9a478f9 100644 (file)
@@ -32,7 +32,7 @@ require_login(null, false);
 if (isguestuser()) {
     throw new require_login_exception('Guests are not allowed here.');
 }
-\tool_lp\api::require_enabled();
+\core_competency\api::require_enabled();
 
 $course = $DB->get_record('course', array('id' => $courseid));
 $context = context_course::instance($courseid);
@@ -64,7 +64,7 @@ $competency = new \core_competency\competency($competencyid);
 
 // Does a permissions check for us.
 if ($userid > 0) {
-    $usercompetencycourses = \tool_lp\api::list_user_competencies_in_course($courseid, $userid);
+    $usercompetencycourses = \core_competency\api::list_user_competencies_in_course($courseid, $userid);
 }
 $subtitle = $competency->get_shortname() . ' <em>' . $competency->get_idnumber() . '</em>';
 
@@ -91,8 +91,8 @@ if ($userid > 0) {
     echo $output->render($page);
 
     // Trigger the viewed event.
-    $uc = \tool_lp\api::get_user_competency_in_course($courseid, $userid, $competencyid);
-    \tool_lp\api::user_competency_viewed_in_course($uc, $courseid);
+    $uc = \core_competency\api::get_user_competency_in_course($courseid, $userid, $competencyid);
+    \core_competency\api::user_competency_viewed_in_course($uc, $courseid);
 } else {
     echo $output->container('', 'clearfix');
     echo $output->notify_problem(get_string('noparticipants', 'tool_lp'));
index b042da2..1a1cd28 100644 (file)
@@ -32,11 +32,11 @@ require_login(null, false);
 if (isguestuser()) {
     throw new require_login_exception('Guests are not allowed here.');
 }
-\tool_lp\api::require_enabled();
+\core_competency\api::require_enabled();
 
 $params = array('userid' => $userid, 'competencyid' => $competencyid);
 $params['planid'] = $planid;
-$plan = \tool_lp\api::read_plan($planid);
+$plan = \core_competency\api::read_plan($planid);
 $url = new moodle_url('/admin/tool/lp/user_competency_in_plan.php', $params);
 $competency = new \core_competency\competency($competencyid);
 $framework = $competency->get_framework();
@@ -50,13 +50,13 @@ echo $output->heading($title);
 $page = new \tool_lp\output\user_competency_summary_in_plan($competencyid, $planid);
 echo $output->render($page);
 // Trigger the viewed event.
-$pc = \tool_lp\api::get_plan_competency($plan, $competency->get_id());
+$pc = \core_competency\api::get_plan_competency($plan, $competency->get_id());
 if ($plan->get_status() == \core_competency\plan::STATUS_COMPLETE) {
     $usercompetencyplan = $pc->usercompetencyplan;
-    \tool_lp\api::user_competency_plan_viewed($usercompetencyplan);
+    \core_competency\api::user_competency_plan_viewed($usercompetencyplan);
 } else {
     $usercompetency = $pc->usercompetency;
-    \tool_lp\api::user_competency_viewed_in_plan($usercompetency, $plan->get_id());
+    \core_competency\api::user_competency_viewed_in_plan($usercompetency, $plan->get_id());
 }
 
 echo $output->footer();
index cc76938..8ec2af9 100644 (file)
@@ -28,11 +28,11 @@ require_login(null, false);
 if (isguestuser()) {
     throw new require_login_exception('Guests are not allowed here.');
 }
-\tool_lp\api::require_enabled();
+\core_competency\api::require_enabled();
 
 $id = optional_param('id', null, PARAM_INT);
 
-$userevidence = \tool_lp\api::read_user_evidence($id);
+$userevidence = \core_competency\api::read_user_evidence($id);
 $url = new moodle_url('/admin/tool/lp/user_evidence_list.php', array('id' => $id));
 list($title, $subtitle) = \tool_lp\page_helper::setup_for_user_evidence($userevidence->get_userid(), $url, $userevidence);
 
index 19f6755..33c8e10 100644 (file)
@@ -28,7 +28,7 @@ require_login(null, false);
 if (isguestuser()) {
     throw new require_login_exception('Guests are not allowed here.');
 }
-\tool_lp\api::require_enabled();
+\core_competency\api::require_enabled();
 
 $userid = optional_param('userid', $USER->id, PARAM_INT);
 $id = optional_param('id', null, PARAM_INT);
@@ -43,7 +43,7 @@ if (empty($id)) {
         $pagetitle, $returntype);
 
 } else {
-    $userevidence = \tool_lp\api::read_user_evidence($id);
+    $userevidence = \core_competency\api::read_user_evidence($id);
 
     // The userid parameter must be the same as the owner of the evidence.
     if ($userid != $userevidence->get_userid()) {
@@ -99,11 +99,11 @@ if ($data = $form->get_data()) {
     unset($data->files);
 
     if (empty($userevidence)) {
-        $userevidence = \tool_lp\api::create_user_evidence($data, $draftitemid);
+        $userevidence = \core_competency\api::create_user_evidence($data, $draftitemid);
         $returnurl = new moodle_url('/admin/tool/lp/user_evidence.php', ['id' => $userevidence->get_id()]);
         $returnmsg = get_string('userevidencecreated', 'tool_lp');
     } else {
-        \tool_lp\api::update_user_evidence($data, $draftitemid);
+        \core_competency\api::update_user_evidence($data, $draftitemid);
         $returnmsg = get_string('userevidenceupdated', 'tool_lp');
     }
     redirect($returnurl, $returnmsg, null, \core\output\notification::NOTIFY_SUCCESS);
index 6bc38c6..0299992 100644 (file)
@@ -28,7 +28,7 @@ require_login(null, false);
 if (isguestuser()) {
     throw new require_login_exception('Guests are not allowed here.');
 }
-\tool_lp\api::require_enabled();
+\core_competency\api::require_enabled();
 
 $userid = optional_param('userid', $USER->id, PARAM_INT);
 
similarity index 99%
rename from admin/tool/lp/classes/api.php
rename to competency/classes/api.php
index 330b070..5fbac92 100644 (file)
 /**
  * Class for loading/storing competency frameworks from the DB.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2015 Damyon Wiese
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-namespace tool_lp;
+namespace core_competency;
 defined('MOODLE_INTERNAL') || die();
 
 use stdClass;
+use cm_info;
 use context;
 use context_helper;
 use context_system;
@@ -36,23 +37,6 @@ use require_login_exception;
 use moodle_exception;
 use moodle_url;
 use required_capability_exception;
-use \core_competency\competency;
-use \core_competency\competency_framework;
-use \core_competency\course_competency;
-use \core_competency\course_competency_settings;
-use \core_competency\course_module_competency;
-use \core_competency\evidence;
-use \core_competency\plan;
-use \core_competency\plan_competency;
-use \core_competency\related_competency;
-use \core_competency\template;
-use \core_competency\template_cohort;
-use \core_competency\template_competency;
-use \core_competency\user_competency;
-use \core_competency\user_competency_course;
-use \core_competency\user_competency_plan;
-use \core_competency\user_evidence;
-use \core_competency\user_evidence_competency;
 
 /**
  * Class for doing things with competency frameworks.
@@ -4998,7 +4982,8 @@ class api {
         } else {
             $data = (object) array('courseid' => $courseid, 'pushratingstouserplans' => $pushratingstouserplans);
             $settings = new course_competency_settings(0, $data);
-            return !empty($settings->create());
+            $result = $settings->create();
+            return !empty($result);
         }
     }
 }
index c9f159b..3782a29 100644 (file)
@@ -24,7 +24,7 @@
 namespace core_competency\external;
 defined('MOODLE_INTERNAL') || die();
 
-use tool_lp\api;
+use core_competency\api;
 use renderer_base;
 
 /**
index ed8390b..aaee024 100644 (file)
@@ -25,7 +25,7 @@
 namespace core\task;
 defined('MOODLE_INTERNAL') || die();
 
-use tool_lp\api;
+use core_competency\api;
 use core_competency\plan;
 
 /**
@@ -34,7 +34,7 @@ use core_competency\plan;
  * This task should run relatively often because the plans due dates can be set at
  * any time of the day in any timezone.
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2015 Frédéric Massart - FMCorz.net
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
index 32e0ed7..95733b2 100644 (file)
 namespace core\task;
 defined('MOODLE_INTERNAL') || die();
 
-use tool_lp\api;
+use core_competency\api;
 use core_competency\template_cohort;
 
 /**
  * Synchronise plans from template cohorts.
  *
  *
- * @package    tool_lp
+ * @package    core_competency
  * @copyright  2015 Issam Taboubi <issam.taboubi@umontreal.ca>
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */