Skip to content

Commit fd07733

Browse files
committed
code cleanup based on coding style rules
1 parent 70455f3 commit fd07733

19 files changed

+141
-106
lines changed

backup/moodle2/backup_mediagallery_activity_task.class.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ static public function encode_content_links($content) {
5454
$base = preg_quote($CFG->wwwroot, "/");
5555

5656
// Link to the list of pages.
57-
$search="/(".$base."\/mod\/mediagallery\/index.php\?id\=)([0-9]+)/";
58-
$content= preg_replace($search, '$@MEDIAGALLERYINDEX*$2@$', $content);
57+
$search = "/(".$base."\/mod\/mediagallery\/index.php\?id\=)([0-9]+)/";
58+
$content = preg_replace($search, '$@MEDIAGALLERYINDEX*$2@$', $content);
5959

6060
// Link to page view by moduleid.
61-
$search="/(".$base."\/mod\/mediagallery\/view.php\?id\=)([0-9]+)/";
62-
$content= preg_replace($search, '$@MEDIAGALLERYVIEWBYID*$2@$', $content);
61+
$search = "/(".$base."\/mod\/mediagallery\/view.php\?id\=)([0-9]+)/";
62+
$content = preg_replace($search, '$@MEDIAGALLERYVIEWBYID*$2@$', $content);
6363

6464
return $content;
6565
}

backup/moodle2/restore_mediagallery_activity_task.class.php

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
* @copyright 2014 NetSpot Pty Ltd
2020
* @author Adam Olley <[email protected]>
2121
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22-
2322
*/
2423

2524
defined('MOODLE_INTERNAL') || die();

