MDL-51031 tool_lp: Templates can be created on a category level
This commit is contained in:
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
@@ -1 +1 @@
|
||||
define(["jquery","core/templates","core/ajax","core/notification","core/str"],function(a,b,c,d,e){var f=0,g=function(c,d){a('[data-region="managetemplates"]').replaceWith(c),b.runTemplateJS(d)},h=function(a){b.render("tool_lp/manage_templates_page",a).done(g).fail(d.exception)},i=function(){var a=c.call([{methodname:"tool_lp_delete_template",args:{id:f}},{methodname:"tool_lp_data_for_templates_manage_page",args:[]}]);a[1].done(h).fail(d.exception)},j=function(b){b.preventDefault();var g=a(this).attr("data-templateid");f=g;var h=c.call([{methodname:"tool_lp_read_template",args:{id:f}}]);h[0].done(function(a){e.get_strings([{key:"confirm",component:"moodle"},{key:"deletetemplate",component:"tool_lp",param:a.shortname},{key:"delete",component:"moodle"},{key:"cancel",component:"moodle"}]).done(function(a){d.confirm(a[0],a[1],a[2],a[3],i)}).fail(d.exception)}).fail(d.exception)};return{deleteHandler:j}});
|
||||
define(["jquery","core/templates","core/ajax","core/notification","core/str"],function(a,b,c,d,e){var f=0,g=0,h=function(c,d){a('[data-region="managetemplates"]').replaceWith(c),b.runTemplateJS(d)},i=function(a){b.render("tool_lp/manage_templates_page",a).done(h).fail(d.exception)},j=function(){var a=c.call([{methodname:"tool_lp_delete_template",args:{id:g}},{methodname:"tool_lp_data_for_templates_manage_page",args:{pagecontext:{contextid:f}}}]);a[1].done(i).fail(d.exception)},k=function(b){b.preventDefault();var f=a(this).attr("data-templateid");g=f;var h=c.call([{methodname:"tool_lp_read_template",args:{id:g}}]);h[0].done(function(a){e.get_strings([{key:"confirm",component:"moodle"},{key:"deletetemplate",component:"tool_lp",param:a.shortname},{key:"delete",component:"moodle"},{key:"cancel",component:"moodle"}]).done(function(a){d.confirm(a[0],a[1],a[2],a[3],j)}).fail(d.exception)}).fail(d.exception)};return{deleteHandler:k,init:function(a){f=a}}});
|
||||
@@ -220,7 +220,7 @@ define(['jquery',
|
||||
{ methodname: 'tool_lp_add_competency_to_template',
|
||||
args: { templateid: localthis.itemid, competencyid: localthis.selectedCompetency } },
|
||||
{ methodname: 'tool_lp_data_for_template_competencies_page',
|
||||
args: { templateid: localthis.itemid } }
|
||||
args: { templateid: localthis.itemid, pagecontext: { contextid: localthis.pageContextId } } }
|
||||
]);
|
||||
pagerender = 'tool_lp/template_competencies_page';
|
||||
pageregion = 'templatecompetenciespage';
|
||||
@@ -272,7 +272,7 @@ define(['jquery',
|
||||
{ methodname: 'tool_lp_remove_competency_from_template',
|
||||
args: { templateid: localthis.itemid, competencyid: deleteid } },
|
||||
{ methodname: 'tool_lp_data_for_template_competencies_page',
|
||||
args: { templateid: localthis.itemid } }
|
||||
args: { templateid: localthis.itemid, pagecontext: { contextid: localthis.pageContextId } } }
|
||||
]);
|
||||
pagerender = 'tool_lp/template_competencies_page';
|
||||
pageregion = 'templatecompetenciespage';
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
define(['jquery', 'core/templates', 'core/ajax', 'core/notification', 'core/str'], function($, templates, ajax, notification, str) {
|
||||
// Private variables and functions.
|
||||
|
||||
/** @var {Number} pagecontextid The id of the context */
|
||||
var pagecontextid = 0;
|
||||
|
||||
/** @var {Number} templateid The id of the template */
|
||||
var templateid = 0;
|
||||
|
||||
@@ -63,7 +66,11 @@ define(['jquery', 'core/templates', 'core/ajax', 'core/notification', 'core/str'
|
||||
args: { id: templateid }
|
||||
}, {
|
||||
methodname: 'tool_lp_data_for_templates_manage_page',
|
||||
args: []
|
||||
args: {
|
||||
pagecontext: {
|
||||
contextid: pagecontextid
|
||||
}
|
||||
}
|
||||
}]);
|
||||
requests[1].done(reloadList).fail(notification.exception);
|
||||
};
|
||||
@@ -111,7 +118,15 @@ define(['jquery', 'core/templates', 'core/ajax', 'core/notification', 'core/str'
|
||||
* @method deleteHandler
|
||||
* @param {Event} e
|
||||
*/
|
||||
deleteHandler: confirmDelete
|
||||
deleteHandler: confirmDelete,
|
||||
|
||||
/**
|
||||
* Initialise the module.
|
||||
* @method init
|
||||
* @param {Number} contextid The context id of the page.
|
||||
*/
|
||||
init: function(contextid) {
|
||||
pagecontextid = contextid;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@@ -416,7 +416,7 @@ class api {
|
||||
global $DB;
|
||||
|
||||
// Get all the relevant contexts.
|
||||
$contexts = self::get_framework_related_contexts($context, $includes,
|
||||
$contexts = self::get_related_contexts($context, $includes,
|
||||
array('tool/lp:competencyread', 'tool/lp:competencymanage'));
|
||||
|
||||
if (empty($contexts)) {
|
||||
@@ -446,7 +446,7 @@ class api {
|
||||
global $DB;
|
||||
|
||||
// Get all the relevant contexts.
|
||||
$contexts = self::get_framework_related_contexts($context, $includes,
|
||||
$contexts = self::get_related_contexts($context, $includes,
|
||||
array('tool/lp:competencyread', 'tool/lp:competencymanage'));
|
||||
|
||||
if (empty($contexts)) {
|
||||
@@ -460,7 +460,9 @@ class api {
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches all the contexts relevant to frameworks.
|
||||
* Fetches all the relevant contexts.
|
||||
*
|
||||
* Note: This currently only supports system and category contexts.
|
||||
*
|
||||
* @param context $context The context to start from.
|
||||
* @param string $includes Defines what other contexts to find.
|
||||
@@ -471,7 +473,7 @@ class api {
|
||||
* @param array $hasanycapability Array of capabilities passed to {@link has_any_capability()} in each context.
|
||||
* @return context[] An array of contexts where keys are context IDs.
|
||||
*/
|
||||
public static function get_framework_related_contexts($context, $includes, array $hasanycapability = null) {
|
||||
public static function get_related_contexts($context, $includes, array $hasanycapability = null) {
|
||||
global $DB;
|
||||
|
||||
if (!in_array($includes, array('children', 'parents', 'self'))) {
|
||||
@@ -745,17 +747,18 @@ class api {
|
||||
/**
|
||||
* Create a learning plan template from a record containing all the data for the class.
|
||||
*
|
||||
* Requires tool/lp:templatemanage capability at the system context.
|
||||
* Requires tool/lp:templatemanage capability.
|
||||
*
|
||||
* @param stdClass $record Record containing all the data for an instance of the class.
|
||||
* @return template
|
||||
*/
|
||||
public static function create_template(stdClass $record) {
|
||||
$template = new template(0, $record);
|
||||
|
||||
// First we do a permissions check.
|
||||
require_capability('tool/lp:templatemanage', context_system::instance());
|
||||
require_capability('tool/lp:templatemanage', $template->get_context());
|
||||
|
||||
// OK - all set.
|
||||
$template = new template(0, $record);
|
||||
$id = $template->create();
|
||||
return $template;
|
||||
}
|
||||
@@ -763,35 +766,39 @@ class api {
|
||||
/**
|
||||
* Delete a learning plan template by id.
|
||||
*
|
||||
* Requires tool/lp:templatemanage capability at the system context.
|
||||
* Requires tool/lp:templatemanage capability.
|
||||
*
|
||||
* @param int $id The record to delete.
|
||||
* @return boolean
|
||||
*/
|
||||
public static function delete_template($id) {
|
||||
$template = new template($id);
|
||||
|
||||
// First we do a permissions check.
|
||||
require_capability('tool/lp:templatemanage', context_system::instance());
|
||||
require_capability('tool/lp:templatemanage', $template->get_context());
|
||||
|
||||
// OK - all set.
|
||||
$template = new template();
|
||||
$template->set_id($id);
|
||||
return $template->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the details for a learning plan template.
|
||||
*
|
||||
* Requires tool/lp:templatemanage capability at the system context.
|
||||
* Requires tool/lp:templatemanage capability.
|
||||
*
|
||||
* @param stdClass $record The new details for the template. Note - must contain an id that points to the template to update.
|
||||
* @return boolean
|
||||
*/
|
||||
public static function update_template($record) {
|
||||
// First we do a permissions check.
|
||||
require_capability('tool/lp:templatemanage', context_system::instance());
|
||||
$template = new template($record->id);
|
||||
|
||||
// OK - all set.
|
||||
$template = new template(0, $record);
|
||||
// First we do a permissions check.
|
||||
require_capability('tool/lp:templatemanage', $template->get_context());
|
||||
if (isset($record->contextid) && $record->contextid != $template->get_contextid()) {
|
||||
throw new coding_exception('Changing the context of an existing tempalte is forbidden.');
|
||||
}
|
||||
|
||||
$template->from_record($record);
|
||||
return $template->update();
|
||||
}
|
||||
|
||||
@@ -804,15 +811,17 @@ class api {
|
||||
* @return template
|
||||
*/
|
||||
public static function read_template($id) {
|
||||
$template = new template($id);
|
||||
$context = $template->get_context();
|
||||
|
||||
// First we do a permissions check.
|
||||
$context = context_system::instance();
|
||||
$caps = array('tool/lp:templateread', 'tool/lp:templatemanage');
|
||||
if (!has_any_capability($caps, $context)) {
|
||||
throw new required_capability_exception($context, 'tool/lp:templateread', 'nopermissions', '');
|
||||
}
|
||||
|
||||
// OK - all set.
|
||||
return new template($id);
|
||||
return $template;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -857,24 +866,40 @@ class api {
|
||||
*
|
||||
* Requires tool/lp:templateread capability at the system context.
|
||||
*
|
||||
* @param array $filters A list of filters to apply to the list.
|
||||
* @param string $sort The column to sort on
|
||||
* @param string $order ('ASC' or 'DESC')
|
||||
* @param int $skip Number of records to skip (pagination)
|
||||
* @param int $limit Max of records to return (pagination)
|
||||
* @param context $context The parent context of the frameworks.
|
||||
* @param string $includes Defines what other contexts to fetch frameworks from.
|
||||
* Accepted values are:
|
||||
* - children: All descendants
|
||||
* - parents: All parents, grand parents, etc...
|
||||
* - self: Context passed only.
|
||||
* @return array of competency_framework
|
||||
*/
|
||||
public static function list_templates($filters = array(), $sort = '', $order = 'ASC', $skip = 0, $limit = 0) {
|
||||
public static function list_templates($sort, $order, $skip, $limit, $context, $includes = 'children') {
|
||||
global $DB;
|
||||
|
||||
// Get all the relevant contexts.
|
||||
$contexts = self::get_related_contexts($context, $includes,
|
||||
array('tool/lp:templateread', 'tool/lp:templatemanage'));
|
||||
|
||||
// First we do a permissions check.
|
||||
$context = context_system::instance();
|
||||
$caps = array('tool/lp:templateread', 'tool/lp:templatemanage');
|
||||
if (!has_any_capability($caps, $context)) {
|
||||
if (empty($contexts)) {
|
||||
throw new required_capability_exception($context, 'tool/lp:templateread', 'nopermissions', '');
|
||||
}
|
||||
|
||||
// Make the order by.
|
||||
$orderby = '';
|
||||
if (!empty($sort)) {
|
||||
$orderby = $sort . ' ' . $order;
|
||||
}
|
||||
|
||||
// OK - all set.
|
||||
$template = new template();
|
||||
return $template->get_records($filters, $sort, $order, $skip, $limit);
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -882,20 +907,29 @@ class api {
|
||||
*
|
||||
* Requires tool/lp:templateread capability at the system context.
|
||||
*
|
||||
* @param array $filters A list of filters to apply to the list.
|
||||
* @param context $context The parent context of the frameworks.
|
||||
* @param string $includes Defines what other contexts to fetch frameworks from.
|
||||
* Accepted values are:
|
||||
* - children: All descendants
|
||||
* - parents: All parents, grand parents, etc...
|
||||
* - self: Context passed only.
|
||||
* @return int
|
||||
*/
|
||||
public static function count_templates($filters) {
|
||||
public static function count_templates($context, $includes) {
|
||||
global $DB;
|
||||
|
||||
// First we do a permissions check.
|
||||
$context = context_system::instance();
|
||||
$caps = array('tool/lp:templateread', 'tool/lp:templatemanage');
|
||||
if (!has_any_capability($caps, $context)) {
|
||||
$contexts = self::get_related_contexts($context, $includes,
|
||||
array('tool/lp:templateread', 'tool/lp:templatemanage'));
|
||||
|
||||
if (empty($contexts)) {
|
||||
throw new required_capability_exception($context, 'tool/lp:templateread', 'nopermissions', '');
|
||||
}
|
||||
|
||||
// OK - all set.
|
||||
$template = new template();
|
||||
return $template->count_records($filters);
|
||||
list($insql, $inparams) = $DB->get_in_or_equal(array_keys($contexts), SQL_PARAMS_NAMED);
|
||||
return $template->count_records_select("contextid $insql", $inparams);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -957,7 +991,8 @@ class api {
|
||||
*/
|
||||
public static function count_competencies_in_template($templateid) {
|
||||
// First we do a permissions check.
|
||||
$context = context_system::instance();
|
||||
$template = new template($templateid);
|
||||
$context = $template->get_context();
|
||||
$onlyvisible = 1;
|
||||
|
||||
$capabilities = array('tool/lp:templateread', 'tool/lp:templatemanage');
|
||||
@@ -982,7 +1017,8 @@ class api {
|
||||
*/
|
||||
public static function list_competencies_in_template($templateid) {
|
||||
// First we do a permissions check.
|
||||
$context = context_system::instance();
|
||||
$template = new template($templateid);
|
||||
$context = $template->get_context();
|
||||
$onlyvisible = 1;
|
||||
|
||||
$capabilities = array('tool/lp:templateread', 'tool/lp:templatemanage');
|
||||
@@ -1008,9 +1044,8 @@ class api {
|
||||
*/
|
||||
public static function add_competency_to_template($templateid, $competencyid) {
|
||||
// First we do a permissions check.
|
||||
$context = context_system::instance();
|
||||
|
||||
require_capability('tool/lp:templatemanage', $context);
|
||||
$template = new template($templateid);
|
||||
require_capability('tool/lp:templatemanage', $template->get_context());
|
||||
|
||||
$record = new stdClass();
|
||||
$record->templateid = $templateid;
|
||||
@@ -1042,15 +1077,14 @@ class api {
|
||||
*/
|
||||
public static function remove_competency_from_template($templateid, $competencyid) {
|
||||
// First we do a permissions check.
|
||||
$context = context_system::instance();
|
||||
|
||||
require_capability('tool/lp:templatemanage', $context);
|
||||
$template = new template($templateid);
|
||||
require_capability('tool/lp:templatemanage', $template->get_context());
|
||||
|
||||
$record = new stdClass();
|
||||
$record->templateid = $templateid;
|
||||
$record->competencyid = $competencyid;
|
||||
|
||||
$competency = new competency();
|
||||
$competency = new competency($competencyid);
|
||||
$competency->set_id($competencyid);
|
||||
if (!$competency->read()) {
|
||||
throw new coding_exception('The competency does not exist');
|
||||
|
||||
@@ -2145,6 +2145,10 @@ class external extends external_api {
|
||||
PARAM_INT,
|
||||
'User who modified this record last'
|
||||
);
|
||||
$contextid = new external_value(
|
||||
PARAM_INT,
|
||||
'The context ID the template belongs to'
|
||||
);
|
||||
|
||||
$returns = array(
|
||||
'id' => $id,
|
||||
@@ -2158,6 +2162,7 @@ class external extends external_api {
|
||||
'timecreated' => $timecreated,
|
||||
'timemodified' => $timemodified,
|
||||
'usermodified' => $usermodified,
|
||||
'contextid' => $contextid,
|
||||
);
|
||||
return new external_single_structure($returns);
|
||||
}
|
||||
@@ -2210,6 +2215,7 @@ class external extends external_api {
|
||||
'description' => $description,
|
||||
'descriptionformat' => $descriptionformat,
|
||||
'visible' => $visible,
|
||||
'context' => self::get_context_parameters()
|
||||
);
|
||||
return new external_function_parameters($params);
|
||||
}
|
||||
@@ -2231,9 +2237,10 @@ class external extends external_api {
|
||||
* @param string $description The description of the template.
|
||||
* @param int $descriptionformat The format of the description
|
||||
* @param bool $visible Is this template visible.
|
||||
* @param array $context The context info.
|
||||
* @return \stdClass Record of new template.
|
||||
*/
|
||||
public static function create_template($shortname, $idnumber, $duedate, $description, $descriptionformat, $visible) {
|
||||
public static function create_template($shortname, $idnumber, $duedate, $description, $descriptionformat, $visible, $context) {
|
||||
$params = self::validate_parameters(self::create_template_parameters(),
|
||||
array(
|
||||
'shortname' => $shortname,
|
||||
@@ -2242,9 +2249,14 @@ class external extends external_api {
|
||||
'description' => $description,
|
||||
'descriptionformat' => $descriptionformat,
|
||||
'visible' => $visible,
|
||||
'context' => $context
|
||||
));
|
||||
$context = self::get_context_from_params($params['context']);
|
||||
self::validate_context($context);
|
||||
|
||||
unset($params['context']);
|
||||
$params = (object) $params;
|
||||
$params->contextid = $context->id;
|
||||
|
||||
$result = api::create_template($params);
|
||||
return $result->to_record();
|
||||
@@ -2471,7 +2483,46 @@ class external extends external_api {
|
||||
* @return \external_function_parameters
|
||||
*/
|
||||
public static function list_templates_parameters() {
|
||||
return self::list_parameters_structure();
|
||||
$sort = new external_value(
|
||||
PARAM_ALPHANUMEXT,
|
||||
'Column to sort by.',
|
||||
VALUE_DEFAULT,
|
||||
''
|
||||
);
|
||||
$order = new external_value(
|
||||
PARAM_ALPHA,
|
||||
'Sort direction. Should be either ASC or DESC',
|
||||
VALUE_DEFAULT,
|
||||
''
|
||||
);
|
||||
$skip = new external_value(
|
||||
PARAM_INT,
|
||||
'Skip this number of records before returning results',
|
||||
VALUE_DEFAULT,
|
||||
0
|
||||
);
|
||||
$limit = new external_value(
|
||||
PARAM_INT,
|
||||
'Return this number of records at most.',
|
||||
VALUE_DEFAULT,
|
||||
0
|
||||
);
|
||||
$includes = new external_value(
|
||||
PARAM_ALPHA,
|
||||
'What other contexts to fetch the templates from. (children, parents, self)',
|
||||
VALUE_DEFAULT,
|
||||
'children'
|
||||
);
|
||||
|
||||
$params = array(
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'skip' => $skip,
|
||||
'limit' => $limit,
|
||||
'context' => self::get_context_parameters(),
|
||||
'includes' => $includes
|
||||
);
|
||||
return new external_function_parameters($params);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2485,42 +2536,39 @@ class external extends external_api {
|
||||
/**
|
||||
* List the existing learning plan templates
|
||||
*
|
||||
* @param array $filters Filters to apply.
|
||||
* @param string $sort Field to sort by.
|
||||
* @param string $order Sort order.
|
||||
* @param int $skip Limitstart.
|
||||
* @param int $limit Number of rows to return.
|
||||
* @param array $context
|
||||
* @param bool $includes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function list_templates($filters, $sort, $order, $skip, $limit) {
|
||||
public static function list_templates($sort, $order, $skip, $limit, $context, $includes) {
|
||||
$params = self::validate_parameters(self::list_templates_parameters(),
|
||||
array(
|
||||
'filters' => $filters,
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'skip' => $skip,
|
||||
'limit' => $limit
|
||||
'limit' => $limit,
|
||||
'context' => $context,
|
||||
'includes' => $includes
|
||||
));
|
||||
|
||||
$context = self::get_context_from_params($params['context']);
|
||||
self::validate_context($context);
|
||||
|
||||
if ($params['order'] !== '' && $params['order'] !== 'ASC' && $params['order'] !== 'DESC') {
|
||||
throw new invalid_parameter_exception('Invalid order param. Must be ASC, DESC or empty.');
|
||||
}
|
||||
|
||||
$safefilters = array();
|
||||
$validcolumns = array('id', 'shortname', 'description', 'sortorder', 'idnumber', 'visible');
|
||||
foreach ($params['filters'] as $filter) {
|
||||
if (!in_array($filter->column, $validcolumns)) {
|
||||
throw new invalid_parameter_exception('Filter column was invalid');
|
||||
}
|
||||
$safefilters[$filter->column] = $filter->value;
|
||||
}
|
||||
|
||||
$results = api::list_templates($safefilters,
|
||||
$params['sort'],
|
||||
$params['order'],
|
||||
$params['skip'],
|
||||
$params['limit']);
|
||||
$results = api::list_templates($params['sort'],
|
||||
$params['order'],
|
||||
$params['skip'],
|
||||
$params['limit'],
|
||||
$context,
|
||||
$params['includes']);
|
||||
$records = array();
|
||||
foreach ($results as $result) {
|
||||
$record = $result->to_record();
|
||||
@@ -2544,15 +2592,16 @@ class external extends external_api {
|
||||
* @return \external_function_parameters
|
||||
*/
|
||||
public static function count_templates_parameters() {
|
||||
$filters = new external_multiple_structure(new external_single_structure(
|
||||
array(
|
||||
'column' => new external_value(PARAM_ALPHANUMEXT, 'Column name to filter by'),
|
||||
'value' => new external_value(PARAM_TEXT, 'Value to filter by. Must be exact match')
|
||||
)
|
||||
));
|
||||
$includes = new external_value(
|
||||
PARAM_ALPHA,
|
||||
'What other contextes to fetch the frameworks from. (children, parents, self)',
|
||||
VALUE_DEFAULT,
|
||||
'children'
|
||||
);
|
||||
|
||||
$params = array(
|
||||
'filters' => $filters,
|
||||
'context' => self::get_context_parameters(),
|
||||
'includes' => $includes
|
||||
);
|
||||
return new external_function_parameters($params);
|
||||
}
|
||||
@@ -2571,22 +2620,16 @@ class external extends external_api {
|
||||
* @param array $filters Filters to allow.
|
||||
* @return boolean
|
||||
*/
|
||||
public static function count_templates($filters) {
|
||||
public static function count_templates($context, $includes) {
|
||||
$params = self::validate_parameters(self::count_templates_parameters(),
|
||||
array(
|
||||
'filters' => $filters
|
||||
'context' => $context,
|
||||
'includes' => $includes
|
||||
));
|
||||
$context = self::get_context_from_params($params['context']);
|
||||
self::validate_context($context);
|
||||
|
||||
$safefilters = array();
|
||||
$validcolumns = array('id', 'shortname', 'description', 'sortorder', 'idnumber', 'visible');
|
||||
foreach ($params['filters'] as $filter) {
|
||||
if (!in_array($filter->column, $validcolumns)) {
|
||||
throw new invalid_parameter_exception('Filter column was invalid');
|
||||
}
|
||||
$safefilters[$filter->column] = $filter->value;
|
||||
}
|
||||
|
||||
return api::count_templates($safefilters);
|
||||
return api::count_templates($context, $includes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2660,8 +2703,7 @@ class external extends external_api {
|
||||
* @return \external_function_parameters
|
||||
*/
|
||||
public static function data_for_templates_manage_page_parameters() {
|
||||
// No params required.
|
||||
$params = array();
|
||||
$params = array('pagecontext' => self::get_context_parameters());
|
||||
return new external_function_parameters($params);
|
||||
}
|
||||
|
||||
@@ -2676,12 +2718,19 @@ class external extends external_api {
|
||||
/**
|
||||
* Loads the data required to render the templates_manage_page template.
|
||||
*
|
||||
* @param array $pagecontext The page context info.
|
||||
* @return boolean
|
||||
*/
|
||||
public static function data_for_templates_manage_page() {
|
||||
public static function data_for_templates_manage_page($pagecontext) {
|
||||
global $PAGE;
|
||||
|
||||
$renderable = new output\manage_templates_page();
|
||||
$params = self::validate_parameters(self::data_for_templates_manage_page_parameters(), array(
|
||||
'pagecontext' => $pagecontext
|
||||
));
|
||||
$context = self::get_context_from_params($params['pagecontext']);
|
||||
self::validate_context($context);
|
||||
|
||||
$renderable = new output\manage_templates_page($context);
|
||||
$renderer = $PAGE->get_renderer('tool_lp');
|
||||
|
||||
$data = $renderable->export_for_template($renderer);
|
||||
@@ -3039,7 +3088,7 @@ class external extends external_api {
|
||||
'The template id',
|
||||
VALUE_REQUIRED
|
||||
);
|
||||
$params = array('templateid' => $templateid);
|
||||
$params = array('templateid' => $templateid, 'pagecontext' => self::get_context_parameters());
|
||||
return new external_function_parameters($params);
|
||||
}
|
||||
|
||||
@@ -3055,16 +3104,21 @@ class external extends external_api {
|
||||
* Loads the data required to render the template_competencies_page template.
|
||||
*
|
||||
* @param int $templateid Template id.
|
||||
* @param array $pagecontext The page context info.
|
||||
* @return boolean
|
||||
*/
|
||||
public static function data_for_template_competencies_page($templateid) {
|
||||
public static function data_for_template_competencies_page($templateid, $pagecontext) {
|
||||
global $PAGE;
|
||||
$params = self::validate_parameters(self::data_for_template_competencies_page_parameters(),
|
||||
array(
|
||||
'templateid' => $templateid,
|
||||
'pagecontext' => $pagecontext
|
||||
));
|
||||
|
||||
$renderable = new output\template_competencies_page($params['templateid']);
|
||||
$context = self::get_context_from_params($params['pagecontext']);
|
||||
self::validate_context($context);
|
||||
|
||||
$renderable = new output\template_competencies_page($params['templateid'], $context);
|
||||
$renderer = $PAGE->get_renderer('tool_lp');
|
||||
|
||||
$data = $renderable->export_for_template($renderer);
|
||||
|
||||
@@ -45,7 +45,8 @@ class template extends moodleform {
|
||||
*/
|
||||
public function definition() {
|
||||
$mform = $this->_form;
|
||||
$id = $this->_customdata;
|
||||
$id = $this->_customdata['id'];
|
||||
$context = $this->_customdata['context'];
|
||||
|
||||
$mform->addElement('hidden', 'id');
|
||||
$mform->setType('id', PARAM_INT);
|
||||
@@ -72,6 +73,9 @@ class template extends moodleform {
|
||||
$mform->setDefault('visible', true);
|
||||
$mform->addHelpButton('visible', 'visible', 'tool_lp');
|
||||
|
||||
$mform->addElement('static', 'context', get_string('context', 'core_role'));
|
||||
$mform->setDefault('context', $context->get_context_name());
|
||||
|
||||
$this->add_action_buttons(true, get_string('savechanges', 'tool_lp'));
|
||||
|
||||
if (!empty($id)) {
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
*/
|
||||
namespace tool_lp\output;
|
||||
|
||||
use context;
|
||||
use renderable;
|
||||
use templatable;
|
||||
use renderer_base;
|
||||
@@ -40,29 +41,29 @@ use tool_lp\api;
|
||||
*/
|
||||
class manage_templates_page implements renderable, templatable {
|
||||
|
||||
/** @var context The context in which everything is happening. */
|
||||
protected $pagecontext;
|
||||
|
||||
/** @var array $navigation List of links to display on the page. Each link contains a url and a title. */
|
||||
protected $navigation = array();
|
||||
|
||||
/** @var array $templates List of learning plan templates. */
|
||||
protected $templates = array();
|
||||
|
||||
/** @var bool $canmanage Result of permissions checks. */
|
||||
protected $canmanage = false;
|
||||
|
||||
/**
|
||||
* Construct this renderable.
|
||||
*/
|
||||
public function __construct() {
|
||||
public function __construct(context $pagecontext) {
|
||||
$this->pagecontext = $pagecontext;
|
||||
|
||||
$addpage = new single_button(
|
||||
new moodle_url('/admin/tool/lp/edittemplate.php'),
|
||||
get_string('addnewtemplate', 'tool_lp')
|
||||
new moodle_url('/admin/tool/lp/edittemplate.php', array('pagecontextid' => $this->pagecontext->id)),
|
||||
get_string('addnewtemplate', 'tool_lp'),
|
||||
'get'
|
||||
);
|
||||
$this->navigation[] = $addpage;
|
||||
|
||||
$this->templates = api::list_templates(array(), 'sortorder', 'ASC', 0, 0);
|
||||
|
||||
$context = context_system::instance();
|
||||
$this->canmanage = has_capability('tool/lp:planmanageall', $context);
|
||||
$this->templates = api::list_templates('sortorder', 'ASC', 0, 0, $this->pagecontext);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,10 +74,12 @@ class manage_templates_page implements renderable, templatable {
|
||||
*/
|
||||
public function export_for_template(renderer_base $output) {
|
||||
$data = new stdClass();
|
||||
$data->canmanage = $this->canmanage;
|
||||
$data->pagecontextid = $this->pagecontext->id;
|
||||
$data->templates = array();
|
||||
foreach ($this->templates as $template) {
|
||||
$record = $template->to_record();
|
||||
$record->canmanage = has_capability('tool/lp:templatemanage', $template->get_context());
|
||||
$record->contextname = $template->get_context()->get_context_name();
|
||||
$data->templates[] = $record;
|
||||
}
|
||||
$data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
|
||||
|
||||
@@ -28,7 +28,7 @@ use templatable;
|
||||
use renderer_base;
|
||||
use stdClass;
|
||||
use moodle_url;
|
||||
use context_system;
|
||||
use context;
|
||||
use tool_lp\api;
|
||||
|
||||
/**
|
||||
@@ -54,19 +54,22 @@ class template_competencies_page implements renderable, templatable {
|
||||
/** @var string $manageurl manage url. */
|
||||
protected $manageurl = null;
|
||||
|
||||
/** @var context $pagecontext The page context. */
|
||||
protected $pagecontext = null;
|
||||
|
||||
/**
|
||||
* Construct this renderable.
|
||||
*
|
||||
* @param int $templateid The learning plan template id for this page.
|
||||
*/
|
||||
public function __construct($templateid) {
|
||||
$context = context_system::instance();
|
||||
|
||||
public function __construct($templateid, context $pagecontext) {
|
||||
$this->pagecontext = $pagecontext;
|
||||
$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:templatemanage', $context);
|
||||
$this->manageurl = new moodle_url('/admin/tool/lp/competencyframeworks.php');
|
||||
$this->canmanagecompetencyframeworks = has_capability('tool/lp:competencymanage', $this->pagecontext);
|
||||
$this->canmanagetemplatecompetencies = has_capability('tool/lp:templatemanage', $this->pagecontext);
|
||||
$this->manageurl = new moodle_url('/admin/tool/lp/competencyframeworks.php',
|
||||
array('pagecontextid' => $this->pagecontext->id));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,6 +80,7 @@ class template_competencies_page implements renderable, templatable {
|
||||
*/
|
||||
public function export_for_template(renderer_base $output) {
|
||||
$data = new stdClass();
|
||||
$data->pagecontextid = $this->pagecontext->id;
|
||||
$data->templateid = $this->templateid;
|
||||
$data->competencies = array();
|
||||
foreach ($this->competencies as $competency) {
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
*/
|
||||
namespace tool_lp;
|
||||
|
||||
use context;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
@@ -36,7 +37,7 @@ class template extends persistent {
|
||||
/** @var string $shortname Short name for this template */
|
||||
private $shortname = '';
|
||||
|
||||
/** @var string $description Description for this framework */
|
||||
/** @var string $description Description for this template */
|
||||
private $description = '';
|
||||
|
||||
/** @var int $descriptionformat Format for the description */
|
||||
@@ -54,6 +55,8 @@ class template extends persistent {
|
||||
/** @var bool $visible Used to show/hide this template */
|
||||
private $visible = true;
|
||||
|
||||
/** @var int $contextid The context ID in which the template is set. */
|
||||
private $contextid = null;
|
||||
/**
|
||||
* Method that provides the table name matching this class.
|
||||
*
|
||||
@@ -81,6 +84,24 @@ class template extends persistent {
|
||||
$this->shortname = $shortname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the context.
|
||||
*
|
||||
* @return context The context
|
||||
*/
|
||||
public function get_context() {
|
||||
return context::instance_by_id($this->contextid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contextid.
|
||||
*
|
||||
* @return string The contextid
|
||||
*/
|
||||
public function get_contextid() {
|
||||
return $this->contextid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the description format.
|
||||
*
|
||||
@@ -229,6 +250,9 @@ class template extends persistent {
|
||||
if (isset($record->usermodified)) {
|
||||
$this->set_usermodified($record->usermodified);
|
||||
}
|
||||
if (isset($record->contextid)) {
|
||||
$this->contextid = $record->contextid;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -255,6 +279,7 @@ class template extends persistent {
|
||||
$record->timecreated = $this->get_timecreated();
|
||||
$record->timemodified = $this->get_timemodified();
|
||||
$record->usermodified = $this->get_usermodified();
|
||||
$record->contextid = $this->get_contextid();
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
@@ -98,14 +98,14 @@ $capabilities = array(
|
||||
),
|
||||
'tool/lp:templatemanage' => array(
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_SYSTEM,
|
||||
'contextlevel' => CONTEXT_COURSECAT,
|
||||
'archetypes' => array(
|
||||
),
|
||||
'clonepermissionsfrom' => 'moodle/site:config'
|
||||
),
|
||||
'tool/lp:templateread' => array(
|
||||
'captype' => 'read',
|
||||
'contextlevel' => CONTEXT_SYSTEM,
|
||||
'contextlevel' => CONTEXT_COURSECAT,
|
||||
'archetypes' => array(
|
||||
'user' => CAP_ALLOW
|
||||
),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="admin/tool/lp/db" VERSION="20150814" COMMENT="XMLDB file for Moodle admin/tool/lp"
|
||||
<XMLDB PATH="admin/tool/lp/db" VERSION="20150917" COMMENT="XMLDB file for Moodle admin/tool/lp"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
@@ -92,6 +92,7 @@
|
||||
<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="contextid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||
<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"/>
|
||||
|
||||
@@ -70,7 +70,7 @@ function xmldb_tool_lp_upgrade($oldversion) {
|
||||
// Define field contextid to be added to tool_lp_competency_framework.
|
||||
$table = new xmldb_table('tool_lp_competency_framework');
|
||||
$field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null,
|
||||
context_system::instance()->id, 'id');
|
||||
context_system::instance()->id, 'shortname');
|
||||
|
||||
// Conditionally launch add field contextid.
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
@@ -96,6 +96,23 @@ function xmldb_tool_lp_upgrade($oldversion) {
|
||||
upgrade_plugin_savepoint(true, 2015052406, 'tool', 'lp');
|
||||
}
|
||||
|
||||
if ($oldversion < 2015052407) {
|
||||
|
||||
// Define field contextid to be added to tool_lp_template.
|
||||
$table = new xmldb_table('tool_lp_template');
|
||||
$field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null,
|
||||
context_system::instance()->id, 'shortname');
|
||||
|
||||
// Conditionally launch add field contextid.
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// Lp savepoint reached.
|
||||
upgrade_plugin_savepoint(true, 2015052407, 'tool', 'lp');
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -25,26 +25,45 @@
|
||||
require_once(__DIR__ . '/../../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
admin_externalpage_setup('toollplearningplans');
|
||||
$id = optional_param('id', 0, PARAM_INT);
|
||||
$pagecontextid = required_param('pagecontextid', PARAM_INT); // Reference to where we can from.
|
||||
|
||||
if (!empty($id)) {
|
||||
// Always use the context from the framework when it exists.
|
||||
$template = new \tool_lp\template($id);
|
||||
$context = $template->get_context();
|
||||
} else {
|
||||
$context = context::instance_by_id($pagecontextid);
|
||||
}
|
||||
|
||||
// We check that we have the permission to edit this framework, in its own context.
|
||||
require_login();
|
||||
require_capability('tool/lp:templatemanage', $context);
|
||||
|
||||
// We keep the original context in the URLs, so that we remain in the same context.
|
||||
$url = new moodle_url("/admin/tool/lp/edittemplate.php", array('id' => $id, 'pagecontextid' => $pagecontextid));
|
||||
$templatesurl = new moodle_url('/admin/tool/lp/learningplans.php', array('pagecontextid' => $pagecontextid));
|
||||
$formurl = new moodle_url("/admin/tool/lp/edittemplate.php", array('pagecontextid' => $pagecontextid));
|
||||
|
||||
$title = get_string('templates', 'tool_lp');
|
||||
$id = optional_param('id', 0, PARAM_INT);
|
||||
if (empty($id)) {
|
||||
$pagetitle = get_string('addnewtemplate', 'tool_lp');
|
||||
} else {
|
||||
$pagetitle = get_string('edittemplate', 'tool_lp');
|
||||
}
|
||||
// Set up the page.
|
||||
$url = new moodle_url("/admin/tool/lp/edittemplate.php", array('id' => $id));
|
||||
$PAGE->navigation->override_active_url($templatesurl);
|
||||
$PAGE->set_context(context::instance_by_id($pagecontextid));
|
||||
$PAGE->set_pagelayout('admin');
|
||||
$PAGE->set_url($url);
|
||||
$PAGE->set_title($title);
|
||||
$PAGE->set_heading($title);
|
||||
$output = $PAGE->get_renderer('tool_lp');
|
||||
|
||||
$form = new \tool_lp\form\template(null, $id);
|
||||
$form = new \tool_lp\form\template($formurl->out(false), array('id' => $id, 'context' => $context));
|
||||
|
||||
if ($form->is_cancelled()) {
|
||||
redirect(new moodle_url('/admin/tool/lp/learningplans.php'));
|
||||
redirect($templatesurl);
|
||||
}
|
||||
|
||||
echo $output->header();
|
||||
@@ -59,14 +78,15 @@ if ($data) {
|
||||
if (empty($data->id)) {
|
||||
// Create new template.
|
||||
require_sesskey();
|
||||
$data->contextid = $context->id;
|
||||
\tool_lp\api::create_template($data);
|
||||
echo $output->notification(get_string('templatecreated', 'tool_lp'), 'notifysuccess');
|
||||
echo $output->continue_button('/admin/tool/lp/learningplans.php');
|
||||
echo $output->continue_button($templatesurl);
|
||||
} else {
|
||||
require_sesskey();
|
||||
\tool_lp\api::update_template($data);
|
||||
echo $output->notification(get_string('templateupdated', 'tool_lp'), 'notifysuccess');
|
||||
echo $output->continue_button('/admin/tool/lp/learningplans.php');
|
||||
echo $output->continue_button($templatesurl);
|
||||
}
|
||||
} else {
|
||||
$form->display();
|
||||
|
||||
@@ -25,12 +25,20 @@
|
||||
require_once(__DIR__ . '/../../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
admin_externalpage_setup('toollplearningplans');
|
||||
$pagecontextid = required_param('pagecontextid', PARAM_INT);
|
||||
$context = context::instance_by_id($pagecontextid);
|
||||
|
||||
$url = new moodle_url('/admin/tool/lp/learningplans.php', array('pagecontextid' => $pagecontextid));
|
||||
|
||||
require_login();
|
||||
require_capability('tool/lp:templatemanage', $context);
|
||||
|
||||
$title = get_string('learningplans', 'tool_lp');
|
||||
$pagetitle = get_string('templates', 'tool_lp');
|
||||
|
||||
// Set up the page.
|
||||
$url = new moodle_url("/admin/tool/lp/learningplans.php");
|
||||
$PAGE->set_context($context);
|
||||
$PAGE->set_pagelayout('admin');
|
||||
$PAGE->set_url($url);
|
||||
$PAGE->set_title($title);
|
||||
$PAGE->set_heading($title);
|
||||
@@ -38,7 +46,7 @@ $output = $PAGE->get_renderer('tool_lp');
|
||||
echo $output->header();
|
||||
echo $output->heading($pagetitle);
|
||||
|
||||
$page = new \tool_lp\output\manage_templates_page();
|
||||
$page = new \tool_lp\output\manage_templates_page($context);
|
||||
echo $output->render($page);
|
||||
|
||||
echo $output->footer();
|
||||
|
||||
@@ -37,8 +37,8 @@ $ADMIN->add('root', $temp, 'badges');
|
||||
$temp = new admin_externalpage(
|
||||
'toollplearningplans',
|
||||
get_string('learningplans', 'tool_lp'),
|
||||
new moodle_url('/admin/tool/lp/learningplans.php'),
|
||||
'tool/lp:planmanageall'
|
||||
new moodle_url('/admin/tool/lp/learningplans.php', array('pagecontextid' => context_system::instance()->id)),
|
||||
'tool/lp:templatemanage'
|
||||
);
|
||||
$ADMIN->add('root', $temp, 'toollpcompetencies');
|
||||
|
||||
|
||||
@@ -26,15 +26,27 @@ require_once(__DIR__ . '/../../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
$templateid = required_param('templateid', PARAM_INT);
|
||||
$pagecontextid = required_param('pagecontextid', PARAM_INT); // Reference to the context we came from.
|
||||
|
||||
require_login();
|
||||
|
||||
$pagecontext = context::instance_by_id($pagecontextid);
|
||||
$template = \tool_lp\api::read_template($templateid);
|
||||
|
||||
admin_externalpage_setup('toollplearningplans');
|
||||
$context = $template->get_context();
|
||||
require_capability('tool/lp:templatemanage', $context);
|
||||
|
||||
// Set up the page.
|
||||
$url = new moodle_url('/admin/tool/lp/templatecompetencies.php', array('templateid' => $template->get_id()));
|
||||
$url = new moodle_url('/admin/tool/lp/templatecompetencies.php', array('templateid' => $template->get_id(),
|
||||
'pagecontextid' => $pagecontextid));
|
||||
$templatesurl = new moodle_url('/admin/tool/lp/learningplans.php', array('pagecontextid' => $pagecontextid));
|
||||
|
||||
$PAGE->navigation->override_active_url($templatesurl);
|
||||
$PAGE->set_context($pagecontext);
|
||||
|
||||
$title = get_string('templatecompetencies', 'tool_lp');
|
||||
$templatename = format_text($template->get_shortname());
|
||||
|
||||
$PAGE->set_pagelayout('admin');
|
||||
$PAGE->set_url($url);
|
||||
$PAGE->set_title($title);
|
||||
$PAGE->set_heading($templatename);
|
||||
@@ -44,6 +56,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->get_id());
|
||||
$page = new \tool_lp\output\template_competencies_page($template->get_id(), $pagecontext);
|
||||
echo $output->render($page);
|
||||
echo $output->footer();
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
|
||||
Context variables required for this template:
|
||||
* templates - array of objects containing id, shortname, idnumber, sortorder, visible
|
||||
* canmanage - true if this user has permission to manage the templates
|
||||
* navigation - array of strings containing buttons for navigation
|
||||
}}
|
||||
<div data-region="managetemplates">
|
||||
@@ -39,13 +38,15 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">{{#str}}templatename, tool_lp{{/str}}</th>
|
||||
<th scope="col">{{#str}}context, core_role{{/str}}</th>
|
||||
<th scope="col">{{#str}}actions, tool_lp{{/str}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="drag-parentnode">
|
||||
{{#templates}}
|
||||
<tr class="drag-samenode" data-templateid="{{id}}">
|
||||
<td><span class="drag-handlecontainer"></span><span><a href="{{pluginbaseurl}}/templatecompetencies.php?templateid={{id}}">{{shortname}} {{idnumber}}</a></span> {{^visible}}{{#str}}hiddenhint, tool_lp{{/str}}{{/visible}}</td>
|
||||
<td><span class="drag-handlecontainer"></span><span><a href="{{pluginbaseurl}}/templatecompetencies.php?templateid={{id}}&pagecontextid={{pagecontextid}}">{{shortname}} {{idnumber}}</a></span> {{^visible}}{{#str}}hiddenhint, tool_lp{{/str}}{{/visible}}</td>
|
||||
<td>{{contextname}}</td>
|
||||
<td>
|
||||
{{#canmanage}}
|
||||
<ul class="templateactions">
|
||||
@@ -53,7 +54,7 @@
|
||||
<a href="#">{{#str}}edit{{/str}}</a><b class="caret"></b>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a href="{{pluginbaseurl}}/edittemplate.php?id={{id}}">
|
||||
<a href="{{pluginbaseurl}}/edittemplate.php?id={{id}}&pagecontextid={{pagecontextid}}">
|
||||
{{#pix}}t/edit{{/pix}} {{#str}}edit{{/str}}
|
||||
</a>
|
||||
</li>
|
||||
@@ -90,6 +91,8 @@ require(['tool_lp/templatedelete',
|
||||
'tool_lp/templatemove'],
|
||||
function(deleteMod, menubar, moveMod) {
|
||||
|
||||
deleteMod.init({{pagecontextid}});
|
||||
|
||||
moveMod.init();
|
||||
|
||||
menubar.enhance('.templateactions', {
|
||||
|
||||
@@ -53,6 +53,6 @@
|
||||
</div>
|
||||
{{#js}}
|
||||
require(['tool_lp/competencies'], function(mod) {
|
||||
(new mod({{templateid}}, 'template'));
|
||||
(new mod({{templateid}}, 'template', {{pagecontextid}}));
|
||||
});
|
||||
{{/js}}
|
||||
|
||||
@@ -42,6 +42,7 @@ class tool_lp_api_testcase extends advanced_testcase {
|
||||
$cat1 = $dg->create_category();
|
||||
$cat2 = $dg->create_category(array('parent' => $cat1->id));
|
||||
$cat3 = $dg->create_category(array('parent' => $cat2->id));
|
||||
$c1 = $dg->create_course(array('category' => $cat2->id)); // This context should not be returned.
|
||||
|
||||
$cat1ctx = context_coursecat::instance($cat1->id);
|
||||
$cat2ctx = context_coursecat::instance($cat2->id);
|
||||
@@ -49,13 +50,13 @@ class tool_lp_api_testcase extends advanced_testcase {
|
||||
$sysctx = context_system::instance();
|
||||
|
||||
$expected = array($cat1ctx->id => $cat1ctx);
|
||||
$this->assertEquals($expected, api::get_framework_related_contexts($cat1ctx, 'self'));
|
||||
$this->assertEquals($expected, api::get_related_contexts($cat1ctx, 'self'));
|
||||
|
||||
$expected = array($cat1ctx->id => $cat1ctx, $cat2ctx->id => $cat2ctx, $cat3ctx->id => $cat3ctx);
|
||||
$this->assertEquals($expected, api::get_framework_related_contexts($cat1ctx, 'children'));
|
||||
$this->assertEquals($expected, api::get_related_contexts($cat1ctx, 'children'));
|
||||
|
||||
$expected = array($sysctx->id => $sysctx, $cat1ctx->id => $cat1ctx, $cat2ctx->id => $cat2ctx);
|
||||
$this->assertEquals($expected, api::get_framework_related_contexts($cat2ctx, 'parents'));
|
||||
$this->assertEquals($expected, api::get_related_contexts($cat2ctx, 'parents'));
|
||||
}
|
||||
|
||||
public function test_get_framework_related_contexts_with_capabilities() {
|
||||
@@ -65,6 +66,7 @@ class tool_lp_api_testcase extends advanced_testcase {
|
||||
$cat1 = $dg->create_category();
|
||||
$cat2 = $dg->create_category(array('parent' => $cat1->id));
|
||||
$cat3 = $dg->create_category(array('parent' => $cat2->id));
|
||||
$c1 = $dg->create_course(array('category' => $cat2->id)); // This context should not be returned.
|
||||
|
||||
$cat1ctx = context_coursecat::instance($cat1->id);
|
||||
$cat2ctx = context_coursecat::instance($cat2->id);
|
||||
@@ -86,12 +88,74 @@ class tool_lp_api_testcase extends advanced_testcase {
|
||||
$requiredcap = array('tool/lp:competencyread');
|
||||
|
||||
$expected = array();
|
||||
$this->assertEquals($expected, api::get_framework_related_contexts($cat2ctx, 'self', $requiredcap));
|
||||
$this->assertEquals($expected, api::get_related_contexts($cat2ctx, 'self', $requiredcap));
|
||||
|
||||
$expected = array($cat1ctx->id => $cat1ctx);
|
||||
$this->assertEquals($expected, api::get_framework_related_contexts($cat1ctx, 'children', $requiredcap));
|
||||
$this->assertEquals($expected, api::get_related_contexts($cat1ctx, 'children', $requiredcap));
|
||||
|
||||
$expected = array($sysctx->id => $sysctx, $cat1ctx->id => $cat1ctx);
|
||||
$this->assertEquals($expected, api::get_framework_related_contexts($cat2ctx, 'parents', $requiredcap));
|
||||
$this->assertEquals($expected, api::get_related_contexts($cat2ctx, 'parents', $requiredcap));
|
||||
}
|
||||
|
||||
public function test_get_template_related_contexts() {
|
||||
$this->resetAfterTest(true);
|
||||
$dg = $this->getDataGenerator();
|
||||
$cat1 = $dg->create_category();
|
||||
$cat2 = $dg->create_category(array('parent' => $cat1->id));
|
||||
$cat3 = $dg->create_category(array('parent' => $cat2->id));
|
||||
$c1 = $dg->create_course(array('category' => $cat2->id)); // This context should not be returned.
|
||||
|
||||
$cat1ctx = context_coursecat::instance($cat1->id);
|
||||
$cat2ctx = context_coursecat::instance($cat2->id);
|
||||
$cat3ctx = context_coursecat::instance($cat3->id);
|
||||
$sysctx = context_system::instance();
|
||||
|
||||
$expected = array($cat1ctx->id => $cat1ctx);
|
||||
$this->assertEquals($expected, api::get_related_contexts($cat1ctx, 'self'));
|
||||
|
||||
$expected = array($cat1ctx->id => $cat1ctx, $cat2ctx->id => $cat2ctx, $cat3ctx->id => $cat3ctx);
|
||||
$this->assertEquals($expected, api::get_related_contexts($cat1ctx, 'children'));
|
||||
|
||||
$expected = array($sysctx->id => $sysctx, $cat1ctx->id => $cat1ctx, $cat2ctx->id => $cat2ctx);
|
||||
$this->assertEquals($expected, api::get_related_contexts($cat2ctx, 'parents'));
|
||||
}
|
||||
|
||||
public function test_get_template_related_contexts_with_capabilities() {
|
||||
$this->resetAfterTest(true);
|
||||
$dg = $this->getDataGenerator();
|
||||
$user = $dg->create_user();
|
||||
$cat1 = $dg->create_category();
|
||||
$cat2 = $dg->create_category(array('parent' => $cat1->id));
|
||||
$cat3 = $dg->create_category(array('parent' => $cat2->id));
|
||||
$c1 = $dg->create_course(array('category' => $cat2->id)); // This context should not be returned.
|
||||
|
||||
$cat1ctx = context_coursecat::instance($cat1->id);
|
||||
$cat2ctx = context_coursecat::instance($cat2->id);
|
||||
$cat3ctx = context_coursecat::instance($cat3->id);
|
||||
$sysctx = context_system::instance();
|
||||
|
||||
$roleallow = create_role('Allow', 'allow', 'Allow read');
|
||||
assign_capability('tool/lp:templateread', CAP_ALLOW, $roleallow, $sysctx->id);
|
||||
role_assign($roleallow, $user->id, $sysctx->id);
|
||||
|
||||
$roleprevent = create_role('Prevent', 'prevent', 'Prevent read');
|
||||
assign_capability('tool/lp:templateread', CAP_PROHIBIT, $roleprevent, $sysctx->id);
|
||||
role_assign($roleprevent, $user->id, $cat2ctx->id);
|
||||
|
||||
accesslib_clear_all_caches_for_unit_testing();
|
||||
$this->setUser($user);
|
||||
$this->assertFalse(has_capability('tool/lp:templateread', $cat2ctx));
|
||||
|
||||
$requiredcap = array('tool/lp:templateread');
|
||||
|
||||
$expected = array();
|
||||
$this->assertEquals($expected, api::get_related_contexts($cat2ctx, 'self', $requiredcap));
|
||||
|
||||
$expected = array($cat1ctx->id => $cat1ctx);
|
||||
$this->assertEquals($expected, api::get_related_contexts($cat1ctx, 'children', $requiredcap));
|
||||
|
||||
$expected = array($sysctx->id => $sysctx, $cat1ctx->id => $cat1ctx);
|
||||
$this->assertEquals($expected, api::get_related_contexts($cat2ctx, 'parents', $requiredcap));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1141,7 +1141,8 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
|
||||
$syscontext = context_system::instance();
|
||||
|
||||
// Create a template.
|
||||
$template = external::create_template('shortname', 'idnumber', time(), 'description', FORMAT_HTML, true);
|
||||
$template = external::create_template('shortname', 'idnumber', time(), 'description', FORMAT_HTML, true,
|
||||
array('contextid' => $syscontext->id));
|
||||
$template = (object) external_api::clean_returnvalue(external::create_template_returns(), $template);
|
||||
|
||||
// Create a competency.
|
||||
@@ -1176,7 +1177,8 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
|
||||
$syscontext = context_system::instance();
|
||||
|
||||
// Create a template.
|
||||
$template = external::create_template('shortname', 'idnumber', time(), 'description', FORMAT_HTML, true);
|
||||
$template = external::create_template('shortname', 'idnumber', time(), 'description', FORMAT_HTML, true,
|
||||
array('contextid' => $syscontext->id));
|
||||
$template = (object) external_api::clean_returnvalue(external::create_template_returns(), $template);
|
||||
|
||||
// Create a competency.
|
||||
@@ -1220,7 +1222,8 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
|
||||
$syscontext = context_system::instance();
|
||||
|
||||
// Create a template.
|
||||
$template = external::create_template('shortname', 'idnumber', time(), 'description', FORMAT_HTML, true);
|
||||
$template = external::create_template('shortname', 'idnumber', time(), 'description', FORMAT_HTML, true,
|
||||
array('contextid' => $syscontext->id));
|
||||
$template = (object) external_api::clean_returnvalue(external::create_template_returns(), $template);
|
||||
|
||||
// Create a competency framework.
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2015052406; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2015052407; // 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).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user