Merge branch 'MDL-57273-master' of git://github.com/damyon/moodle

This commit is contained in:
Andrew Nicols
2017-01-25 08:48:27 +08:00
180 changed files with 4865 additions and 4055 deletions
+5 -5
View File
@@ -149,13 +149,13 @@ class api {
// We build an better structure to loop on.
$info = array();
foreach ($all as $cra) {
if (!isset($info[$cra->get_userid()])) {
$info[$cra->get_userid()] = array();
if (!isset($info[$cra->get('userid')])) {
$info[$cra->get('userid')] = array();
}
if (!isset($info[$cra->get_userid()][$cra->get_roleid()])) {
$info[$cra->get_userid()][$cra->get_roleid()] = array();
if (!isset($info[$cra->get('userid')][$cra->get('roleid')])) {
$info[$cra->get('userid')][$cra->get('roleid')] = array();
}
array_push($info[$cra->get_userid()][$cra->get_roleid()], $cra->get_cohortid());
array_push($info[$cra->get('userid')][$cra->get('roleid')], $cra->get('cohortid'));
}
// Then for each user+role combo - find user context in the cohort without a role assigned.
+7 -7
View File
@@ -96,10 +96,10 @@ class tool_cohortroles_api_testcase extends advanced_testcase {
'cohortid' => $this->cohort->id
);
$result = api::create_cohort_role_assignment($params);
$this->assertNotEmpty($result->get_id());
$this->assertEquals($result->get_userid(), $this->userassignto->id);
$this->assertEquals($result->get_roleid(), $this->roleid);
$this->assertEquals($result->get_cohortid(), $this->cohort->id);
$this->assertNotEmpty($result->get('id'));
$this->assertEquals($result->get('userid'), $this->userassignto->id);
$this->assertEquals($result->get('roleid'), $this->roleid);
$this->assertEquals($result->get('cohortid'), $this->cohort->id);
}
/**
@@ -114,7 +114,7 @@ class tool_cohortroles_api_testcase extends advanced_testcase {
);
$result = api::create_cohort_role_assignment($params);
$this->setUser($this->userassignto);
api::delete_cohort_role_assignment($result->get_id());
api::delete_cohort_role_assignment($result->get('id'));
}
/**
@@ -128,7 +128,7 @@ class tool_cohortroles_api_testcase extends advanced_testcase {
'cohortid' => $this->cohort->id
);
$result = api::create_cohort_role_assignment($params);
api::delete_cohort_role_assignment($result->get_id() + 1);
api::delete_cohort_role_assignment($result->get('id') + 1);
}
public function test_delete_cohort_role_assignment() {
@@ -139,7 +139,7 @@ class tool_cohortroles_api_testcase extends advanced_testcase {
'cohortid' => $this->cohort->id
);
$result = api::create_cohort_role_assignment($params);
$worked = api::delete_cohort_role_assignment($result->get_id());
$worked = api::delete_cohort_role_assignment($result->get('id'));
$this->assertTrue($worked);
}
@@ -65,7 +65,7 @@ class tool_lp_course_competencies_form_element extends MoodleQuickForm_autocompl
$current = \core_competency\api::list_course_module_competencies_in_course_module($options['cmid']);
$ids = array();
foreach ($current as $coursemodulecompetency) {
array_push($ids, $coursemodulecompetency->get_competencyid());
array_push($ids, $coursemodulecompetency->get('competencyid'));
}
$this->setValue($ids);
}
@@ -76,10 +76,10 @@ class tool_lp_course_competencies_form_element extends MoodleQuickForm_autocompl
$context = context_course::instance($courseid);
foreach ($competencies as $competency) {
// We don't need to show the description as part of the options, so just set this to null.
$competency['competency']->set_description(null);
$competency['competency']->set('description', null);
$exporter = new competency_exporter($competency['competency'], array('context' => $context));
$templatecontext = array('competency' => $exporter->export($OUTPUT));
$id = $competency['competency']->get_id();
$id = $competency['competency']->get('id');
$validoptions[$id] = $OUTPUT->render_from_template('tool_lp/competency_summary', $templatecontext);
}
$attributes['tags'] = false;
@@ -65,7 +65,7 @@ class tool_lp_course_competency_rule_form_element extends MoodleQuickForm_select
// forcing them to be all the same for each activity.
if (!empty($current)) {
$one = array_pop($current);
$this->setValue($one->get_ruleoutcome());
$this->setValue($one->get('ruleoutcome'));
}
}
$validoptions = course_module_competency::get_ruleoutcome_list();
+4 -4
View File
@@ -42,12 +42,12 @@ use external_multiple_structure;
use invalid_parameter_exception;
use required_capability_exception;
use tool_lp\external\cohort_summary_exporter;
use core_cohort\external\cohort_summary_exporter;
use tool_lp\external\competency_path_exporter;
use tool_lp\external\competency_summary_exporter;
use tool_lp\external\course_competency_statistics_exporter;
use tool_lp\external\course_module_summary_exporter;
use tool_lp\external\course_summary_exporter;
use core_course\external\course_module_summary_exporter;
use core_course\external\course_summary_exporter;
use tool_lp\external\template_statistics_exporter;
use tool_lp\external\user_competency_summary_exporter;
use tool_lp\external\user_competency_summary_in_course_exporter;
@@ -66,7 +66,7 @@ use core_competency\external\template_exporter;
use core_competency\external\user_competency_course_exporter;
use core_competency\external\user_competency_exporter;
use core_competency\external\user_competency_plan_exporter;
use core_competency\external\user_summary_exporter;
use core_user\external\user_summary_exporter;
/**
* This is the external API for this tool.
@@ -33,7 +33,7 @@ use moodle_url;
* @copyright 2016 Issam Taboubi <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class competency_path_exporter extends \core_competency\external\exporter {
class competency_path_exporter extends \core\external\exporter {
/**
* Constructor.
@@ -72,7 +72,7 @@ class competency_path_exporter extends \core_competency\external\exporter {
'type' => path_node_exporter::read_properties_definition()
],
'pluginbaseurl' => [
'type' => PARAM_TEXT
'type' => PARAM_URL
],
'pagecontextid' => [
'type' => PARAM_INT
@@ -93,8 +93,8 @@ class competency_path_exporter extends \core_competency\external\exporter {
$i = 1;
foreach ($this->related['ancestors'] as $competency) {
$exporter = new path_node_exporter([
'id' => $competency->get_id(),
'name' => $competency->get_idnumber(),
'id' => $competency->get('id'),
'name' => $competency->get('idnumber'),
'position' => $i,
'first' => $i == 1,
'last' => $i == $nodescount
@@ -107,8 +107,8 @@ class competency_path_exporter extends \core_competency\external\exporter {
}
$result->ancestors = $ancestors;
$exporter = new path_node_exporter([
'id' => $this->related['framework']->get_id(),
'name' => $this->related['framework']->get_shortname(),
'id' => $this->related['framework']->get('id'),
'name' => $this->related['framework']->get('shortname'),
'first' => 0,
'last' => 0,
'position' => -1
@@ -30,6 +30,7 @@ use stdClass;
use core_competency\competency_framework;
use core_competency\external\competency_exporter;
use core_competency\external\competency_framework_exporter;
use core_course\external\course_summary_exporter;
/**
* Class for exporting competency data with additional related data.
@@ -37,7 +38,7 @@ use core_competency\external\competency_framework_exporter;
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class competency_summary_exporter extends \core_competency\external\exporter {
class competency_summary_exporter extends \core\external\exporter {
protected static function define_related() {
// We cache the context so it does not need to be retrieved from the framework every time.
@@ -115,11 +116,11 @@ class competency_summary_exporter extends \core_competency\external\exporter {
$exporter = new competency_framework_exporter($this->related['framework']);
$result->framework = $exporter->export($output);
$scaleconfiguration = $this->related['framework']->get_scaleconfiguration();
$scaleid = $this->related['framework']->get_scaleid();
if ($competency->get_scaleid()) {
$scaleconfiguration = $competency->get_scaleconfiguration();
$scaleid = $competency->get_scaleid();
$scaleconfiguration = $this->related['framework']->get('scaleconfiguration');
$scaleid = $this->related['framework']->get('scaleid');
if ($competency->get('scaleid')) {
$scaleconfiguration = $competency->get('scaleconfiguration');
$scaleid = $competency->get('scaleid');
}
$result->scaleconfiguration = $scaleconfiguration;
$result->scaleid = $scaleid;
@@ -27,6 +27,7 @@ defined('MOODLE_INTERNAL') || die();
use renderer_base;
use moodle_url;
use core_competency\external\competency_exporter;
use core_competency\external\performance_helper;
/**
* Class for exporting a course competency statistics summary.
@@ -34,7 +35,7 @@ use core_competency\external\competency_exporter;
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_competency_statistics_exporter extends \core_competency\external\exporter {
class course_competency_statistics_exporter extends \core\external\exporter {
public static function define_properties() {
return array(
@@ -84,12 +85,9 @@ class course_competency_statistics_exporter extends \core_competency\external\ex
$proficientcompetencypercentageformatted = format_float($proficientcompetencypercentage);
}
$competencies = array();
$contextcache = array();
$helper = new performance_helper();
foreach ($this->data->leastproficientcompetencies as $competency) {
if (!isset($contextcache[$competency->get_competencyframeworkid()])) {
$contextcache[$competency->get_competencyframeworkid()] = $competency->get_context();
}
$context = $contextcache[$competency->get_competencyframeworkid()];
$context = $helper->get_context_from_competency($competency);
$exporter = new competency_exporter($competency, array('context' => $context));
$competencies[] = $exporter->export($output);
}
+30 -1
View File
@@ -24,6 +24,7 @@
namespace tool_lp\external;
defined('MOODLE_INTERNAL') || die();
use context_system;
/**
* Class for exporting path_node data.
@@ -31,7 +32,35 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2016 Issam Taboubi <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class path_node_exporter extends \core_competency\external\exporter {
class path_node_exporter extends \core\external\exporter {
/**
* Constructor - saves the persistent object, and the related objects.
*
* @param mixed $data The data.
* @param array $related Array of relateds.
*/
public function __construct($data, $related = array()) {
if (!isset($related['context'])) {
// Previous code was automatically using the system context which was not always correct.
// We let developers know that they must fix their code without breaking anything,
// and fallback on the previous behaviour. This should be removed at a later stage: Moodle 3.5.
debugging('Missing related context in path_node_exporter.', DEBUG_DEVELOPER);
$related['context'] = context_system::instance();
}
parent::__construct($data, $related);
}
/**
* Return the list of properties.
*
* @return array
*/
protected static function define_related() {
return [
'context' => 'context'
];
}
/**
* Return the list of properties.
@@ -27,6 +27,7 @@ defined('MOODLE_INTERNAL') || die();
use renderer_base;
use moodle_url;
use core_competency\external\competency_exporter;
use core_competency\external\performance_helper;
/**
* Class for exporting a cohort summary from an stdClass.
@@ -34,7 +35,7 @@ use core_competency\external\competency_exporter;
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class template_statistics_exporter extends \core_competency\external\exporter {
class template_statistics_exporter extends \core\external\exporter {
public static function define_properties() {
return array(
@@ -118,12 +119,9 @@ class template_statistics_exporter extends \core_competency\external\exporter {
$proficientusercompetencyplanpercentageformatted = format_float($proficientusercompetencyplanpercentage);
}
$competencies = array();
$contextcache = array();
$helper = new performance_helper();
foreach ($this->data->leastproficientcompetencies as $competency) {
if (!isset($contextcache[$competency->get_competencyframeworkid()])) {
$contextcache[$competency->get_competencyframeworkid()] = $competency->get_context();
}
$context = $contextcache[$competency->get_competencyframeworkid()];
$context = $helper->get_context_from_competency($competency);
$exporter = new competency_exporter($competency, array('context' => $context));
$competencies[] = $exporter->export($output);
}
@@ -22,16 +22,17 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\external;
defined('MOODLE_INTERNAL') || die();
use context_user;
use renderer_base;
use stdClass;
use core_competency\external\comment_area_exporter;
use core_comment\external\comment_area_exporter;
use core_competency\external\evidence_exporter;
use core_competency\external\user_competency_exporter;
use core_competency\external\user_competency_plan_exporter;
use core_competency\external\user_competency_course_exporter;
use core_competency\external\user_summary_exporter;
use core_user\external\user_summary_exporter;
use core_competency\user_competency;
/**
@@ -40,7 +41,7 @@ use core_competency\user_competency;
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_competency_summary_exporter extends \core_competency\external\exporter {
class user_competency_summary_exporter extends \core\external\exporter {
protected static function define_related() {
// We cache the context so it does not need to be retrieved from the framework every time.
@@ -132,9 +133,9 @@ class user_competency_summary_exporter extends \core_competency\external\exporte
$result->evidence = array();
if (count($this->related['evidence'])) {
foreach ($this->related['evidence'] as $evidence) {
$actionuserid = $evidence->get_actionuserid();
$actionuserid = $evidence->get('actionuserid');
if (!empty($actionuserid)) {
$usercache[$evidence->get_actionuserid()] = true;
$usercache[$evidence->get('actionuserid')] = true;
}
}
$users = array();
@@ -148,11 +149,12 @@ class user_competency_summary_exporter extends \core_competency\external\exporte
}
foreach ($this->related['evidence'] as $evidence) {
$actionuserid = $evidence->get_actionuserid();
$actionuserid = $evidence->get('actionuserid');
$related = array(
'scale' => $scale,
'usercompetency' => ($this->related['usercompetency'] ? $this->related['usercompetency'] : null),
'usercompetencyplan' => ($this->related['usercompetencyplan'] ? $this->related['usercompetencyplan'] : null),
'context' => $evidence->get_context()
);
$related['actionuser'] = !empty($actionuserid) ? $usercache[$actionuserid] : null;
$exporter = new evidence_exporter($evidence, $related);
@@ -22,9 +22,12 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\external;
defined('MOODLE_INTERNAL') || die();
use core_competency\api;
use core_competency\user_competency;
use core_course\external\course_module_summary_exporter;
use core_course\external\course_summary_exporter;
use context_course;
use renderer_base;
use stdClass;
@@ -35,7 +38,7 @@ use stdClass;
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_competency_summary_in_course_exporter extends \core_competency\external\exporter {
class user_competency_summary_in_course_exporter extends \core\external\exporter {
protected static function define_related() {
// We cache the context so it does not need to be retrieved from the framework every time.
@@ -80,7 +83,7 @@ class user_competency_summary_in_course_exporter extends \core_competency\extern
$exporter = new course_summary_exporter($this->related['course'], array('context' => $context));
$result->course = $exporter->export($output);
$coursemodules = api::list_course_modules_using_competency($this->related['competency']->get_id(),
$coursemodules = api::list_course_modules_using_competency($this->related['competency']->get('id'),
$this->related['course']->id);
$fastmodinfo = get_fast_modinfo($this->related['course']->id);
@@ -22,6 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\external;
defined('MOODLE_INTERNAL') || die();
use context_user;
use renderer_base;
@@ -34,7 +35,7 @@ use core_competency\external\plan_exporter;
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_competency_summary_in_plan_exporter extends \core_competency\external\exporter {
class user_competency_summary_in_plan_exporter extends \core\external\exporter {
protected static function define_related() {
// We cache the context so it does not need to be retrieved from the framework every time.
@@ -22,6 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\external;
defined('MOODLE_INTERNAL') || die();
use moodle_url;
use renderer_base;
@@ -34,7 +35,7 @@ use core_competency\external\user_competency_exporter;
* @copyright 2016 Serge Gauthier - <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_evidence_competency_summary_exporter extends \core_competency\external\exporter {
class user_evidence_competency_summary_exporter extends \core\external\exporter {
protected static function define_related() {
return array('competency' => '\\core_competency\\competency',
@@ -26,7 +26,8 @@ defined('MOODLE_INTERNAL') || die();
use moodle_url;
use renderer_base;
use core_competency\external\stored_file_exporter;
use core_files\external\stored_file_exporter;
use core_competency\external\performance_helper;
/**
* Class for exporting user evidence with all competencies.
@@ -34,10 +35,10 @@ use core_competency\external\stored_file_exporter;
* @copyright 2016 Serge Gauthier - <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_evidence_summary_exporter extends \core_competency\external\persistent_exporter {
class user_evidence_summary_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return 'core_competency\\user_evidence';
return \core_competency\user_evidence::class;
}
protected static function define_other_properties() {
@@ -74,7 +75,7 @@ class user_evidence_summary_exporter extends \core_competency\external\persisten
protected function get_other_values(renderer_base $output) {
$urlshort = '';
$url = $this->persistent->get_url();
$url = $this->persistent->get('url');
if (!empty($url)) {
$murl = new moodle_url($url);
$shorturl = preg_replace('@^https?://(www\.)?@', '', $murl->out(false));
@@ -91,32 +92,19 @@ class user_evidence_summary_exporter extends \core_competency\external\persisten
}
$userevidencecompetencies = array();
$frameworks = array();
$scales = array();
$usercompetencies = $this->persistent->get_user_competencies();
$helper = new performance_helper();
foreach ($usercompetencies as $usercompetency) {
$competency = $usercompetency->get_competency();
// Get the framework.
if (!isset($frameworks[$competency->get_competencyframeworkid()])) {
$frameworks[$competency->get_competencyframeworkid()] = $competency->get_framework();
}
$framework = $frameworks[$competency->get_competencyframeworkid()];
// Get the scale.
$scaleid = $competency->get_scaleid();
if ($scaleid === null) {
$scaleid = $framework->get_scaleid();
}
if (!isset($scales[$framework->get_scaleid()])) {
$scales[$framework->get_scaleid()] = $framework->get_scale();
}
$scale = $scales[$framework->get_scaleid()];
$context = $helper->get_context_from_competency($competency);
$framework = $helper->get_framework_from_competency($competency);
$scale = $helper->get_scale_from_competency($competency);
$related = array('competency' => $competency,
'usercompetency' => $usercompetency,
'scale' => $scale,
'context' => $framework->get_context());
'context' => $context);
$userevidencecompetencysummaryexporter = new user_evidence_competency_summary_exporter(null, $related);
+16 -12
View File
@@ -26,6 +26,7 @@ namespace tool_lp\form;
defined('MOODLE_INTERNAL') || die();
use stdClass;
use core\form\persistent;
/**
* Competency framework form.
@@ -53,26 +54,29 @@ class competency extends persistent {
$mform->addElement('hidden', 'competencyframeworkid');
$mform->setType('competencyframeworkid', PARAM_INT);
$mform->setConstant('competencyframeworkid', $framework->get_id());
$mform->setConstant('competencyframeworkid', $framework->get('id'));
$mform->addElement('header', 'generalhdr', get_string('general'));
$mform->addElement('static',
'frameworkdesc',
get_string('competencyframework', 'tool_lp'),
s($framework->get_shortname()));
s($framework->get('shortname')));
$mform->addElement('hidden', 'parentid', '', array('id' => 'tool_lp_parentcompetency'));
$mform->setType('parentid', PARAM_INT);
$mform->setConstant('parentid', ($parent) ? $parent->get_id() : 0);
$parentlevel = ($parent) ? $parent->get_level() : 0;
$parentname = ($parent) ? $parent->get_shortname() : get_string('competencyframeworkroot', 'tool_lp');
$parentlabel = ($competency->get_id()) ?
get_string('taxonomy_parent_' . $framework->get_taxonomy($parentlevel), 'tool_lp') :
get_string('parentcompetency', 'tool_lp');
$mform->setConstant('parentid', ($parent) ? $parent->get('id') : 0);
$parentlevel = ($parent) ? $parent->get('level') : 0;
$parentname = ($parent) ? $parent->get('shortname') : get_string('competencyframeworkroot', 'tool_lp');
$parentlabel = '';
if (!empty($competency->get('id'))) {
$parentlabel = get_string('taxonomy_parent_' . $framework->get_taxonomy($parentlevel), 'tool_lp');
} else {
$parentlabel = get_string('parentcompetency', 'tool_lp');
}
$editaction = '';
if (!$competency->get_id()) {
if (!$competency->get('id')) {
$icon = $OUTPUT->pix_icon('t/editinline', get_string('parentcompetency_edit', 'tool_lp'));
$editaction = $OUTPUT->action_link('#', $icon, null, array('id' => 'id_parentcompetencybutton'));
}
@@ -82,12 +86,12 @@ class competency extends persistent {
$parentlabel,
"<span id='id_parentdesc'>$parentname</span>&nbsp;".$editaction);
// Set the picker competency when adding new competency.
if (!$competency->get_id()) {
if (!$competency->get('id')) {
// Call the parentcompetency_form init to initialize the competency picker for parent competency.
$PAGE->requires->js_call_amd('tool_lp/parentcompetency_form', 'init', array('#id_parentcompetencybutton',
'#tool_lp_parentcompetency',
'#id_parentdesc',
$framework->get_id(),
$framework->get('id'),
$pagecontextid));
}
@@ -123,7 +127,7 @@ class competency extends persistent {
// configuration requires this field so we only disable it. It is fine as setting the value
// as a constant will ensure that nobody can change it. And it's validated in the persistent anyway.
$scaleid->updateAttributes(array('disabled' => 'disabled'));
$mform->setConstant('scaleid', $competency->get_scaleid());
$mform->setConstant('scaleid', $competency->get('scaleid'));
}
// Disable short forms.
@@ -26,6 +26,7 @@ namespace tool_lp\form;
defined('MOODLE_INTERNAL') || die();
use stdClass;
use core\form\persistent;
/**
* Competency framework form.
@@ -79,7 +80,7 @@ class competency_framework extends persistent {
// configuration requires this field so we only disable it. It is fine as setting the value
// as a constant will ensure that nobody can change it. And it's validated in the persistent anyway.
$scaleid->updateAttributes(array('readonly' => 'readonly'));
$mform->setConstant('scaleid', $framework->get_scaleid());
$mform->setConstant('scaleid', $framework->get('scaleid'));
}
$mform->addElement('button', 'scaleconfigbutton', get_string('configurescale', 'tool_lp'));
@@ -148,7 +149,7 @@ class competency_framework extends persistent {
*/
protected function get_default_data() {
$data = parent::get_default_data();
$data->taxonomies = $this->get_persistent()->get_taxonomies();
$data->taxonomies = $this->get_persistent()->get('taxonomies');
return $data;
}
@@ -109,11 +109,11 @@ class framework_autocomplete extends MoodleQuickForm_autocomplete {
if (!has_any_capability(array('moodle/competency:competencyview', 'moodle/competency:competencymanage'),
$framework->get_context())) {
continue;
} else if ($this->onlyvisible && !$framework->get_visible()) {
} else if ($this->onlyvisible && !$framework->get('visible')) {
continue;
}
$this->addOption($framework->get_shortname() . ' ' . $framework->get_idnumber(), $framework->get_id());
array_push($toselect, $framework->get_id());
$this->addOption($framework->get('shortname') . ' ' . $framework->get('idnumber'), $framework->get('id'));
array_push($toselect, $framework->get('id'));
}
return $this->setSelected($toselect);
+2 -1
View File
@@ -25,6 +25,7 @@
namespace tool_lp\form;
defined('MOODLE_INTERNAL') || die();
use core\form\persistent;
use core_competency\plan as planpersistent;
use required_capability_exception;
@@ -68,7 +69,7 @@ class plan extends persistent {
// When the plan was already saved then the status can not be changed via this form.
$status = planpersistent::get_status_list($this->_customdata['userid']);
$plan = $this->get_persistent();
if ($plan->get_id()) {
if ($plan->get('id')) {
// The current status is not selectable (workflow status probably), we just display it.
$mform->addElement('static', 'staticstatus', get_string('status', 'tool_lp'), $plan->get_statusname());
} else if (!empty($status) && count($status) > 1) {
+2
View File
@@ -25,6 +25,8 @@
namespace tool_lp\form;
defined('MOODLE_INTERNAL') || die();
use core\form\persistent;
/**
* Learning plan template form.
*
@@ -26,6 +26,7 @@ namespace tool_lp\form;
defined('MOODLE_INTERNAL') || die();
use moodleform;
use core\form\persistent;
require_once($CFG->libdir . '/formslib.php');
@@ -26,6 +26,7 @@ namespace tool_lp\form;
defined('MOODLE_INTERNAL') || die();
use moodleform;
use core\form\persistent;
require_once($CFG->libdir . '/formslib.php');
@@ -25,6 +25,8 @@
namespace tool_lp\form;
defined('MOODLE_INTERNAL') || die();
use core\form\persistent;
/**
* User evidence form class.
*
@@ -27,7 +27,8 @@ use renderable;
use renderer_base;
use templatable;
use context_course;
use \core_competency\external\competency_exporter;
use core_competency\external\competency_exporter;
use core_competency\external\performance_helper;
use stdClass;
/**
@@ -82,13 +83,9 @@ class competency_plan_navigation implements renderable, templatable {
$plancompetencies = \core_competency\api::list_plan_competencies($data->planid);
$data->competencies = array();
$contextcache = array();
$helper = new performance_helper();
foreach ($plancompetencies as $plancompetency) {
$frameworkid = $plancompetency->competency->get_competencyframeworkid();
if (!isset($contextcache[$frameworkid])) {
$contextcache[$frameworkid] = $plancompetency->competency->get_context();
}
$context = $contextcache[$frameworkid];
$context = $helper->get_context_from_competency($plancompetency->competency);
$exporter = new competency_exporter($plancompetency->competency, array('context' => $context));
$competency = $exporter->export($output);
if ($competency->id == $this->competencyid) {
@@ -63,11 +63,11 @@ class competency_summary implements renderable, templatable {
$this->competency = $competency;
$this->framework = $framework;
if ($includerelated) {
$this->relatedcompetencies = api::list_related_competencies($competency->get_id());
$this->relatedcompetencies = api::list_related_competencies($competency->get('id'));
}
if ($includecourses) {
$this->courses = api::list_courses_using_competency($competency->get_id());
$this->courses = api::list_courses_using_competency($competency->get('id'));
}
}
@@ -35,6 +35,7 @@ use core_competency\api;
use tool_lp\course_competency_statistics;
use core_competency\competency;
use core_competency\course_competency;
use core_competency\external\performance_helper;
use core_competency\external\competency_exporter;
use core_competency\external\course_competency_exporter;
use core_competency\external\course_competency_settings_exporter;
@@ -42,7 +43,7 @@ use core_competency\external\user_competency_course_exporter;
use core_competency\external\user_competency_exporter;
use tool_lp\external\competency_path_exporter;
use tool_lp\external\course_competency_statistics_exporter;
use tool_lp\external\course_module_summary_exporter;
use core_course\external\course_module_summary_exporter;
/**
* Class containing data for course competencies page
@@ -112,7 +113,6 @@ class course_competencies_page implements renderable, templatable {
$data->courseid = $this->courseid;
$data->pagecontextid = $this->context->id;
$data->competencies = array();
$contextcache = array();
$gradable = is_enrolled($this->context, $USER, 'moodle/competency:coursecompetencygradable');
if ($gradable) {
@@ -126,21 +126,19 @@ class course_competencies_page implements renderable, templatable {
$ruleoutcomeoptions[$value] = array('value' => $value, 'text' => (string) $text, 'selected' => false);
}
$helper = new performance_helper();
foreach ($this->coursecompetencylist as $coursecompetencyelement) {
$coursecompetency = $coursecompetencyelement['coursecompetency'];
$competency = $coursecompetencyelement['competency'];
if (!isset($contextcache[$competency->get_competencyframeworkid()])) {
$contextcache[$competency->get_competencyframeworkid()] = $competency->get_context();
}
$context = $contextcache[$competency->get_competencyframeworkid()];
$context = $helper->get_context_from_competency($competency);
$compexporter = new competency_exporter($competency, array('context' => $context));
$ccexporter = new course_competency_exporter($coursecompetency, array('context' => $context));
$ccoutcomeoptions = (array) (object) $ruleoutcomeoptions;
$ccoutcomeoptions[$coursecompetency->get_ruleoutcome()]['selected'] = true;
$ccoutcomeoptions[$coursecompetency->get('ruleoutcome')]['selected'] = true;
$coursemodules = api::list_course_modules_using_competency($competency->get_id(), $this->courseid);
$coursemodules = api::list_course_modules_using_competency($competency->get('id'), $this->courseid);
$fastmodinfo = get_fast_modinfo($this->courseid);
$exportedmodules = array();
@@ -152,7 +150,7 @@ class course_competencies_page implements renderable, templatable {
// Competency path.
$pathexporter = new competency_path_exporter([
'ancestors' => $competency->get_ancestors(),
'framework' => $competency->get_framework(),
'framework' => $helper->get_framework_from_competency($competency),
'context' => $context
]);
@@ -166,13 +164,13 @@ class course_competencies_page implements renderable, templatable {
if ($gradable) {
$foundusercompetencycourse = false;
foreach ($usercompetencycourses as $usercompetencycourse) {
if ($usercompetencycourse->get_competencyid() == $competency->get_id()) {
if ($usercompetencycourse->get('competencyid') == $competency->get('id')) {
$foundusercompetencycourse = $usercompetencycourse;
}
}
if ($foundusercompetencycourse) {
$related = array(
'scale' => $competency->get_scale()
'scale' => $helper->get_scale_from_competency($competency)
);
$exporter = new user_competency_course_exporter($foundusercompetencycourse, $related);
$onerow['usercompetencycourse'] = $exporter->export($output);
+8 -23
View File
@@ -29,6 +29,7 @@ use templatable;
use stdClass;
use moodle_url;
use core_competency\api;
use core_competency\external\performance_helper;
use core_competency\plan;
use core_competency\external\competency_exporter;
use core_competency\external\plan_exporter;
@@ -62,9 +63,6 @@ class plan_page implements renderable, templatable {
* @return stdClass
*/
public function export_for_template(\renderer_base $output) {
$frameworks = array();
$scales = array();
$planexporter = new plan_exporter($this->plan, array('template' => $this->plan->get_template()));
$data = new stdClass();
@@ -81,40 +79,27 @@ class plan_page implements renderable, templatable {
$ucexporter = 'core_competency\\external\\user_competency_exporter';
}
$helper = new performance_helper();
$pclist = api::list_plan_competencies($this->plan);
$proficientcount = 0;
foreach ($pclist as $pc) {
$comp = $pc->competency;
$usercomp = $pc->$ucproperty;
// Get the framework.
if (!isset($frameworks[$comp->get_competencyframeworkid()])) {
$frameworks[$comp->get_competencyframeworkid()] = $comp->get_framework();
}
$framework = $frameworks[$comp->get_competencyframeworkid()];
// Get the scale.
$scaleid = $comp->get_scaleid();
$compscale = $comp->get_scale();
if ($scaleid === null) {
$scaleid = $framework->get_scaleid();
$compscale = $framework->get_scale();
}
if (!isset($scales[$scaleid])) {
$scales[$scaleid] = $compscale;
}
$scale = $scales[$scaleid];
$compcontext = $helper->get_context_from_competency($comp);
$framework = $helper->get_framework_from_competency($comp);
$scale = $helper->get_scale_from_competency($comp);
// Prepare the data.
$record = new stdClass();
$exporter = new competency_exporter($comp, array('context' => $framework->get_context()));
$exporter = new competency_exporter($comp, array('context' => $compcontext));
$record->competency = $exporter->export($output);
// Competency path.
$exporter = new competency_path_exporter([
'ancestors' => $comp->get_ancestors(),
'framework' => $framework,
'context' => $framework->get_context()
'context' => $compcontext
]);
$record->comppath = $exporter->export($output);
@@ -122,7 +107,7 @@ class plan_page implements renderable, templatable {
$record->$ucproperty = $exporter->export($output);
$data->competencies[] = $record;
if ($usercomp->get_proficiency()) {
if ($usercomp->get('proficiency')) {
$proficientcount++;
}
}
@@ -142,7 +142,7 @@ class template_cohorts_table extends table_sql {
FROM {" . \core_competency\template_cohort::TABLE . "} tc
JOIN {cohort} c ON c.id = tc.cohortid
WHERE tc.templateid = :templateid";
$params = array('templateid' => $this->template->get_id());
$params = array('templateid' => $this->template->get('id'));
// Add order by if needed.
if (!$count && $sqlsort = $this->get_sql_sort()) {
@@ -34,6 +34,7 @@ use moodle_url;
use core_competency\external\template_exporter;
use core_competency\template;
use core_competency\api;
use core_competency\external\performance_helper;
use tool_lp\external\competency_summary_exporter;
use tool_lp\external\template_statistics_exporter;
use tool_lp\template_statistics;
@@ -76,7 +77,7 @@ class template_competencies_page implements renderable, templatable {
public function __construct(template $template, context $pagecontext) {
$this->pagecontext = $pagecontext;
$this->template = $template;
$this->templatestatistics = new template_statistics($template->get_id());
$this->templatestatistics = new template_statistics($template->get('id'));
$this->competencies = api::list_competencies_in_template($template);
$this->canmanagecompetencyframeworks = has_capability('moodle/competency:competencymanage', $this->pagecontext);
$this->canmanagetemplatecompetencies = has_capability('moodle/competency:templatemanage', $this->pagecontext);
@@ -95,20 +96,13 @@ class template_competencies_page implements renderable, templatable {
$data->template = (new template_exporter($this->template))->export($output);
$data->pagecontextid = $this->pagecontext->id;
$data->competencies = array();
$contextcache = array();
$frameworkcache = array();
$helper = new performance_helper();
foreach ($this->competencies as $competency) {
if (!isset($contextcache[$competency->get_competencyframeworkid()])) {
$contextcache[$competency->get_competencyframeworkid()] = $competency->get_context();
}
$context = $contextcache[$competency->get_competencyframeworkid()];
if (!isset($frameworkcache[$competency->get_competencyframeworkid()])) {
$frameworkcache[$competency->get_competencyframeworkid()] = $competency->get_framework();
}
$framework = $frameworkcache[$competency->get_competencyframeworkid()];
$context = $helper->get_context_from_competency($competency);
$framework = $helper->get_framework_from_competency($competency);
$courses = api::list_courses_using_competency($competency->get_id());
$relatedcompetencies = api::list_related_competencies($competency->get_id());
$courses = api::list_courses_using_competency($competency->get('id'));
$relatedcompetencies = api::list_related_competencies($competency->get('id'));
$related = array(
'competency' => $competency,
@@ -151,7 +151,7 @@ class template_plans_table extends table_sql {
FROM {" . \core_competency\plan::TABLE . "} p
JOIN {user} u ON u.id = p.userid
WHERE p.templateid = :templateid";
$params = array('templateid' => $this->template->get_id());
$params = array('templateid' => $this->template->get('id'));
// Add order by if needed.
if (!$count && $sqlsort = $this->get_sql_sort()) {
@@ -27,8 +27,9 @@ use renderable;
use renderer_base;
use templatable;
use context_course;
use \core_competency\external\competency_exporter;
use \core_competency\external\user_summary_exporter;
use core_competency\external\competency_exporter;
use core_user\external\user_summary_exporter;
use core_competency\external\performance_helper;
use stdClass;
/**
@@ -118,14 +119,9 @@ class user_competency_course_navigation implements renderable, templatable {
$coursecompetencies = \core_competency\api::list_course_competencies($this->courseid);
$data->competencies = array();
$contextcache = array();
$helper = new performance_helper();
foreach ($coursecompetencies as $coursecompetency) {
$frameworkid = $coursecompetency['competency']->get_competencyframeworkid();
if (!isset($contextcache[$frameworkid])) {
$contextcache[$frameworkid] = $coursecompetency['competency']->get_context();
}
$context = $contextcache[$frameworkid];
$coursecompetencycontext = $context;
$coursecompetencycontext = $helper->get_context_from_competency($coursecompetency['competency']);
$exporter = new competency_exporter($coursecompetency['competency'], array('context' => $coursecompetencycontext));
$competency = $exporter->export($output);
if ($competency->id == $this->competencyid) {
@@ -65,7 +65,7 @@ class user_competency_summary implements renderable, templatable {
*/
public function export_for_template(renderer_base $output) {
if (!isset($related['user'])) {
$related['user'] = core_user::get_user($this->usercompetency->get_userid());
$related['user'] = core_user::get_user($this->usercompetency->get('userid'));
}
if (!isset($related['competency'])) {
$related['competency'] = $this->usercompetency->get_competency();
@@ -75,8 +75,8 @@ class user_competency_summary implements renderable, templatable {
'usercompetency' => $this->usercompetency,
'usercompetencyplan' => null,
'usercompetencycourse' => null,
'evidence' => api::list_evidence($this->usercompetency->get_userid(), $this->usercompetency->get_competencyid()),
'relatedcompetencies' => api::list_related_competencies($this->usercompetency->get_competencyid())
'evidence' => api::list_evidence($this->usercompetency->get('userid'), $this->usercompetency->get('competencyid')),
'relatedcompetencies' => api::list_related_competencies($this->usercompetency->get('competencyid'))
);
$exporter = new user_competency_summary_exporter(null, $related);
$data = $exporter->export($output);
@@ -76,7 +76,7 @@ class user_competency_summary_in_course implements renderable, templatable {
throw new \invalid_parameter_exception('Invalid params. The competency does not belong to the course.');
}
$relatedcompetencies = api::list_related_competencies($competency->get_id());
$relatedcompetencies = api::list_related_competencies($competency->get('id'));
$user = $DB->get_record('user', array('id' => $this->userid));
$evidence = api::list_evidence_in_course($this->userid, $this->courseid, $this->competencyid);
$course = $DB->get_record('course', array('id' => $this->courseid));
@@ -74,10 +74,10 @@ class user_competency_summary_in_plan implements renderable, templatable {
throw new \invalid_parameter_exception('Invalid params. The competency does not belong to the plan.');
}
$relatedcompetencies = api::list_related_competencies($competency->get_id());
$userid = $plan->get_userid();
$relatedcompetencies = api::list_related_competencies($competency->get('id'));
$userid = $plan->get('userid');
$user = $DB->get_record('user', array('id' => $userid));
$evidence = api::list_evidence($userid, $this->competencyid, $plan->get_id());
$evidence = api::list_evidence($userid, $this->competencyid, $plan->get('id'));
$params = array(
'competency' => $competency,
+11 -11
View File
@@ -121,7 +121,7 @@ class page_helper {
$templateurl = null;
if ($template) {
$templateurl = new moodle_url('/admin/tool/lp/templatecompetencies.php', [
'templateid' => $template->get_id(),
'templateid' => $template->get('id'),
'pagecontextid' => $pagecontextid
]);
}
@@ -135,7 +135,7 @@ class page_helper {
$PAGE->set_context($pagecontext);
if (!empty($template)) {
$title = format_string($template->get_shortname(), true, array('context' => $context));
$title = format_string($template->get('shortname'), true, array('context' => $context));
} else {
$title = get_string('templates', 'tool_lp');
}
@@ -199,7 +199,7 @@ class page_helper {
$plansurl = new moodle_url('/admin/tool/lp/plans.php', array('userid' => $userid));
$planurl = null;
if ($plan) {
$planurl = new moodle_url('/admin/tool/lp/plan.php', array('id' => $plan->get_id()));
$planurl = new moodle_url('/admin/tool/lp/plan.php', array('id' => $plan->get('id')));
}
$returnurl = $plansurl;
@@ -218,7 +218,7 @@ class page_helper {
}
if (!empty($plan)) {
$title = format_string($plan->get_name(), true, array('context' => $context));
$title = format_string($plan->get('name'), true, array('context' => $context));
} else {
$title = get_string('learningplans', 'tool_lp');
}
@@ -273,7 +273,7 @@ class page_helper {
$evidencelisturl = new moodle_url('/admin/tool/lp/user_evidence_list.php', array('userid' => $userid));
$evidenceurl = null;
if ($evidence) {
$evidenceurl = new moodle_url('/admin/tool/lp/user_evidence.php', array('id' => $evidence->get_id()));
$evidenceurl = new moodle_url('/admin/tool/lp/user_evidence.php', array('id' => $evidence->get('id')));
}
$returnurl = $evidencelisturl;
@@ -292,7 +292,7 @@ class page_helper {
}
if (!empty($evidence)) {
$title = format_string($evidence->get_name(), true, array('context' => $context));
$title = format_string($evidence->get('name'), true, array('context' => $context));
} else {
$title = get_string('userevidence', 'tool_lp');
}
@@ -352,7 +352,7 @@ class page_helper {
$url->remove_params(array('id'));
$PAGE->navbar->add($pagesubtitle, $url);
} else {
$pagetitle = $framework->get_shortname();
$pagetitle = $framework->get('shortname');
$pagesubtitle = get_string('editcompetencyframework', 'tool_lp');
if ($returntype == 'competencies') {
$frameworksurl = new moodle_url('/admin/tool/lp/competencies.php', array(
@@ -417,18 +417,18 @@ class page_helper {
// Set return url.
$returnurloptions = [
'competencyframeworkid' => $framework->get_id(),
'competencyframeworkid' => $framework->get('id'),
'pagecontextid' => $pagecontextid
];
$returnurl = new moodle_url('/admin/tool/lp/competencies.php', $returnurloptions);
$PAGE->navbar->add($framework->get_shortname(), $returnurl);
$PAGE->navbar->add($framework->get('shortname'), $returnurl);
// Set page layout.
$PAGE->set_pagelayout('admin');
if (empty($competency)) {
// Add mode.
$title = format_string($framework->get_shortname(), true, ['context' => $pagecontext]);
$title = format_string($framework->get('shortname'), true, ['context' => $pagecontext]);
// Set the sub-title for add mode.
$level = $parent ? $parent->get_level() + 1 : 1;
@@ -436,7 +436,7 @@ class page_helper {
} else {
// Edit mode.
$title = format_string($competency->get_shortname(), true, ['context' => $competency->get_context()]);
$title = format_string($competency->get('shortname'), true, ['context' => $competency->get_context()]);
// Add competency name to breadcrumbs, if available.
$PAGE->navbar->add($title);
+3 -3
View File
@@ -41,10 +41,10 @@ if (!\core_competency\competency_framework::can_read_context($context)) {
}
$title = get_string('competencies', 'core_competency');
$pagetitle = get_string('competenciesforframework', 'tool_lp', $framework->get_shortname());
$pagetitle = get_string('competenciesforframework', 'tool_lp', $framework->get('shortname'));
// Set up the page.
$url = new moodle_url("/admin/tool/lp/competencies.php", array('competencyframeworkid' => $framework->get_id(),
$url = new moodle_url("/admin/tool/lp/competencies.php", array('competencyframeworkid' => $framework->get('id'),
'pagecontextid' => $pagecontextid));
$frameworksurl = new moodle_url('/admin/tool/lp/competencyframeworks.php', array('pagecontextid' => $pagecontextid));
@@ -52,7 +52,7 @@ $PAGE->navigation->override_active_url($frameworksurl);
$PAGE->set_context($pagecontext);
$PAGE->set_pagelayout('admin');
$PAGE->set_url($url);
$PAGE->navbar->add($framework->get_shortname(), $url);
$PAGE->navbar->add($framework->get('shortname'), $url);
$PAGE->set_title($title);
$PAGE->set_heading($title);
$output = $PAGE->get_renderer('tool_lp');
+32
View File
@@ -0,0 +1,32 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains renamed classes mappings.
*
* @package tool_lp
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$renamedclasses = array(
'tool_lp\\external\\cohort_summary_exporter' => 'core_cohort\\external\\cohort_summary_exporter',
'tool_lp\\external\\course_module_summary_exporter' => 'core_course\\external\\course_module_summary_exporter',
'tool_lp\\external\\course_summary_exporter' => 'core_course\\external\\course_summary_exporter',
'tool_lp\\form\\persistent' => 'core\\form\\persistent',
);
+1 -1
View File
@@ -63,7 +63,7 @@ if ($competency) {
// Get page URL.
$urloptions = [
'id' => $id,
'competencyframeworkid' => $competencyframework->get_id(),
'competencyframeworkid' => $competencyframework->get('id'),
'parentid' => $parentid,
'pagecontextid' => $pagecontextid
];
+1 -1
View File
@@ -58,7 +58,7 @@ if ($form->is_cancelled()) {
$framework = \core_competency\api::create_framework($data);
$frameworkmanageurl = new moodle_url('/admin/tool/lp/competencies.php', array(
'pagecontextid' => $pagecontextid,
'competencyframeworkid' => $framework->get_id()
'competencyframeworkid' => $framework->get('id')
));
$messagesuccess = get_string('competencyframeworkcreated', 'tool_lp');
redirect($frameworkmanageurl, $messagesuccess, 0, \core\output\notification::NOTIFY_SUCCESS);
+2 -2
View File
@@ -42,7 +42,7 @@ if (empty($id)) {
$plan = \core_competency\api::read_plan($id);
// The userid parameter must be the same as the owner of the plan.
if ($userid != $plan->get_userid()) {
if ($userid != $plan->get('userid')) {
throw new coding_exception('Inconsistency between the userid parameter and the userid of the plan');
}
@@ -81,7 +81,7 @@ $data = $form->get_data();
if ($data) {
if (empty($data->id)) {
$plan = \core_competency\api::create_plan($data);
$returnurl = new moodle_url('/admin/tool/lp/plan.php', ['id' => $plan->get_id()]);
$returnurl = new moodle_url('/admin/tool/lp/plan.php', ['id' => $plan->get('id')]);
$returnmsg = get_string('plancreated', 'tool_lp');
} else {
\core_competency\api::update_plan($data);
+1 -1
View File
@@ -71,7 +71,7 @@ if ($data) {
if (empty($data->id)) {
$template = \core_competency\api::create_template($data);
$returnurl = new moodle_url('/admin/tool/lp/templatecompetencies.php', [
'templateid' => $template->get_id(),
'templateid' => $template->get('id'),
'pagecontextid' => $pagecontextid
]);
$returnmsg = get_string('templatecreated', 'tool_lp');
+1 -1
View File
@@ -183,7 +183,7 @@ function tool_lp_coursemodule_edit_post_actions($data, $course) {
$existingids = array();
foreach ($existing as $cmc) {
array_push($existingids, $cmc->get_competencyid());
array_push($existingids, $cmc->get('competencyid'));
}
$newids = isset($data->competencies) ? $data->competencies : array();
+1 -1
View File
@@ -35,7 +35,7 @@ if (isguestuser()) {
$plan = \core_competency\api::read_plan($id);
$url = new moodle_url('/admin/tool/lp/plan.php', array('id' => $id));
list($title, $subtitle) = \tool_lp\page_helper::setup_for_plan($plan->get_userid(), $url, $plan);
list($title, $subtitle) = \tool_lp\page_helper::setup_for_plan($plan->get('userid'), $url, $plan);
$output = $PAGE->get_renderer('tool_lp');
echo $output->header();
+4 -4
View File
@@ -34,7 +34,7 @@ $template = \core_competency\api::read_template($id);
$context = $template->get_context();
$canreadtemplate = $template->can_read();
$canmanagetemplate = $template->can_manage();
$duedatereached = $template->get_duedate() > 0 && $template->get_duedate() < time();
$duedatereached = $template->get('duedate') > 0 && $template->get('duedate') < time();
if (!$canreadtemplate) {
throw new required_capability_exception($context, 'moodle/competency:templateview', 'nopermissions', '');
@@ -65,10 +65,10 @@ if ($canmanagetemplate && ($data = $form->get_data()) && !empty($data->cohorts))
$relation = \core_competency\api::create_template_cohort($template, $cohortid);
// Create a plan for each member if template visible, and the due date is not reached, and we didn't reach our limit yet.
if ($template->get_visible() && $i < $maxtocreate && !$duedatereached) {
if ($template->get('visible') && $i < $maxtocreate && !$duedatereached) {
// Only create a few plans right now.
$tocreate = \core_competency\template_cohort::get_missing_plans($template->get_id(), $cohortid);
$tocreate = \core_competency\template_cohort::get_missing_plans($template->get('id'), $cohortid);
if ($i + count($tocreate) <= $maxtocreate) {
$i += \core_competency\api::create_plans_from_template_cohort($template, $cohortid);
} else {
@@ -94,7 +94,7 @@ echo $output->header();
echo $output->heading($title);
echo $output->heading($subtitle, 3);
if ($canmanagetemplate) {
if ($template->get_visible() == false) {
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('templatecohortnotsyncedwhilehidden', 'tool_lp'));
} else if ($duedatereached) {
+3 -3
View File
@@ -51,7 +51,7 @@ $form = new \tool_lp\form\template_plans($url->out(false));
if ($canmanagetemplate && ($data = $form->get_data()) && !empty($data->users)) {
$i = 0;
foreach ($data->users as $userid) {
$result = \core_competency\api::create_plan_from_template($template->get_id(), $userid);
$result = \core_competency\api::create_plan_from_template($template->get('id'), $userid);
if ($result) {
$i++;
}
@@ -74,10 +74,10 @@ echo $output->heading($subtitle, 3);
// Do not display form when the template is hidden.
if ($canmanagetemplate) {
if (!$template->get_visible()) {
if (!$template->get('visible')) {
// Display message that plan can not be created if the template is hidden.
echo $output->notify_message(get_string('cannotcreateuserplanswhentemplatehidden', 'tool_lp'));
} else if ($template->get_duedate() > 0 && $template->get_duedate() < time() + 900) {
} else if ($template->get('duedate') > 0 && $template->get('duedate') < time() + 900) {
// Prevent the user from creating plans when the due date is passed, or in less than 15 minutes.
echo $output->notify_message(get_string('cannotcreateuserplanswhentemplateduedateispassed', 'tool_lp'));
} else {
+1 -1
View File
@@ -42,7 +42,7 @@ if (!$template->can_read()) {
\core_competency\api::template_viewed($template);
// 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));
list($title, $subtitle) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, $template);
+25 -7
View File
@@ -423,19 +423,19 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
$f1 = $lpg->create_framework();
$c1 = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id()));
$c1 = $lpg->create_competency(array('competencyframeworkid' => $f1->get('id')));
$tpl = $lpg->create_template();
$lpg->create_template_competency(array('templateid' => $tpl->get_id(), 'competencyid' => $c1->get_id()));
$lpg->create_template_competency(array('templateid' => $tpl->get('id'), 'competencyid' => $c1->get('id')));
$plan = $lpg->create_plan(array('userid' => $this->user->id, 'templateid' => $tpl->get_id(), 'name' => 'Evil'));
$plan = $lpg->create_plan(array('userid' => $this->user->id, 'templateid' => $tpl->get('id'), 'name' => 'Evil'));
$uc = $lpg->create_user_competency(array('userid' => $this->user->id, 'competencyid' => $c1->get_id()));
$uc = $lpg->create_user_competency(array('userid' => $this->user->id, 'competencyid' => $c1->get('id')));
$evidence = \core_competency\external::grade_competency_in_plan($plan->get_id(), $c1->get_id(), 1, true);
$evidence = \core_competency\external::grade_competency_in_plan($plan->get_id(), $c1->get_id(), 2, true);
$evidence = \core_competency\external::grade_competency_in_plan($plan->get('id'), $c1->get('id'), 1, true);
$evidence = \core_competency\external::grade_competency_in_plan($plan->get('id'), $c1->get('id'), 2, true);
$summary = external::data_for_user_competency_summary_in_plan($c1->get_id(), $plan->get_id());
$summary = external::data_for_user_competency_summary_in_plan($c1->get('id'), $plan->get('id'));
$this->assertTrue($summary->usercompetencysummary->cangrade);
$this->assertEquals('Evil', $summary->plan->name);
$this->assertEquals('B', $summary->usercompetencysummary->usercompetency->gradename);
@@ -443,6 +443,24 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
$this->assertEquals('A', $summary->usercompetencysummary->evidence[1]->gradename);
}
public function test_data_for_user_competency_summary() {
$this->setUser($this->creator);
$dg = $this->getDataGenerator();
$lpg = $dg->get_plugin_generator('core_competency');
$f1 = $lpg->create_framework();
$c1 = $lpg->create_competency(array('competencyframeworkid' => $f1->get('id')));
$evidence = \core_competency\external::grade_competency($this->user->id, $c1->get('id'), 1, true);
$evidence = \core_competency\external::grade_competency($this->user->id, $c1->get('id'), 2, true);
$summary = external::data_for_user_competency_summary($this->user->id, $c1->get('id'));
$this->assertTrue($summary->cangrade);
$this->assertEquals('B', $summary->usercompetency->gradename);
$this->assertEquals('B', $summary->evidence[0]->gradename);
$this->assertEquals('A', $summary->evidence[1]->gradename);
}
/**
* Search cohorts.
*/
+7
View File
@@ -1,6 +1,13 @@
This files describes changes in /admin/tool/lp/* - plugins,
information provided here is intended especially for developers.
=== 3.3 ===
* Deprecated classes and their new equivalent:
- tool_lp\external\cohort_summary_exporter   -> core_cohort\external\cohort_summary_exporter
- tool_lp\external\course_summary_exporter -> core_course\external\course_summary_exporter
- tool_lp\external\course_module_summary_exporter -> core_course\external\course_module_summary_exporter
=== 3.2 ===
* The icon 'competency.png/svg' has been removed, please use i/competencies instead.
+2 -2
View File
@@ -36,7 +36,7 @@ $uc = \core_competency\api::get_user_competency_by_id($id);
$params = array('id' => $id);
$url = new moodle_url('/admin/tool/lp/user_competency.php', $params);
$user = core_user::get_user($uc->get_userid());
$user = core_user::get_user($uc->get('userid'));
if (!$user || !core_user::is_real_user($user->id)) {
throw new moodle_exception('invaliduser', 'error');
}
@@ -47,7 +47,7 @@ $compexporter = new \core_competency\external\competency_exporter($competency, a
$PAGE->set_pagelayout('standard');
$PAGE->set_url($url);
$PAGE->navigation->override_active_url(new moodle_url('/admin/tool/lp/plans.php', array('userid' => $uc->get_userid())));
$PAGE->navigation->override_active_url(new moodle_url('/admin/tool/lp/plans.php', array('userid' => $uc->get('userid'))));
$PAGE->set_context($uc->get_context());
if (!$iscurrentuser) {
$PAGE->navigation->extend_for_user($user);
+1 -1
View File
@@ -66,7 +66,7 @@ $competency = new \core_competency\competency($competencyid);
if ($userid > 0) {
$usercompetencycourses = \core_competency\api::list_user_competencies_in_course($courseid, $userid);
}
$subtitle = $competency->get_shortname() . ' <em>' . $competency->get_idnumber() . '</em>';
$subtitle = $competency->get('shortname') . ' <em>' . $competency->get('idnumber') . '</em>';
list($title, $subtitle) = \tool_lp\page_helper::setup_for_course($url, $course, $subtitle);
+3 -3
View File
@@ -54,13 +54,13 @@ echo $output->render($nav);
$page = new \tool_lp\output\user_competency_summary_in_plan($competencyid, $planid);
echo $output->render($page);
// Trigger the viewed event.
$pc = \core_competency\api::get_plan_competency($plan, $competency->get_id());
if ($plan->get_status() == \core_competency\plan::STATUS_COMPLETE) {
$pc = \core_competency\api::get_plan_competency($plan, $competency->get('id'));
if ($plan->get('status') == \core_competency\plan::STATUS_COMPLETE) {
$usercompetencyplan = $pc->usercompetencyplan;
\core_competency\api::user_competency_plan_viewed($usercompetencyplan);
} else {
$usercompetency = $pc->usercompetency;
\core_competency\api::user_competency_viewed_in_plan($usercompetency, $plan->get_id());
\core_competency\api::user_competency_viewed_in_plan($usercompetency, $plan->get('id'));
}
echo $output->footer();
+1 -1
View File
@@ -34,7 +34,7 @@ $id = required_param('id', PARAM_INT);
$userevidence = \core_competency\api::read_user_evidence($id);
$url = new moodle_url('/admin/tool/lp/user_evidence.php', array('id' => $id));
list($title, $subtitle) = \tool_lp\page_helper::setup_for_user_evidence($userevidence->get_userid(), $url, $userevidence);
list($title, $subtitle) = \tool_lp\page_helper::setup_for_user_evidence($userevidence->get('userid'), $url, $userevidence);
$output = $PAGE->get_renderer('tool_lp');
echo $output->header();
+3 -3
View File
@@ -46,7 +46,7 @@ if (empty($id)) {
$userevidence = \core_competency\api::read_user_evidence($id);
// The userid parameter must be the same as the owner of the evidence.
if ($userid != $userevidence->get_userid()) {
if ($userid != $userevidence->get('userid')) {
throw new coding_exception('Inconsistency between the userid parameter and the userid of the plan.');
}
@@ -84,7 +84,7 @@ if ($form->is_cancelled()) {
// Load existing user evidence.
$itemid = null;
if ($userevidence) {
$itemid = $userevidence->get_id();
$itemid = $userevidence->get('id');
}
// Massaging the file API.
@@ -100,7 +100,7 @@ if ($data = $form->get_data()) {
if (empty($userevidence)) {
$userevidence = \core_competency\api::create_user_evidence($data, $draftitemid);
$returnurl = new moodle_url('/admin/tool/lp/user_evidence.php', ['id' => $userevidence->get_id()]);
$returnurl = new moodle_url('/admin/tool/lp/user_evidence.php', ['id' => $userevidence->get('id')]);
$returnmsg = get_string('userevidencecreated', 'tool_lp');
} else {
\core_competency\api::update_user_evidence($data, $draftitemid);
@@ -52,7 +52,7 @@ class export extends moodleform {
$options = array();
foreach ($frameworks as $framework) {
$options[$framework->get_id()] = $framework->get_shortname();
$options[$framework->get('id')] = $framework->get('shortname');
}
if (empty($options)) {
$mform->addElement('static', 'frameworkid', '', get_string('noframeworks', 'tool_lpimportcsv'));
@@ -61,7 +61,7 @@ class framework_exporter {
require_once($CFG->libdir . '/csvlib.class.php');
$writer = new csv_export_writer();
$filename = clean_param($this->framework->get_shortname() . '-' . $this->framework->get_idnumber(), PARAM_FILE);
$filename = clean_param($this->framework->get('shortname') . '-' . $this->framework->get('idnumber'), PARAM_FILE);
$writer->set_filename($filename);
$headers = framework_importer::list_required_headers();
@@ -71,44 +71,44 @@ class framework_exporter {
// Order and number of columns must match framework_importer::list_required_headers().
$row = array(
'',
$this->framework->get_idnumber(),
$this->framework->get_shortname(),
$this->framework->get_description(),
$this->framework->get_descriptionformat(),
$this->framework->get('idnumber'),
$this->framework->get('shortname'),
$this->framework->get('description'),
$this->framework->get('descriptionformat'),
$this->framework->get_scale()->compact_items(),
$this->framework->get_scaleconfiguration(),
$this->framework->get('scaleconfiguration'),
'',
'',
'',
'',
'',
true,
implode(',', $this->framework->get_taxonomies())
implode(',', $this->framework->get('taxonomies'))
);
$writer->add_data($row);
$filters = array('competencyframeworkid' => $this->framework->get_id());
$filters = array('competencyframeworkid' => $this->framework->get('id'));
$competencies = api::list_competencies($filters);
// Index by id so we can lookup parents.
$indexed = array();
foreach ($competencies as $competency) {
$indexed[$competency->get_id()] = $competency;
$indexed[$competency->get('id')] = $competency;
}
foreach ($competencies as $competency) {
$parentidnumber = '';
if ($competency->get_parentid() > 0) {
$parent = $indexed[$competency->get_parentid()];
$parentidnumber = $parent->get_idnumber();
if ($competency->get('parentid') > 0) {
$parent = $indexed[$competency->get('parentid')];
$parentidnumber = $parent->get('idnumber');
}
$scalevalues = '';
$scaleconfig = '';
if ($competency->get_scaleid() !== null) {
if ($competency->get('scaleid') !== null) {
$scalevalues = $competency->get_scale()->compact_items();
$scaleconfig = $competency->get_scaleconfiguration();
$scaleconfig = $competency->get('scaleconfiguration');
}
$ruleconfig = $competency->get_ruleconfig();
$ruleconfig = $competency->get('ruleconfig');
if ($ruleconfig === null) {
$ruleconfig = "null";
}
@@ -117,24 +117,24 @@ class framework_exporter {
$relatedidnumbers = array();
foreach ($allrelated as $onerelated) {
$relatedidnumbers[] = str_replace(',', '%2C', $onerelated->get_idnumber());
$relatedidnumbers[] = str_replace(',', '%2C', $onerelated->get('idnumber'));
}
$relatedidnumbers = implode(',', $relatedidnumbers);
// Order and number of columns must match framework_importer::list_required_headers().
$row = array(
$parentidnumber,
$competency->get_idnumber(),
$competency->get_shortname(),
$competency->get_description(),
$competency->get_descriptionformat(),
$competency->get('idnumber'),
$competency->get('shortname'),
$competency->get('description'),
$competency->get('descriptionformat'),
$scalevalues,
$scaleconfig,
$competency->get_ruletype(),
$competency->get_ruleoutcome(),
$competency->get('ruletype'),
$competency->get('ruleoutcome'),
$ruleconfig,
$relatedidnumbers,
$competency->get_id(),
$competency->get('id'),
false,
''
);
@@ -320,7 +320,7 @@ class framework_importer {
*/
public function create_competency($record, $parent, $framework) {
$competency = new stdClass();
$competency->competencyframeworkid = $framework->get_id();
$competency->competencyframeworkid = $framework->get('id');
$competency->shortname = $record->shortname;
if (!empty($record->description)) {
$competency->description = $record->description;
@@ -331,7 +331,7 @@ class framework_importer {
$competency->scaleconfiguration = $this->get_scale_configuration($competency->scaleid, $record->scaleconfiguration);
}
if ($parent) {
$competency->parentid = $parent->get_id();
$competency->parentid = $parent->get('id');
} else {
$competency->parentid = 0;
}
@@ -414,7 +414,7 @@ class framework_importer {
if (isset($this->flat[$idnumber])) {
$relatedcomp = $this->flat[$idnumber]->createdcomp;
api::add_related_competency($comp->get_id(), $relatedcomp->get_id());
api::add_related_competency($comp->get('id'), $relatedcomp->get('id'));
}
}
}
@@ -437,9 +437,9 @@ class framework_importer {
$oldruleconfig = null;
}
$newruleconfig = $class::migrate_config($oldruleconfig, $this->mappings);
$comp->set_ruleconfig($newruleconfig);
$comp->set_ruletype($class);
$comp->set_ruleoutcome($record->ruleoutcome);
$comp->set('ruleconfig', $newruleconfig);
$comp->set('ruletype', $class);
$comp->set('ruleoutcome', $record->ruleoutcome);
$comp->update();
}
}
+1 -1
View File
@@ -62,7 +62,7 @@ if ($form->is_cancelled()) {
$form->set_import_error($error);
} else {
$framework = $importer->import();
$urlparams = ['competencyframeworkid' => $framework->get_id(), 'pagecontextid' => $context->id];
$urlparams = ['competencyframeworkid' => $framework->get('id'), 'pagecontextid' => $context->id];
$frameworksurl = new moodle_url('/admin/tool/lp/competencies.php', $urlparams);
echo $OUTPUT->notification(get_string('competencyframeworkcreated', 'tool_lp'), 'notifysuccess');
echo $OUTPUT->continue_button($frameworksurl);
+2 -2
View File
@@ -47,10 +47,10 @@ class tool_lpimportcsv_import_testcase extends advanced_testcase {
$framework = $importer->import();
$this->assertEmpty('', $importer->get_error());
$this->assertGreaterThan(0, $framework->get_id());
$this->assertGreaterThan(0, $framework->get('id'));
$filters = [
'competencyframeworkid' => $framework->get_id()
'competencyframeworkid' => $framework->get('id')
];
$count = api::count_competencies($filters);
$this->assertEquals(64, $count);
@@ -80,8 +80,8 @@ class framework_mapper {
// Find mappings.
foreach ($collectionfrom as $keyfrom => $compfrom) {
foreach ($collectionto as $keyto => $compto) {
if ($compfrom->get_idnumber() == $compto->get_idnumber()) {
$map[$compfrom->get_id()] = $compto->get_id();
if ($compfrom->get('idnumber') == $compto->get('idnumber')) {
$map[$compfrom->get('id')] = $compto->get('id');
unset($collectionfrom[$keyfrom]);
unset($collectionto[$keyto]);
break;
+75 -75
View File
@@ -55,16 +55,16 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
$f2 = $lpg->create_framework(array('idnumber' => 'BIO2016'));
$f1comps = array();
$f1comps['A1'] = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id(), 'idnumber' => 'A1'));
$f1comps['A2'] = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id(), 'idnumber' => 'A2'));
$f1comps['A3'] = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id(), 'idnumber' => 'A3'));
$f1comps['X1'] = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id(), 'idnumber' => 'X1'));
$f1comps['A1'] = $lpg->create_competency(array('competencyframeworkid' => $f1->get('id'), 'idnumber' => 'A1'));
$f1comps['A2'] = $lpg->create_competency(array('competencyframeworkid' => $f1->get('id'), 'idnumber' => 'A2'));
$f1comps['A3'] = $lpg->create_competency(array('competencyframeworkid' => $f1->get('id'), 'idnumber' => 'A3'));
$f1comps['X1'] = $lpg->create_competency(array('competencyframeworkid' => $f1->get('id'), 'idnumber' => 'X1'));
$f2comps = array();
$f2comps['A1'] = $lpg->create_competency(array('competencyframeworkid' => $f2->get_id(), 'idnumber' => 'A1'));
$f2comps['A2'] = $lpg->create_competency(array('competencyframeworkid' => $f2->get_id(), 'idnumber' => 'A2'));
$f2comps['A3'] = $lpg->create_competency(array('competencyframeworkid' => $f2->get_id(), 'idnumber' => 'A3'));
$f2comps['Y1'] = $lpg->create_competency(array('competencyframeworkid' => $f2->get_id(), 'idnumber' => 'Y1'));
$f2comps['A1'] = $lpg->create_competency(array('competencyframeworkid' => $f2->get('id'), 'idnumber' => 'A1'));
$f2comps['A2'] = $lpg->create_competency(array('competencyframeworkid' => $f2->get('id'), 'idnumber' => 'A2'));
$f2comps['A3'] = $lpg->create_competency(array('competencyframeworkid' => $f2->get('id'), 'idnumber' => 'A3'));
$f2comps['Y1'] = $lpg->create_competency(array('competencyframeworkid' => $f2->get('id'), 'idnumber' => 'Y1'));
$c1 = $dg->create_course(array('startdate' => time() - 72000));
$c2 = $dg->create_course(array('startdate' => time() + 72000));
@@ -83,47 +83,47 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
// Course CompetencieS.
$ccs = array(
$c1->id => array(
$f1comps['A1']->get_id() => $lpg->create_course_competency(array('courseid' => $c1->id,
'competencyid' => $f1comps['A1']->get_id())),
$f1comps['A3']->get_id() => $lpg->create_course_competency(array('courseid' => $c1->id,
'competencyid' => $f1comps['A3']->get_id())),
$f1comps['X1']->get_id() => $lpg->create_course_competency(array('courseid' => $c1->id,
'competencyid' => $f1comps['X1']->get_id())),
$f1comps['A1']->get('id') => $lpg->create_course_competency(array('courseid' => $c1->id,
'competencyid' => $f1comps['A1']->get('id'))),
$f1comps['A3']->get('id') => $lpg->create_course_competency(array('courseid' => $c1->id,
'competencyid' => $f1comps['A3']->get('id'))),
$f1comps['X1']->get('id') => $lpg->create_course_competency(array('courseid' => $c1->id,
'competencyid' => $f1comps['X1']->get('id'))),
),
$c2->id => array(
$f1comps['A2']->get_id() => $lpg->create_course_competency(array('courseid' => $c2->id,
'competencyid' => $f1comps['A2']->get_id())),
$f1comps['A3']->get_id() => $lpg->create_course_competency(array('courseid' => $c2->id,
'competencyid' => $f1comps['A3']->get_id())),
$f1comps['A2']->get('id') => $lpg->create_course_competency(array('courseid' => $c2->id,
'competencyid' => $f1comps['A2']->get('id'))),
$f1comps['A3']->get('id') => $lpg->create_course_competency(array('courseid' => $c2->id,
'competencyid' => $f1comps['A3']->get('id'))),
)
);
// Course Module CompetencieS.
$cmcs = array(
$cms[$c1->id]['F1']->cmid => array(
$f1comps['A1']->get_id() => $lpg->create_course_module_competency(array(
$f1comps['A1']->get('id') => $lpg->create_course_module_competency(array(
'cmid' => $cms[$c1->id]['F1']->cmid,
'competencyid' => $f1comps['A1']->get_id()
'competencyid' => $f1comps['A1']->get('id')
)),
$f1comps['X1']->get_id() => $lpg->create_course_module_competency(array(
$f1comps['X1']->get('id') => $lpg->create_course_module_competency(array(
'cmid' => $cms[$c1->id]['F1']->cmid,
'competencyid' => $f1comps['X1']->get_id()
'competencyid' => $f1comps['X1']->get('id')
)),
),
$cms[$c1->id]['P1']->cmid => array(
$f1comps['A3']->get_id() => $lpg->create_course_module_competency(array(
$f1comps['A3']->get('id') => $lpg->create_course_module_competency(array(
'cmid' => $cms[$c1->id]['P1']->cmid,
'competencyid' => $f1comps['A3']->get_id()
'competencyid' => $f1comps['A3']->get('id')
)),
),
$cms[$c2->id]['F1']->cmid => array(
$f1comps['A2']->get_id() => $lpg->create_course_module_competency(array(
$f1comps['A2']->get('id') => $lpg->create_course_module_competency(array(
'cmid' => $cms[$c2->id]['F1']->cmid,
'competencyid' => $f1comps['A2']->get_id()
'competencyid' => $f1comps['A2']->get('id')
)),
$f1comps['A3']->get_id() => $lpg->create_course_module_competency(array(
$f1comps['A3']->get('id') => $lpg->create_course_module_competency(array(
'cmid' => $cms[$c2->id]['F1']->cmid,
'competencyid' => $f1comps['A3']->get_id()
'competencyid' => $f1comps['A3']->get('id')
)),
),
);
@@ -153,7 +153,7 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
public function test_simple_migration() {
$this->setAdminUser();
$mapper = new framework_mapper($this->f1->get_id(), $this->f2->get_id());
$mapper = new framework_mapper($this->f1->get('id'), $this->f2->get('id'));
$mapper->automap();
$processor = new framework_processor($mapper);
$processor->proceed();
@@ -170,7 +170,7 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
$this->assertEquals(array(), $processor->get_warnings());
$this->assertEquals(array(), $processor->get_errors());
$this->assertEquals(array($this->f1comps['X1']->get_id() => true), $processor->get_missing_mappings());
$this->assertEquals(array($this->f1comps['X1']->get('id') => true), $processor->get_missing_mappings());
$this->assertCourseCompetencyMigrated($this->c1, $this->f1comps['A1'], $this->f2comps['A1']);
$this->assertCourseCompetencyMigrated($this->c1, $this->f1comps['A3'], $this->f2comps['A3']);
@@ -189,7 +189,7 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
public function test_remove_when_missing() {
$this->setAdminUser();
$mapper = new framework_mapper($this->f1->get_id(), $this->f2->get_id());
$mapper = new framework_mapper($this->f1->get('id'), $this->f2->get('id'));
$mapper->automap();
$processor = new framework_processor($mapper);
$processor->set_remove_when_mapping_is_missing(true);
@@ -215,7 +215,7 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
public function test_allowed_courses() {
$this->setAdminUser();
$mapper = new framework_mapper($this->f1->get_id(), $this->f2->get_id());
$mapper = new framework_mapper($this->f1->get('id'), $this->f2->get('id'));
$mapper->automap();
$processor = new framework_processor($mapper);
$processor->set_allowedcourses(array($this->c1->id));
@@ -248,7 +248,7 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
public function test_disallowed_courses() {
$this->setAdminUser();
$mapper = new framework_mapper($this->f1->get_id(), $this->f2->get_id());
$mapper = new framework_mapper($this->f1->get('id'), $this->f2->get('id'));
$mapper->automap();
$processor = new framework_processor($mapper);
$processor->set_disallowedcourses(array($this->c2->id));
@@ -281,7 +281,7 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
public function test_course_start_date_from() {
$this->setAdminUser();
$mapper = new framework_mapper($this->f1->get_id(), $this->f2->get_id());
$mapper = new framework_mapper($this->f1->get('id'), $this->f2->get('id'));
$mapper->automap();
$processor = new framework_processor($mapper);
$processor->set_course_start_date_from(time());
@@ -316,15 +316,15 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
$lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
// Pre-add the new competency to course 1.
$lpg->create_course_competency(array('courseid' => $this->c1->id, 'competencyid' => $this->f2comps['A1']->get_id()));
$lpg->create_course_competency(array('courseid' => $this->c1->id, 'competencyid' => $this->f2comps['A1']->get('id')));
// Pre-add the new competency to module in course 2.
$lpg->create_course_module_competency(array(
'cmid' => $this->cms[$this->c2->id]['F1']->cmid,
'competencyid' => $this->f2comps['A2']->get_id()
'competencyid' => $this->f2comps['A2']->get('id')
));
$mapper = new framework_mapper($this->f1->get_id(), $this->f2->get_id());
$mapper = new framework_mapper($this->f1->get('id'), $this->f2->get('id'));
$mapper->automap();
$processor = new framework_processor($mapper);
$processor->proceed();
@@ -345,13 +345,13 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
$warning = array_shift($warnings);
$this->assertEquals($this->c1->id, $warning['courseid']);
$this->assertEquals($this->f1comps['A1']->get_id(), $warning['competencyid']);
$this->assertEquals($this->f1comps['A1']->get('id'), $warning['competencyid']);
$this->assertEquals(null, $warning['cmid']);
$this->assertRegexp('/competency already exists/', $warning['message']);
$warning = array_shift($warnings);
$this->assertEquals($this->c2->id, $warning['courseid']);
$this->assertEquals($this->f1comps['A2']->get_id(), $warning['competencyid']);
$this->assertEquals($this->f1comps['A2']->get('id'), $warning['competencyid']);
$this->assertEquals($this->cms[$this->c2->id]['F1']->cmid, $warning['cmid']);
$this->assertRegexp('/competency already exists/', $warning['message']);
@@ -364,15 +364,15 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
$lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
// Pre-add the new competency to course 1.
$lpg->create_course_competency(array('courseid' => $this->c1->id, 'competencyid' => $this->f2comps['A1']->get_id()));
$lpg->create_course_competency(array('courseid' => $this->c1->id, 'competencyid' => $this->f2comps['A1']->get('id')));
// Pre-add the new competency to module in course 2.
$lpg->create_course_module_competency(array(
'cmid' => $this->cms[$this->c2->id]['F1']->cmid,
'competencyid' => $this->f2comps['A2']->get_id()
'competencyid' => $this->f2comps['A2']->get('id')
));
$mapper = new framework_mapper($this->f1->get_id(), $this->f2->get_id());
$mapper = new framework_mapper($this->f1->get('id'), $this->f2->get('id'));
$mapper->automap();
$processor = new framework_processor($mapper);
$processor->set_remove_original_when_destination_already_present(true);
@@ -414,7 +414,7 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
$this->setUser($u);
// Do C1 first.
$mapper = new framework_mapper($this->f1->get_id(), $this->f2->get_id());
$mapper = new framework_mapper($this->f1->get('id'), $this->f2->get('id'));
$mapper->automap();
$processor = new framework_processor($mapper);
$processor->set_allowedcourses(array($this->c1->id));
@@ -434,10 +434,10 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
$errors = $processor->get_errors();
$this->assertCount(2, $errors);
$this->assertEquals($this->c1->id, $errors[0]['courseid']);
$this->assertEquals($this->f1comps['A1']->get_id(), $errors[0]['competencyid']);
$this->assertEquals($this->f1comps['A1']->get('id'), $errors[0]['competencyid']);
$this->assertEquals(null, $errors[0]['cmid']);
$this->assertRegexp('/Sorry, but you do not currently have permissions to do that/', $errors[0]['message']);
$this->assertEquals($this->f1comps['A3']->get_id(), $errors[1]['competencyid']);
$this->assertEquals($this->f1comps['A3']->get('id'), $errors[1]['competencyid']);
$this->assertCourseCompetencyNotMigrated($this->c1, $this->f1comps['A1'], $this->f2comps['A1']);
$this->assertCourseCompetencyNotMigrated($this->c1, $this->f1comps['A3'], $this->f2comps['A3']);
@@ -463,10 +463,10 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
$errors = $processor->get_errors();
$this->assertCount(2, $errors);
$this->assertEquals($this->c2->id, $errors[0]['courseid']);
$this->assertEquals($this->f1comps['A2']->get_id(), $errors[0]['competencyid']);
$this->assertEquals($this->f1comps['A2']->get('id'), $errors[0]['competencyid']);
$this->assertEquals($this->cms[$this->c2->id]['F1']->cmid, $errors[0]['cmid']);
$this->assertRegexp('/Sorry, but you do not currently have permissions to do that/', $errors[0]['message']);
$this->assertEquals($this->f1comps['A3']->get_id(), $errors[1]['competencyid']);
$this->assertEquals($this->f1comps['A3']->get('id'), $errors[1]['competencyid']);
// The new competencies were added to the course, but the old ones were not removed because they are still in modules.
$this->assertCourseCompetencyExists($this->c2, $this->f1comps['A2']);
@@ -487,7 +487,7 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
*/
protected function assertCourseCompetencyExists($course, $competency) {
$this->assertTrue(course_competency::record_exists_select("courseid = :courseid AND competencyid = :competencyid",
array('courseid' => $course->id, 'competencyid' => $competency->get_id())));
array('courseid' => $course->id, 'competencyid' => $competency->get('id'))));
}
/**
@@ -498,7 +498,7 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
*/
protected function assertCourseCompetencyNotExists($course, $competency) {
$this->assertFalse(course_competency::record_exists_select("courseid = :courseid AND competencyid = :competencyid",
array('courseid' => $course->id, 'competencyid' => $competency->get_id())));
array('courseid' => $course->id, 'competencyid' => $competency->get('id'))));
}
/**
@@ -514,16 +514,16 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
$this->assertCourseCompetencyNotExists($course, $compfrom);
$this->assertCourseCompetencyExists($course, $compto);
$before = $ccs[$compfrom->get_id()];
$before = $ccs[$compfrom->get('id')];
$after = course_competency::get_record(array(
'courseid' => $course->id,
'competencyid' => $compto->get_id()
'competencyid' => $compto->get('id')
));
$this->assertNotEquals($before->get_id(), $after->get_id());
$this->assertEquals($before->get_courseid(), $after->get_courseid());
$this->assertEquals($before->get_sortorder(), $after->get_sortorder());
$this->assertEquals($before->get_ruleoutcome(), $after->get_ruleoutcome());
$this->assertNotEquals($before->get('id'), $after->get('id'));
$this->assertEquals($before->get('courseid'), $after->get('courseid'));
$this->assertEquals($before->get('sortorder'), $after->get('sortorder'));
$this->assertEquals($before->get('ruleoutcome'), $after->get('ruleoutcome'));
}
/**
@@ -539,13 +539,13 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
$this->assertCourseCompetencyExists($course, $compfrom);
$this->assertCourseCompetencyNotExists($course, $compto);
$before = $ccs[$compfrom->get_id()];
$after = $ccs[$compfrom->get_id()];
$before = $ccs[$compfrom->get('id')];
$after = $ccs[$compfrom->get('id')];
$this->assertEquals($before->get_id(), $after->get_id());
$this->assertEquals($before->get_courseid(), $after->get_courseid());
$this->assertEquals($before->get_sortorder(), $after->get_sortorder());
$this->assertEquals($before->get_ruleoutcome(), $after->get_ruleoutcome());
$this->assertEquals($before->get('id'), $after->get('id'));
$this->assertEquals($before->get('courseid'), $after->get('courseid'));
$this->assertEquals($before->get('sortorder'), $after->get('sortorder'));
$this->assertEquals($before->get('ruleoutcome'), $after->get('ruleoutcome'));
}
/**
@@ -556,7 +556,7 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
*/
protected function assertModuleCompetencyExists($cm, $competency) {
$this->assertTrue(course_module_competency::record_exists_select("cmid = :cmid AND competencyid = :competencyid",
array('cmid' => $cm->cmid, 'competencyid' => $competency->get_id())));
array('cmid' => $cm->cmid, 'competencyid' => $competency->get('id'))));
}
/**
@@ -567,7 +567,7 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
*/
protected function assertModuleCompetencyNotExists($cm, $competency) {
$this->assertFalse(course_module_competency::record_exists_select("cmid = :cmid AND competencyid = :competencyid",
array('cmid' => $cm->cmid, 'competencyid' => $competency->get_id())));
array('cmid' => $cm->cmid, 'competencyid' => $competency->get('id'))));
}
/**
@@ -583,16 +583,16 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
$this->assertModuleCompetencyNotExists($cm, $compfrom);
$this->assertModuleCompetencyExists($cm, $compto);
$before = $cmcs[$compfrom->get_id()];
$before = $cmcs[$compfrom->get('id')];
$after = course_module_competency::get_record(array(
'cmid' => $cm->cmid,
'competencyid' => $compto->get_id()
'competencyid' => $compto->get('id')
));
$this->assertNotEquals($before->get_id(), $after->get_id());
$this->assertEquals($before->get_cmid(), $after->get_cmid());
$this->assertEquals($before->get_sortorder(), $after->get_sortorder());
$this->assertEquals($before->get_ruleoutcome(), $after->get_ruleoutcome());
$this->assertNotEquals($before->get('id'), $after->get('id'));
$this->assertEquals($before->get('cmid'), $after->get('cmid'));
$this->assertEquals($before->get('sortorder'), $after->get('sortorder'));
$this->assertEquals($before->get('ruleoutcome'), $after->get('ruleoutcome'));
}
/**
@@ -608,13 +608,13 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase {
$this->assertModuleCompetencyExists($cm, $compfrom);
$this->assertModuleCompetencyNotExists($cm, $compto);
$before = $cmcs[$compfrom->get_id()];
$after = $cmcs[$compfrom->get_id()];
$before = $cmcs[$compfrom->get('id')];
$after = $cmcs[$compfrom->get('id')];
$this->assertEquals($before->get_id(), $after->get_id());
$this->assertEquals($before->get_cmid(), $after->get_cmid());
$this->assertEquals($before->get_sortorder(), $after->get_sortorder());
$this->assertEquals($before->get_ruleoutcome(), $after->get_ruleoutcome());
$this->assertEquals($before->get('id'), $after->get('id'));
$this->assertEquals($before->get('cmid'), $after->get('cmid'));
$this->assertEquals($before->get('sortorder'), $after->get('sortorder'));
$this->assertEquals($before->get('ruleoutcome'), $after->get('ruleoutcome'));
}
}
@@ -32,7 +32,7 @@ use moodle_url;
use core_competency\api;
use core_competency\external\competency_exporter;
use core_competency\external\user_competency_exporter;
use core_competency\external\user_summary_exporter;
use core_user\external\user_summary_exporter;
/**
* Competencies to review renderable class.
@@ -31,7 +31,7 @@ use stdClass;
use moodle_url;
use core_competency\api;
use core_competency\external\plan_exporter;
use core_competency\external\user_summary_exporter;
use core_user\external\user_summary_exporter;
/**
* Plans to review renderable class.
+2 -2
View File
@@ -29,7 +29,7 @@ use core_competency\api;
use core_competency\external\competency_exporter;
use core_competency\external\plan_exporter;
use core_competency\external\user_competency_exporter;
use core_competency\external\user_summary_exporter;
use core_user\external\user_summary_exporter;
use core_competency\plan;
use core_competency\url;
use renderable;
@@ -83,7 +83,7 @@ class summary implements renderable, templatable {
if (count($plans) >= 3) {
break;
}
if ($plan->get_status() == plan::STATUS_ACTIVE) {
if ($plan->get('status') == plan::STATUS_ACTIVE) {
$plans[] = $plan;
}
}
@@ -17,15 +17,14 @@
/**
* Class for exporting a cohort summary from an stdClass.
*
* @package tool_lp
* @package core_cohort
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\external;
namespace core_cohort\external;
defined('MOODLE_INTERNAL') || die();
use renderer_base;
use moodle_url;
/**
* Class for exporting a cohort summary from an stdClass.
@@ -33,7 +32,7 @@ use moodle_url;
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cohort_summary_exporter extends \core_competency\external\exporter {
class cohort_summary_exporter extends \core\external\exporter {
protected static function define_related() {
// Cohorts can exist on a category context.
@@ -62,7 +61,8 @@ class cohort_summary_exporter extends \core_competency\external\exporter {
public static function define_other_properties() {
return array(
'contextname' => array(
'type' => PARAM_TEXT
// The method context::get_context_name() already formats the string, and may return HTML.
'type' => PARAM_RAW
),
);
}
@@ -19,16 +19,15 @@
*
* A comment area is the set of information about a defined comments area.
*
* @package core_competency
* @package core_comment
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_competency\external;
require_once($CFG->dirroot . '/comment/lib.php');
// TODO MDL-52243 Move this to core.
namespace core_comment\external;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/comment/lib.php');
use comment;
use renderer_base;
use stdClass;
@@ -36,11 +35,11 @@ use stdClass;
/**
* Class for exporting a comment area.
*
* @package core_competency
* @package core_comment
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class comment_area_exporter extends exporter {
class comment_area_exporter extends \core\external\exporter {
/** @var comment The comment instance. */
protected $comment = null;
+265 -265
View File
File diff suppressed because it is too large Load Diff
+48 -48
View File
@@ -129,11 +129,11 @@ class competency extends persistent {
$this->newparent = null;
// During update.
if ($this->get_id()) {
$this->beforeupdate = new competency($this->get_id());
if ($this->get('id')) {
$this->beforeupdate = new competency($this->get('id'));
// The parent ID has changed.
if ($this->beforeupdate->get_parentid() != $this->get_parentid()) {
if ($this->beforeupdate->get('parentid') != $this->get('parentid')) {
$this->newparent = $this->get_parent();
// Update path and sortorder.
@@ -166,8 +166,8 @@ class competency extends persistent {
}
// The parent ID has changed, we need to fix all the paths of the children.
if ($this->beforeupdate->get_parentid() != $this->get_parentid()) {
$beforepath = $this->beforeupdate->get_path() . $this->get_id() . '/';
if ($this->beforeupdate->get('parentid') != $this->get('parentid')) {
$beforepath = $this->beforeupdate->get('path') . $this->get('id') . '/';
$like = $DB->sql_like('path', '?');
$likesearch = $DB->sql_like_escape($beforepath) . '%';
@@ -176,7 +176,7 @@ class competency extends persistent {
$sql = "UPDATE $table SET path = REPLACE(path, ?, ?) WHERE " . $like;
$DB->execute($sql, array(
$beforepath,
$this->get_path() . $this->get_id() . '/',
$this->get('path') . $this->get('id') . '/',
$likesearch
));
@@ -184,9 +184,9 @@ class competency extends persistent {
$table = '{' . self::TABLE . '}';
$sql = "UPDATE $table SET sortorder = sortorder -1 "
. " WHERE competencyframeworkid = ? AND parentid = ? AND sortorder > ?";
$DB->execute($sql, array($this->get_competencyframeworkid(),
$this->beforeupdate->get_parentid(),
$this->beforeupdate->get_sortorder()
$DB->execute($sql, array($this->get('competencyframeworkid'),
$this->beforeupdate->get('parentid'),
$this->beforeupdate->get('sortorder')
));
}
@@ -209,7 +209,7 @@ class competency extends persistent {
// Resolving sortorder holes left after delete.
$table = '{' . self::TABLE . '}';
$sql = "UPDATE $table SET sortorder = sortorder -1 WHERE competencyframeworkid = ? AND parentid = ? AND sortorder > ?";
$DB->execute($sql, array($this->get_competencyframeworkid(), $this->get_parentid(), $this->get_sortorder()));
$DB->execute($sql, array($this->get('competencyframeworkid'), $this->get('parentid'), $this->get('sortorder')));
}
/**
@@ -221,10 +221,10 @@ class competency extends persistent {
* @return array(int grade, bool proficient)
*/
public function get_default_grade() {
$scaleid = $this->get_scaleid();
$scaleconfig = $this->get_scaleconfiguration();
$scaleid = $this->get('scaleid');
$scaleconfig = $this->get('scaleconfiguration');
if ($scaleid === null) {
$scaleconfig = $this->get_framework()->get_scaleconfiguration();
$scaleconfig = $this->get_framework()->get('scaleconfiguration');
}
return competency_framework::get_default_grade_from_scale_configuration($scaleconfig);
}
@@ -235,7 +235,7 @@ class competency extends persistent {
* @return competency_framework
*/
public function get_framework() {
return new competency_framework($this->get_competencyframeworkid());
return new competency_framework($this->get('competencyframeworkid'));
}
/**
@@ -244,7 +244,7 @@ class competency extends persistent {
* @return int
*/
public function get_level() {
$path = $this->get_path();
$path = $this->get('path');
$path = trim($path, '/');
return substr_count($path, '/') + 1;
}
@@ -255,7 +255,7 @@ class competency extends persistent {
* @return null|competency
*/
public function get_parent() {
$parentid = $this->get_parentid();
$parentid = $this->get('parentid');
if (!$parentid) {
return null;
}
@@ -269,10 +269,10 @@ class competency extends persistent {
* @return array(int grade, bool proficient)
*/
public function get_proficiency_of_grade($grade) {
$scaleid = $this->get_scaleid();
$scaleconfig = $this->get_scaleconfiguration();
$scaleid = $this->get('scaleid');
$scaleconfig = $this->get('scaleconfiguration');
if ($scaleid === null) {
$scaleconfig = $this->get_framework()->get_scaleconfiguration();
$scaleconfig = $this->get_framework()->get('scaleconfiguration');
}
return competency_framework::get_proficiency_of_grade_from_scale_configuration($scaleconfig, $grade);
}
@@ -283,7 +283,7 @@ class competency extends persistent {
* @return competency[]
*/
public function get_related_competencies() {
return related_competency::get_related_competencies($this->get_id());
return related_competency::get_related_competencies($this->get('id'));
}
/**
@@ -292,7 +292,7 @@ class competency extends persistent {
* @return null|competency_rule
*/
public function get_rule_object() {
$rule = $this->get_ruletype();
$rule = $this->get('ruletype');
if (!$rule || !is_subclass_of($rule, 'core_competency\\competency_rule')) {
// Double check that the rule is extending the right class to avoid bad surprises.
@@ -308,7 +308,7 @@ class competency extends persistent {
* @return \grade_scale
*/
public function get_scale() {
$scaleid = $this->get_scaleid();
$scaleid = $this->get('scaleid');
if ($scaleid === null) {
return $this->get_framework()->get_scale();
}
@@ -325,8 +325,8 @@ class competency extends persistent {
* @return boolean
*/
public function has_user_competencies() {
return user_competency::has_records_for_competency($this->get_id()) ||
user_competency_plan::has_records_for_competency($this->get_id());
return user_competency::has_records_for_competency($this->get('id')) ||
user_competency_plan::has_records_for_competency($this->get('id'));
}
/**
@@ -339,7 +339,7 @@ class competency extends persistent {
global $DB;
list($insql, $params) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED);
$params['parentid'] = $this->get_id();
$params['parentid'] = $this->get('id');
return $DB->count_records_select(self::TABLE, "id $insql AND parentid = :parentid", $params) == count($ids);
}
@@ -350,9 +350,9 @@ class competency extends persistent {
* @return void
*/
public function reset_rule() {
$this->set_ruleoutcome(static::OUTCOME_NONE);
$this->set_ruletype(null);
$this->set_ruleconfig(null);
$this->raw_set('ruleoutcome', static::OUTCOME_NONE);
$this->raw_set('ruletype', null);
$this->raw_set('ruleconfig', null);
}
/**
@@ -363,11 +363,11 @@ class competency extends persistent {
*/
protected function set_new_path(competency $parent = null) {
$path = '/0/';
if ($this->get_parentid()) {
if ($this->get('parentid')) {
$parent = $parent !== null ? $parent : $this->get_parent();
$path = $parent->get_path() . $this->get_parentid() . '/';
$path = $parent->get('path') . $this->get('parentid') . '/';
}
$this->set('path', $path);
$this->raw_set('path', $path);
}
/**
@@ -376,8 +376,8 @@ class competency extends persistent {
* @return void
*/
protected function set_new_sortorder() {
$search = array('parentid' => $this->get_parentid(), 'competencyframeworkid' => $this->get_competencyframeworkid());
$this->set('sortorder', $this->count_records($search));
$search = array('parentid' => $this->get('parentid'), 'competencyframeworkid' => $this->get('competencyframeworkid'));
$this->raw_set('sortorder', $this->count_records($search));
}
/**
@@ -437,7 +437,7 @@ class competency extends persistent {
// Convert to instances of this class.
foreach ($records as $record) {
$newrecord = new static(0, $record);
$instances[$newrecord->get_id()] = $newrecord;
$instances[$newrecord->get('id')] = $newrecord;
}
return $instances;
}
@@ -451,10 +451,10 @@ class competency extends persistent {
protected function validate_competencyframeworkid($value) {
// During update.
if ($this->get_id()) {
if ($this->get('id')) {
// Ensure that we are not trying to move the competency across frameworks.
if ($this->beforeupdate->get_competencyframeworkid() != $value) {
if ($this->beforeupdate->get('competencyframeworkid') != $value) {
return new lang_string('invaliddata', 'error');
}
@@ -480,9 +480,9 @@ class competency extends persistent {
global $DB;
$sql = 'idnumber = :idnumber AND competencyframeworkid = :competencyframeworkid AND id <> :id';
$params = array(
'id' => $this->get_id(),
'id' => $this->get('id'),
'idnumber' => $value,
'competencyframeworkid' => $this->get_competencyframeworkid()
'competencyframeworkid' => $this->get('competencyframeworkid')
);
if ($DB->record_exists_select(self::TABLE, $sql, $params)) {
return new lang_string('idnumbertaken', 'error');
@@ -499,7 +499,7 @@ class competency extends persistent {
protected function validate_path($value) {
// The last item should be the parent ID.
$id = $this->get_parentid();
$id = $this->get('parentid');
if (substr($value, -(strlen($id) + 2)) != '/' . $id . '/') {
return new lang_string('invaliddata', 'error');
@@ -525,13 +525,13 @@ class competency extends persistent {
}
// During update.
if ($this->get_id()) {
if ($this->get('id')) {
// If there is a new parent.
if ($this->beforeupdate->get_parentid() != $value && $this->newparent) {
if ($this->beforeupdate->get('parentid') != $value && $this->newparent) {
// Check that the new parent belongs to the same framework.
if ($this->newparent->get_competencyframeworkid() != $this->get_competencyframeworkid()) {
if ($this->newparent->get('competencyframeworkid') != $this->get('competencyframeworkid')) {
return new lang_string('invaliddata', 'error');
}
}
@@ -608,10 +608,10 @@ class competency extends persistent {
}
// During update.
if ($this->get_id()) {
if ($this->get('id')) {
// Validate that we can only change the scale when it is not used yet.
if ($this->beforeupdate->get_scaleid() != $value) {
if ($this->beforeupdate->get('scaleid') != $value) {
if ($this->has_user_competencies()) {
return new lang_string('errorscalealreadyused', 'core_competency');
}
@@ -746,10 +746,10 @@ class competency extends persistent {
protected static function build_tree($all, $parentid) {
$tree = array();
foreach ($all as $one) {
if ($one->get_parentid() == $parentid) {
if ($one->get('parentid') == $parentid) {
$node = new stdClass();
$node->competency = $one;
$node->children = self::build_tree($all, $one->get_id());
$node->children = self::build_tree($all, $one->get('id'));
$tree[] = $node;
}
}
@@ -819,7 +819,7 @@ class competency extends persistent {
public static function get_descendants_ids($competency) {
global $DB;
$path = $DB->sql_like_escape($competency->get_path() . $competency->get_id() . '/') . '%';
$path = $DB->sql_like_escape($competency->get('path') . $competency->get('id') . '/') . '%';
$like = $DB->sql_like('path', ':likepath');
return $DB->get_fieldset_select(self::TABLE, 'id', $like, array('likepath' => $path));
}
@@ -859,7 +859,7 @@ class competency extends persistent {
public function get_ancestors() {
global $DB;
$ancestors = array();
$ancestorsids = explode('/', trim($this->get_path(), '/'));
$ancestorsids = explode('/', trim($this->get('path'), '/'));
// Drop the root item from the array /0/.
array_shift($ancestorsids);
if (!empty($ancestorsids)) {
+16 -16
View File
@@ -73,7 +73,7 @@ class competency_framework extends persistent {
* @return context The context
*/
public function get_context() {
return context::instance_by_id($this->get_contextid());
return context::instance_by_id($this->get('contextid'));
}
/**
@@ -127,8 +127,8 @@ class competency_framework extends persistent {
$this->beforeupdate = null;
// During update.
if ($this->get_id()) {
$this->beforeupdate = new competency_framework($this->get_id());
if ($this->get('id')) {
$this->beforeupdate = new competency_framework($this->get('id'));
}
}
@@ -140,7 +140,7 @@ class competency_framework extends persistent {
* @return int
*/
public function get_depth() {
return competency::get_framework_depth($this->get_id());
return competency::get_framework_depth($this->get('id'));
}
/**
@@ -149,7 +149,7 @@ class competency_framework extends persistent {
* @return \grade_scale
*/
public function get_scale() {
$scale = \grade_scale::fetch(array('id' => $this->get_scaleid()));
$scale = \grade_scale::fetch(array('id' => $this->get('scaleid')));
$scale->load_items();
return $scale;
}
@@ -178,8 +178,8 @@ class competency_framework extends persistent {
*
* @return array Contains the list of taxonomy constants indexed by level.
*/
public function get_taxonomies() {
$taxonomies = explode(',', $this->get('taxonomies'));
protected function get_taxonomies() {
$taxonomies = explode(',', $this->raw_get('taxonomies'));
// Indexing first level at 1.
array_unshift($taxonomies, null);
@@ -203,8 +203,8 @@ class competency_framework extends persistent {
* @return boolean
*/
public function has_user_competencies() {
return user_competency::has_records_for_framework($this->get_id()) ||
user_competency_plan::has_records_for_framework($this->get_id());
return user_competency::has_records_for_framework($this->get('id')) ||
user_competency_plan::has_records_for_framework($this->get('id'));
}
/**
@@ -212,11 +212,11 @@ class competency_framework extends persistent {
*
* @param string|array $taxonomies A string, or an array where the values are the term constants.
*/
public function set_taxonomies($taxonomies) {
protected function set_taxonomies($taxonomies) {
if (is_array($taxonomies)) {
$taxonomies = implode(',', $taxonomies);
}
$this->set('taxonomies', $taxonomies);
$this->raw_set('taxonomies', $taxonomies);
}
/**
@@ -236,11 +236,11 @@ class competency_framework extends persistent {
}
// During update.
if ($this->get_id()) {
if ($this->get('id')) {
// The context must never change.
$oldcontextid = $DB->get_field(self::TABLE, 'contextid', array('id' => $this->get_id()), MUST_EXIST);
if ($this->get_contextid() != $oldcontextid) {
$oldcontextid = $DB->get_field(self::TABLE, 'contextid', array('id' => $this->get('id')), MUST_EXIST);
if ($this->get('contextid') != $oldcontextid) {
return new lang_string('invalidcontext', 'error');
}
}
@@ -284,10 +284,10 @@ class competency_framework extends persistent {
}
// During update.
if ($this->get_id()) {
if ($this->get('id')) {
// Validate that we can only change the scale when it is not used yet.
if ($this->beforeupdate->get_scaleid() != $value) {
if ($this->beforeupdate->get('scaleid') != $value) {
if ($this->beforeupdate->has_user_competencies()) {
return new lang_string('errorscalealreadyused', 'core_competency');
}
+2 -2
View File
@@ -48,7 +48,7 @@ abstract class competency_rule {
* @param competency $competency The competency.
*/
public function __construct(competency $competency) {
$class = $competency->get_ruletype();
$class = $competency->get('ruletype');
if (!$class || !($this instanceof $class)) {
throw new coding_exception('This competency does not use this rule.');
}
@@ -62,7 +62,7 @@ abstract class competency_rule {
* @return mixed
*/
protected function get_config() {
return $this->competency->get_ruleconfig();
return $this->competency->get('ruleconfig');
}
/**
+3 -3
View File
@@ -48,7 +48,7 @@ class competency_rule_all extends competency_rule {
global $DB;
// TODO Improve performance here, perhaps the caller could already provide records.
$children = competency::get_records(array('parentid' => $this->competency->get_id()));
$children = competency::get_records(array('parentid' => $this->competency->get('id')));
if (empty($children)) {
// Leaves are not compatible with this rule.
@@ -57,14 +57,14 @@ class competency_rule_all extends competency_rule {
$ids = array();
foreach ($children as $child) {
$ids[] = $child->get_id();
$ids[] = $child->get('id');
}
list($insql, $params) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED);
$sql = "userid = :userid
AND proficiency = :proficiency
AND competencyid $insql";
$params['userid'] = $usercompetency->get_userid();
$params['userid'] = $usercompetency->get('userid');
$params['proficiency'] = 1;
// Is the user is marked as proficient in all children?
@@ -77,7 +77,7 @@ class competency_rule_points extends competency_rule {
$sql = "userid = :userid
AND proficiency = :proficiency
AND competencyid $insql";
$params['userid'] = $usercompetency->get_userid();
$params['userid'] = $usercompetency->get('userid');
$params['proficiency'] = 1;
$ucs = user_competency::get_records_select($sql, $params, '', 'competencyid');
@@ -133,7 +133,7 @@ class competency_rule_points extends competency_rule {
foreach ($config->competencies as $competency) {
// Cannot include self.
if ($competency->id == $this->competency->get_id()) {
if ($competency->id == $this->competency->get('id')) {
return false;
}
@@ -204,7 +204,7 @@ class competency_rule_points extends competency_rule {
foreach ($ruleconfig['competencies'] as $key => $rulecomp) {
$rulecmpid = $rulecomp['id'];
if (array_key_exists($rulecmpid, $mappings)) {
$ruleconfig['competencies'][$key]['id'] = $mappings[$rulecmpid]->get_id();
$ruleconfig['competencies'][$key]['id'] = $mappings[$rulecmpid]->get('id');
} else {
throw new coding_exception("The competency id is not found in the matchids.");
}
+4 -4
View File
@@ -81,8 +81,8 @@ class course_competency extends persistent {
* @return void
*/
protected function before_validate() {
if (($this->get_id() && $this->get_sortorder() === null) || !$this->get_id()) {
$this->set('sortorder', $this->count_records(array('courseid' => $this->get_courseid())));
if (($this->get('id') && $this->get('sortorder') === null) || !$this->get('id')) {
$this->set('sortorder', $this->count_records(array('courseid' => $this->get('courseid'))));
}
}
@@ -294,7 +294,7 @@ class course_competency extends persistent {
$instances = array();
foreach ($results as $result) {
$comp = new competency(0, $result);
$instances[$comp->get_id()] = $comp;
$instances[$comp->get('id')] = $comp;
}
$results->close();
@@ -340,7 +340,7 @@ class course_competency extends persistent {
$table = '{' . self::TABLE . '}';
$sql = "UPDATE $table SET sortorder = sortorder -1 WHERE courseid = ? AND sortorder > ?";
$DB->execute($sql, array($this->get_courseid(), $this->get_sortorder()));
$DB->execute($sql, array($this->get('courseid'), $this->get('sortorder')));
}
/**
@@ -113,7 +113,7 @@ class course_competency_settings extends persistent {
* @return bool
*/
public function can_manage() {
return static::can_manage_course($this->get_courseid());
return static::can_manage_course($this->get('courseid'));
}
/**
@@ -136,6 +136,6 @@ class course_competency_settings extends persistent {
* @return context The context
*/
public function get_context() {
return context_course::instance($this->get_courseid());
return context_course::instance($this->get('courseid'));
}
}
@@ -80,8 +80,8 @@ class course_module_competency extends persistent {
* @return void
*/
protected function before_validate() {
if (($this->get_id() && $this->get_sortorder() === null) || !$this->get_id()) {
$this->set('sortorder', $this->count_records(array('cmid' => $this->get_cmid())));
if (($this->get('id') && $this->get('sortorder') === null) || !$this->get('id')) {
$this->set('sortorder', $this->count_records(array('cmid' => $this->get('cmid'))));
}
}
@@ -222,7 +222,7 @@ class course_module_competency extends persistent {
$instances = array();
foreach ($results as $result) {
$comp = new competency(0, $result);
$instances[$comp->get_id()] = $comp;
$instances[$comp->get('id')] = $comp;
}
$results->close();
@@ -268,7 +268,7 @@ class course_module_competency extends persistent {
$table = '{' . self::TABLE . '}';
$sql = "UPDATE $table SET sortorder = sortorder -1 WHERE cmid = ? AND sortorder > ?";
$DB->execute($sql, array($this->get_cmid(), $this->get_sortorder()));
$DB->execute($sql, array($this->get('cmid'), $this->get('sortorder')));
}
/**
+17 -8
View File
@@ -107,7 +107,16 @@ class evidence extends persistent {
* @return competency
*/
public function get_competency() {
return user_competency::get_competency_by_usercompetencyid($this->get_usercompetencyid());
return user_competency::get_competency_by_usercompetencyid($this->get('usercompetencyid'));
}
/**
* Return the evidence's context.
*
* @return context
*/
public function get_context() {
return context::instance_by_id($this->get('contextid'));
}
/**
@@ -115,8 +124,8 @@ class evidence extends persistent {
*
* @return mixed
*/
public function get_desca() {
$value = $this->get('desca');
protected function get_desca() {
$value = $this->raw_get('desca');
if ($value !== null) {
$value = json_decode($value);
}
@@ -138,14 +147,14 @@ class evidence extends persistent {
* @param mixed $value
* @return mixed
*/
public function set_desca($value) {
protected function set_desca($value) {
if ($value !== null) {
if (!is_scalar($value) && !is_array($value) && !($value instanceof stdClass)) {
throw new coding_exception('$a format not supported.');
}
$value = json_encode($value);
}
$this->set('desca', $value);
$this->raw_set('desca', $value);
}
/**
@@ -153,11 +162,11 @@ class evidence extends persistent {
*
* @param null|string|moodle_url $url The URL.
*/
public function set_url($url) {
protected function set_url($url) {
if ($url instanceof \moodle_url) {
$url = $url->out(false);
}
$this->set('url', $url);
$this->raw_set('url', $url);
}
/**
@@ -220,7 +229,7 @@ class evidence extends persistent {
* @return true|lang_string
*/
protected function validate_descidentifier($value) {
if (!$this->get_id() && !get_string_manager()->string_exists($value, $this->get('desccomponent'))) {
if (!$this->get('id') && !get_string_manager()->string_exists($value, $this->get('desccomponent'))) {
return new lang_string('invalidevidencedesc', 'core_competency');
}
+21 -33
View File
@@ -49,13 +49,13 @@ use core_competency\external\competency_framework_exporter;
use core_competency\external\course_competency_exporter;
use core_competency\external\course_competency_settings_exporter;
use core_competency\external\evidence_exporter;
use core_competency\external\performance_helper;
use core_competency\external\plan_exporter;
use core_competency\external\template_exporter;
use core_competency\external\user_competency_exporter;
use core_competency\external\user_competency_plan_exporter;
use core_competency\external\user_evidence_competency_exporter;
use core_competency\external\user_evidence_exporter;
use core_competency\external\user_summary_exporter;
/**
* External API class.
@@ -1338,14 +1338,12 @@ class external extends external_api {
$result = array();
$contextcache = array();
$helper = new performance_helper();
foreach ($competencies as $competency) {
if (!isset($contextcache[$competency['competency']->get_competencyframeworkid()])) {
$contextcache[$competency['competency']->get_competencyframeworkid()] = $competency['competency']->get_context();
}
$context = $contextcache[$competency['competency']->get_competencyframeworkid()];
$context = $helper->get_context_from_competency($competency['competency']);
$exporter = new competency_exporter($competency['competency'], array('context' => $context));
$competencyrecord = $exporter->export($output);
$exporter = new course_competency_exporter($competency['coursecompetency'], array('context' => $context));
$exporter = new course_competency_exporter($competency['coursecompetency']);
$coursecompetencyrecord = $exporter->export($output);
$result[] = array(
@@ -2149,13 +2147,10 @@ class external extends external_api {
$competencies = api::list_competencies_in_template($params['id']);
$results = array();
$contextcache = array();
$helper = new performance_helper();
foreach ($competencies as $competency) {
if (!isset($contextcache[$competency->get_competencyframeworkid()])) {
$contextcache[$competency->get_competencyframeworkid()] = $competency->get_context();
}
$context = $contextcache[$competency->get_competencyframeworkid()];
$context = $helper->get_context_from_competency($competency);
$exporter = new competency_exporter($competency, array('context' => $context));
$record = $exporter->export($output);
array_push($results, $record);
@@ -2710,9 +2705,8 @@ class external extends external_api {
$params = (object) $params;
$result = api::update_plan($params);
$exporter = plan_exporter($result);
$record = $exporter->export($output);
return external_api::clean_returnvalue(self::update_plan_returns(), $record);
$exporter = new plan_exporter($result, ['template' => $plan->get_template()]);
return $exporter->export($output);
}
/**
@@ -3139,25 +3133,16 @@ class external extends external_api {
$result = api::list_plan_competencies($plan);
if ($plan->get_status() == plan::STATUS_COMPLETE) {
if ($plan->get('status') == plan::STATUS_COMPLETE) {
$ucproperty = 'usercompetencyplan';
} else {
$ucproperty = 'usercompetency';
}
$contextcache = array();
$scalecache = array();
$helper = new performance_helper();
foreach ($result as $key => $r) {
if (!isset($scalecache[$r->competency->get_competencyframeworkid()])) {
$scalecache[$r->competency->get_competencyframeworkid()] = $r->competency->get_framework()->get_scale();
}
$scale = $scalecache[$r->competency->get_competencyframeworkid()];
if (!isset($contextcache[$r->competency->get_competencyframeworkid()])) {
$contextcache[$r->competency->get_competencyframeworkid()] = $r->competency->get_context();
}
$context = $contextcache[$r->competency->get_competencyframeworkid()];
$context = $helper->get_context_from_competency($r->competency);
$scale = $helper->get_scale_from_competency($r->competency);
$exporter = new competency_exporter($r->competency, array('context' => $context));
$r->competency = $exporter->export($output);
@@ -3307,7 +3292,7 @@ class external extends external_api {
$userevidence = api::read_user_evidence($params['id']);
self::validate_context($userevidence->get_context());
return api::delete_user_evidence($userevidence->get_id());
return api::delete_user_evidence($userevidence->get('id'));
}
/**
@@ -3638,7 +3623,7 @@ class external extends external_api {
));
$coursecompetency = new course_competency($params['coursecompetencyid']);
self::validate_context(context_course::instance($coursecompetency->get_courseid()));
self::validate_context(context_course::instance($coursecompetency->get('courseid')));
return api::set_course_competency_ruleoutcome($coursecompetency, $params['ruleoutcome']);
}
@@ -3712,8 +3697,8 @@ class external extends external_api {
$output = $PAGE->get_renderer('core');
$evidence = api::grade_competency(
$uc->get_userid(),
$uc->get_competencyid(),
$uc->get('userid'),
$uc->get('competencyid'),
$params['grade'],
$params['note']
);
@@ -3724,6 +3709,7 @@ class external extends external_api {
'scale' => $scale,
'usercompetency' => $uc,
'usercompetencyplan' => null,
'context' => $evidence->get_context()
]);
return $exporter->export($output);
}
@@ -3798,7 +3784,7 @@ class external extends external_api {
$output = $PAGE->get_renderer('core');
$evidence = api::grade_competency_in_plan(
$plan->get_id(),
$plan->get('id'),
$params['competencyid'],
$params['grade'],
$params['note']
@@ -3810,6 +3796,7 @@ class external extends external_api {
'scale' => $scale,
'usercompetency' => null,
'usercompetencyplan' => null,
'context' => $evidence->get_context()
]);
return $exporter->export($output);
}
@@ -4122,6 +4109,7 @@ class external extends external_api {
'scale' => $scale,
'usercompetency' => null,
'usercompetencyplan' => null,
'context' => $evidence->get_context(),
));
return $exporter->export($output);
}
@@ -4302,7 +4290,7 @@ class external extends external_api {
));
$evidence = api::read_evidence($params['id']);
$uc = api::get_user_competency_by_id($evidence->get_usercompetencyid());
$uc = api::get_user_competency_by_id($evidence->get('usercompetencyid'));
self::validate_context($uc->get_context());
return api::delete_evidence($evidence);
+2 -2
View File
@@ -30,10 +30,10 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class competency_exporter extends persistent_exporter {
class competency_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return 'core_competency\\competency';
return \core_competency\competency::class;
}
protected static function define_related() {
@@ -33,7 +33,7 @@ use renderer_base;
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class competency_framework_exporter extends persistent_exporter {
class competency_framework_exporter extends \core\external\persistent_exporter {
/**
* Define the name of persistent class.
@@ -41,7 +41,7 @@ class competency_framework_exporter extends persistent_exporter {
* @return string
*/
protected static function define_class() {
return 'core_competency\\competency_framework';
return \core_competency\competency_framework::class;
}
/**
@@ -51,7 +51,7 @@ class competency_framework_exporter extends persistent_exporter {
* @return Array
*/
protected function get_other_values(renderer_base $output) {
$filters = array('competencyframeworkid' => $this->persistent->get_id());
$filters = array('competencyframeworkid' => $this->persistent->get('id'));
$context = $this->persistent->get_context();
return array(
'canmanage' => has_capability('moodle/competency:competencymanage', $context),
@@ -74,11 +74,14 @@ class competency_framework_exporter extends persistent_exporter {
'competenciescount' => array(
'type' => PARAM_INT
),
// Both contexts need to be PARAM_RAW because the method context::get_context_name()
// already applies the formatting and thus could return HTML content.
'contextname' => array(
'type' => PARAM_TEXT
'type' => PARAM_RAW
),
'contextnamenoprefix' => array(
'type' => PARAM_TEXT
'type' => PARAM_RAW
)
);
}
+2 -2
View File
@@ -30,9 +30,9 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_competency_exporter extends persistent_exporter {
class course_competency_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return 'core_competency\\course_competency';
return \core_competency\course_competency::class;
}
}
@@ -22,6 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
/**
* Class for exporting course_competency_settings data.
@@ -30,10 +31,10 @@ namespace core_competency\external;
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_competency_settings_exporter extends persistent_exporter {
class course_competency_settings_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return 'core_competency\\course_competency_settings';
return \core_competency\course_competency_settings::class;
}
}
@@ -30,9 +30,9 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_module_competency_exporter extends persistent_exporter {
class course_module_competency_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return 'core_competency\\course_module_competency';
return \core_competency\course_module_competency::class;
}
}
+43 -11
View File
@@ -22,10 +22,13 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
use context_system;
use renderer_base;
use core_competency\evidence;
use core_competency\user_competency;
use core_user\external\user_summary_exporter;
/**
* Class for exporting evidence data.
@@ -33,11 +36,29 @@ use core_competency\user_competency;
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class evidence_exporter extends persistent_exporter {
class evidence_exporter extends \core\external\persistent_exporter {
/**
* Constructor.
*
* @param mixed $data The data.
* @param array $related Array of relateds.
*/
public function __construct($data, $related = array()) {
if (!isset($related['context'])) {
// Previous code was automatically using the system context which was not correct.
// We let developers know that they must fix their code without breaking anything, and
// fallback on the previous behaviour. This should be removed at a later stage: Moodle 3.5.
debugging('Missing related context in evidence_exporter.', DEBUG_DEVELOPER);
$related['context'] = context_system::instance();
}
parent::__construct($data, $related);
}
protected static function define_related() {
return array(
'actionuser' => 'stdClass?',
'context' => 'context',
'scale' => 'grade_scale',
'usercompetency' => 'core_competency\\user_competency?',
'usercompetencyplan' => 'core_competency\\user_competency_plan?',
@@ -45,7 +66,7 @@ class evidence_exporter extends persistent_exporter {
}
protected static function define_class() {
return 'core_competency\\evidence';
return evidence::class;
}
protected function get_other_values(renderer_base $output) {
@@ -59,30 +80,41 @@ class evidence_exporter extends persistent_exporter {
$other['description'] = $this->persistent->get_description();
$other['userdate'] = userdate($this->persistent->get_timecreated());
$other['userdate'] = userdate($this->persistent->get('timecreated'));
if ($this->persistent->get_grade() === null) {
if ($this->persistent->get('grade') === null) {
$gradename = '-';
} else {
$gradename = $this->related['scale']->scale_items[$this->persistent->get_grade() - 1];
$gradename = $this->related['scale']->scale_items[$this->persistent->get('grade') - 1];
}
$other['gradename'] = $gradename;
// Try to guess the user from the user competency.
$userid = null;
if ($this->related['usercompetency']) {
$userid = $this->related['usercompetency']->get_userid();
$userid = $this->related['usercompetency']->get('userid');
} else if ($this->related['usercompetencyplan']) {
$userid = $this->related['usercompetencyplan']->get_userid();
$userid = $this->related['usercompetencyplan']->get('userid');
} else {
$uc = user_competency::get_record(['id' => $this->persistent->get_usercompetencyid()]);
$userid = $uc->get_userid();
$uc = user_competency::get_record(['id' => $this->persistent->get('usercompetencyid')]);
$userid = $uc->get('userid');
}
$other['candelete'] = evidence::can_delete_user($userid);
return $other;
}
/**
* Get the format parameters for gradename.
*
* @return array
*/
protected function get_format_parameters_for_gradename() {
return [
'context' => context_system::instance(), // The system context is cached, so we can get it right away.
];
}
public static function define_other_properties() {
return array(
'actionuser' => array(
@@ -90,13 +122,13 @@ class evidence_exporter extends persistent_exporter {
'optional' => true
),
'description' => array(
'type' => PARAM_TEXT,
'type' => PARAM_TEXT, // The description may contain course names, etc.. which may need filtering.
),
'gradename' => array(
'type' => PARAM_TEXT,
),
'userdate' => array(
'type' => PARAM_TEXT
'type' => PARAM_NOTAGS
),
'candelete' => array(
'type' => PARAM_BOOL
+111
View File
@@ -0,0 +1,111 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Performance helper.
*
* @package core_competency
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
use core_competency\competency;
/**
* Performance helper class.
*
* This tool keeps a local cache of certain items, which means that subsequent
* calls to get the resource will not query the database. You will want to use
* this when many resources could be shared and need to be queried in a loop.
*
* Note that some of these improvements can only be achieved by knowing the
* logic deeper in other modules. For instance we know that a competency's context
* is the one of its framework. This tool must be kept in sync with those APIs.
*
* @package core_competency
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class performance_helper {
/** @var \context Cache of contexts by framework ID. */
protected $frameworkscontexts = [];
/** @var competency_framework Cache of frameworks by framework ID. */
protected $frameworks = [];
/** @var \grade_scale[] Cache of scales by scale ID. */
protected $scales = [];
/**
* Get the context of a competency.
*
* @param competency $competency The competency.
* @return \context
*/
public function get_context_from_competency(competency $competency) {
$frameworkid = $competency->get('competencyframeworkid');
if (!isset($this->frameworkscontexts[$frameworkid])) {
$framework = $this->get_framework_from_competency($competency);
$this->frameworkscontexts[$frameworkid] = $framework->get_context();
}
return $this->frameworkscontexts[$frameworkid];
}
/**
* Get the framework of a competency.
*
* @param competency $competency The competency.
* @return competency_framework
*/
public function get_framework_from_competency(competency $competency) {
$frameworkid = $competency->get('competencyframeworkid');
if (!isset($this->frameworks[$frameworkid])) {
$this->frameworks[$frameworkid] = $competency->get_framework();
}
return $this->frameworks[$frameworkid];
}
/**
* Get the scale of a competency.
*
* /!\ Make sure that this is always kept in sync with:
* - core_competency\competency::get_scale()
* - core_competency\competency_framework::get_scale()
*
* @param competency $competency The competency.
* @return \grade_scale
*/
public function get_scale_from_competency(competency $competency) {
$scaleid = $competency->get('scaleid');
if ($scaleid !== null && !isset($this->scales[$scaleid])) {
$this->scales[$scaleid] = $competency->get_scale();
} else if ($scaleid === null) {
$framework = $this->get_framework_from_competency($competency);
$scaleid = $framework->get('scaleid');
if (!isset($this->scales[$scaleid])) {
$this->scales[$scaleid] = $framework->get_scale();
}
}
return $this->scales[$scaleid];
}
}
+2 -2
View File
@@ -30,9 +30,9 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class plan_competency_exporter extends persistent_exporter {
class plan_competency_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return 'core_competency\\plan_competency';
return \core_competency\plan_competency::class;
}
}
+8 -6
View File
@@ -29,6 +29,8 @@ use renderer_base;
use stdClass;
use moodle_url;
use core_competency\url;
use core_comment\external\comment_area_exporter;
use core_user\external\user_summary_exporter;
/**
* Class for exporting plan data.
@@ -36,10 +38,10 @@ use core_competency\url;
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class plan_exporter extends persistent_exporter {
class plan_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return 'core_competency\\plan';
return \core_competency\plan::class;
}
protected static function define_related() {
@@ -48,7 +50,7 @@ class plan_exporter extends persistent_exporter {
protected function get_other_values(renderer_base $output) {
$classname = static::define_class();
$status = $this->persistent->get_status();
$status = $this->persistent->get('status');
$values = new stdClass();
@@ -85,7 +87,7 @@ class plan_exporter extends persistent_exporter {
$values->isunapproveallowed = $values->canreview && $values->isactive;
}
$values->duedateformatted = userdate($this->persistent->get_duedate());
$values->duedateformatted = userdate($this->persistent->get('duedate'));
if ($this->persistent->is_based_on_template()) {
$exporter = new template_exporter($this->related['template']);
@@ -94,13 +96,13 @@ class plan_exporter extends persistent_exporter {
if (!empty($values->isinreview)) {
// TODO Make this more efficient.
$userexporter = new user_summary_exporter(core_user::get_user($this->persistent->get_reviewerid(), '*', MUST_EXIST));
$userexporter = new user_summary_exporter(core_user::get_user($this->persistent->get('reviewerid'), '*', MUST_EXIST));
$values->reviewer = $userexporter->export($output);
}
$commentareaexporter = new comment_area_exporter($this->persistent->get_comment_object());
$values->commentarea = $commentareaexporter->export($output);
$values->url = url::plan($this->persistent->get_id())->out(false);
$values->url = url::plan($this->persistent->get('id'))->out(false);
return (array) $values;
}
@@ -30,9 +30,9 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class related_competency_exporter extends persistent_exporter {
class related_competency_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return 'core_competency\\related_competency';
return \core_competency\related_competency::class;
}
}
@@ -30,9 +30,9 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class template_competency_exporter extends persistent_exporter {
class template_competency_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return 'core_competency\\template_competency';
return \core_competency\template_competency::class;
}
}
+5 -5
View File
@@ -35,18 +35,18 @@ use core_competency\template_cohort;
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class template_exporter extends persistent_exporter {
class template_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return 'core_competency\\template';
return \core_competency\template::class;
}
protected function get_other_values(renderer_base $output) {
$context = $this->persistent->get_context();
return array(
'duedateformatted' => userdate($this->persistent->get_duedate()),
'cohortscount' => template_cohort::count_records(array('templateid' => $this->persistent->get_id())),
'planscount' => plan::count_records(array('templateid' => $this->persistent->get_id())),
'duedateformatted' => userdate($this->persistent->get('duedate')),
'cohortscount' => template_cohort::count_records(array('templateid' => $this->persistent->get('id'))),
'planscount' => plan::count_records(array('templateid' => $this->persistent->get('id'))),
'canmanage' => $this->persistent->can_manage(),
'canread' => $this->persistent->can_read(),
'contextname' => $context->get_context_name(),
@@ -24,7 +24,7 @@
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
use core_user;
use context_system;
use renderer_base;
use stdClass;
@@ -34,10 +34,10 @@ use stdClass;
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_competency_course_exporter extends persistent_exporter {
class user_competency_course_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return 'core_competency\\user_competency_course';
return \core_competency\user_competency_course::class;
}
protected static function define_related() {
@@ -48,23 +48,34 @@ class user_competency_course_exporter extends persistent_exporter {
protected function get_other_values(renderer_base $output) {
$result = new stdClass();
if ($this->persistent->get_grade() === null) {
if ($this->persistent->get('grade') === null) {
$gradename = '-';
} else {
$gradename = $this->related['scale']->scale_items[$this->persistent->get_grade() - 1];
$gradename = $this->related['scale']->scale_items[$this->persistent->get('grade') - 1];
}
$result->gradename = $gradename;
if ($this->persistent->get_proficiency() === null) {
if ($this->persistent->get('proficiency') === null) {
$proficiencyname = get_string('no');
} else {
$proficiencyname = get_string($this->persistent->get_proficiency() ? 'yes' : 'no');
$proficiencyname = get_string($this->persistent->get('proficiency') ? 'yes' : 'no');
}
$result->proficiencyname = $proficiencyname;
return (array) $result;
}
/**
* Get the format parameters for gradename.
*
* @return array
*/
protected function get_format_parameters_for_gradename() {
return [
'context' => context_system::instance(), // The system context is cached, so we can get it right away.
];
}
protected static function define_other_properties() {
return array(
'gradename' => array(
+26 -13
View File
@@ -24,11 +24,13 @@
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
use context_system;
use core_user;
use renderer_base;
use stdClass;
use core_competency\url;
use core_competency\user_competency;
use core_user\external\user_summary_exporter;
/**
* Class for exporting user competency data.
@@ -36,10 +38,10 @@ use core_competency\user_competency;
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_competency_exporter extends persistent_exporter {
class user_competency_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return 'core_competency\\user_competency';
return user_competency::class;
}
protected static function define_related() {
@@ -50,32 +52,32 @@ class user_competency_exporter extends persistent_exporter {
protected function get_other_values(renderer_base $output) {
$result = new stdClass();
if ($this->persistent->get_grade() === null) {
if ($this->persistent->get('grade') === null) {
$gradename = '-';
} else {
$gradename = $this->related['scale']->scale_items[$this->persistent->get_grade() - 1];
$gradename = $this->related['scale']->scale_items[$this->persistent->get('grade') - 1];
}
$result->gradename = $gradename;
if ($this->persistent->get_proficiency() === null) {
if ($this->persistent->get('proficiency') === null) {
$proficiencyname = get_string('no');
} else {
$proficiencyname = get_string($this->persistent->get_proficiency() ? 'yes' : 'no');
$proficiencyname = get_string($this->persistent->get('proficiency') ? 'yes' : 'no');
}
$result->proficiencyname = $proficiencyname;
$statusname = '-';
if ($this->persistent->get_status() != user_competency::STATUS_IDLE) {
$statusname = (string) user_competency::get_status_name($this->persistent->get_status());
if ($this->persistent->get('status') != user_competency::STATUS_IDLE) {
$statusname = (string) user_competency::get_status_name($this->persistent->get('status'));
}
$result->statusname = $statusname;
$result->canrequestreview = $this->persistent->can_request_review();
$result->canreview = $this->persistent->can_review();
$result->isstatusidle = $this->persistent->get_status() == user_competency::STATUS_IDLE;
$result->isstatusinreview = $this->persistent->get_status() == user_competency::STATUS_IN_REVIEW;
$result->isstatuswaitingforreview = $this->persistent->get_status() == user_competency::STATUS_WAITING_FOR_REVIEW;
$result->isstatusidle = $this->persistent->get('status') == user_competency::STATUS_IDLE;
$result->isstatusinreview = $this->persistent->get('status') == user_competency::STATUS_IN_REVIEW;
$result->isstatuswaitingforreview = $this->persistent->get('status') == user_competency::STATUS_WAITING_FOR_REVIEW;
$result->isrequestreviewallowed = $result->canrequestreview && $result->isstatusidle;
$result->iscancelreviewrequestallowed = $result->canrequestreview && $result->isstatuswaitingforreview;
@@ -84,15 +86,26 @@ class user_competency_exporter extends persistent_exporter {
if (!empty($result->isstatusinreview)) {
// TODO Make this more efficient.
$userexporter = new user_summary_exporter(core_user::get_user($this->persistent->get_reviewerid(), '*', MUST_EXIST));
$userexporter = new user_summary_exporter(core_user::get_user($this->persistent->get('reviewerid'), '*', MUST_EXIST));
$result->reviewer = $userexporter->export($output);
}
$result->url = url::user_competency($this->persistent->get_id())->out(false);
$result->url = url::user_competency($this->persistent->get('id'))->out(false);
return (array) $result;
}
/**
* Get the format parameters for gradename.
*
* @return array
*/
protected function get_format_parameters_for_gradename() {
return [
'context' => context_system::instance(), // The system context is cached, so we can get it right away.
];
}
protected static function define_other_properties() {
return array(
'canrequestreview' => array(
@@ -24,6 +24,7 @@
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
use context_system;
use renderer_base;
use stdClass;
@@ -33,10 +34,10 @@ use stdClass;
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_competency_plan_exporter extends persistent_exporter {
class user_competency_plan_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return 'core_competency\\user_competency_plan';
return \core_competency\user_competency_plan::class;
}
protected static function define_related() {
@@ -47,23 +48,34 @@ class user_competency_plan_exporter extends persistent_exporter {
protected function get_other_values(renderer_base $output) {
$result = new stdClass();
if ($this->persistent->get_grade() === null) {
if ($this->persistent->get('grade') === null) {
$gradename = '-';
} else {
$gradename = $this->related['scale']->scale_items[$this->persistent->get_grade() - 1];
$gradename = $this->related['scale']->scale_items[$this->persistent->get('grade') - 1];
}
$result->gradename = $gradename;
if ($this->persistent->get_proficiency() === null) {
if ($this->persistent->get('proficiency') === null) {
$proficiencyname = get_string('no');
} else {
$proficiencyname = get_string($this->persistent->get_proficiency() ? 'yes' : 'no');
$proficiencyname = get_string($this->persistent->get('proficiency') ? 'yes' : 'no');
}
$result->proficiencyname = $proficiencyname;
return (array) $result;
}
/**
* Get the format parameters for gradename.
*
* @return array
*/
protected function get_format_parameters_for_gradename() {
return [
'context' => context_system::instance(), // The system context is cached, so we can get it right away.
];
}
protected static function define_other_properties() {
return array(
'gradename' => array(
@@ -32,10 +32,10 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_evidence_competency_exporter extends persistent_exporter {
class user_evidence_competency_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return 'core_competency\\user_evidence_competency';
return \core_competency\user_evidence_competency::class;
}
}
+8 -9
View File
@@ -22,9 +22,12 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_competency\external;
defined('MOODLE_INTERNAL') || die();
use moodle_url;
use renderer_base;
use core_competency\external\performance_helper;
use core_files\external\stored_file_exporter;
/**
* Class for exporting user_evidence data.
@@ -33,10 +36,10 @@ use renderer_base;
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_evidence_exporter extends persistent_exporter {
class user_evidence_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return 'core_competency\\user_evidence';
return \core_competency\user_evidence::class;
}
protected static function define_other_properties() {
@@ -75,21 +78,17 @@ class user_evidence_exporter extends persistent_exporter {
}
protected function get_other_values(renderer_base $output) {
$contextcache = array();
$helper = new performance_helper();
$competencies = array();
foreach ($this->related['competencies'] as $competency) {
if (!isset($contextcache[$competency->get_competencyframeworkid()])) {
$contextcache[$competency->get_competencyframeworkid()] = $competency->get_context();
}
$context = $contextcache[$competency->get_competencyframeworkid()];
$context = $helper->get_context_from_competency($competency);
$compexporter = new competency_exporter($competency, array('context' => $context));
$competencies[] = $compexporter->export($output);
}
$urlshort = '';
$url = $this->persistent->get_url();
$url = $this->persistent->get('url');
if (!empty($url)) {
$murl = new moodle_url($url);
$shorturl = preg_replace('@^https?://(www\.)?@', '', $murl->out(false));
@@ -26,24 +26,16 @@ namespace core_competency;
defined('MOODLE_INTERNAL') || die();
debugging('The class core_competency\\invalid_persistent_exception is deprecated. ' .
'Please use core\\invalid_persistent_exception instead.');
/**
* Invalid persistent exception class.
*
* @package core_competency
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @deprecated since Moodle 3.3
*/
class invalid_persistent_exception extends \moodle_exception {
public function __construct(array $errors = array()) {
$forhumans = array();
$debuginfo = array();
foreach ($errors as $key => $message) {
$debuginfo[] = "$key: $message";
$forhumans[] = $message;
}
parent::__construct('invalidpersistenterror', 'core_competency', null,
implode(', ', $forhumans), implode(' - ', $debuginfo));
}
class invalid_persistent_exception extends \core\invalid_persistent_exception {
}
+16 -815
View File
@@ -24,57 +24,37 @@
namespace core_competency;
defined('MOODLE_INTERNAL') || die();
use coding_exception;
use invalid_parameter_exception;
use lang_string;
use ReflectionMethod;
use stdClass;
use renderer_base;
// We need to alias the invalid_persistent_exception, because the persistent classes from
// core_competency used to throw a \core_competency\invalid_persistent_exception. They now
// fully inherit from \core\persistent which throws a core exception. Using class_alias
// ensures that previous try/catch statements still work. Also note that we always need
// need to alias, we cannot do it passively in the classloader because try/catch statements
// do not trigger a class loading. Note that for this trick to work, all the classes
// which were extending \core_competency\persistent still need to extend it or the alias
// won't be effective.
class_alias('core\\invalid_persistent_exception', 'core_competency\\invalid_persistent_exception');
/**
* Abstract class for core_competency objects saved to the DB.
*
* This is a legacy class which all core_competency persistent classes created prior
* to 3.3 must extend.
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class persistent {
/** The table name. */
const TABLE = null;
/** @var array The model data. */
private $data = array();
/** @var array The list of validation errors. */
private $errors = array();
/** @var boolean If the data was already validated. */
private $validated = false;
/**
* Create an instance of this class.
*
* @param int $id If set, this is the id of an existing record, used to load the data.
* @param stdClass $record If set will be passed to {@link self::from_record()}.
*/
public function __construct($id = 0, stdClass $record = null) {
if ($id > 0) {
$this->set('id', $id);
$this->read();
}
if (!empty($record)) {
$this->from_record($record);
}
}
abstract class persistent extends \core\persistent {
/**
* Magic method to capture getters and setters.
* This is only available for competency persistents for backwards compatibility.
* It is recommended to use get('propertyname') and set('propertyname', 'value') directly.
*
* @param string $method Callee.
* @param array $arguments List of arguments.
* @return mixed
*/
final public function __call($method, $arguments) {
debugging('Use of magic setters and getters is deprecated. Use get() and set().', DEBUG_DEVELOPER);
if (strpos($method, 'get_') === 0) {
return $this->get(substr($method, 4));
} else if (strpos($method, 'set_') === 0) {
@@ -83,783 +63,4 @@ abstract class persistent {
throw new coding_exception('Unexpected method call: ' . $method);
}
/**
* Data getter.
*
* This is the main getter for all the properties. Developers can implement their own getters
* but they should be calling {@link self::get()} in order to retrieve the value. Essentially
* the getters defined by the developers would only ever be used as helper methods and will not
* be called internally at this stage. In other words, do not expect {@link self::to_record()} or
* {@link self::from_record()} to use them.
*
* This is protected because we wouldn't want the developers to get into the habit of
* using $persistent->get('property_name'), the lengthy getters must be used.
*
* @param string $property The property name.
* @return mixed
*/
final protected function get($property) {
if (!static::has_property($property)) {
throw new coding_exception('Unexpected property \'' . s($property) .'\' requested.');
}
if (!array_key_exists($property, $this->data) && !static::is_property_required($property)) {
$this->set($property, static::get_property_default_value($property));
}
return isset($this->data[$property]) ? $this->data[$property] : null;
}
/**
* Data setter.
*
* This is the main setter for all the properties. Developers can implement their own setters
* but they should always be calling {@link self::set()} in order to set the value. Essentially
* the setters defined by the developers are helper methods and will not be called internally
* at this stage. In other words do not expect {@link self::to_record()} or
* {@link self::from_record()} to use them.
*
* This is protected because we wouldn't want the developers to get into the habit of
* using $persistent->set('property_name', ''), the lengthy setters must be used.
*
* @param string $property The property name.
* @param mixed $value The value.
* @return mixed
*/
final protected function set($property, $value) {
if (!static::has_property($property)) {
throw new coding_exception('Unexpected property \'' . s($property) .'\' requested.');
}
if (!array_key_exists($property, $this->data) || $this->data[$property] != $value) {
// If the value is changing, we invalidate the model.
$this->validated = false;
}
$this->data[$property] = $value;
}
/**
* Return the custom definition of the properties of this model.
*
* Each property MUST be listed here.
*
* The result of this method is cached internally for the whole request.
*
* The 'default' value can be a Closure when its value may change during a single request.
* For example if the default value is based on a $CFG property, then it should be wrapped in a closure
* to avoid running into scenarios where the true value of $CFG is not reflected in the definition.
* Do not abuse closures as they obviously add some overhead.
*
* Examples:
*
* array(
* 'property_name' => array(
* 'default' => 'Default value', // When not set, the property is considered as required.
* 'message' => new lang_string(...), // Defaults to invalid data error message.
* 'null' => NULL_ALLOWED, // Defaults to NULL_NOT_ALLOWED. Takes NULL_NOW_ALLOWED or NULL_ALLOWED.
* 'type' => PARAM_TYPE, // Mandatory.
* 'choices' => array(1, 2, 3) // An array of accepted values.
* )
* )
*
* array(
* 'dynamic_property_name' => array(
* 'default' => function() {
* return $CFG->something;
* },
* 'type' => PARAM_INT,
* )
* )
*
* @return array Where keys are the property names.
*/
protected static function define_properties() {
return array();
}
/**
* Get the properties definition of this model..
*
* @return array
*/
final public static function properties_definition() {
global $CFG;
static $def = null;
if ($def !== null) {
return $def;
}
$def = static::define_properties();
$def['id'] = array(
'default' => 0,
'type' => PARAM_INT,
);
$def['timecreated'] = array(
'default' => 0,
'type' => PARAM_INT,
);
$def['timemodified'] = array(
'default' => 0,
'type' => PARAM_INT
);
$def['usermodified'] = array(
'default' => 0,
'type' => PARAM_INT
);
// List of reserved property names. Mostly because we have methods (getters/setters) which would confict with them.
// Think about backwards compability before adding new ones here!
$reserved = array('errors', 'formatted_properties', 'records', 'records_select', 'property_default_value',
'property_error_message', 'sql_fields');
foreach ($def as $property => $definition) {
// Ensures that the null property is always set.
if (!array_key_exists('null', $definition)) {
$def[$property]['null'] = NULL_NOT_ALLOWED;
}
// Warn the developers when they are doing something wrong.
if ($CFG->debugdeveloper) {
if (!array_key_exists('type', $definition)) {
throw new coding_exception('Missing type for: ' . $property);
} else if (isset($definition['message']) && !($definition['message'] instanceof lang_string)) {
throw new coding_exception('Invalid error message for: ' . $property);
} else if (in_array($property, $reserved)) {
throw new coding_exception('This property cannot be defined: ' . $property);
}
}
}
return $def;
}
/**
* Gets all the formatted properties.
*
* Formatted properties are properties which have a format associated with them.
*
* @return array Keys are property names, values are property format names.
*/
final public static function get_formatted_properties() {
$properties = static::properties_definition();
$formatted = array();
foreach ($properties as $property => $definition) {
$propertyformat = $property . 'format';
if ($definition['type'] == PARAM_RAW && array_key_exists($propertyformat, $properties)
&& $properties[$propertyformat]['type'] == PARAM_INT) {
$formatted[$property] = $propertyformat;
}
}
return $formatted;
}
/**
* Gets the default value for a property.
*
* This assumes that the property exists.
*
* @param string $property The property name.
* @return mixed
*/
final protected static function get_property_default_value($property) {
$properties = static::properties_definition();
if (!isset($properties[$property]['default'])) {
return null;
}
$value = $properties[$property]['default'];
if ($value instanceof \Closure) {
return $value();
}
return $value;
}
/**
* Gets the error message for a property.
*
* This assumes that the property exists.
*
* @param string $property The property name.
* @return lang_string
*/
final protected static function get_property_error_message($property) {
$properties = static::properties_definition();
if (!isset($properties[$property]['message'])) {
return new lang_string('invaliddata', 'error');
}
return $properties[$property]['message'];
}
/**
* Returns whether or not a property was defined.
*
* @param string $property The property name.
* @return boolean
*/
final public static function has_property($property) {
$properties = static::properties_definition();
return isset($properties[$property]);
}
/**
* Returns whether or not a property is required.
*
* By definition a property with a default value is not required.
*
* @param string $property The property name.
* @return boolean
*/
final public static function is_property_required($property) {
$properties = static::properties_definition();
return !array_key_exists('default', $properties[$property]);
}
/**
* Populate this class with data from a DB record.
*
* Note that this does not use any custom setter because the data here is intended to
* represent what is stored in the database.
*
* @param \stdClass $record A DB record.
* @return persistent
*/
final public function from_record(stdClass $record) {
$record = (array) $record;
foreach ($record as $property => $value) {
$this->set($property, $value);
}
return $this;
}
/**
* Create a DB record from this class.
*
* Note that this does not use any custom getter because the data here is intended to
* represent what is stored in the database.
*
* @return \stdClass
*/
final public function to_record() {
$data = new stdClass();
$properties = static::properties_definition();
foreach ($properties as $property => $definition) {
$data->$property = $this->get($property);
}
return $data;
}
/**
* Load the data from the DB.
*
* @return persistent
*/
final public function read() {
global $DB;
if ($this->get_id() <= 0) {
throw new coding_exception('id is required to load');
}
$record = $DB->get_record(static::TABLE, array('id' => $this->get_id()), '*', MUST_EXIST);
$this->from_record($record);
// Validate the data as it comes from the database.
$this->validated = true;
return $this;
}
/**
* Hook to execute before a create.
*
* Please note that at this stage the data has already been validated and therefore
* any new data being set will not be validated before it is sent to the database.
*
* This is only intended to be used by child classes, do not put any logic here!
*
* @return void
*/
protected function before_create() {
}
/**
* Insert a record in the DB.
*
* @return persistent
*/
final public function create() {
global $DB, $USER;
if ($this->get_id()) {
// The validation methods rely on the ID to know if we're updating or not, the ID should be
// falsy whenever we are creating an object.
throw new coding_exception('Cannot create an object that has an ID defined.');
}
if (!$this->is_valid()) {
throw new invalid_persistent_exception($this->get_errors());
}
// Before create hook.
$this->before_create();
// We can safely set those values bypassing the validation because we know what we're doing.
$now = time();
$this->set('timecreated', $now);
$this->set('timemodified', $now);
$this->set('usermodified', $USER->id);
$record = $this->to_record();
unset($record->id);
$id = $DB->insert_record(static::TABLE, $record);
$this->set('id', $id);
// We ensure that this is flagged as validated.
$this->validated = true;
// After create hook.
$this->after_create();
return $this;
}
/**
* Hook to execute after a create.
*
* This is only intended to be used by child classes, do not put any logic here!
*
* @return void
*/
protected function after_create() {
}
/**
* Hook to execute before an update.
*
* Please note that at this stage the data has already been validated and therefore
* any new data being set will not be validated before it is sent to the database.
*
* This is only intended to be used by child classes, do not put any logic here!
*
* @return void
*/
protected function before_update() {
}
/**
* Update the existing record in the DB.
*
* @return bool True on success.
*/
final public function update() {
global $DB, $USER;
if ($this->get_id() <= 0) {
throw new coding_exception('id is required to update');
} else if (!$this->is_valid()) {
throw new invalid_persistent_exception($this->get_errors());
}
// Before update hook.
$this->before_update();
// We can safely set those values after the validation because we know what we're doing.
$this->set('timemodified', time());
$this->set('usermodified', $USER->id);
$record = $this->to_record();
unset($record->timecreated);
$record = (array) $record;
// Save the record.
$result = $DB->update_record(static::TABLE, $record);
// We ensure that this is flagged as validated.
$this->validated = true;
// After update hook.
$this->after_update($result);
return $result;
}
/**
* Hook to execute after an update.
*
* This is only intended to be used by child classes, do not put any logic here!
*
* @param bool $result Whether or not the update was successful.
* @return void
*/
protected function after_update($result) {
}
/**
* Hook to execute before a delete.
*
* This is only intended to be used by child classes, do not put any logic here!
*
* @return void
*/
protected function before_delete() {
}
/**
* Delete an entry from the database.
*
* @return bool True on success.
*/
final public function delete() {
global $DB;
if ($this->get_id() <= 0) {
throw new coding_exception('id is required to delete');
}
// Hook before delete.
$this->before_delete();
$result = $DB->delete_records(static::TABLE, array('id' => $this->get_id()));
// Hook after delete.
$this->after_delete($result);
// Reset the ID to avoid any confusion, this also invalidates the model's data.
if ($result) {
$this->set('id', 0);
}
return $result;
}
/**
* Hook to execute after a delete.
*
* This is only intended to be used by child classes, do not put any logic here!
*
* @param bool $result Whether or not the delete was successful.
* @return void
*/
protected function after_delete($result) {
}
/**
* Hook to execute before the validation.
*
* This hook will not affect the validation results in any way but is useful to
* internally set properties which will need to be validated.
*
* This is only intended to be used by child classes, do not put any logic here!
*
* @return void
*/
protected function before_validate() {
}
/**
* Validates the data.
*
* Developers can implement addition validation by defining a method as follows. Note that
* the method MUST return a lang_string() when there is an error, and true when the data is valid.
*
* protected function validate_propertyname($value) {
* if ($value !== 'My expected value') {
* return new lang_string('invaliddata', 'error');
* }
* return true
* }
*
* It is OK to use other properties in your custom validation methods when you need to, however note
* they might not have been validated yet, so try not to rely on them too much.
*
* Note that the validation methods should be protected. Validating just one field is not
* recommended because of the possible dependencies between one field and another,also the
* field ID can be used to check whether the object is being updated or created.
*
* When validating foreign keys the persistent should only check that the associated model
* exists. The validation methods should not be used to check for a change in that relationship.
* The API method setting the attributes on the model should be responsible for that.
* E.g. On a course model, the method validate_categoryid will check that the category exists.
* However, if a course can never be moved outside of its category it would be up to the calling
* code to ensure that the category ID will not be altered.
*
* @return array|true Returns true when the validation passed, or an array of properties with errors.
*/
final public function validate() {
global $CFG;
// Before validate hook.
$this->before_validate();
// If this object has not been validated yet.
if ($this->validated !== true) {
$errors = array();
$properties = static::properties_definition();
foreach ($properties as $property => $definition) {
// Get the data, bypassing the potential custom getter which could alter the data.
$value = $this->get($property);
// Check if the property is required.
if ($value === null && static::is_property_required($property)) {
$errors[$property] = new lang_string('requiredelement', 'form');
continue;
}
// Check that type of value is respected.
try {
if ($definition['type'] === PARAM_BOOL && $value === false) {
// Validate_param() does not like false with PARAM_BOOL, better to convert it to int.
$value = 0;
}
validate_param($value, $definition['type'], $definition['null']);
} catch (invalid_parameter_exception $e) {
$errors[$property] = static::get_property_error_message($property);
continue;
}
// Check that the value is part of a list of allowed values.
if (isset($definition['choices']) && !in_array($value, $definition['choices'])) {
$errors[$property] = static::get_property_error_message($property);
continue;
}
// Call custom validation method.
$method = 'validate_' . $property;
if (method_exists($this, $method)) {
// Warn the developers when they are doing something wrong.
if ($CFG->debugdeveloper) {
$reflection = new ReflectionMethod($this, $method);
if (!$reflection->isProtected()) {
throw new coding_exception('The method ' . get_class($this) . '::'. $method . ' should be protected.');
}
}
$valid = $this->{$method}($value);
if ($valid !== true) {
if (!($valid instanceof lang_string)) {
throw new coding_exception('Unexpected error message.');
}
$errors[$property] = $valid;
continue;
}
}
}
$this->validated = true;
$this->errors = $errors;
}
return empty($this->errors) ? true : $this->errors;
}
/**
* Returns whether or not the model is valid.
*
* @return boolean True when it is.
*/
final public function is_valid() {
return $this->validate() === true;
}
/**
* Returns the validation errors.
*
* @return array
*/
final public function get_errors() {
$this->validate();
return $this->errors;
}
/**
* Extract a record from a row of data.
*
* Most likely used in combination with {@link self::get_sql_fields()}. This method is
* simple enough to be used by non-persistent classes, keep that in mind when modifying it.
*
* e.g. persistent::extract_record($row, 'user'); should work.
*
* @param stdClass $row The row of data.
* @param string $prefix The prefix the data fields are prefixed with, defaults to the table name followed by underscore.
* @return stdClass The extracted data.
*/
public static function extract_record($row, $prefix = null) {
if ($prefix === null) {
$prefix = str_replace('_', '', static::TABLE) . '_';
}
$prefixlength = strlen($prefix);
$data = new stdClass();
foreach ($row as $property => $value) {
if (strpos($property, $prefix) === 0) {
$propertyname = substr($property, $prefixlength);
$data->$propertyname = $value;
}
}
return $data;
}
/**
* Load a list of records.
*
* @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.
*
* @return \core_competency\persistent[]
*/
public static function get_records($filters = array(), $sort = '', $order = 'ASC', $skip = 0, $limit = 0) {
global $DB;
$orderby = '';
if (!empty($sort)) {
$orderby = $sort . ' ' . $order;
}
$records = $DB->get_records(static::TABLE, $filters, $orderby, '*', $skip, $limit);
$instances = array();
foreach ($records as $record) {
$newrecord = new static(0, $record);
array_push($instances, $newrecord);
}
return $instances;
}
/**
* Load a single record.
*
* @param array $filters Filters to apply.
* @return false|\core_competency\persistent
*/
public static function get_record($filters = array()) {
global $DB;
$record = $DB->get_record(static::TABLE, $filters);
return $record ? new static(0, $record) : false;
}
/**
* Load a list of records based on a select query.
*
* @param string $select
* @param array $params
* @param string $sort
* @param string $fields
* @param int $limitfrom
* @param int $limitnum
* @return \core_competency\persistent[]
*/
public static function get_records_select($select, $params = null, $sort = '', $fields = '*', $limitfrom = 0, $limitnum = 0) {
global $DB;
$records = $DB->get_records_select(static::TABLE, $select, $params, $sort, $fields, $limitfrom, $limitnum);
// We return class instances.
$instances = array();
foreach ($records as $key => $record) {
$instances[$key] = new static(0, $record);
}
return $instances;
}
/**
* Return the list of fields for use in a SELECT clause.
*
* Having the complete list of fields prefixed allows for multiple persistents to be fetched
* in a single query. Use {@link self::extract_record()} to extract the records from the query result.
*
* @param string $alias The alias used for the table.
* @param string $prefix The prefix to use for each field, defaults to the table name followed by underscore.
* @return string The SQL fragment.
*/
public static function get_sql_fields($alias, $prefix = null) {
global $CFG;
$fields = array();
if ($prefix === null) {
$prefix = str_replace('_', '', static::TABLE) . '_';
}
// Get the properties and move ID to the top.
$properties = static::properties_definition();
$id = $properties['id'];
unset($properties['id']);
$properties = array('id' => $id) + $properties;
foreach ($properties as $property => $definition) {
$as = $prefix . $property;
$fields[] = $alias . '.' . $property . ' AS ' . $as;
// Warn developers that the query will not always work.
if ($CFG->debugdeveloper && strlen($as) > 30) {
throw new coding_exception("The alias '$as' for column '$alias.$property' exceeds 30 characters" .
" and will therefore not work across all supported databases.");
}
}
return implode(', ', $fields);
}
/**
* Count a list of records.
*
* @param array $conditions An array of conditions.
* @return int
*/
public static function count_records(array $conditions = array()) {
global $DB;
$count = $DB->count_records(static::TABLE, $conditions);
return $count;
}
/**
* Count a list of records.
*
* @param string $select
* @param array $params
* @return int
*/
public static function count_records_select($select, $params = null) {
global $DB;
$count = $DB->count_records_select(static::TABLE, $select, $params);
return $count;
}
/**
* Check if a record exists by ID.
*
* @param int $id Record ID.
* @return bool
*/
public static function record_exists($id) {
global $DB;
return $DB->record_exists(static::TABLE, array('id' => $id));
}
/**
* Check if a records exists.
*
* @param string $select
* @param array $params
* @return bool
*/
public static function record_exists_select($select, array $params = null) {
global $DB;
return $DB->record_exists_select(static::TABLE, $select, $params);
}
}
+36 -36
View File
@@ -119,8 +119,8 @@ class plan extends persistent {
$this->beforeupdate = null;
// During update.
if ($this->get_id()) {
$this->beforeupdate = new self($this->get_id());
if ($this->get('id')) {
$this->beforeupdate = new self($this->get('id'));
}
}
@@ -130,7 +130,7 @@ class plan extends persistent {
* @return bool
*/
public function can_comment() {
return static::can_comment_user($this->get_userid());
return static::can_comment_user($this->get('userid'));
}
/**
@@ -140,9 +140,9 @@ class plan extends persistent {
*/
public function can_manage() {
if ($this->is_draft()) {
return self::can_manage_user_draft($this->get_userid());
return self::can_manage_user_draft($this->get('userid'));
}
return self::can_manage_user($this->get_userid());
return self::can_manage_user($this->get('userid'));
}
/**
@@ -152,9 +152,9 @@ class plan extends persistent {
*/
public function can_read() {
if ($this->is_draft()) {
return self::can_read_user_draft($this->get_userid());
return self::can_read_user_draft($this->get('userid'));
}
return self::can_read_user($this->get_userid());
return self::can_read_user($this->get('userid'));
}
/**
@@ -172,7 +172,7 @@ class plan extends persistent {
* @return bool
*/
public function can_request_review() {
return self::can_request_review_user($this->get_userid());
return self::can_request_review_user($this->get('userid'));
}
/**
@@ -181,7 +181,7 @@ class plan extends persistent {
* @return bool
*/
public function can_review() {
return self::can_review_user($this->get_userid());
return self::can_review_user($this->get('userid'));
}
/**
@@ -193,15 +193,15 @@ class plan extends persistent {
global $CFG;
require_once($CFG->dirroot . '/comment/lib.php');
if (!$this->get_id()) {
if (!$this->get('id')) {
throw new \coding_exception('The plan must exist.');
}
$comment = new comment((object) array(
'client_id' => 'plancommentarea' . $this->get_id(),
'client_id' => 'plancommentarea' . $this->get('id'),
'context' => $this->get_context(),
'component' => 'competency', // This cannot be named 'core_competency'.
'itemid' => $this->get_id(),
'itemid' => $this->get('id'),
'area' => 'plan',
'showcount' => true,
));
@@ -217,15 +217,15 @@ class plan extends persistent {
public function get_competencies() {
$competencies = array();
if ($this->get_status() == self::STATUS_COMPLETE) {
if ($this->get('status') == self::STATUS_COMPLETE) {
// Get the competencies from the archive of the plan.
$competencies = user_competency_plan::list_competencies($this->get_id(), $this->get_userid());
$competencies = user_competency_plan::list_competencies($this->get('id'), $this->get('userid'));
} else if ($this->is_based_on_template()) {
// Get the competencies from the template.
$competencies = template_competency::list_competencies($this->get_templateid());
$competencies = template_competency::list_competencies($this->get('templateid'));
} else {
// Get the competencies from the plan.
$competencies = plan_competency::list_competencies($this->get_id());
$competencies = plan_competency::list_competencies($this->get('id'));
}
return $competencies;
@@ -242,15 +242,15 @@ class plan extends persistent {
public function get_competency($competencyid) {
$competency = null;
if ($this->get_status() == self::STATUS_COMPLETE) {
if ($this->get('status') == self::STATUS_COMPLETE) {
// Get the competency from the archive of the plan.
$competency = user_competency_plan::get_competency_by_planid($this->get_id(), $competencyid);
$competency = user_competency_plan::get_competency_by_planid($this->get('id'), $competencyid);
} else if ($this->is_based_on_template()) {
// Get the competency from the template.
$competency = template_competency::get_competency($this->get_templateid(), $competencyid);
$competency = template_competency::get_competency($this->get('templateid'), $competencyid);
} else {
// Get the competency from the plan.
$competency = plan_competency::get_competency($this->get_id(), $competencyid);
$competency = plan_competency::get_competency($this->get('id'), $competencyid);
}
return $competency;
}
@@ -261,7 +261,7 @@ class plan extends persistent {
* @return context_user
*/
public function get_context() {
return context_user::instance($this->get_userid());
return context_user::instance($this->get('userid'));
}
/**
@@ -271,7 +271,7 @@ class plan extends persistent {
*/
public function get_statusname() {
$status = $this->get_status();
$status = $this->get('status');
switch ($status) {
case self::STATUS_DRAFT:
@@ -303,7 +303,7 @@ class plan extends persistent {
* @return template|null
*/
public function get_template() {
$templateid = $this->get_templateid();
$templateid = $this->get('templateid');
if ($templateid === null) {
return null;
}
@@ -319,7 +319,7 @@ class plan extends persistent {
* @return boolean
*/
public function is_draft() {
return in_array($this->get_status(), static::get_draft_statuses());
return in_array($this->get('status'), static::get_draft_statuses());
}
/**
@@ -348,7 +348,7 @@ class plan extends persistent {
global $DB;
// During create.
if (!$this->get_id()) {
if (!$this->get('id')) {
// Check that the user exists. We do not need to do that on update because
// the userid of a plan should never change.
@@ -590,13 +590,13 @@ class plan extends persistent {
}
$params = array(
'templateid' => $template->get_id(),
'templateid' => $template->get('id'),
'status' => self::STATUS_COMPLETE,
'name' => $template->get_shortname(),
'description' => $template->get_description(),
'descriptionformat' => $template->get_descriptionformat(),
'duedate' => $template->get_duedate(),
'name' => $template->get('shortname'),
'description' => $template->get('description'),
'descriptionformat' => $template->get('descriptionformat'),
'duedate' => $template->get('duedate'),
);
$sql = "UPDATE {" . self::TABLE . "}
@@ -616,7 +616,7 @@ class plan extends persistent {
* @return bool
*/
public function is_based_on_template() {
return $this->get_templateid() !== null;
return $this->get('templateid') !== null;
}
/**
@@ -625,7 +625,7 @@ class plan extends persistent {
* @return bool
*/
public function can_be_edited() {
return !$this->is_based_on_template() && $this->get_status() != self::STATUS_COMPLETE && $this->can_manage();
return !$this->is_based_on_template() && $this->get('status') != self::STATUS_COMPLETE && $this->can_manage();
}
/**
@@ -640,15 +640,15 @@ class plan extends persistent {
// We do not check duedate when plan is draft, complete, unset, or based on a template.
if ($this->is_based_on_template()
|| $this->is_draft()
|| $this->get_status() == self::STATUS_COMPLETE
|| $this->get('status') == self::STATUS_COMPLETE
|| empty($value)) {
return true;
}
// During update.
if ($this->get_id()) {
$before = $this->beforeupdate->get_duedate();
$beforestatus = $this->beforeupdate->get_status();
if ($this->get('id')) {
$before = $this->beforeupdate->get('duedate');
$beforestatus = $this->beforeupdate->get('status');
// The value has not changed, then it's always OK. Though if we're going
// from draft to active it has to has to be validated.
+3 -3
View File
@@ -117,8 +117,8 @@ class plan_competency extends persistent {
* @return void
*/
protected function before_validate() {
if (($this->get_id() && $this->get_sortorder() === null) || !$this->get_id()) {
$this->set_sortorder($this->count_records(array('planid' => $this->get_planid())));
if (($this->get('id') && $this->get('sortorder') === null) || !$this->get('id')) {
$this->set('sortorder', $this->count_records(array('planid' => $this->get('planid'))));
}
}
@@ -162,7 +162,7 @@ class plan_competency extends persistent {
$table = '{' . self::TABLE . '}';
$sql = "UPDATE $table SET sortorder = sortorder -1 WHERE planid = ? AND sortorder > ?";
$DB->execute($sql, array($this->get_planid(), $this->get_sortorder()));
$DB->execute($sql, array($this->get('planid'), $this->get('sortorder')));
}
/**
+9 -9
View File
@@ -75,18 +75,18 @@ class related_competency extends persistent {
*/
protected function validate_relatedcompetencyid($data) {
if ($this->get_competencyid() == $data) {
if ($this->get('competencyid') == $data) {
// A competency cannot be related to itself.
return new lang_string('invaliddata', 'error');
} if ($this->get_competencyid() > $data) {
} if ($this->get('competencyid') > $data) {
// The competency ID must be lower than the related competency ID.
return new lang_string('invaliddata', 'error');
} else if (!competency::record_exists($data)) {
return new lang_string('invaliddata', 'error');
} else if (!competency::share_same_framework(array($data, $this->get_competencyid()))) {
} else if (!competency::share_same_framework(array($data, $this->get('competencyid')))) {
// The competencies must belong to the same framework.
return new lang_string('invaliddata', 'error');
}
@@ -110,17 +110,17 @@ class related_competency extends persistent {
// Lower id always as competencyid so we know which one is competencyid and which one relatedcompetencyid.
$relation = new static();
if ($competencyid > $relatedcompetencyid) {
$relation->set_competencyid($relatedcompetencyid);
$relation->set_relatedcompetencyid($competencyid);
$relation->set('competencyid', $relatedcompetencyid);
$relation->set('relatedcompetencyid', $competencyid);
} else {
$relation->set_competencyid($competencyid);
$relation->set_relatedcompetencyid($relatedcompetencyid);
$relation->set('competencyid', $competencyid);
$relation->set('relatedcompetencyid', $relatedcompetencyid);
}
// We can do it because we have bidirectional relations in the DB.
$params = array(
'competencyid' => $relation->get_competencyid(),
'relatedcompetencyid' => $relation->get_relatedcompetencyid()
'competencyid' => $relation->get('competencyid'),
'relatedcompetencyid' => $relation->get('relatedcompetencyid')
);
if ($record = $DB->get_record(self::TABLE, $params)) {
$relation->from_record($record);
+6 -6
View File
@@ -93,8 +93,8 @@ class template extends persistent {
$this->beforeupdate = null;
// During update.
if ($this->get_id()) {
$this->beforeupdate = new self($this->get_id());
if ($this->get('id')) {
$this->beforeupdate = new self($this->get('id'));
}
}
@@ -142,7 +142,7 @@ class template extends persistent {
* @return context The context
*/
public function get_context() {
return context::instance_by_id($this->get_contextid());
return context::instance_by_id($this->get('contextid'));
}
/**
@@ -174,8 +174,8 @@ class template extends persistent {
protected function validate_duedate($value) {
// During update.
if ($this->get_id()) {
$before = $this->beforeupdate->get_duedate();
if ($this->get('id')) {
$before = $this->beforeupdate->get('duedate');
// The value has not changed, then it's always OK.
if ($before == $value) {
@@ -199,7 +199,7 @@ class template extends persistent {
* @return boolean
*/
public function has_plans() {
return plan::has_records_for_template($this->get_id());
return plan::has_records_for_template($this->get('id'));
}
}
+2 -2
View File
@@ -224,8 +224,8 @@ class template_cohort extends persistent {
unset($usertemplate->userid);
unset($usertemplate->uniqueid);
$template = new template(0, $usertemplate);
$missingplans[$template->get_id()]['template'] = $template;
$missingplans[$template->get_id()]['userids'][] = $userid;
$missingplans[$template->get('id')]['template'] = $template;
$missingplans[$template->get('id')]['userids'][] = $userid;
}
}
return array_values($missingplans);

Some files were not shown because too many files have changed in this diff Show More