Commit ae099a2a authored by Andrew Nicols's avatar Andrew Nicols
Browse files

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

parents 88671590 6b206c53
......@@ -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.
......
......@@ -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();
......
......@@ -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 <issam.taboubi@umontreal.ca>
* @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);
}
......
......@@ -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 <issam.taboubi@umontreal.ca>
* @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 - <serge.gauthier.2@umontreal.ca>
* @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 - <serge.gauthier.2@umontreal.ca>
* @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);
......
......@@ -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;
}