MDL-67613 availability_completion: replacing old arrays

This commit is contained in:
Ferran Recio
2020-05-06 11:27:34 +02:00
parent c54b183c8d
commit 1db6424ceb
3 changed files with 165 additions and 126 deletions
@@ -37,7 +37,7 @@ class frontend extends \core_availability\frontend {
/**
* @var array Cached init parameters
*/
protected $cacheparams = array();
protected $cacheparams = [];
/**
* @var string IDs of course, cm, and section for cache (if any)
@@ -45,8 +45,8 @@ class frontend extends \core_availability\frontend {
protected $cachekey = '';
protected function get_javascript_strings() {
return array('option_complete', 'option_fail', 'option_incomplete', 'option_pass',
'label_cm', 'label_completion');
return ['option_complete', 'option_fail', 'option_incomplete', 'option_pass',
'label_cm', 'label_completion'];
}
protected function get_javascript_init_params($course, \cm_info $cm = null,
@@ -59,29 +59,29 @@ class frontend extends \core_availability\frontend {
// Get list of activities on course which have completion values,
// to fill the dropdown.
$context = \context_course::instance($course->id);
$cms = array();
$cms = [];
$modinfo = get_fast_modinfo($course);
$previouscm = false;
foreach ($modinfo->cms as $id => $othercm) {
// Add each course-module if it has completion turned on and is not
// the one currently being edited.
if ($othercm->completion && (empty($cm) || $cm->id != $id) && !$othercm->deletioninprogress) {
$cms[] = (object)array('id' => $id,
'name' => format_string($othercm->name, true, array('context' => $context)),
'completiongradeitemnumber' => $othercm->completiongradeitemnumber);
$cms[] = (object)['id' => $id,
'name' => format_string($othercm->name, true, ['context' => $context]),
'completiongradeitemnumber' => $othercm->completiongradeitemnumber];
}
if (count($cms) && (empty($cm) || $cm->id == $id)) {
$previouscm = true;
}
}
if ($previouscm) {
$previous = (object)array('id' => \availability_completion\condition::OPTION_PREVIOUS,
$previous = (object)['id' => \availability_completion\condition::OPTION_PREVIOUS,
'name' => get_string('option_previous', 'availability_completion'),
'completiongradeitemnumber' => \availability_completion\condition::OPTION_PREVIOUS);
'completiongradeitemnumber' => \availability_completion\condition::OPTION_PREVIOUS];
array_unshift($cms, $previous);
}
$this->cachekey = $cachekey;
$this->cacheinitparams = array($cms);
$this->cacheinitparams = [$cms];
}
return $this->cacheinitparams;
}