MDL-50608 tool_lp: tidy up and bug fixes
authorMark Nelson <markn@moodle.com>
Fri, 5 Jun 2015 05:59:28 +0000 (22:59 -0700)
committerFrederic Massart <fred@moodle.com>
Mon, 18 Apr 2016 02:58:33 +0000 (10:58 +0800)
19 files changed:
admin/tool/lp/amd/build/competencies.min.js
admin/tool/lp/amd/src/competencies.js
admin/tool/lp/classes/api.php
admin/tool/lp/classes/output/manage_templates_page.php
admin/tool/lp/classes/output/template_competencies_page.php
admin/tool/lp/classes/plan.php
admin/tool/lp/classes/template.php
admin/tool/lp/db/access.php
admin/tool/lp/db/install.xml
admin/tool/lp/db/services.php
admin/tool/lp/editplan.php
admin/tool/lp/lang/en/tool_lp.php
admin/tool/lp/plans.php
admin/tool/lp/settings.php
admin/tool/lp/templatecompetencies.php
admin/tool/lp/templates/link_competencies.mustache [moved from admin/tool/lp/templates/link_course_competencies.mustache with 93% similarity]
admin/tool/lp/templates/manage_competency_frameworks_page.mustache
admin/tool/lp/templates/manage_templates_page.mustache
admin/tool/lp/tests/externallib_test.php

index 59ea262..3ce41c8 100644 (file)
Binary files a/admin/tool/lp/amd/build/competencies.min.js and b/admin/tool/lp/amd/build/competencies.min.js differ
index f278b44..2a8334e 100644 (file)
@@ -153,9 +153,9 @@ define(['jquery',
                 competencies: competencies,
                 search: searchText
             };
-            templates.render('tool_lp/link_course_competencies', context).done(function(html) {
+            templates.render('tool_lp/link_competencies', context).done(function(html) {
                 $('[data-region="competencylinktree"]').replaceWith(html);
-                localthis.initLinkCourseCompetencies();
+                localthis.initLinkCompetencies();
             }).fail(notification.exception);
         }).fail(notification.exception);
     };
