MDL-78168 mod_assign: Stop storing properties dynamically

In PHP 8.2 and later, setting a value to an undeclared class property is
deprecated and emits a deprecation notice.
So we need to add missing class properties that still need to be declared.

In these cases, mod_assign was treating other unrelated objects as its
personal object store. These have been updated to not require this.
This commit is contained in:
Andrew Nicols
2023-06-24 13:35:13 +08:00
parent 56c8910c4b
commit cb6d999911
3 changed files with 77 additions and 45 deletions
+29 -40
View File
@@ -746,49 +746,38 @@ class assign_files implements renderable {
* @param array $dir
* @param string $filearea
* @param string $component
* @return void
*/
public function preprocess($dir, $filearea, $component) {
global $CFG;
// Nothing to do here any more.
}
foreach ($dir['subdirs'] as $subdir) {
$this->preprocess($subdir, $filearea, $component);
}
foreach ($dir['files'] as $file) {
$file->portfoliobutton = '';
/**
* Get the modified time of the specified file.
* @param stored_file $file
* @return string
*/
public function get_modified_time(stored_file $file): string {
return userdate(
$file->get_timemodified(),
get_string('strftimedatetime', 'langconfig'),
);
}
$file->timemodified = userdate(
$file->get_timemodified(),
get_string('strftimedatetime', 'langconfig')
);
if (!empty($CFG->enableportfolios)) {
require_once($CFG->libdir . '/portfoliolib.php');
$button = new portfolio_add_button();
if (has_capability('mod/assign:exportownsubmission', $this->context)) {
$portfolioparams = array('cmid' => $this->cm->id, 'fileid' => $file->get_id());
$button->set_callback_options('assign_portfolio_caller',
$portfolioparams,
'mod_assign');
$button->set_format_by_file($file);
$file->portfoliobutton = $button->to_html(PORTFOLIO_ADD_ICON_LINK);
}
}
$path = '/' .
$this->context->id .
'/' .
$component .
'/' .
$filearea .
'/' .
$file->get_itemid() .
$file->get_filepath() .
$file->get_filename();
$url = file_encode_url("$CFG->wwwroot/pluginfile.php", $path, true);
$filename = $file->get_filename();
$file->fileurl = html_writer::link($url, $filename, [
'target' => '_blank',
]);
}
/**
* Get the URL used to view the file.
*
* @param stored_file
* @return moodle_url
*/
public function get_file_url(stored_file $file): moodle_url {
return \moodle_url::make_pluginfile_url(
$this->context->id,
$file->get_component(),
$file->get_filearea(),
$file->get_itemid(),
$file->get_filepath(),
$file->get_filename(),
true,
);
}
}