Merge branch 'MDL-53994' of git://github.com/stronk7/moodle
authorDavid Monllao <davidm@moodle.com>
Mon, 2 May 2016 02:04:36 +0000 (10:04 +0800)
committerDavid Monllao <davidm@moodle.com>
Mon, 2 May 2016 02:04:36 +0000 (10:04 +0800)
admin/tool/cohortroles/index.php
admin/tool/lp/classes/external.php
admin/tool/lp/classes/output/course_competencies_page.php
admin/tool/lp/templates/course_competencies_page.mustache
admin/tool/lp/tests/behat/behat_tool_lp.php

index a202be6..d53af3e 100644 (file)
@@ -57,15 +57,15 @@ if ($removeid) {
     require_sesskey();
     // We must create them all or none.
     $saved = 0;
-    foreach ($data->userids as $userid) {
-        if (empty($data->cohortids)) {
-            $data->cohortids = array();
-        }
-        foreach ($data->cohortids as $cohortid) {
-            $params = (object) array('userid' => $userid, 'cohortid' => $cohortid, 'roleid' => $data->roleid);
-            $result = \tool_cohortroles\api::create_cohort_role_assignment($params);
-            if ($result) {
-                $saved++;
+    // Loop through userids and cohortids only if both of them are not empty.
+    if (!empty($data->userids) && !empty($data->cohortids)) {
+        foreach ($data->userids as $userid) {
+            foreach ($data->cohortids as $cohortid) {
+                $params = (object) array('userid' => $userid, 'cohortid' => $cohortid, 'roleid' => $data->roleid);
+                $result = \tool_cohortroles\api::create_cohort_role_assignment($params);
+                if ($result) {
+                    $saved++;
+                }
             }
         }
     }
index 61a922f..59608c5 100644 (file)
@@ -404,6 +404,7 @@ class external extends external_api {
             'canmanagecompetencyframeworks' => new external_value(PARAM_BOOL, 'User can manage competency frameworks'),
             'canmanagecoursecompetencies' => new external_value(PARAM_BOOL, 'User can manage linked course competencies'),
             'canconfigurecoursecompetencies' => new external_value(PARAM_BOOL, 'User can configure course competency settings'),
+            'cangradecompetencies' => new external_value(PARAM_BOOL, 'User can grade competencies.'),
             'settings' => course_competency_settings_exporter::get_read_structure(),
             'statistics' => course_competency_statistics_exporter::get_read_structure(),
             'competencies' => new external_multiple_structure(new external_single_structure(array(
index 45c5cbf..395561f 100644 (file)
@@ -80,6 +80,7 @@ class course_competencies_page implements renderable, templatable {
         $this->coursecompetencylist = api::list_course_competencies($courseid);
         $this->canmanagecoursecompetencies = has_capability('moodle/competency:coursecompetencymanage', $this->context);
         $this->canconfigurecoursecompetencies = has_capability('moodle/competency:coursecompetencyconfigure', $this->context);
+        $this->cangradecompetencies = has_capability('moodle/competency:competencygrade', $this->context);
         $this->coursecompetencysettings = api::read_course_competency_settings($courseid);
         $this->coursecompetencystatistics = new course_competency_statistics($courseid);
 
@@ -183,6 +184,7 @@ class course_competencies_page implements renderable, templatable {
         $data->canmanagecompetencyframeworks = $this->canmanagecompetencyframeworks;
         $data->canmanagecoursecompetencies = $this->canmanagecoursecompetencies;
         $data->canconfigurecoursecompetencies = $this->canconfigurecoursecompetencies;
+        $data->cangradecompetencies = $this->cangradecompetencies;
         $exporter = new course_competency_settings_exporter($this->coursecompetencysettings);
         $data->settings = $exporter->export($output);
         $related = array('context' => $this->context);
index fd5f7d3..0a65312 100644 (file)
             {{/canmanagecoursecompetencies}}
         </div>
     </div>
-<div data-region="configurecoursecompetencies">
-{{#settings.pushratingstouserplans}}
-    <p class="alert">
-    {{#str}}coursecompetencyratingsarepushedtouserplans, tool_lp{{/str}}
-{{/settings.pushratingstouserplans}}
-{{^settings.pushratingstouserplans}}
-    <p class="alert alert-info">
-    {{#str}}coursecompetencyratingsarenotpushedtouserplans, tool_lp{{/str}}
-{{/settings.pushratingstouserplans}}
-{{#canconfigurecoursecompetencies}}
-    <a href="#"
-        data-action="configure-course-competency-settings"
-        data-courseid="{{courseid}}"
-        data-pushratingstouserplans="{{settings.pushratingstouserplans}}"
-        >{{#pix}}t/edit, core, {{#str}}edit{{/str}}{{/pix}}</a>
-    </p>
-{{/canconfigurecoursecompetencies}}
-</div>
+    <div data-region="configurecoursecompetencies">
+    {{#cangradecompetencies}}
+        <p class="alert {{^settings.pushratingstouserplans}}alert-info{{/settings.pushratingstouserplans}}">
+        {{#settings.pushratingstouserplans}}
+            {{#str}}coursecompetencyratingsarepushedtouserplans, tool_lp{{/str}}
+        {{/settings.pushratingstouserplans}}
+        {{^settings.pushratingstouserplans}}
+            {{#str}}coursecompetencyratingsarenotpushedtouserplans, tool_lp{{/str}}
+        {{/settings.pushratingstouserplans}}
+        {{#canconfigurecoursecompetencies}}
+            <a href="#"
+               data-action="configure-course-competency-settings"
+               data-courseid="{{courseid}}"
+               data-pushratingstouserplans="{{settings.pushratingstouserplans}}">
+                {{#pix}}t/edit, core, {{#str}}edit{{/str}}{{/pix}}
+            </a>
+        {{/canconfigurecoursecompetencies}}
+        </p>
+    {{/cangradecompetencies}}
+    </div>
 {{#statistics}}
 {{> tool_lp/course_competency_statistics }}
 {{/statistics}}
index 6b0bf40..0a5fea5 100644 (file)
@@ -25,8 +25,6 @@
 
 require_once(__DIR__ . '/../../../../../lib/behat/behat_base.php');
 
-use Behat\Behat\Context\Step\Given as Given;
-
 /**
  * Step definition for learning plan system.
  *
@@ -44,17 +42,12 @@ class behat_tool_lp extends behat_base {
      *
      * @param string $nodetext
      * @param string $rowname
-     * @return Given[] array of steps
      */
     public function click_on_edit_menu_of_the_row($nodetext, $rowname) {
-        $steps = array();
-
-        $xpathtarget = "//ul//li//ul//li[@class='tool-lp-menu-item']//a[contains(.,'". $nodetext ."')]";
+        $xpathtarget = "//ul//li//ul//li[@class='tool-lp-menu-item']//a[contains(.,'" . $nodetext . "')]";
 
-        $steps[] = new Given('I click on "Edit" "link" in the "' . $this->escape($rowname) . '" "table_row"');
-        $steps[] = new Given('I click on "'.$xpathtarget.'" "xpath_element" in the "' . $this->escape($rowname) . '" "table_row"');
-
-        return $steps;
+        $this->execute('behat_general::i_click_on_in_the', [get_string('edit'), 'link', $this->escape($rowname), 'table_row']);
+        $this->execute('behat_general::i_click_on_in_the', [$xpathtarget, 'xpath_element', $this->escape($rowname), 'table_row']);
     }
 
     /**
@@ -63,16 +56,11 @@ class behat_tool_lp extends behat_base {
      * @Given /^I select "([^"]*)" of the competency tree$/
      *
      * @param string $competencyname
-     * @return Given[] array of steps
      */
     public function select_of_the_competency_tree($competencyname) {
-        $steps = array();
-
-        $xpathtarget = "//li[@role='tree-item']//span[contains(.,'". $competencyname ."')]";
+        $xpathtarget = "//li[@role='tree-item']//span[contains(.,'" . $competencyname . "')]";
 
-        $steps[] = new Given('I click on "' . $xpathtarget . '" "xpath_element"');
-
-        return $steps;
+        $this->execute('behat_general::i_click_on', [$xpathtarget, 'xpath_element']);
     }
 
     /**
@@ -81,15 +69,10 @@ class behat_tool_lp extends behat_base {
      * @Given /^I click on "([^"]*)" item in the autocomplete list$/
      *
      * @param string $item
-     * @return Given[] array of steps
      */
     public function i_click_on_item_in_the_autocomplete_list($item) {
-        $steps = array();
-
-        $xpathtarget = "//ul[@class='form-autocomplete-suggestions']//li//span//span[contains(.,'". $item ."')]";
-
-        $steps[] = new Given('I click on "' . $xpathtarget . '" "xpath_element"');
+        $xpathtarget = "//ul[@class='form-autocomplete-suggestions']//li//span//span[contains(.,'" . $item . "')]";
 
-        return $steps;
+        $this->execute('behat_general::i_click_on', [$xpathtarget, 'xpath_element']);
     }
 }