@@ -163,9 +163,9 @@ define(['jquery',
     /**
      * The link course competencies popup was just opened and we need to initialise it.
      *
-     * @method initLinkCourseCompetencies
+     * @method initLinkCompetencies
      */
-    competencies.prototype.initLinkCourseCompetencies = function() {
+    competencies.prototype.initLinkCompetencies = function() {
         var localthis = this;
 
         new Ariatree('[data-enhance=linktree]', function(target) {
@@ -356,13 +356,13 @@ define(['jquery',
             var framework = localthis.frameworks[0];
             framework.selected = true;
             var context = { framework: framework, frameworks: localthis.frameworks, competencies: competencies, search: '' };
-            templates.render('tool_lp/link_course_competencies', context).done(function(html) {
+            templates.render('tool_lp/link_competencies', context).done(function(html) {
                 str.get_string('linkcompetencies', 'tool_lp').done(function(title) {
                     localthis.popup = new Dialogue(
                         title,
                         html, // The link UI.
                         function() {
-                            localthis.initLinkCourseCompetencies.call(localthis);
+                            localthis.initLinkCompetencies.call(localthis);
                         }
                     );
                 }).fail(notification.exception);
@@ -370,5 +370,5 @@ define(['jquery',
         }).fail(notification.exception);
     };
 
-    return /** @alias module:tool_lp/coursecompetencies */ competencies;
+    return competencies;
 });
index 8959fe9..635f6e2 100644 (file)
@@ -366,7 +366,7 @@ class api {
      * Requires tool/lp:competencyread capability at the system context.
      *
      * @param int $id The id of the framework to read.
-     * @return stdClass
+     * @return competency_framework
      */
     public static function read_framework($id) {
         // First we do a permissions check.
@@ -751,7 +751,7 @@ class api {
      * Requires tool/lp:templateread capability at the system context.
      *
      * @param int $id The id of the template to read.
-     * @return stdClass
+     * @return template
      */
     public static function read_template($id) {
         // First we do a permissions check.
@@ -960,7 +960,7 @@ class api {
         // First we do a permissions check.
         $context = context_system::instance();
 
-        require_capability('tool/lp:templatecompetencymanage', $context);
+        require_capability('tool/lp:templatemanage', $context);
 
         $record = new stdClass();
         $record->templateid = $templateid;
@@ -994,7 +994,7 @@ class api {
         // First we do a permissions check.
         $context = context_system::instance();
 
-        require_capability('tool/lp:templatecompetencymanage', $context);
+        require_capability('tool/lp:templatemanage', $context);
 
         $record = new stdClass();
         $record->templateid = $templateid;
@@ -1015,10 +1015,62 @@ class api {
         return false;
     }
 
+    /**
+     * Move the template competency up or down in the display list.
+     *
+     * Requires tool/lp:templatemanage capability at the system context.
+     *
+     * @param int $templateid The template id
+     * @param int $competencyidfrom The id of the competency we are moving.
+     * @param int $competencyidto The id of the competency we are moving to.
+     * @return boolean
+     */
+    public static function reorder_template_competency($templateid, $competencyidfrom, $competencyidto) {
+        // First we do a permissions check.
+        $context = context_system::instance();
+
+        require_capability('tool/lp:templatemanage', $context);
+
+        $down = true;
+        $templatecompetency = new template_competency();
+        $matches = $templatecompetency->get_records(array('templateid' => $templateid, 'competencyid' => $competencyidfrom));
+        if (count($matches) == 0) {
+            throw new coding_exception('The link does not exist');
+        }
+
+        $competencyfrom = array_pop($matches);
+        $matches = $templatecompetency->get_records(array('templateid' => $templateid, 'competencyid' => $competencyidto));
+        if (count($matches) == 0) {
+            throw new coding_exception('The link does not exist');
+        }
+
+        $competencyto = array_pop($matches);
+
+        $all = $templatecompetency->get_records(array('templateid' => $templateid), 'sortorder', 'ASC', 0, 0);
+
+        if ($competencyfrom->get_sortorder() > $competencyto->get_sortorder()) {
+            // We are moving up, so put it before the "to" item.
+            $down = false;
+        }
+
+        foreach ($all as $id => $templatecompetency) {
+            $sort = $templatecompetency->get_sortorder();
+            if ($down && $sort > $competencyfrom->get_sortorder() && $sort <= $competencyto->get_sortorder()) {
+                $templatecompetency->set_sortorder($templatecompetency->get_sortorder() - 1);
+                $templatecompetency->update();
+            } else if (!$down && $sort >= $competencyto->get_sortorder() && $sort < $competencyfrom->get_sortorder()) {
+                $templatecompetency->set_sortorder($templatecompetency->get_sortorder() + 1);
+                $templatecompetency->update();
+            }
+        }
+        $competencyfrom->set_sortorder($competencyto->get_sortorder());
+        return $competencyfrom->update();
+    }
+
     /**
      * Lists user plans.
      *
-     * @param int userid
+     * @param int $userid
      * @return \tool_lp\plan[]
      */
     public static function list_user_plans($userid) {
@@ -1037,7 +1089,7 @@ class api {
         }
 
         // Users that can manage plans can only see active and completed plans.
-        if (!has_any_capability(array('tool/lp:planmanage', 'tool/lp:planmanageown', 'tool/lp:plancreatedraft'), $context)) {
+        if (!has_any_capability(array('tool/lp:planmanageall', 'tool/lp:planmanageown', 'tool/lp:plancreatedraft'), $context)) {
             $select = ' AND status != :statusdraft';
             $params['statusdraft'] = plan::STATUS_DRAFT;
         }
@@ -1057,7 +1109,7 @@ class api {
 
         $context = context_user::instance($record->userid);
 
-        $manageplans = has_capability('tool/lp:planmanage', $context);
+        $manageplans = has_capability('tool/lp:planmanageall', $context);
         $createdraft = has_capability('tool/lp:plancreatedraft', $context);
         $manageownplan = has_capability('tool/lp:planmanageown', $context);
 
@@ -1066,7 +1118,7 @@ class api {
             // Exception about plancreatedraft as it is the one that is closer to basic users.
             throw new required_capability_exception($context, 'tool/lp:plancreatedraft', 'nopermissions', '');
         } else if ($USER->id != $record->userid && !$manageplans) {
-            throw new required_capability_exception($context, 'tool/lp:planmanage', 'nopermissions', '');
+            throw new required_capability_exception($context, 'tool/lp:planmanageall', 'nopermissions', '');
         }
 
         if (!isset($record->status)) {
@@ -1093,7 +1145,7 @@ class api {
 
         $context = context_user::instance($record->userid);
 
-        $manageplans = has_capability('tool/lp:planmanage', $context);
+        $manageplans = has_capability('tool/lp:planmanageall', $context);
         $createdraft = has_capability('tool/lp:plancreatedraft', $context);
         $manageownplan = has_capability('tool/lp:planmanageown', $context);
 
@@ -1101,7 +1153,7 @@ class api {
         if ($USER->id == $record->userid && !$manageplans && !$createdraft && !$manageownplan) {
             throw new required_capability_exception($context, 'tool/lp:planmanageown', 'nopermissions', '');
         } else if (!$manageplans) {
-            throw new required_capability_exception($context, 'tool/lp:planmanage', 'nopermissions', '');
+            throw new required_capability_exception($context, 'tool/lp:planmanageall', 'nopermissions', '');
         }
 
         $current = new plan($record->id);
@@ -1111,7 +1163,7 @@ class api {
         if (!$manageplans && !$manageownplan && $USER->id != $current->get_usermodified()) {
             throw new moodle_exception('erroreditingmodifiedplan', 'tool_lp');
         } else if (!$manageplans && $USER->id != $current->get_userid()) {
-            throw new required_capability_exception($context, 'tool/lp:planmanage', 'nopermissions', '');
+            throw new required_capability_exception($context, 'tool/lp:planmanageall', 'nopermissions', '');
         }
 
         // If the user can only create drafts we don't allow them to set other status.
@@ -1143,7 +1195,7 @@ class api {
 
         // We require any of these capabilities to retrieve draft plans.
         if ($plan->get_status() === plan::STATUS_DRAFT &&
-                !has_any_capability(array('tool/lp:planmanageown', 'tool/lp:planmanage', 'tool/lp:plancreatedraft'), $context)) {
+                !has_any_capability(array('tool/lp:planmanageown', 'tool/lp:planmanageall', 'tool/lp:plancreatedraft'), $context)) {
             // Exception about plancreatedraft as it is the one that is closer to basic users.
             throw new required_capability_exception($context, 'tool/lp:plancreatedraft', 'nopermissions', '');
         }
@@ -1163,7 +1215,7 @@ class api {
 
         $context = context_user::instance($plan->get_userid());
 
-        $manageplans = has_capability('tool/lp:planmanage', $context);
+        $manageplans = has_capability('tool/lp:planmanageall', $context);
         $manageownplan = has_capability('tool/lp:planmanageown', $context);
 
         if ($USER->id == $plan->get_userid() && $USER->id != $plan->get_usermodified() &&
@@ -1172,61 +1224,9 @@ class api {
             throw new required_capability_exception($context, 'tool/lp:planmanageown', 'nopermissions', '');
         } else if ($USER->id != $plan->get_userid() && !$manageplans) {
             // Other users needs to have tool/lp:planmanage.
-            throw new required_capability_exception($context, 'tool/lp:planmanage', 'nopermissions', '');
+            throw new required_capability_exception($context, 'tool/lp:planmanageall', 'nopermissions', '');
         }
 
         return $plan->delete();
     }
-
-    /**
-     * Move the template competency up or down in the display list.
-     *
-     * Requires tool/lp:templatecompetencymanage capability at the system context.
-     *
-     * @param int $templateid The template id
-     * @param int $competencyidfrom The id of the competency we are moving.
-     * @param int $competencyidto The id of the competency we are moving to.
-     * @return boolean
-     */
-    public static function reorder_template_competency($templateid, $competencyidfrom, $competencyidto) {
-        // First we do a permissions check.
-        $context = context_system::instance();
-
-        require_capability('tool/lp:templatecompetencymanage', $context);
-
-        $down = true;
-        $templatecompetency = new template_competency();
-        $matches = $templatecompetency->get_records(array('templateid' => $templateid, 'competencyid' => $competencyidfrom));
-        if (count($matches) == 0) {
-            throw new coding_exception('The link does not exist');
-        }
-
-        $competencyfrom = array_pop($matches);
-        $matches = $templatecompetency->get_records(array('templateid' => $templateid, 'competencyid' => $competencyidto));
-        if (count($matches) == 0) {
-            throw new coding_exception('The link does not exist');
-        }
-
-        $competencyto = array_pop($matches);
-
-        $all = $templatecompetency->get_records(array('templateid' => $templateid), 'sortorder', 'ASC', 0, 0);
-
-        if ($competencyfrom->get_sortorder() > $competencyto->get_sortorder()) {
-            // We are moving up, so put it before the "to" item.
-            $down = false;
-        }
-
-        foreach ($all as $id => $templatecompetency) {
-            $sort = $templatecompetency->get_sortorder();
-            if ($down && $sort > $competencyfrom->get_sortorder() && $sort <= $competencyto->get_sortorder()) {
-                $templatecompetency->set_sortorder($templatecompetency->get_sortorder() - 1);
-                $templatecompetency->update();
-            } else if (!$down && $sort >= $competencyto->get_sortorder() && $sort < $competencyfrom->get_sortorder()) {
-                $templatecompetency->set_sortorder($templatecompetency->get_sortorder() + 1);
-                $templatecompetency->update();
-            }
-        }
-        $competencyfrom->set_sortorder($competencyto->get_sortorder());
-        return $competencyfrom->update();
-    }
 }
index 7a08883..4f5e39c 100644 (file)
@@ -62,7 +62,7 @@ class manage_templates_page implements renderable, templatable {
         $this->templates = api::list_templates(array(), 'sortorder', 'ASC', 0, 0);
 
         $context = context_system::instance();
-        $this->canmanage = has_capability('tool/lp:planmanage', $context);
+        $this->canmanage = has_capability('tool/lp:planmanageall', $context);
     }
 
     /**
index 710eb3e..65d453b 100644 (file)
@@ -49,7 +49,7 @@ class template_competencies_page implements renderable, templatable {
         $this->templateid = $templateid;
         $this->competencies = api::list_competencies_in_template($templateid);
         $this->canmanagecompetencyframeworks = has_capability('tool/lp:competencymanage', $context);
-        $this->canmanagetemplatecompetencies = has_capability('tool/lp:templatecompetencymanage', $context);
+        $this->canmanagetemplatecompetencies = has_capability('tool/lp:templatemanage', $context);
         $this->manageurl = new moodle_url('/admin/tool/lp/competencyframeworks.php');
     }
 
index c4814aa..dd0b235 100644 (file)
@@ -174,7 +174,7 @@ class plan extends persistent {
         $context = context_user::instance($userid);
 
         // Not all users can edit all plans, the template should know about it.
-        if (has_capability('tool/lp:planmanage', $context) ||
+        if (has_capability('tool/lp:planmanageall', $context) ||
                 has_capability('tool/lp:planmanageown', $context)) {
             return true;
 
index 8f5988f..200f117 100644 (file)
@@ -60,7 +60,7 @@ class template extends persistent {
      * @return string
      */
     public function get_table_name() {
-        return 'tool_lp_plan_template';
+        return 'tool_lp_template';
     }
 
     /**
index 69a5fb5..31328e3 100644 (file)
@@ -58,21 +58,6 @@ $capabilities = array(
         ),
         'clonepermissionsfrom' =>  'moodle/site:config'
     ),
-    'tool/lp:templatecompetencyread' => array(
-        'captype' => 'read',
-        'contextlevel' => CONTEXT_COURSE,
-        'archetypes' => array(
-            'user' => CAP_ALLOW
-        ),
-        'clonepermissionsfrom' =>  'moodle/block:view'
-    ),
-    'tool/lp:templatecompetencymanage' => array(
-        'captype' => 'write',
-        'contextlevel' => CONTEXT_SYSTEM,
-        'archetypes' => array(
-        ),
-        'clonepermissionsfrom' =>  'moodle/site:config'
-    ),
     'tool/lp:plancreatedraft' => array(
         'captype' => 'write',
         'contextlevel' => CONTEXT_SYSTEM,
@@ -80,7 +65,7 @@ $capabilities = array(
         ),
         'clonepermissionsfrom' =>  'moodle/site:config'
     ),
-    'tool/lp:planmanage' => array(
+    'tool/lp:planmanageall' => array(
         'captype' => 'write',
         'contextlevel' => CONTEXT_SYSTEM,
         'archetypes' => array(
index 0805e6e..b0bec35 100755 (executable)
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
       </KEYS>
     </TABLE>
-    <TABLE NAME="tool_lp_plan_template" COMMENT="Learning plan templates.">
-      <FIELDS>
-        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
-        <FIELD NAME="shortname" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false" COMMENT="Short name for the learning plan template."/>
-        <FIELD NAME="idnumber" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false" COMMENT="Unique idnumber for this learning plan template."/>
-        <FIELD NAME="description" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Description of this learning plan template"/>
-        <FIELD NAME="descriptionformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="The format of the description field"/>
-        <FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Defined sort order for this template when it is displayed in a list."/>
-        <FIELD NAME="visible" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="Used to show/hide this learning plan template."/>
-        <FIELD NAME="duedate" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="The default due date for instances of this plan."/>
-        <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The time this learning plan template was created."/>
-        <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The time this learning plan template was last modified."/>
-        <FIELD NAME="usermodified" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="The user who last modified this learning plan template"/>
-      </FIELDS>
-      <KEYS>
-        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
-      </KEYS>
-    </TABLE>
     <TABLE NAME="tool_lp_course_competency" COMMENT="Link a competency to a course.">
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
         <KEY NAME="competencyid" TYPE="foreign" FIELDS="competencyid" REFTABLE="tool_lp_competency" REFFIELDS="id" COMMENT="Competency foreign key."/>
       </KEYS>
     </TABLE>
-    <TABLE NAME="tool_lp_template_competency" COMMENT="Link a competency to a learning plan template.">
-      <FIELDS>
-        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
-        <FIELD NAME="templateid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The template this competency is linked to."/>
-        <FIELD NAME="competencyid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The competency that is linked to this course."/>
-        <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The time this link was created."/>
-        <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The time this link was modified."/>
-        <FIELD NAME="usermodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The user who modified this link."/>
-        <FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Relative sort order"/>
-      </FIELDS>
-      <KEYS>
-        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
-        <KEY NAME="templateidlink" TYPE="foreign" FIELDS="templateid" REFTABLE="tool_lp_plan_template" REFFIELDS="id" COMMENT="Template foreign key."/>
-        <KEY NAME="competencyid" TYPE="foreign" FIELDS="competencyid" REFTABLE="tool_lp_competency" REFFIELDS="id" COMMENT="Competency foreign key."/>
-      </KEYS>
-    </TABLE>
     <TABLE NAME="tool_lp_plan" COMMENT="Learning plans">
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
         <INDEX NAME="templateid" UNIQUE="false" FIELDS="templateid"/>
       </INDEXES>
     </TABLE>
+    <TABLE NAME="tool_lp_template" COMMENT="Learning plan templates.">
+      <FIELDS>
+        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
+        <FIELD NAME="shortname" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false" COMMENT="Short name for the learning plan template."/>
+        <FIELD NAME="idnumber" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false" COMMENT="Unique idnumber for this learning plan template."/>
+        <FIELD NAME="description" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Description of this learning plan template"/>
+        <FIELD NAME="descriptionformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="The format of the description field"/>
+        <FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Defined sort order for this template when it is displayed in a list."/>
+        <FIELD NAME="visible" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="Used to show/hide this learning plan template."/>
+        <FIELD NAME="duedate" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="The default due date for instances of this plan."/>
+        <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The time this learning plan template was created."/>
+        <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The time this learning plan template was last modified."/>
+        <FIELD NAME="usermodified" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="The user who last modified this learning plan template"/>
+      </FIELDS>
+      <KEYS>
+        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+      </KEYS>
+    </TABLE>
+    <TABLE NAME="tool_lp_template_competency" COMMENT="Link a competency to a learning plan template.">
+      <FIELDS>
+        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
+        <FIELD NAME="templateid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The template this competency is linked to."/>
+        <FIELD NAME="competencyid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The competency that is linked to this course."/>
+        <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The time this link was created."/>
+        <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The time this link was modified."/>
+        <FIELD NAME="usermodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The user who modified this link."/>
+        <FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Relative sort order"/>
+      </FIELDS>
+      <KEYS>
+        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+        <KEY NAME="templateidlink" TYPE="foreign" FIELDS="templateid" REFTABLE="tool_lp_template" REFFIELDS="id" COMMENT="Template foreign key."/>
+        <KEY NAME="competencyid" TYPE="foreign" FIELDS="competencyid" REFTABLE="tool_lp_competency" REFFIELDS="id" COMMENT="Competency foreign key."/>
+      </KEYS>
+    </TABLE>
   </TABLES>
 </XMLDB>
index 64915f3..d5a5441 100644 (file)
@@ -226,7 +226,7 @@ $functions = array(
         'classpath'   => '',
         'description' => 'Add the competency to a template',
         'type'        => 'write',
-        'capabilities'=> 'tool/lp:templatecompetencymanage',
+        'capabilities'=> 'tool/lp:templatemanage',
     ),
     'tool_lp_remove_competency_from_course' => array(
         'classname'   => 'tool_lp\external',
@@ -242,7 +242,7 @@ $functions = array(
         'classpath'   => '',
         'description' => 'Remove a competency from a template',
         'type'        => 'write',
-        'capabilities'=> 'tool/lp:templatecompetencymanage',
+        'capabilities'=> 'tool/lp:templatemanage',
     ),
     'tool_lp_data_for_course_competencies_page' => array(
         'classname'   => 'tool_lp\external',
@@ -258,7 +258,7 @@ $functions = array(
         'classpath'   => '',
         'description' => 'Load the data for the template competencies page template.',
         'type'        => 'read',
-        'capabilities'=> 'tool/lp:templatecompetencyread',
+        'capabilities'=> 'tool/lp:templateread',
     ),
     'tool_lp_reorder_course_competency' => array(
         'classname'   => 'tool_lp\external',
@@ -274,7 +274,7 @@ $functions = array(
         'classpath'   => '',
         'description' => 'Move a template competency to a new relative sort order.',
         'type'        => 'write',
-        'capabilities'=> 'tool/lp:templatecompetencymanage',
+        'capabilities'=> 'tool/lp:templatemanage',
     ),
     'tool_lp_create_template' => array(
         'classname'   => 'tool_lp\external',
@@ -346,7 +346,7 @@ $functions = array(
         'classpath'   => '',
         'description' => 'Creates a learning plan.',
         'type'        => 'write',
-        'capabilities'=> 'tool/lp:planmanage',
+        'capabilities'=> 'tool/lp:planmanageall',
     ),
     'tool_lp_update_plan' => array(
         'classname'   => 'tool_lp\external',
@@ -354,15 +354,7 @@ $functions = array(
         'classpath'   => '',
         'description' => 'Updates a learning plan.',
         'type'        => 'write',
-        'capabilities'=> 'tool/lp:planmanage',
-    ),
-    'tool_lp_read_plan' => array(
-        'classname'   => 'tool_lp\external',
-        'methodname'  => 'read_plan',
-        'classpath'   => '',
-        'description' => 'Load a learning plan.',
-        'type'        => 'read',
-        'capabilities'=> 'tool/lp:planviewown',
+        'capabilities'=> 'tool/lp:planmanageall',
     ),
     'tool_lp_read_plan' => array(
         'classname'   => 'tool_lp\external',
@@ -378,7 +370,7 @@ $functions = array(
         'classpath'   => '',
         'description' => 'Delete a learning plan.',
         'type'        => 'write',
-        'capabilities'=> 'tool/lp:planmanage',
+        'capabilities'=> 'tool/lp:planmanageall',
     ),
     'tool_lp_data_for_plans_page' => array(
         'classname'   => 'tool_lp\external',
index 9cc94cb..74ba3da 100644 (file)
@@ -55,12 +55,12 @@ $PAGE->set_pagelayout('admin');
 $PAGE->set_heading($pagetitle);
 $output = $PAGE->get_renderer('tool_lp');
 
-$manageplans = has_capability('tool/lp:planmanage', $context);
+$manageplans = has_capability('tool/lp:planmanageall', $context);
 $owncapabilities = array('tool/lp:plancreatedraft', 'tool/lp:planmanageown');
 if ($USER->id === $userid && !has_any_capability($owncapabilities, $context) && !$manageplans) {
     throw new required_capability_exception($context, 'tool/lp:planmanageown', 'nopermissions', '');
 } else if (!$manageplans) {
-    throw new required_capability_exception($context, 'tool/lp:planmanage', 'nopermissions', '');
+    throw new required_capability_exception($context, 'tool/lp:planmanageall', 'nopermissions', '');
 }
 
 // Passing the templates list to the form.
index 6cbb040..2b62a97 100644 (file)
@@ -24,7 +24,7 @@
 
 $string['pluginname'] = 'Learning Plans';
 $string['lp:plancreatedraft'] = 'Create draft learning plans';
-$string['lp:planmanage'] = 'Manage learning plans';
+$string['lp:planmanageall'] = 'Manage learning plans';
 $string['lp:planmanageown'] = 'Manage own learning plans';
 $string['lp:planviewall'] = 'View all learning plans';
 $string['lp:planviewown'] = 'View own learning plans';
@@ -32,8 +32,6 @@ $string['lp:competencymanage'] = 'Manage competency frameworks';
 $string['lp:competencyread'] = 'View competency frameworks';
 $string['lp:coursecompetencymanage'] = 'Manage course competencies';
 $string['lp:coursecompetencyread'] = 'View course competencies';
-$string['lp:templatecompetencymanage'] = 'Manage template competencies';
-$string['lp:templatecompetencyread'] = 'View template competencies';
 $string['lp:templatemanage'] = 'Manage templates';
 $string['lp:templateread'] = 'View template';
 $string['competencies'] = 'Competencies';
@@ -49,7 +47,7 @@ $string['addcompetency'] = 'Add competency';
 $string['default'] = 'Default';
 $string['editcompetencyframework'] = 'Edit competency framework';
 $string['erroreditingmodifiedplan'] = 'You can not edit a learning plan modified by another user if you don\'t have tool/lp:planmanage or tool/lp:planmanageown capabilities.';
-$string['errorplanstatus'] = 'Learning plans {$a} status unknown';
+$string['errorplanstatus'] = 'Learning plans \'{$a}\' status unknown';
 $string['listcompetencyframeworkscaption'] = 'List of competency frameworks';
 $string['listtemplatescaption'] = 'List of learning plan templates';
 $string['listplanscaption'] = 'List of learning plans';
@@ -78,16 +76,13 @@ $string['parentcompetency'] = 'Parent competency';
 $string['competencyframeworkcreated'] = 'Competency framework created.';
 $string['competencyframeworkupdated'] = 'Competency framework updated.';
 $string['editcompetencyframework'] = 'Edit competency framework';
-$string['editthiscompetencyframework'] = 'Edit';
 $string['editplan'] = 'Edit learning plan';
 $string['editthisplan'] = 'Edit this learning plan';
 $string['deletethisplan'] = 'Delete this learning plan';
-$string['deletethiscompetencyframework'] = 'Delete';
-$string['deletethistemplate'] = 'Delete';
 $string['hiddenhint'] = '(hidden)';
 $string['movecompetencyframework'] = 'Move competency framework';
 $string['movetonewparent'] = 'Relocate';
-$string['moveframeworkafter'] = 'Move competency framework after {$a}';
+$string['moveframeworkafter'] = 'Move competency framework after \'{$a}\'';
 $string['selectedcompetency'] = 'Selected competency';
 $string['nocompetencyselected'] = 'No competency selected';
 $string['plancreated'] = 'Learning plan created';
@@ -104,9 +99,9 @@ $string['hidden'] = 'Hidden';
 $string['editcompetency'] = 'Edit competency';
 $string['confirm'] = 'Confirm';
 $string['delete'] = 'Delete';
-$string['deletecompetency'] = 'Delete competency {$a}?';
-$string['deletecompetencyframework'] = 'Delete competency framework {$a}?';
-$string['deleteplan'] = 'Delete plan {$a}?';
+$string['deletecompetency'] = 'Delete competency \'{$a}\'?';
+$string['deletecompetencyframework'] = 'Delete competency framework \'{$a}\'?';
+$string['deleteplan'] = 'Delete plan \'{$a}\'?';
 $string['cancel'] = 'Cancel';
 $string['move'] = 'Move';
 $string['movecompetency'] = 'Move competency: {$a}';
@@ -125,14 +120,13 @@ $string['learningplans'] = 'Learning plans';
 $string['plantemplate'] = 'Select template';
 $string['plantemplate_help'] = 'A learning plan created from a template will contain a list of competencies that match the template. Updates to the template will be reflected in any plan created from that template.';
 $string['movecompetency'] = 'Move competency';
-$string['movecompetencyafter'] = 'Move competency after {$a}';
+$string['movecompetencyafter'] = 'Move competency after \'{$a}\'';
 $string['templatecompetencies'] = 'Template competencies';
 $string['templates'] = 'Learning plan templates';
 $string['templatename'] = 'Name';
-$string['editthistemplate'] = 'Edit';
 $string['templatecreated'] = 'Learning plan template created';
 $string['templateupdated'] = 'Learning plan template updated';
 $string['edittemplate'] = 'Edit learning plan template';
-$string['deletetemplate'] = 'Delete learning plan template? {$a}';
+$string['deletetemplate'] = 'Delete learning plan template \'{$a}\'?';
 $string['duedate'] = 'Due date';
 $string['duedate_help'] = 'The date that a learning plan should be completed by.';
index 4e4e1bf..bd557fc 100644 (file)
@@ -28,7 +28,7 @@ $userid = optional_param('userid', false, PARAM_INT);
 
 require_login(null, false);
 if (isguestuser()) {
-    throw new require_login_exception();
+    throw new require_login_exception('Guests are not allowed here.');
 }
 
 $iscurrentuser = $userid == $USER->id;
@@ -46,8 +46,9 @@ if (!$user || !core_user::is_real_user($userid)) {
 if (!has_capability('tool/lp:planviewall', $context)) {
     if ($iscurrentuser) {
         require_capability('tool/lp:planviewown', $context);
+    } else {
+        throw new required_capability_exception($context, 'tool/lp:planviewall', 'nopermissions', '');
     }
-    throw new required_capability_exception($context, 'tool/lp:planviewall', 'nopermissions', '');
 }
 
 $url = new moodle_url('/admin/tool/lp/plans.php', array('userid' => $userid));
index ec2d589..d9b6570 100644 (file)
@@ -38,7 +38,7 @@ $temp = new admin_externalpage(
     'toollplearningplans',
     get_string('learningplans', 'tool_lp'),
     new moodle_url('/admin/tool/lp/learningplans.php'),
-    'tool/lp:planmanage'
+    'tool/lp:planmanageall'
 );
 $ADMIN->add('root', $temp, 'toollpcompetencies');
 
index c9d8423..de0320a 100644 (file)
 require_once(__DIR__ . '/../../../config.php');
 require_once($CFG->libdir.'/adminlib.php');
 
-$id = required_param('templateid', PARAM_INT);
+$templateid = required_param('templateid', PARAM_INT);
 
-$template = $DB->get_record('tool_lp_plan_template', array('id' => $id), '*', MUST_EXIST);
+$template = \tool_lp\api::read_template($templateid);
 
 admin_externalpage_setup('toollplearningplans');
 
 // Set up the page.
-$url = new moodle_url('/admin/tool/lp/templatecompetencies.php', array('templateid' => $id));
+$url = new moodle_url('/admin/tool/lp/templatecompetencies.php', array('templateid' => $template->get_id()));
 $title = get_string('templatecompetencies', 'tool_lp');
-$templatename = format_text($template->shortname);
+$templatename = format_text($template->get_shortname());
 $PAGE->set_url($url);
 $PAGE->set_title($title);
 $PAGE->set_heading($templatename);
@@ -44,6 +44,6 @@ $PAGE->navbar->add($templatename, $url);
 $output = $PAGE->get_renderer('tool_lp');
 echo $output->header();
 echo $output->heading($title);
-$page = new \tool_lp\output\template_competencies_page($template->id);
+$page = new \tool_lp\output\template_competencies_page($template->get_id());
 echo $output->render($page);
 echo $output->footer();
@@ -7,11 +7,10 @@
 </select>
 <h3>{{#str}}locatecompetency, tool_lp{{/str}}</h3>
 
-
 <form data-region="filtercompetencies" data-frameworkid="{{framework.id}}">
     <label class="accesshide" for="filter{{uniqid}}">{{#str}}search, tool_lp{{/str}}</label>
     <input type="text" id="filter{{uniqid}}" placeholder="{{#str}}search, tool_lp{{/str}}" value="{{search}}">
-    <button>{{#pix}}a/search, , {{#str}}search{{/str}}{{/pix}}</button>
+    <button>{{#pix}}a/search, ,{{#str}}search{{/str}}{{/pix}}</button>
 </form>
 <ul data-enhance="linktree">
     <li>{{framework.shortname}}
index e34232d..2518420 100644 (file)
                     <ul class="dropdown-menu">
                         <li>
                             <a href="{{pluginbaseurl}}/editcompetencyframework.php?id={{id}}">
-                                {{#pix}}t/edit{{/pix}} {{#str}}editthiscompetencyframework, tool_lp{{/str}}
+                                {{#pix}}t/edit{{/pix}} {{#str}}edit, tool_lp{{/str}}
                             </a>
                         </li>
                         <li>
                             <a data-action="deletecompetencyframework" data-frameworkid="{{id}}" href="#">
-                                {{#pix}}t/delete{{/pix}} {{#str}}deletethiscompetencyframework, tool_lp{{/str}}
+                                {{#pix}}t/delete{{/pix}} {{#str}}delete, tool_lp{{/str}}
                             </a>
                         </li>
                     </ul>
index bb0c9cb..f693946 100644 (file)
                     <ul class="dropdown-menu">
                         <li>
                             <a href="{{pluginbaseurl}}/edittemplate.php?id={{id}}">
-                                {{#pix}}t/edit{{/pix}} {{#str}}editthistemplate, tool_lp{{/str}}
+                                {{#pix}}t/edit{{/pix}} {{#str}}edit, tool_lp{{/str}}
                             </a>
                         </li>
                         <li>
                             <a data-action="deletetemplate" data-templateid="{{id}}" href="#">
-                                {{#pix}}t/delete{{/pix}} {{#str}}deletethistemplate, tool_lp{{/str}}
+                                {{#pix}}t/delete{{/pix}} {{#str}}delete, tool_lp{{/str}}
                             </a>
                         </li>
                     </ul>
index a1b4118..975eece 100644 (file)
@@ -62,11 +62,11 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
 
         assign_capability('tool/lp:competencymanage', CAP_ALLOW, $this->creatorrole, $syscontext->id);
         assign_capability('tool/lp:competencyview', CAP_ALLOW, $this->userrole, $syscontext->id);
-        assign_capability('tool/lp:planmanage', CAP_ALLOW, $this->creatorrole, $syscontext->id);
+        assign_capability('tool/lp:planmanageall', CAP_ALLOW, $this->creatorrole, $syscontext->id);
         assign_capability('tool/lp:planmanageown', CAP_ALLOW, $this->creatorrole, $syscontext->id);
         assign_capability('tool/lp:planviewall', CAP_ALLOW, $this->creatorrole, $syscontext->id);
         assign_capability('tool/lp:templatemanage', CAP_ALLOW, $this->creatorrole, $syscontext->id);
-        assign_capability('tool/lp:templatecompetencymanage', CAP_ALLOW, $this->creatorrole, $syscontext->id);
+        assign_capability('tool/lp:templatemanage', CAP_ALLOW, $this->creatorrole, $syscontext->id);
 
         role_assign($this->creatorrole, $creator->id, $syscontext->id);
         role_assign($this->userrole, $user->id, $syscontext->id);
@@ -716,7 +716,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
 
         $this->assertTrue(external::delete_plan($plan1['id']));
 
-        unassign_capability('tool/lp:planmanage', $this->creatorrole, $syscontext->id);
+        unassign_capability('tool/lp:planmanageall', $this->creatorrole, $syscontext->id);
         accesslib_clear_all_caches_for_unit_testing();
 
         try {
@@ -775,7 +775,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
         $this->assertEquals(1, external::count_competencies_in_template($template->id));
 
         // Unassign capability.
-        unassign_capability('tool/lp:templatecompetencymanage', $this->creatorrole, $syscontext->id);
+        unassign_capability('tool/lp:templatemanage', $this->creatorrole, $syscontext->id);
         accesslib_clear_all_caches_for_unit_testing();
 
         // Check we can not add the competency now.
@@ -815,7 +815,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
         $this->assertEquals(0, external::count_competencies_in_template($template->id));
 
         // Unassign capability.
-        unassign_capability('tool/lp:templatecompetencymanage', $this->creatorrole, $syscontext->id);
+        unassign_capability('tool/lp:templatemanage', $this->creatorrole, $syscontext->id);
         accesslib_clear_all_caches_for_unit_testing();
 
         // Check we can not remove the competency now.