Skip to content

Commit

Permalink
MDL-57273 core: Remove magic setters and getters
Browse files Browse the repository at this point in the history
Remove the magic getters and setters from persistent. They are deprecated only in the persistent
class for competencies.
  • Loading branch information
Damyon Wiese committed Jan 20, 2017
1 parent 32896dc commit 9c91a95
Show file tree
Hide file tree
Showing 120 changed files with 2,881 additions and 2,836 deletions.
10 changes: 5 additions & 5 deletions admin/tool/cohortroles/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ public static function sync_all_cohort_roles() {
// 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.

Expand Down
14 changes: 7 additions & 7 deletions admin/tool/cohortroles/tests/api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ public function test_create_cohort_role_assignment() {
'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);
}

/**
Expand All @@ -114,7 +114,7 @@ public function test_delete_cohort_role_assignment_without_permission() {
);
$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'));
}

/**
Expand All @@ -128,7 +128,7 @@ public function test_delete_cohort_role_assignment_with_invalid_data() {
'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() {
Expand All @@ -139,7 +139,7 @@ public function test_delete_cohort_role_assignment() {
'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);
}

Expand Down
6 changes: 3 additions & 3 deletions admin/tool/lp/classes/course_competencies_form_element.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct($elementName=null, $elementLabel=null, $options=arra
$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);
}
Expand All @@ -76,10 +76,10 @@ public function __construct($elementName=null, $elementLabel=null, $options=arra
$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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct($elementName=null, $elementLabel=null, $options=arra
// 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();
Expand Down
8 changes: 4 additions & 4 deletions admin/tool/lp/classes/external/competency_path_exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ protected function get_other_values(renderer_base $output) {
$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
Expand All @@ -107,8 +107,8 @@ protected function get_other_values(renderer_base $output) {
}
$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
Expand Down
12 changes: 6 additions & 6 deletions admin/tool/lp/classes/external/competency_summary_exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,16 @@ protected function get_other_values(renderer_base $output) {

$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;

$level = $competency->get_level();
$level = $competency->get('level');
$taxonomy = $this->related['framework']->get_taxonomy($level);
$result->taxonomyterm = (string) (competency_framework::get_taxonomies_list()[$taxonomy]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ protected function get_other_values(renderer_base $output) {
$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();
Expand All @@ -149,7 +149,7 @@ protected function get_other_values(renderer_base $output) {
}

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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function get_other_values(renderer_base $output) {
$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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected static function define_other_properties() {

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));
Expand Down
27 changes: 15 additions & 12 deletions admin/tool/lp/classes/form/competency.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,29 @@ public function definition() {

$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'));
}
Expand All @@ -83,12 +86,12 @@ public function definition() {
$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));
}

Expand Down Expand Up @@ -124,7 +127,7 @@ public function definition() {
// 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.
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/lp/classes/form/competency_framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function definition() {
// 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'));
Expand Down
6 changes: 3 additions & 3 deletions admin/tool/lp/classes/form/framework_autocomplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ public function setValue($value) {
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);
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/lp/classes/form/plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function definition() {
// 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) {
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/lp/classes/output/competency_summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public function __construct($competency, $framework, $includerelated, $includeco
$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'));
}
}

Expand Down
6 changes: 3 additions & 3 deletions admin/tool/lp/classes/output/course_competencies_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ public function export_for_template(renderer_base $output) {
$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();
Expand All @@ -164,7 +164,7 @@ public function export_for_template(renderer_base $output) {
if ($gradable) {
$foundusercompetencycourse = false;
foreach ($usercompetencycourses as $usercompetencycourse) {
if ($usercompetencycourse->get_competencyid() == $competency->get_id()) {
if ($usercompetencycourse->get('competencyid') == $competency->get('id')) {
$foundusercompetencycourse = $usercompetencycourse;
}
}
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/lp/classes/output/plan_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function export_for_template(\renderer_base $output) {
$record->$ucproperty = $exporter->export($output);

$data->competencies[] = $record;
if ($usercomp->get_proficiency()) {
if ($usercomp->get('proficiency')) {
$proficientcount++;
}
}
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/lp/classes/output/template_cohorts_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected function get_sql_and_params($count = false) {
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()) {
Expand Down
6 changes: 3 additions & 3 deletions admin/tool/lp/classes/output/template_competencies_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,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);
Expand All @@ -101,8 +101,8 @@ public function export_for_template(renderer_base $output) {
$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,
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/lp/classes/output/template_plans_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected function get_sql_and_params($count = false) {
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()) {
Expand Down
Loading

0 comments on commit 9c91a95

Please sign in to comment.