MDL-52229 tool_lp: Handle hidden templates/frameworks

This commit is contained in:
Issam Taboubi
2016-04-18 10:58:46 +08:00
committed by Frederic Massart
parent ed549dbfcb
commit 964afa98e7
25 changed files with 226 additions and 170 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -376,7 +376,6 @@ define(['jquery',
idnumber: relatedTarget.idnumber,
description: relatedTarget.description,
descriptionformat: relatedTarget.descriptionformat,
visible: relatedTarget.visible,
ruletype: config.ruletype,
ruleoutcome: config.ruleoutcome,
ruleconfig: config.ruleconfig
+4 -1
View File
@@ -80,6 +80,8 @@ define(['jquery',
Picker.prototype._singleFramework = false;
/** @type {Boolean} Do we allow multi select? */
Picker.prototype._multiSelect = true;
/** @type {Boolean} Do we allow to display hidden framework? */
Picker.prototype._onlyVisible = true;
/**
* Hook to executed after the view is rendered.
@@ -324,7 +326,8 @@ define(['jquery',
{ methodname: 'tool_lp_list_competency_frameworks', args: {
sort: 'shortname',
context: { contextid: self._pageContextId },
includes: self._pageContextIncludes
includes: self._pageContextIncludes,
onlyvisible: self._onlyVisible
}}
])[0];
}
+51 -48
View File
@@ -502,9 +502,10 @@ class api {
* - children: All descendants
* - parents: All parents, grand parents, etc...
* - self: Context passed only.
* @param bool $onlyvisible If true return only visible frameworks
* @return array of competency_framework
*/
public static function list_frameworks($sort, $order, $skip, $limit, $context, $includes = 'children') {
public static function list_frameworks($sort, $order, $skip, $limit, $context, $includes = 'children', $onlyvisible = false) {
global $DB;
// Get all the relevant contexts.
@@ -517,7 +518,13 @@ class api {
// OK - all set.
list($insql, $inparams) = $DB->get_in_or_equal(array_keys($contexts), SQL_PARAMS_NAMED);
return competency_framework::get_records_select("contextid $insql", $inparams, $sort . ' ' . $order, '*', $skip, $limit);
$select = "contextid $insql";
if ($onlyvisible) {
$select .= " AND visible = :visible";
$inparams['visible'] = 1;
}
return competency_framework::get_records_select($select, $inparams, $sort . ' ' . $order, '*', $skip, $limit);
}
/**
@@ -682,19 +689,14 @@ class api {
// First we do a permissions check.
$context = context_course::instance($courseid);
$onlyvisible = 1;
$capabilities = array('tool/lp:coursecompetencyread', 'tool/lp:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'tool/lp:coursecompetencyread', 'nopermissions', '');
}
if (has_capability('tool/lp:coursecompetencymanage', $context)) {
$onlyvisible = 0;
}
// OK - all set.
return course_competency::count_competencies($courseid, $onlyvisible);
return course_competency::count_competencies($courseid);
}
/**
@@ -715,22 +717,17 @@ class api {
// Check the user have access to the course.
self::validate_course($course);
$context = context_course::instance($course->id);
$onlyvisible = 1;
$capabilities = array('tool/lp:coursecompetencyread', 'tool/lp:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'tool/lp:coursecompetencyread', 'nopermissions', '');
}
if (has_capability('tool/lp:coursecompetencymanage', $context)) {
$onlyvisible = 0;
}
$result = array();
// TODO We could improve the performance of this into one single query.
$coursecompetencies = course_competency::list_course_competencies($course->id, $onlyvisible);
$competencies = course_competency::list_competencies($course->id, $onlyvisible);
$coursecompetencies = course_competency::list_course_competencies($course->id);
$competencies = course_competency::list_competencies($course->id);
// Build the return values.
foreach ($coursecompetencies as $key => $coursecompetency) {
@@ -763,10 +760,11 @@ class api {
$record->courseid = $courseid;
$record->competencyid = $competencyid;
$competency = new competency();
$competency->set_id($competencyid);
if (!$competency->read()) {
throw new coding_exception('The competency does not exist');
$competency = new competency($competencyid);
// Can not add a competency that belong to a hidden framework.
if ($competency->get_framework()->get_visible() == false) {
throw new coding_exception('A competency belonging to hidden framework can not be linked to course');
}
$coursecompetency = new course_competency();
@@ -800,12 +798,7 @@ class api {
$record->courseid = $courseid;
$record->competencyid = $competencyid;
$competency = new competency();
$competency->set_id($competencyid);
if (!$competency->read()) {
throw new coding_exception('The competency does not exist');
}
$competency = new competency($competencyid);
$coursecompetency = new course_competency();
$exists = $coursecompetency->get_records(array('courseid' => $courseid, 'competencyid' => $competencyid));
if ($exists) {
@@ -1055,9 +1048,10 @@ class api {
* - children: All descendants
* - parents: All parents, grand parents, etc...
* - self: Context passed only.
* @param bool $onlyvisible If should list only visible templates
* @return array of competency_framework
*/
public static function list_templates($sort, $order, $skip, $limit, $context, $includes = 'children') {
public static function list_templates($sort, $order, $skip, $limit, $context, $includes = 'children', $onlyvisible = false) {
global $DB;
// Get all the relevant contexts.
@@ -1077,8 +1071,14 @@ class api {
// OK - all set.
$template = new template();
list($insql, $inparams) = $DB->get_in_or_equal(array_keys($contexts), SQL_PARAMS_NAMED);
return $template->get_records_select("contextid $insql", $inparams, $orderby, '*', $skip, $limit);
list($insql, $params) = $DB->get_in_or_equal(array_keys($contexts), SQL_PARAMS_NAMED);
$select = "contextid $insql";
if ($onlyvisible) {
$select .= " AND visible = :visible";
$params['visible'] = 1;
}
return $template->get_records_select($select, $params, $orderby, '*', $skip, $limit);
}
/**
@@ -1170,18 +1170,13 @@ class api {
// First we do a permissions check.
$template = new template($templateid);
$context = $template->get_context();
$onlyvisible = 1;
if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'tool/lp:templateread', 'nopermissions', '');
}
if ($template->can_manage()) {
$onlyvisible = 0;
}
// OK - all set.
return template_competency::count_competencies($templateid, $onlyvisible);
return template_competency::count_competencies($templateid);
}
/**
@@ -1194,18 +1189,13 @@ class api {
// First we do a permissions check.
$template = new template($templateid);
$context = $template->get_context();
$onlyvisible = 1;
if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'tool/lp:templateread', 'nopermissions', '');
}
if ($template->can_manage()) {
$onlyvisible = 0;
}
// OK - all set.
return template_competency::list_competencies($templateid, $onlyvisible);
return template_competency::list_competencies($templateid);
}
/**
@@ -1226,10 +1216,11 @@ class api {
$record->templateid = $templateid;
$record->competencyid = $competencyid;
$competency = new competency();
$competency->set_id($competencyid);
if (!$competency->read()) {
throw new coding_exception('The competency does not exist');
$competency = new competency($competencyid);
// Can not add a competency that belong to a hidden framework.
if ($competency->get_framework()->get_visible() == false) {
throw new coding_exception('A competency belonging to hidden framework can not be added');
}
$exists = template_competency::get_records(array('templateid' => $templateid, 'competencyid' => $competencyid));
@@ -1260,10 +1251,6 @@ class api {
$record->competencyid = $competencyid;
$competency = new competency($competencyid);
$competency->set_id($competencyid);
if (!$competency->read()) {
throw new coding_exception('The competency does not exist');
}
$exists = template_competency::get_records(array('templateid' => $templateid, 'competencyid' => $competencyid));
if ($exists) {
@@ -1461,6 +1448,10 @@ class api {
if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'tool/lp:templateread', 'nopermissions', '');
}
// Can not create plan from a hidden template.
if ($template->get_visible() == false) {
throw new coding_exception('A plan can not be created from a hidden template');
}
// Convert the template to a plan.
$record = $template->to_record();
@@ -1520,6 +1511,11 @@ class api {
throw new required_capability_exception($template->get_context(), 'tool/lp:templateread', 'nopermissions', '');
}
// Can not create plan from a hidden template.
if ($template->get_visible() == false) {
throw new coding_exception('A plan can not be created from a hidden template');
}
// The user must be able to view the cohort.
$cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
$cohortctx = context::instance_by_id($cohort->contextid);
@@ -1904,6 +1900,13 @@ class api {
throw new coding_exception('A competency can not be added to a learning plan completed');
}
$competency = new competency($competencyid);
// Can not add a competency that belong to a hidden framework.
if ($competency->get_framework()->get_visible() == false) {
throw new coding_exception('A competency belonging to hidden framework can not be added');
}
$exists = plan_competency::get_record(array('planid' => $planid, 'competencyid' => $competencyid));
if (!$exists) {
$record = new stdClass();
-4
View File
@@ -79,10 +79,6 @@ class competency extends persistent {
'default' => null,
'type' => PARAM_INT
),
'visible' => array(
'default' => 1,
'type' => PARAM_BOOL
),
'parentid' => array(
'default' => 0,
'type' => PARAM_INT
+3 -21
View File
@@ -200,10 +200,9 @@ class course_competency extends persistent {
* Count the competencies in this course.
*
* @param int $courseid The course id
* @param bool $onlyvisible If true, only count visible competencies in this course.
* @return int
*/
public static function count_competencies($courseid, $onlyvisible) {
public static function count_competencies($courseid) {
global $DB;
$sql = 'SELECT COUNT(comp.id)
@@ -213,11 +212,6 @@ class course_competency extends persistent {
WHERE coursecomp.courseid = ? ';
$params = array($courseid);
if ($onlyvisible) {
$sql .= ' AND comp.visible = ?';
$params[] = 1;
}
$results = $DB->count_records_sql($sql, $params);
return $results;
@@ -227,10 +221,9 @@ class course_competency extends persistent {
* List the competencies in this course.
*
* @param int $courseid The course id
* @param bool $onlyvisible If true, only count visible competencies in this course.
* @return competency[] Indexed by competency ID.
*/
public static function list_competencies($courseid, $onlyvisible) {
public static function list_competencies($courseid) {
global $DB;
$sql = 'SELECT comp.*
@@ -240,11 +233,6 @@ class course_competency extends persistent {
WHERE coursecomp.courseid = ?';
$params = array($courseid);
if ($onlyvisible) {
$sql .= ' AND comp.visible = ?';
$params[] = 1;
}
$sql .= ' ORDER BY coursecomp.sortorder ASC';
$results = $DB->get_recordset_sql($sql, $params);
$instances = array();
@@ -278,10 +266,9 @@ class course_competency extends persistent {
* List the course_competencies in this course.
*
* @param int $courseid The course id
* @param bool $onlyvisible If true, only count visible competencies in this course.
* @return course_competency[]
*/
public static function list_course_competencies($courseid, $onlyvisible) {
public static function list_course_competencies($courseid) {
global $DB;
$sql = 'SELECT coursecomp.*
@@ -291,11 +278,6 @@ class course_competency extends persistent {
WHERE coursecomp.courseid = ?';
$params = array($courseid);
if ($onlyvisible) {
$sql .= ' AND comp.visible = ?';
$params[] = 1;
}
$sql .= ' ORDER BY coursecomp.sortorder ASC';
$results = $DB->get_recordset_sql($sql, $params);
$instances = array();
+30 -10
View File
@@ -431,6 +431,12 @@ class external extends external_api {
VALUE_DEFAULT,
'children'
);
$onlyvisible = new external_value(
PARAM_BOOL,
'Only visible frameworks will be returned if visible true',
VALUE_DEFAULT,
false
);
$params = array(
'sort' => $sort,
@@ -438,7 +444,8 @@ class external extends external_api {
'skip' => $skip,
'limit' => $limit,
'context' => self::get_context_parameters(),
'includes' => $includes
'includes' => $includes,
'onlyvisible' => $onlyvisible
);
return new external_function_parameters($params);
}
@@ -453,12 +460,13 @@ class external extends external_api {
* @param int $limit
* @param array $context
* @param bool $includes
* @param bool $onlyvisible
*
* @return array
* @throws \required_capability_exception
* @throws invalid_parameter_exception
*/
public static function list_competency_frameworks($sort, $order, $skip, $limit, $context, $includes) {
public static function list_competency_frameworks($sort, $order, $skip, $limit, $context, $includes, $onlyvisible) {
global $PAGE;
$params = self::validate_parameters(self::list_competency_frameworks_parameters(),
@@ -468,7 +476,8 @@ class external extends external_api {
'skip' => $skip,
'limit' => $limit,
'context' => $context,
'includes' => $includes
'includes' => $includes,
'onlyvisible' => $onlyvisible
));
$context = self::get_context_from_params($params['context']);
@@ -484,7 +493,8 @@ class external extends external_api {
$params['skip'],
$params['limit'],
$context,
$params['includes']);
$params['includes'],
$params['onlyvisible']);
$records = array();
foreach ($results as $result) {
$exporter = new competency_framework_exporter($result);
@@ -827,7 +837,7 @@ class external extends external_api {
$safefilters = array();
$validcolumns = array('id', 'shortname', 'description', 'sortorder',
'idnumber', 'visible', 'parentid', 'competencyframeworkid');
'idnumber', 'parentid', 'competencyframeworkid');
foreach ($params['filters'] as $filter) {
if (!in_array($filter->column, $validcolumns)) {
throw new invalid_parameter_exception('Filter column was invalid');
@@ -962,7 +972,7 @@ class external extends external_api {
$safefilters = array();
$validcolumns = array('id', 'shortname', 'description', 'sortorder', 'idnumber',
'visible', 'parentid', 'competencyframeworkid');
'parentid', 'competencyframeworkid');
foreach ($params['filters'] as $filter) {
if (!in_array($filter['column'], $validcolumns)) {
throw new invalid_parameter_exception('Filter column was invalid');
@@ -2033,6 +2043,12 @@ class external extends external_api {
VALUE_DEFAULT,
'children'
);
$onlyvisible = new external_value(
PARAM_BOOL,
'If should list only visible templates',
VALUE_DEFAULT,
false
);
$params = array(
'sort' => $sort,
@@ -2040,7 +2056,8 @@ class external extends external_api {
'skip' => $skip,
'limit' => $limit,
'context' => self::get_context_parameters(),
'includes' => $includes
'includes' => $includes,
'onlyvisible' => $onlyvisible
);
return new external_function_parameters($params);
}
@@ -2054,10 +2071,11 @@ class external extends external_api {
* @param int $limit Number of rows to return.
* @param array $context
* @param bool $includes
* @param bool $onlyvisible
*
* @return array
*/
public static function list_templates($sort, $order, $skip, $limit, $context, $includes) {
public static function list_templates($sort, $order, $skip, $limit, $context, $includes, $onlyvisible) {
global $PAGE;
$params = self::validate_parameters(self::list_templates_parameters(),
@@ -2067,7 +2085,8 @@ class external extends external_api {
'skip' => $skip,
'limit' => $limit,
'context' => $context,
'includes' => $includes
'includes' => $includes,
'onlyvisible' => $onlyvisible
));
$context = self::get_context_from_params($params['context']);
@@ -2083,7 +2102,8 @@ class external extends external_api {
$params['skip'],
$params['limit'],
$context,
$params['includes']);
$params['includes'],
$params['onlyvisible']);
$records = array();
foreach ($results as $result) {
$exporter = new template_exporter($result);
@@ -99,11 +99,6 @@ class competency extends persistent {
$mform->setConstant('scaleid', $competency->get_scaleid());
}
$mform->addElement('selectyesno', 'visible',
get_string('visible', 'tool_lp'));
$mform->setDefault('visible', true);
$mform->addHelpButton('visible', 'visible', 'tool_lp');
$this->add_action_buttons(true, get_string('savechanges', 'tool_lp'));
}
+2 -14
View File
@@ -121,10 +121,9 @@ class template_competency extends persistent {
* Count the competencies in a template.
*
* @param int $templateid The template id
* @param bool $onlyvisible If true, only count visible competencies in this template.
* @return int
*/
public static function count_competencies($templateid, $onlyvisible) {
public static function count_competencies($templateid) {
global $DB;
$sql = 'SELECT COUNT(comp.id)
@@ -134,11 +133,6 @@ class template_competency extends persistent {
WHERE tplcomp.templateid = ? ';
$params = array($templateid);
if ($onlyvisible) {
$sql .= ' AND comp.visible = ?';
$params[] = 1;
}
$results = $DB->count_records_sql($sql, $params);
return $results;
@@ -148,10 +142,9 @@ class template_competency extends persistent {
* List the competencies in this template.
*
* @param int $templateid The template id
* @param bool $onlyvisible If true, only count visible competencies in this template.
* @return array[competency]
*/
public static function list_competencies($templateid, $onlyvisible) {
public static function list_competencies($templateid) {
global $DB;
$sql = 'SELECT comp.*
@@ -161,11 +154,6 @@ class template_competency extends persistent {
WHERE tplcomp.templateid = ?';
$params = array($templateid);
if ($onlyvisible) {
$sql .= ' AND comp.visible = ?';
$params[] = 1;
}
$sql .= 'ORDER BY tplcomp.sortorder ASC';
$results = $DB->get_records_sql($sql, $params);
-1
View File
@@ -13,7 +13,6 @@
<FIELD NAME="idnumber" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="competencyframeworkid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The framework this competency relates to."/>
<FIELD NAME="parentid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="The parent competency."/>
<FIELD NAME="visible" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Used to hide the competency."/>
<FIELD NAME="path" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Used to speed up queries that use an entire branch of the tree. Looks like /5/34/54."/>
<FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Relative sort order within the branch"/>
<FIELD NAME="ruletype" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false"/>
+15
View File
@@ -636,5 +636,20 @@ function xmldb_tool_lp_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2015111029, 'tool', 'lp');
}
if ($oldversion < 2015111030) {
// Define field visible to be removed from tool_lp_competency.
$table = new xmldb_table('tool_lp_competency');
$field = new xmldb_field('visible');
// Conditionally launch drop field visible.
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
// Lp savepoint reached.
upgrade_plugin_savepoint(true, 2015111030, 'tool', 'lp');
}
return true;
}
+2
View File
@@ -250,9 +250,11 @@ $string['taxonomy_selected_value'] = 'Selected value';
$string['taxonomy_skill'] = 'Skill';
$string['taxonomy_value'] = 'Value';
$string['template'] = 'Template';
$string['templatecohortpagemessage'] = 'Cohorts will not be synchronized while this template is hidden';
$string['templatecompetencies'] = 'Template competencies';
$string['templatecreated'] = 'Learning plan template created';
$string['templatename'] = 'Name';
$string['templateplanspagemessage'] = 'New user plans can not be created while this template is hidden';
$string['templates'] = 'Learning plan templates';
$string['templateupdated'] = 'Learning plan template updated';
$string['totalrequiredtocomplete'] = 'Total required to complete';
+9 -3
View File
@@ -55,8 +55,10 @@ if (($data = $form->get_data()) && !empty($data->cohorts)) {
// Create the template/cohort relationship.
$relation = \tool_lp\api::create_template_cohort($template, $cohortid);
// Create a plan for each member.
$i += \tool_lp\api::create_plans_from_template_cohort($template, $cohortid);
// Create a plan for each member if template visible.
if ($template->get_visible()) {
$i += \tool_lp\api::create_plans_from_template_cohort($template, $cohortid);
}
}
if ($i == 0) {
$notification = get_string('noplanswerecreated', 'tool_lp');
@@ -73,7 +75,11 @@ $output = $PAGE->get_renderer('tool_lp');
echo $output->header();
echo $output->heading($title);
echo $output->heading($subtitle, 3);
$form->display();
if ($template->get_visible() == false) {
// Display message to prevent that cohort will not be synchronzed if the template is hidden.
echo $output->notify_message(get_string('templatecohortpagemessage', 'tool_lp'));
}
echo $form->display();
$page = new \tool_lp\output\template_cohorts_page($template, $url);
echo $output->render($page);
echo $output->footer();
+7 -1
View File
@@ -65,7 +65,13 @@ $output = $PAGE->get_renderer('tool_lp');
echo $output->header();
echo $output->heading($title);
echo $output->heading($subtitle, 3);
echo $form->display();
// Do not display form when the template is hidden.
if ($template->get_visible()) {
echo $form->display();
} else {
// Display message that plan can not be created if the template is hidden.
echo $output->notify_message(get_string('templateplanspagemessage', 'tool_lp'));
}
$page = new \tool_lp\output\template_plans_page($template, $url);
echo $output->render($page);
echo $output->footer();
@@ -24,7 +24,7 @@
Context variables required for this template:
* framework -
* competencies - array of objects containing id, shortname, idnumber, sortorder, visible, parentid, competencyframeworkid, path
* competencies - array of objects containing id, shortname, idnumber, sortorder, parentid, competencyframeworkid, path
}}
<div data-region="competencymovetree" >
<label>{{#str}}selectcompetencymovetarget, tool_lp{{/str}}</label>
@@ -1,5 +1,5 @@
<li data-id="{{id}}">
<span {{^visible}}class="disabled"{{/visible}} draggable="true">
<span draggable="true">
{{shortname}}
</span>
{{#haschildren}}
@@ -6,10 +6,6 @@
<p>{{framework.description}}</p>
{{/framework}}
{{^competency.visible}}
( {{#str}} hidden, tool_lp{{/str}})
{{/competency.visible}}
{{#showrelatedcompetencies}}
{{> tool_lp/related_competencies }}
{{/showrelatedcompetencies}}
@@ -27,7 +27,7 @@
Context variables required for this template:
* framework -
* competencies - array of objects containing id, shortname, idnumber, sortorder, visible, parentid, competencyframeworkid, path
* competencies - array of objects containing id, shortname, idnumber, sortorder, parentid, competencyframeworkid, path
* canmanage - true if this user has permission to manage the competencies
}}
<div data-region="managecompetencies">
@@ -4,20 +4,18 @@
</p>
{{#relatedcompetencies}}
<ul>
{{#visible}}
<li>
{{#showdeleterelatedaction}}
<div class="pull-right">
<a href="#" data-action="deleterelation" id="id-related-{{id}}">{{#pix}}t/delete, core, {{#str}}delete{{/str}}{{/pix}}</a>
</div>
{{/showdeleterelatedaction}}
<p>
<a href="#" data-action="competency-dialogue" data-id="{{id}}">
{{shortname}}{{#idnumber}} {{idnumber}}{{/idnumber}}
</a>
</p>
</li>
{{/visible}}
<li>
{{#showdeleterelatedaction}}
<div class="pull-right">
<a href="#" data-action="deleterelation" id="id-related-{{id}}">{{#pix}}t/delete, core, {{#str}}delete{{/str}}{{/pix}}</a>
</div>
{{/showdeleterelatedaction}}
<p>
<a href="#" data-action="competency-dialogue" data-id="{{id}}">
{{shortname}}{{#idnumber}} {{idnumber}}{{/idnumber}}
</a>
</p>
</li>
</ul>
{{/relatedcompetencies}}
{{^relatedcompetencies}}
+78
View File
@@ -1620,4 +1620,82 @@ class tool_lp_api_testcase extends advanced_testcase {
}
}
/**
* Test when adding competency that belong to hidden framework to plan/template/course.
*/
public function test_hidden_framework() {
$this->resetAfterTest(true);
$this->setAdminUser();
$dg = $this->getDataGenerator();
$lpg = $this->getDataGenerator()->get_plugin_generator('tool_lp');
$user = $dg->create_user();
// Create a course.
$cat1 = $dg->create_category();
$course = $dg->create_course(array('category' => $cat1->id));
// Create a template.
$template = $lpg->create_template();
// Create a plan.
$plan = $lpg->create_plan(array('userid' => $user->id));
// Create a hidden framework.
$frm = array(
'visible' => false
);
$framework = $lpg->create_framework($frm);
$competency = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
// Linking competency that belong to hidden framework to course.
try {
api::add_competency_to_course($course->id, $competency->get_id());
$this->fail('A competency belonging to hidden framework can not be linked to course');
} catch (coding_exception $e) {
$this->assertTrue(true);
}
// Adding competency that belong to hidden framework to template.
try {
api::add_competency_to_template($template->get_id(), $competency->get_id());
$this->fail('A competency belonging to hidden framework can not be added to template');
} catch (coding_exception $e) {
$this->assertTrue(true);
}
// Adding competency that belong to hidden framework to plan.
try {
api::add_competency_to_plan($plan->get_id(), $competency->get_id());
$this->fail('A competency belonging to hidden framework can not be added to plan');
} catch (coding_exception $e) {
$this->assertTrue(true);
}
}
/**
* Test when using hidden template in plan/cohort.
*/
public function test_hidden_template() {
$this->resetAfterTest(true);
$this->setAdminUser();
$dg = $this->getDataGenerator();
$lpg = $this->getDataGenerator()->get_plugin_generator('tool_lp');
$user = $dg->create_user();
// Create a cohort.
$cohort = $dg->create_cohort();
// Create a hidden template.
$template = $lpg->create_template(array('visible' => false));
// Can not link hidden template to plan.
try {
api::create_plan_from_template($template->get_id(), $user->id);
$this->fail('Can not link a hidden template to plan');
} catch (coding_exception $e) {
$this->assertTrue(true);
}
// Can associate hidden template to cohort.
$templatecohort = api::create_template_cohort($template->get_id(), $cohort->id);
$this->assertInstanceOf('\tool_lp\template_cohort', $templatecohort);
}
}
+5 -17
View File
@@ -242,7 +242,6 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
'idnumber' => 'idnumber' . $number,
'description' => 'description' . $number,
'descriptionformat' => FORMAT_HTML,
'visible' => true,
'competencyframeworkid' => $frameworkid,
'sortorder' => 0
);
@@ -257,7 +256,6 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
'idnumber' => 'idnumber' . $number,
'description' => 'description' . $number,
'descriptionformat' => FORMAT_HTML,
'visible' => true,
'sortorder' => 0
);
$result = external::update_competency($competency);
@@ -608,7 +606,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
$this->assertEquals($result, 3);
$result = external::list_competency_frameworks('shortname', 'ASC', 0, 10,
array('contextid' => context_system::instance()->id), 'self');
array('contextid' => context_system::instance()->id), 'self', false);
$result = external_api::clean_returnvalue(external::list_competency_frameworks_returns(), $result);
$this->assertEquals(count($result), 3);
@@ -642,7 +640,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
$this->assertEquals($result, 3);
$result = external::list_competency_frameworks('shortname', 'ASC', 0, 10,
array('contextid' => context_system::instance()->id), 'self');
array('contextid' => context_system::instance()->id), 'self', false);
$result = external_api::clean_returnvalue(external::list_competency_frameworks_returns(), $result);
$this->assertEquals(count($result), 3);
@@ -685,7 +683,6 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
$this->assertEquals('idnumber1', $competency->idnumber);
$this->assertEquals('description1', $competency->description);
$this->assertEquals(FORMAT_HTML, $competency->descriptionformat);
$this->assertEquals(true, $competency->visible);
$this->assertEquals(0, $competency->parentid);
$this->assertEquals($framework->id, $competency->competencyframeworkid);
}
@@ -711,7 +708,6 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
$this->assertEquals('idnumber1', $competency->idnumber);
$this->assertEquals('description1', $competency->description);
$this->assertEquals(FORMAT_HTML, $competency->descriptionformat);
$this->assertEquals(true, $competency->visible);
$this->assertEquals(0, $competency->parentid);
$this->assertEquals($incat->id, $competency->competencyframeworkid);
@@ -734,7 +730,6 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
'idnumber' => 'id;"number',
'description' => 'de<>\\..scription',
'descriptionformat' => FORMAT_HTML,
'visible' => true,
'competencyframeworkid' => $framework->id,
'sortorder' => 0
);
@@ -761,7 +756,6 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
$this->assertEquals('idnumber1', $result->idnumber);
$this->assertEquals('description1', $result->description);
$this->assertEquals(FORMAT_HTML, $result->descriptionformat);
$this->assertEquals(true, $result->visible);
$this->assertEquals(0, $result->parentid);
$this->assertEquals($framework->id, $result->competencyframeworkid);
}
@@ -790,7 +784,6 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
$this->assertEquals('idnumber2', $result->idnumber);
$this->assertEquals('description2', $result->description);
$this->assertEquals(FORMAT_HTML, $result->descriptionformat);
$this->assertEquals(true, $result->visible);
$this->assertEquals(0, $result->parentid);
$this->assertEquals($catframework->id, $result->competencyframeworkid);
@@ -822,7 +815,6 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
$this->assertEquals('idnumber1', $result->idnumber);
$this->assertEquals('description1', $result->description);
$this->assertEquals(FORMAT_HTML, $result->descriptionformat);
$this->assertEquals(true, $result->visible);
$this->assertEquals(0, $result->parentid);
$this->assertEquals($framework->id, $result->competencyframeworkid);
}
@@ -850,7 +842,6 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
$this->assertEquals('idnumber2', $result->idnumber);
$this->assertEquals('description2', $result->description);
$this->assertEquals(FORMAT_HTML, $result->descriptionformat);
$this->assertEquals(true, $result->visible);
$this->assertEquals(0, $result->parentid);
$this->assertEquals($catframework->id, $result->competencyframeworkid);
@@ -1021,7 +1012,6 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
$this->assertEquals('shortname1', $result->shortname);
$this->assertEquals('idnumber1', $result->idnumber);
$this->assertEquals('description1', $result->description);
$this->assertEquals(true, $result->visible);
}
/**
@@ -1053,7 +1043,6 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
$this->assertEquals('shortname1', $result->shortname);
$this->assertEquals('idnumber1', $result->idnumber);
$this->assertEquals('description1', $result->description);
$this->assertEquals(true, $result->visible);
}
/**
@@ -1080,7 +1069,6 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
$this->assertEquals('shortname1', $result->shortname);
$this->assertEquals('idnumber1', $result->idnumber);
$this->assertEquals('description1', $result->description);
$this->assertEquals(true, $result->visible);
}
/**
@@ -1919,7 +1907,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
assign_capability('tool/lp:templateread', CAP_PROHIBIT, $this->userrole, $syscontextid, true);
accesslib_clear_all_caches_for_unit_testing();
try {
external::list_templates('id', 'ASC', 0, 10, array('contextid' => $syscontextid), 'children');
external::list_templates('id', 'ASC', 0, 10, array('contextid' => $syscontextid), 'children', false);
$this->fail('Invalid permissions');
} catch (required_capability_exception $e) {
}
@@ -1928,7 +1916,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
assign_capability('tool/lp:templateread', CAP_PREVENT, $this->userrole, $syscontextid, true);
assign_capability('tool/lp:templateread', CAP_ALLOW, $this->userrole, $catcontextid, true);
accesslib_clear_all_caches_for_unit_testing();
$result = external::list_templates('id', 'ASC', 0, 10, array('contextid' => $syscontextid), 'children');
$result = external::list_templates('id', 'ASC', 0, 10, array('contextid' => $syscontextid), 'children', false);
$result = external_api::clean_returnvalue(external::list_templates_returns(), $result);
$this->assertCount(2, $result);
$this->assertEquals($cat1->id, $result[0]['id']);
@@ -1937,7 +1925,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
// User with system permissions.
assign_capability('tool/lp:templateread', CAP_ALLOW, $this->userrole, $syscontextid, true);
accesslib_clear_all_caches_for_unit_testing();
$result = external::list_templates('id', 'DESC', 0, 3, array('contextid' => $catcontextid), 'parents');
$result = external::list_templates('id', 'DESC', 0, 3, array('contextid' => $catcontextid), 'parents', false);
$result = external_api::clean_returnvalue(external::list_templates_returns(), $result);
$this->assertCount(3, $result);
$this->assertEquals($cat2->id, $result[0]['id']);
-3
View File
@@ -103,9 +103,6 @@ class tool_lp_generator extends component_generator_base {
if (!isset($record->descriptionformat)) {
$record->descriptionformat = FORMAT_HTML;
}
if (!isset($record->visible)) {
$record->visible = 1;
}
if (isset($record->scaleconfiguration)
&& (is_array($record->scaleconfiguration) || is_object($record->scaleconfiguration))) {
// Conveniently encode the config.
+2 -17
View File
@@ -65,11 +65,6 @@ class tool_lp_persistent_testcase extends advanced_testcase {
'default' => 0,
'null' => NULL_NOT_ALLOWED
),
'visible' => array(
'type' => PARAM_BOOL,
'default' => true,
'null' => NULL_NOT_ALLOWED
),
'path' => array(
'type' => PARAM_RAW,
'default' => '',
@@ -142,7 +137,6 @@ class tool_lp_persistent_testcase extends advanced_testcase {
'description' => '',
'descriptionformat' => FORMAT_HTML,
'parentid' => 0,
'visible' => true,
'path' => '',
'sortorder' => null,
'competencyframeworkid' => null,
@@ -167,7 +161,6 @@ class tool_lp_persistent_testcase extends advanced_testcase {
'description' => 'xyz',
'descriptionformat' => FORMAT_PLAIN,
'parentid' => 999,
'visible' => false,
'path' => '/a/b/c',
'sortorder' => 12,
'competencyframeworkid' => 5,
@@ -270,15 +263,11 @@ class tool_lp_persistent_testcase extends advanced_testcase {
public function test_validation_type() {
$data = (object) array(
'idnumber' => 'abc',
'sortorder' => 0,
'visible' => 'NaN'
'sortorder' => 'NaN'
);
$p = new tool_lp_testable_persistent(0, $data);
$expected = array(
'visible' => new lang_string('invaliddata', 'error'),
);
$this->assertFalse($p->is_valid());
$this->assertEquals($expected, $p->get_errors());
$this->assertArrayHasKey('sortorder', $p->get_errors());
}
public function test_validation_null() {
@@ -438,10 +427,6 @@ class tool_lp_testable_persistent extends \tool_lp\persistent {
'type' => PARAM_INT,
'default' => 0
),
'visible' => array(
'type' => PARAM_BOOL,
'default' => 1
),
'path' => array(
'type' => PARAM_RAW,
'default' => ''
+1 -1
View File
@@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2015111030; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2015111031; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2014110400; // Requires this Moodle version.
$plugin->component = 'tool_lp'; // Full name of the plugin (used for diagnostics).