classes/collection.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ public function get_submitted_galleries() {
102102
JOIN {assign_plugin_config} apc ON apc.assignment = asub.assignment
103103
JOIN {assign} a ON a.id = asub.assignment
104104
WHERE apc.plugin = 'mediagallery' AND apc.subtype = 'assignsubmission' AND apc.name = 'mediagallery'
105-
AND apc.value = :collection AND asub.status IN ('".ASSIGN_SUBMISSION_STATUS_SUBMITTED."', '".ASSIGN_SUBMISSION_STATUS_REOPENED."')
105+
AND apc.value = :collection
106+
AND asub.status IN ('".ASSIGN_SUBMISSION_STATUS_SUBMITTED."', '".ASSIGN_SUBMISSION_STATUS_REOPENED."')
106107
AND (a.duedate = 0 OR a.duedate < :time)
107108
GROUP BY asub.id, asm.galleryid, asub.assignment, asub.status, asub.attemptnumber, asub.userid
108109
ORDER BY asub.assignment ASC, asub.userid, asub.attemptnumber ASC";

classes/export_form.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function definition() {
4343
// General settings.
4444
$mform->addElement('header', 'general', get_string('export', 'mediagallery'));
4545

46-
$mform->addElement('checkbox', 'completegallery', get_string('completegallery','mediagallery'));
46+
$mform->addElement('checkbox', 'completegallery', get_string('completegallery', 'mediagallery'));
4747

4848
foreach ($gallery->get_items() as $item) {
4949
if (!empty($item->externalurl)) {

classes/gallery.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function copy($targetid) {
6161
$newgalleryrecord->userid = $USER->id;
6262
$newgalleryrecord->groupid = 0;
6363

64-
$newgallery = gallery::create($newgalleryrecord);
64+
$newgallery = self::create($newgalleryrecord);
6565

6666
$thumbnail = 0;
6767
foreach ($this->get_items() as $item) {
@@ -173,7 +173,6 @@ public function get_items() {
173173
$filelist[$file->get_itemid()]['lowres'] = $file;
174174
}
175175

176-
177176
$items = array();
178177
if ($records = $DB->get_records_sql($sql, array('galleryid' => $this->record->id))) {
179178
foreach ($records as $record) {
@@ -240,7 +239,8 @@ public function get_thumbnail() {
240239
public function moral_rights_asserted() {
241240
global $DB;
242241

243-
return $DB->count_records('mediagallery_item', array('galleryid' => $this->record->id, 'moralrights' => 1)) > 0 ? true : false;
242+
$count = $DB->count_records('mediagallery_item', array('galleryid' => $this->record->id, 'moralrights' => 1));
243+
return $count > 0;
244244
}
245245

246246
/**
@@ -264,7 +264,7 @@ public function update_sortorder($data) {
264264
}
265265

266266
// TODO: Optimize this.
267-
foreach($flipped as $id => $order) {
267+
foreach ($flipped as $id => $order) {
268268
$DB->set_field('mediagallery_item', 'sortorder', $order, array('id' => $id));
269269
}
270270
return true;

classes/item.php

+28-15
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function copy($targetid) {
5454
unset($newitemrecord->id);
5555
$newitemrecord->galleryid = $targetid;
5656

57-
$newitem = item::create($newitemrecord);
57+
$newitem = self::create($newitemrecord);
5858

5959
$fs = get_file_storage();
6060
if ($file = $this->get_file()) { // Item.
@@ -98,7 +98,7 @@ public static function create(\stdClass $data) {
9898
return $result;
9999
}
100100

101-
public static function create_from_archive(gallery $gallery, \stored_file $stored_file, $formdata = array()) {
101+
public static function create_from_archive(gallery $gallery, \stored_file $storedfile, $formdata = array()) {
102102
global $DB;
103103
$context = $gallery->get_collection()->context;
104104

@@ -111,18 +111,18 @@ public static function create_from_archive(gallery $gallery, \stored_file $store
111111
$fs = get_file_storage();
112112
$packer = get_file_packer('application/zip');
113113
$fs->delete_area_files($context->id, 'mod_mediagallery', 'unpacktemp', 0);
114-
$stored_file->extract_to_storage($packer, $context->id, 'mod_mediagallery', 'unpacktemp', 0, '/');
114+
$storedfile->extract_to_storage($packer, $context->id, 'mod_mediagallery', 'unpacktemp', 0, '/');
115115
$itemfiles = $fs->get_area_files($context->id, 'mod_mediagallery', 'unpacktemp', 0);
116-
$stored_file->delete();
116+
$storedfile->delete();
117117

118-
foreach ($itemfiles as $stored_file) {
119-
if ($stored_file->get_filesize() == 0 || preg_match('#^/.DS_Store|__MACOSX/#', $stored_file->get_filepath())) {
118+
foreach ($itemfiles as $storedfile) {
119+
if ($storedfile->get_filesize() == 0 || preg_match('#^/.DS_Store|__MACOSX/#', $storedfile->get_filepath())) {
120120
continue;
121121
}
122122
if ($maxitems != 0 && $count >= $maxitems) {
123123
break;
124124
}
125-
$filename = $stored_file->get_filename();
125+
$filename = $storedfile->get_filename();
126126

127127
// Create an item.
128128
$data = new \stdClass();
@@ -159,7 +159,7 @@ public static function create_from_archive(gallery $gallery, \stored_file $store
159159
'filename' => $filename
160160
);
161161
if (!$fs->get_file($context->id, 'mod_mediagallery', 'item', $item->id, '/', $filename)) {
162-
$stored_file = $fs->create_file_from_storedfile($fileinfo, $stored_file);
162+
$storedfile = $fs->create_file_from_storedfile($fileinfo, $storedfile);
163163
}
164164
$item->generate_image_by_type('lowres');
165165
$item->generate_image_by_type('thumbnail');
@@ -212,7 +212,7 @@ public static function delete_all_by_gallery($galleryid) {
212212
return true;
213213
}
214214

215-
public function generate_thumbnail(\stored_file $stored_file = null) {
215+
public function generate_thumbnail(\stored_file $storedfile = null) {
216216
return $this->generate_image_by_type('thumbnail');
217217
}
218218

@@ -260,7 +260,8 @@ public function generate_image_by_type($type = 'thumbnail', $force = false, \sto
260260
return $fs->create_file_from_string($fileinfo, $newfiledata);
261261
}
262262

263-
private function get_image_resized(\stored_file $file = null, $height = 250, $width = 250, $offsetx = 0, $offsety = 0, $crop = true) {
263+
private function get_image_resized(\stored_file $file = null, $height = 250, $width = 250, $offsetx = 0, $offsety = 0,
264+
$crop = true) {
264265
global $CFG;
265266

266267
if (is_null($file) && !$file = $this->get_file_by_type('item')) {
@@ -377,8 +378,14 @@ private function get_file_by_type($type = 'item') {
377378

378379
public function get_metainfo() {
379380
$info = clone $this->record;
380-
$info->timecreatedformatted = $info->timecreated > 0 ? userdate($info->timecreated, get_string('strftimedaydatetime', 'langconfig')) : '';
381-
$info->productiondateformatted = $info->productiondate > 0 ? userdate($info->productiondate, get_string('strftimedaydate', 'langconfig')) : '';
381+
$info->timecreatedformatted = '';
382+
$info->productiondateformatted = '';
383+
if ($info->timecreated > 0) {
384+
$info->timecreatedformatted = userdate($info->timecreated, get_string('strftimedaydatetime', 'langconfig'));
385+
}
386+
if ($info->productiondate > 0) {
387+
$info->productiondateformatted = userdate($info->productiondate, get_string('strftimedaydate', 'langconfig'));
388+
}
382389
return $info;
383390
}
384391

@@ -400,8 +407,14 @@ public function get_structured_metainfo() {
400407
$info->fields = array();
401408

402409
$data = clone $this->record;
403-
$data->timecreatedformatted = $data->timecreated > 0 ? userdate($data->timecreated, get_string('strftimedaydatetime', 'langconfig')) : '';
404-
$data->productiondateformatted = $data->productiondate > 0 ? userdate($data->productiondate, get_string('strftimedaydate', 'langconfig')) : '';
410+
$data->timecreatedformatted = '';
411+
$data->productiondateformatted = '';
412+
if ($data->timecreated > 0) {
413+
$data->timecreatedformatted = userdate($data->timecreated, get_string('strftimedaydatetime', 'langconfig'));
414+
}
415+
if ($data->productiondate > 0) {
416+
$data->productiondateformatted = userdate($data->productiondate, get_string('strftimedaydate', 'langconfig'));
417+
}
405418
$data->moralrightsformatted = $data->moralrights ? get_string('yes') : get_string('no');
406419
foreach ($displayfields as $key => $displayname) {
407420
$info->fields[] = array(
@@ -559,7 +572,7 @@ public function get_socialinfo() {
559572
$info->client_id = isset($matches[1]) ? $matches[1] : null;
560573
}
561574

562-
//Creator name.
575+
// Creator name.
563576
$info->extradetails = '';
564577

565578
return $info;

db/access.php

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
// This file is part of Moodle - http://moodle.org/
43
//
54
// Moodle is free software: you can redistribute it and/or modify

db/log.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
// This file is part of Moodle - http://moodle.org/
43
//
54
// Moodle is free software: you can redistribute it and/or modify
@@ -33,8 +32,8 @@
3332
global $DB;
3433

3534
$logs = array(
36-
array('module'=>'mediagallery', 'action'=>'add', 'mtable'=>'mediagallery', 'field'=>'name'),
37-
array('module'=>'mediagallery', 'action'=>'update', 'mtable'=>'mediagallery', 'field'=>'name'),
38-
array('module'=>'mediagallery', 'action'=>'view', 'mtable'=>'mediagallery', 'field'=>'name'),
39-
array('module'=>'mediagallery', 'action'=>'view all', 'mtable'=>'mediagallery', 'field'=>'name')
35+
array('module' => 'mediagallery', 'action' => 'add', 'mtable' => 'mediagallery', 'field' => 'name'),
36+
array('module' => 'mediagallery', 'action' => 'update', 'mtable' => 'mediagallery', 'field' => 'name'),
37+
array('module' => 'mediagallery', 'action' => 'view', 'mtable' => 'mediagallery', 'field' => 'name'),
38+
array('module' => 'mediagallery', 'action' => 'view all', 'mtable' => 'mediagallery', 'field' => 'name')
4039
);

db/upgrade.php

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
// This file is part of Moodle - http://moodle.org/
43
//
54
// Moodle is free software: you can redistribute it and/or modify

item.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@
8080
$fs = get_file_storage();
8181
$draftid = file_get_submitted_draft_itemid('content');
8282
$files = $fs->get_area_files(context_user::instance($USER->id)->id, 'user', 'draft', $draftid, 'id DESC', false);
83-
$stored_file = reset($files);
84-
\mod_mediagallery\item::create_from_archive($gallery, $stored_file, $data);
83+
$storedfile = reset($files);
84+
\mod_mediagallery\item::create_from_archive($gallery, $storedfile, $data);
8585
} else {
8686
$data->description = $data->description['text'];
8787
$data->galleryid = $gallery->id;
@@ -96,17 +96,17 @@
9696
$info = file_get_draft_area_info($data->content);
9797
file_save_draft_area_files($data->content, $context->id, 'mod_mediagallery', 'item', $item->id, $fmoptions);
9898

99-
$stored_file = null;
99+
$storedfile = null;
100100
if ($gallery->gallerytype != MEDIAGALLERY_TYPE_IMAGE) {
101101
$draftid = file_get_submitted_draft_itemid('customthumbnail');
102102
$fs = get_file_storage();
103103
if ($files = $fs->get_area_files(
104104
context_user::instance($USER->id)->id, 'user', 'draft', $draftid, 'id DESC', false)) {
105-
$stored_file = reset($files);
105+
$storedfile = reset($files);
106106
}
107107
}
108-
$item->generate_image_by_type('lowres', false, $stored_file);
109-
$item->generate_image_by_type('thumbnail', false, $stored_file);
108+
$item->generate_image_by_type('lowres', false, $storedfile);
109+
$item->generate_image_by_type('thumbnail', false, $storedfile);
110110
}
111111

112112
redirect(new moodle_url('/mod/mediagallery/view.php', array('g' => $gallery->id, 'editing' => 1)));
@@ -121,15 +121,15 @@
121121
$data->customthumbnail = $draftitemidthumb;
122122
}
123123

124-
$draftid_editor = file_get_submitted_draft_itemid('description');
125-
$currenttext = file_prepare_draft_area($draftid_editor, $context->id, 'mod_mediagallery',
124+
$draftideditor = file_get_submitted_draft_itemid('description');
125+
$currenttext = file_prepare_draft_area($draftideditor, $context->id, 'mod_mediagallery',
126126
'description', empty($data->id) ? null : $data->id,
127127
array('subdirs' => 0), empty($data->description) ? '' : $data->description);
128128

129129
$data->content = $draftitemid;
130130
$data->description = array('text' => $currenttext,
131131
'format' => editors_get_preferred_format(),
132-
'itemid' => $draftid_editor);
132+
'itemid' => $draftideditor);
133133

134134
$mform->set_data($data);
135135
}

item_form.php

+8-9
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public function definition() {
6868

6969
$mform->addElement('static', 'filecheck', '', get_string('choosecontent', 'mediagallery'));
7070

71-
$mform->addElement('filepicker', 'content', get_string('content', 'mediagallery'), '0', mediagallery_filepicker_options($gallery));
71+
$mform->addElement('filepicker', 'content', get_string('content', 'mediagallery'), '0',
72+
mediagallery_filepicker_options($gallery));
7273
$mform->addHelpButton('content', 'content', 'mediagallery');
7374

7475
$mform->addElement('url', 'externalurl', get_string('externalurl', 'mediagallery'), array('size' => '60'),
@@ -107,21 +108,19 @@ public function validation($data, $files) {
107108
$errors['filecheck'] = get_string('required');
108109
} else if (!empty($url)) {
109110
if (preg_match('|^/|', $url)) {
110-
// links relative to server root are ok - no validation necessary
111-
111+
// Links relative to server root are ok - no validation necessary.
112112
} else if (preg_match('|^[a-z]+://|i', $url) or preg_match('|^https?:|i', $url) or preg_match('|^ftp:|i', $url)) {
113-
// normal URL
113+
// Normal URL.
114114
if (!mediagallery_appears_valid_url($url)) {
115115
$errors['externalurl'] = get_string('invalidurl', 'url');
116116
}
117117

118118
} else if (preg_match('|^[a-z]+:|i', $url)) {
119-
// general URI such as teamspeak, mailto, etc. - it may or may not work in all browsers,
120-
// we do not validate these at all, sorry
121-
119+
// General URI such as teamspeak, mailto, etc. - it may or may not work in all browsers.
120+
// We do not validate these at all, sorry.
122121
} else {
123-
// invalid URI, we try to fix it by adding 'http://' prefix,
124-
// relative links are NOT allowed because we display the link on different pages!
122+
// Invalid URI, we try to fix it by adding 'http://' prefix.
123+
// Relative links are NOT allowed because we display the link on different pages!
125124
require_once($CFG->dirroot."/mod/url/locallib.php");
126125
if (!url_appears_valid_url('http://'.$url)) {
127126
$errors['externalurl'] = get_string('invalidurl', 'url');

lang/en/mediagallery.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
$string['publisher_help'] = 'The publisher (if any) of the work.';
151151
$string['readonlyfrom'] = 'Read only from';
152152
$string['readonlyto'] = 'Read only to';
153-
$string['restrictavailableinfo'] ='To restrict the dates this activity is available between, use the Restrict access section below.';
153+
$string['restrictavailableinfo'] = 'To restrict the dates this activity is available between, use the Restrict access section below.';
154154
$string['sample'] = 'Sample';
155155
$string['search'] = 'Search';
156156
$string['search_help'] = 'Enter the keywords you want to search for.';

lib.php

+29-17
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,32 @@
3535
*/
3636
function mediagallery_supports($feature) {
3737
switch($feature) {
38-
case FEATURE_GROUPS: return true;
39-
case FEATURE_GROUPINGS: return true;
40-
case FEATURE_GROUPMEMBERSONLY: return true;
41-
case FEATURE_MOD_INTRO: return true;
42-
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
43-
case FEATURE_COMPLETION_HAS_RULES: return false;
44-
case FEATURE_GRADE_HAS_GRADE: return false;
45-
case FEATURE_GRADE_OUTCOMES: return false;
46-
case FEATURE_RATE: return false;
47-
case FEATURE_BACKUP_MOODLE2: return true;
48-
case FEATURE_SHOW_DESCRIPTION: return true;
49-
case FEATURE_PLAGIARISM: return false;
50-
51-
default: return null;
38+
case FEATURE_GROUPS:
39+
return true;
40+
case FEATURE_GROUPINGS:
41+
return true;
42+
case FEATURE_GROUPMEMBERSONLY:
43+
return true;
44+
case FEATURE_MOD_INTRO:
45+
return true;
46+
case FEATURE_COMPLETION_TRACKS_VIEWS:
47+
return true;
48+
case FEATURE_COMPLETION_HAS_RULES:
49+
return false;
50+
case FEATURE_GRADE_HAS_GRADE:
51+
return false;
52+
case FEATURE_GRADE_OUTCOMES:
53+
return false;
54+
case FEATURE_RATE:
55+
return false;
56+
case FEATURE_BACKUP_MOODLE2:
57+
return true;
58+
case FEATURE_SHOW_DESCRIPTION:
59+
return true;
60+
case FEATURE_PLAGIARISM:
61+
return false;
62+
default:
63+
return null;
5264
}
5365
}
5466

@@ -414,11 +426,11 @@ function mediagallery_extend_settings_navigation(settings_navigation $settingsna
414426
* }
415427
* @return boolean
416428
*/
417-
function mediagallery_comment_validate($comment_param) {
418-
if ($comment_param->commentarea != 'gallery' && $comment_param->commentarea != 'item') {
429+
function mediagallery_comment_validate($commentparam) {
430+
if ($commentparam->commentarea != 'gallery' && $commentparam->commentarea != 'item') {
419431
throw new comment_exception('invalidcommentarea');
420432
}
421-
if ($comment_param->itemid == 0) {
433+
if ($commentparam->itemid == 0) {
422434
throw new comment_exception('invalidcommentitemid');
423435
}
424436
return true;

0 commit comments

Comments
 (0)