Skip to content

Commit

Permalink
CodeChecker!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
gjb2048 committed Sep 22, 2023
1 parent 5a4290b commit 892864d
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 194 deletions.
4 changes: 2 additions & 2 deletions backup/moodle2/backup_format_grid_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ protected function define_section_plugin_structure() {
// Create one standard named plugin element (the visible container).
// The sectionid and courseid not required as populated on restore.
$recomendedname = $this->get_recommended_name();
$section = new backup_nested_element($recomendedname, array('sectionid'), array('image', 'contenthash'));
$section = new backup_nested_element($recomendedname, ['sectionid'], ['image', 'contenthash']);

// Connect the visible container ASAP.
$plugin->add_child($section);

// Set source to populate the data.
$section->set_source_table('format_grid_image', array('sectionid' => backup::VAR_SECTIONID));
$section->set_source_table('format_grid_image', ['sectionid' => backup::VAR_SECTIONID]);
$section->annotate_files('format_grid', 'sectionimage', 'sectionid');

return $plugin;
Expand Down
16 changes: 8 additions & 8 deletions backup/moodle2/restore_format_grid_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function define_course_plugin_structure() {
$this->originalnumsections = (int)$maxsection;
}

$paths = array();
$paths = [];

// Add own format stuff.
$elename = 'grid'; // This defines the postfix of 'process_*' below.
Expand All @@ -80,14 +80,14 @@ public function process_grid($data) {
$courseid = $this->task->get_courseid();
/* We only process this information if the course we are restoring to
has 'grid' format (target format can change depending of restore options). */
$format = $DB->get_field('course', 'format', array('id' => $courseid));
$format = $DB->get_field('course', 'format', ['id' => $courseid]);
if ($format !== 'grid') {
return;
}

$data->courseid = $courseid;

if (!($course = $DB->get_record('course', array('id' => $data->courseid)))) {
if (!($course = $DB->get_record('course', ['id' => $data->courseid]))) {
throw new \moodle_exception('invalidcourseid', 'format_grid', '',
get_string('invalidcourseid', 'error'));
} // From /course/view.php.
Expand All @@ -107,7 +107,7 @@ public function after_restore_course() {

/* We only process this information if the course we are restoring to
has 'grid' format (target format can change depending of restore options). */
$format = $DB->get_field('course', 'format', array('id' => $courseid));
$format = $DB->get_field('course', 'format', ['id' => $courseid]);
if ($format !== 'grid') {
return;
}
Expand All @@ -123,7 +123,7 @@ public function after_restore_course() {
if (!$file->is_directory()) {
$filename = $file->get_filename();
$filesectionid = $file->get_itemid();
$gridimage = $DB->get_record('format_grid_image', array('sectionid' => $filesectionid), 'image');
$gridimage = $DB->get_record('format_grid_image', ['sectionid' => $filesectionid], 'image');
if (($gridimage) && ($gridimage->image == $filename)) { // Ensure the correct file.
$filerecord = new stdClass();
$filerecord->contextid = $coursecontext->id;
Expand All @@ -134,7 +134,7 @@ public function after_restore_course() {
$newfile = $fs->create_file_from_storedfile($filerecord, $file);
if ($newfile) {
$DB->set_field('format_grid_image', 'contenthash', $newfile->get_contenthash(),
array('sectionid' => $filesectionid));
['sectionid' => $filesectionid]);
}
}
}
Expand Down Expand Up @@ -179,7 +179,7 @@ public function after_restore_course() {
*/
protected function define_section_plugin_structure() {

$paths = array();
$paths = [];

// Add own format stuff.
$elepath = $this->get_pathfor('/'); // Note: $this->get_recommended_name() gets! -> section/the name.
Expand Down Expand Up @@ -220,7 +220,7 @@ public function process_gridsection($data) {
$existinggridimage = false;
if (($target == backup::TARGET_CURRENT_ADDING) ||
($target == backup::TARGET_EXISTING_ADDING)) {
$existinggridimage = $DB->get_record('format_grid_image', array('sectionid' => $newsectionid), 'image');
$existinggridimage = $DB->get_record('format_grid_image', ['sectionid' => $newsectionid], 'image');
}
if (!$existinggridimage) {
// No image, so add the one from the backup file.
Expand Down
10 changes: 5 additions & 5 deletions classes/admin_setting_information.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,19 @@ public function output_html($data, $query='') {
}

$classes[] = 'fa fa-heart';
$attributes = array();
$attributes = [];
$attributes['aria-hidden'] = 'true';
$attributes['class'] = 'fa fa-heart';
$attributes['title'] = get_string('love', 'format_grid');
$content = \html_writer::tag('span', $attributes['title'], array('class' => 'sr-only'));
$content = \html_writer::tag('span', $attributes['title'], ['class' => 'sr-only']);
$content = \html_writer::tag('span', $content, $attributes);
$context['versioninfo'] = get_string('versioninfo', 'format_grid',
array(
[
'moodle' => $CFG->release,
'release' => $plugininfo->release,
'version' => $plugininfo->version,
'love' => $content
)
'love' => $content,
]
);

if (!empty($plugininfo->maturity)) {
Expand Down
2 changes: 1 addition & 1 deletion classes/observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function course_content_deleted(\core\event\course_content_deleted
*/
public static function course_restored(\core\event\course_restored $event) {
global $DB;
$format = $DB->get_field('course', 'format', array('id' => $event->objectid));
$format = $DB->get_field('course', 'format', ['id' => $event->objectid]);
// If not in the grid format, then don't need the images etc.
if ($format != 'grid') {
// Then delete the images.
Expand Down
22 changes: 11 additions & 11 deletions classes/output/courseformat/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
*/
class content extends content_base {

private $sectioncompletionpercentage = array();
private $sectioncompletionmarkup = array();
private $sectioncompletioncalculated = array();
private $sectioncompletionpercentage = [];
private $sectioncompletionmarkup = [];
private $sectioncompletioncalculated = [];

/**
* @var bool Grid format does not add section after each topic.
Expand Down Expand Up @@ -106,11 +106,11 @@ public function export_for_template(\renderer_base $output) {
$data->hasnavigation = true;
$data->singlesection = array_shift($data->sections);
$data->sectionreturn = $singlesection;
$data->maincoursepage = new \moodle_url('/course/view.php', array('id' => $course->id));
$data->maincoursepage = new \moodle_url('/course/view.php', ['id' => $course->id]);
} else {
$coursesettings = $format->get_settings();
$toolbox = \format_grid\toolbox::get_instance();
$coursesectionimages = $DB->get_records('format_grid_image', array('courseid' => $course->id));
$coursesectionimages = $DB->get_records('format_grid_image', ['courseid' => $course->id]);
if (!empty($coursesectionimages)) {
$fs = get_file_storage();
$coursecontext = \context_course::instance($course->id);
Expand All @@ -128,29 +128,29 @@ public function export_for_template(\renderer_base $output) {
$data->popup = false;
if ((!empty($coursesettings['popup'])) && ($coursesettings['popup'] == 2)) {
$data->popup = true;
$data->popupsections = array();
$potentialpopupsections = array();
$data->popupsections = [];
$potentialpopupsections = [];
foreach ($sections as $section) {
$potentialpopupsections[$section->id] = $section;
}
}
}

// Suitable array.
$sectionimages = array();
$sectionimages = [];
foreach ($coursesectionimages as $coursesectionimage) {
$sectionimages[$coursesectionimage->sectionid] = $coursesectionimage;
}

// Now iterate over the sections.
$data->gridsections = array();
$data->gridsections = [];
$sectionsforgrid = $this->get_grid_sections($output, $coursesettings);
$displayediswebp = (get_config('format_grid', 'defaultdisplayedimagefiletype') == 2);

$completionshown = false;
$headerimages = false;
if ($editing) {
$datasectionmap = array();
$datasectionmap = [];
foreach ($data->sections as $datasectionkey => $datasection) {
$datasectionmap[$datasection->id] = $datasectionkey;
}
Expand Down Expand Up @@ -187,7 +187,7 @@ public function export_for_template(\renderer_base $output) {
// Section link.
$sectionimages[$section->id]->sectionurl = new \moodle_url(
'/course/view.php',
array('id' => $course->id, 'section' => $section->num)
['id' => $course->id, 'section' => $section->num]
);
$sectionimages[$section->id]->sectionurl = $sectionimages[$section->id]->sectionurl->out(false);

Expand Down
4 changes: 2 additions & 2 deletions classes/output/courseformat/content/section/controlmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function section_control_items() {
'pixattr' => ['class' => ''],
'attr' => [
'class' => 'editing_highlight',
'data-action' => 'removemarker'
'data-action' => 'removemarker',
],
];
} else {
Expand All @@ -97,7 +97,7 @@ public function section_control_items() {
'pixattr' => ['class' => ''],
'attr' => [
'class' => 'editing_highlight',
'data-action' => 'setmarker'
'data-action' => 'setmarker',
],
];
}
Expand Down
2 changes: 1 addition & 1 deletion classes/output/courseformat/content/section/summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected function singlepagesummaryimage($summary, $output): string {
$sectionid = $this->thesection->id;
$coursesectionimage = $DB->get_record(
'format_grid_image',
array('courseid' => $courseid, 'sectionid' => $sectionid)
['courseid' => $courseid, 'sectionid' => $sectionid]
);
if (!empty($coursesectionimage)) {
$fs = get_file_storage();
Expand Down
39 changes: 20 additions & 19 deletions classes/toolbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ class toolbox {
protected static $instance = null;

// Width constants - 128, 192, 210, 256, 320, 384, 448, 512, 576, 640, 704 and 768:...
private static $imagecontainerwidths = array(128 => '128', 192 => '192', 210 => '210', 256 => '256', 320 => '320',
384 => '384', 448 => '448', 512 => '512', 576 => '576', 640 => '640', 704 => '704', 768 => '768');
private static $imagecontainerwidths = [128 => '128', 192 => '192', 210 => '210', 256 => '256', 320 => '320',
384 => '384', 448 => '448', 512 => '512', 576 => '576', 640 => '640', 704 => '704', 768 => '768', ];
// Ratio constants - 3-2, 3-1, 3-3, 2-3, 1-3, 4-3 and 3-4:...
private static $imagecontainerratios = array(
1 => '3-2', 2 => '3-1', 3 => '3-3', 4 => '2-3', 5 => '1-3', 6 => '4-3', 7 => '3-4');
private static $imagecontainerratios = [
1 => '3-2', 2 => '3-1', 3 => '3-3', 4 => '2-3', 5 => '1-3', 6 => '4-3', 7 => '3-4', ];

/**
* This is a lonely object.
Expand Down Expand Up @@ -221,12 +221,12 @@ public function setup_displayed_image($sectionimage, $sectionfile, $courseid, $s
}
}

$debugdata = array(
$debugdata = [
'id' => $sectionfile->get_id(),
'itemid' => $sectionfile->get_itemid(),
'filename' => $filename,
'sectionid' => $sectionid
);
'sectionid' => $sectionid,
];
$data = self::generate_image($tmpfilepath, $displayedimageinfo['width'], $displayedimageinfo['height'], $crop, $newmime,
$debugdata);
if (!empty($data)) {
Expand All @@ -242,7 +242,7 @@ public function setup_displayed_image($sectionimage, $sectionfile, $courseid, $s
}

$created = time();
$displayedimagefilerecord = array(
$displayedimagefilerecord = [
'contextid' => $coursecontext->id,
'component' => 'format_grid',
'filearea' => 'displayedsectionimage',
Expand All @@ -254,7 +254,8 @@ public function setup_displayed_image($sectionimage, $sectionfile, $courseid, $s
'license' => $sectionfile->get_license(),
'timecreated' => $created,
'timemodified' => $created,
'mimetype' => $mime);
'mimetype' => $mime,
];

if ($isdisplayedwebponly) { // Displayed WebP image from non-WebP original.
// Displayed image is a webp image from the original, so change a few things.
Expand All @@ -269,7 +270,7 @@ public function setup_displayed_image($sectionimage, $sectionfile, $courseid, $s
unlink($tmpfilepath);

$DB->set_field('format_grid_image', 'displayedimagestate', $sectionimage->displayedimagestate,
array('sectionid' => $sectionid));
['sectionid' => $sectionid]);
if ($sectionimage->displayedimagestate == -1) {
throw new \moodle_exception('cannotconvertuploadedimagetodisplayedimage', 'format_grid', '',
get_string('cannotconvertuploadedimagetodisplayedimage', 'format_grid',
Expand All @@ -290,8 +291,8 @@ public function setup_displayed_image($sectionimage, $sectionfile, $courseid, $s
* @return array with the key => value of 'height' and 'width' for the container.
*/
public function get_displayed_image_container_properties($settings) {
return array('height' => self::calculate_height($settings['imagecontainerwidth'], $settings['imagecontainerratio']),
'width' => $settings['imagecontainerwidth']);
return ['height' => self::calculate_height($settings['imagecontainerwidth'], $settings['imagecontainerratio']),
'width' => $settings['imagecontainerwidth'], ];
}

/**
Expand Down Expand Up @@ -401,9 +402,9 @@ private static function generate_image($filepath, $requestedwidth, $requestedhei

$original = imagecreatefromstring(file_get_contents($filepath)); // Need to alter / check for webp support.

$imageargs = array(
1 => null // File.
);
$imageargs = [
1 => null, // File.
];
switch ($mime) {
case 'image/png':
if (function_exists('imagepng')) {
Expand Down Expand Up @@ -607,7 +608,7 @@ private static function update_the_displayed_images($courseid = null) {
global $DB;

if (!empty($courseid)) {
$coursesectionimages = $DB->get_records('format_grid_image', array('courseid' => $courseid));
$coursesectionimages = $DB->get_records('format_grid_image', ['courseid' => $courseid]);
} else {
$coursesectionimages = $DB->get_records('format_grid_image');
}
Expand Down Expand Up @@ -681,7 +682,7 @@ public static function delete_images($courseid) {
$displayedimage->delete();
}

$DB->delete_records("format_grid_image", array('courseid' => $courseid));
$DB->delete_records("format_grid_image", ['courseid' => $courseid]);
}

/**
Expand All @@ -693,7 +694,7 @@ public static function delete_images($courseid) {
public static function delete_image($sectionid, $courseid) {
global $DB;

$coursesectionimage = $DB->get_record('format_grid_image', array('courseid' => $courseid, 'sectionid' => $sectionid));
$coursesectionimage = $DB->get_record('format_grid_image', ['courseid' => $courseid, 'sectionid' => $sectionid]);
if (!empty($coursesectionimage)) {
$fs = get_file_storage();

Expand Down Expand Up @@ -732,7 +733,7 @@ public static function delete_image($sectionid, $courseid) {
get_string('cannotgetmanagesectionimagelock', 'format_grid')
);
}
$DB->delete_records("format_grid_image", array('courseid' => $courseid, 'sectionid' => $sectionid));
$DB->delete_records("format_grid_image", ['courseid' => $courseid, 'sectionid' => $sectionid]);
}
}
}
13 changes: 6 additions & 7 deletions db/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@
defined('MOODLE_INTERNAL') || die();

// List of observers.
$observers = array(

array(
$observers = [
[
'eventname' => '\core\event\course_content_deleted',
'callback' => 'format_grid_observer::course_content_deleted',
),
array(
],
[
'eventname' => '\core\event\course_restored',
'callback' => 'format_grid_observer::course_restored',
)
);
],
];
Loading

0 comments on commit 892864d

Please sign in to comment.