diff --git a/.github/workflows/moodle-ci.yml b/.github/workflows/moodle-ci.yml index dfb9829..fafb898 100644 --- a/.github/workflows/moodle-ci.yml +++ b/.github/workflows/moodle-ci.yml @@ -18,6 +18,7 @@ jobs: ports: - 5432:5432 options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3 + mariadb: image: mariadb:10.6 # Moodle 4.2: >=10.6.7 env: @@ -25,7 +26,6 @@ jobs: MYSQL_ALLOW_EMPTY_PASSWORD: "true" MYSQL_CHARACTER_SET_SERVER: "utf8mb4" MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci" - ports: - 3306:3306 options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3 @@ -34,30 +34,25 @@ jobs: fail-fast: false matrix: include: - # Moodle 4.0, PHP 7.3, PostgreSQL - - php: '7.3' # 7.3-8.0 - moodle-branch: 'MOODLE_400_STABLE' - database: pgsql - plugin-ci: ^3 - # Moodle 4.1, PHP 7.4, MariaDB - - php: '7.4' # 7.4-8.1 - moodle-branch: 'MOODLE_401_STABLE' + # Moodle 4.3, PHP 8.0, MariaDB + - php: '8.0' # 8.0-8.2 + moodle-branch: 'MOODLE_403_STABLE' database: mariadb plugin-ci: ^4 - # Moodle 4.2, PHP 8.0, PostgreSQL - - php: '8.0' # 8.0-8.1 - moodle-branch: 'MOODLE_402_STABLE' + # Moodle 4.4, PHP 8.2, PostgreSQL + - php: '8.2' # 8.1-8.3 + moodle-branch: 'MOODLE_404_STABLE' database: pgsql plugin-ci: ^4 - # Moodle master, PHP 8.1, MariaDB - - php: '8.1' - moodle-branch: 'master' + # Moodle main, PHP 8.3, MariaDB + - php: '8.3' + moodle-branch: 'main' database: mariadb plugin-ci: ^4 steps: - name: Check out repository code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: plugin @@ -80,54 +75,64 @@ jobs: echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV - name: Install moodle-plugin-ci - run: | - moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1 + run: moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1 env: DB: ${{ matrix.database }} MOODLE_BRANCH: ${{ matrix.moodle-branch }} + # Uncomment this to run Behat tests using the Moodle App. + # MOODLE_APP: 'true' - name: PHP Lint - if: ${{ always() }} + if: ${{ !cancelled() }} run: moodle-plugin-ci phplint - - name: PHP Copy/Paste Detector - continue-on-error: true # This step will show errors but will not fail - if: ${{ always() }} - run: moodle-plugin-ci phpcpd - - name: PHP Mess Detector continue-on-error: true # This step will show errors but will not fail - if: ${{ always() }} + if: ${{ !cancelled() }} run: moodle-plugin-ci phpmd - - name: Moodle Code Checker - if: ${{ always() }} - run: moodle-plugin-ci phpcs --max-warnings 0 + #- name: Moodle Code Checker + # if: ${{ !cancelled() }} + # run: moodle-plugin-ci phpcs --max-warnings 0 #- name: Moodle PHPDoc Checker - # if: ${{ always() }} - # run: moodle-plugin-ci phpdoc + # if: ${{ !cancelled() }} + # run: moodle-plugin-ci phpdoc --max-warnings 0 - name: Validating - if: ${{ always() }} + if: ${{ !cancelled() }} run: moodle-plugin-ci validate - name: Check upgrade savepoints - if: ${{ always() }} + if: ${{ !cancelled() }} run: moodle-plugin-ci savepoints - name: Mustache Lint - if: ${{ always() }} + if: ${{ !cancelled() }} run: moodle-plugin-ci mustache #- name: Grunt - # if: ${{ always() }} + # if: ${{ !cancelled() }} # run: moodle-plugin-ci grunt --max-lint-warnings 0 - name: PHPUnit tests - if: ${{ always() }} + if: ${{ !cancelled() }} run: moodle-plugin-ci phpunit --fail-on-warning #- name: Behat features - # if: ${{ always() }} + # id: behat + # if: ${{ !cancelled() }} # run: moodle-plugin-ci behat --profile chrome + + #- name: Upload Behat Faildump + # if: ${{ failure() && steps.behat.outcome == 'failure' }} + # uses: actions/upload-artifact@v4 + # with: + # name: Behat Faildump (${{ join(matrix.*, ', ') }}) + # path: ${{ github.workspace }}/moodledata/behat_dump + # retention-days: 7 + # if-no-files-found: ignore + + - name: Mark cancelled jobs as failed. + if: ${{ cancelled() }} + run: exit 1 diff --git a/backup/moodle2/backup_mediagallery_stepslib.php b/backup/moodle2/backup_mediagallery_stepslib.php index 0e524e1..33ebee7 100644 --- a/backup/moodle2/backup_mediagallery_stepslib.php +++ b/backup/moodle2/backup_mediagallery_stepslib.php @@ -34,43 +34,43 @@ protected function define_structure() { $userinfo = $this->get_setting_value('userinfo'); // Define each element separated. - $mediagallery = new backup_nested_element('mediagallery', array('id'), array( + $mediagallery = new backup_nested_element('mediagallery', ['id'], [ 'course', 'name', 'intro', 'introformat', 'timecreated', 'timemodified', 'thumbnailsperpage', 'thumbnailsperrow', 'displayfullcaption', 'captionposition', 'galleryfocus', 'carousel', 'grid', 'gridrows', 'gridcolumns', 'enforcedefaults', 'readonlyfrom', 'readonlyto', 'maxbytes', 'maxitems', 'maxgalleries', 'allowcomments', 'allowlikes', 'colltype', 'objectid', 'source', 'mode', 'creator', 'userid', - )); + ]); $userfeedbacks = new backup_nested_element('userfeedback'); - $userfeedback = new backup_nested_element('feedback', array('id'), array( - 'itemid', 'userid', 'liked', 'rating' - )); + $userfeedback = new backup_nested_element('feedback', ['id'], [ + 'itemid', 'userid', 'liked', 'rating', + ]); $gallerys = new backup_nested_element('gallerys'); - $gallery = new backup_nested_element('gallery', array('id'), array( + $gallery = new backup_nested_element('gallery', ['id'], [ 'instanceid', 'name', 'userid', 'nameposition', 'exportable', 'galleryview', 'gridrows', 'gridcolumns', 'visibleinstructor', 'visibleother', 'thumbnail', 'galleryfocus', 'groupid', 'mode', 'objectid', 'source', 'creator', 'contributable', - )); + ]); $items = new backup_nested_element('items'); - $item = new backup_nested_element('item', array('id'), array( + $item = new backup_nested_element('item', ['id'], [ 'galleryid', 'userid', 'caption', 'description', 'sortorder', 'display', 'moralrights', 'originalauthor', 'productiondate', 'medium', 'publisher', 'reference', 'externalurl', 'timecreated', 'broadcaster', 'objectid', 'source', 'processing_status', 'creator', - )); + ]); $ctags = new backup_nested_element('collectiontags'); - $ctag = new backup_nested_element('collectiontag', array('id'), array('itemid', 'rawname')); + $ctag = new backup_nested_element('collectiontag', ['id'], ['itemid', 'rawname']); $gtags = new backup_nested_element('gallerytags'); - $gtag = new backup_nested_element('gallerytag', array('id'), array('itemid', 'rawname')); + $gtag = new backup_nested_element('gallerytag', ['id'], ['itemid', 'rawname']); $itags = new backup_nested_element('itemtags'); - $itag = new backup_nested_element('itemtag', array('id'), array('itemid', 'rawname')); + $itag = new backup_nested_element('itemtag', ['id'], ['itemid', 'rawname']); // Build the tree. @@ -90,13 +90,13 @@ protected function define_structure() { $itags->add_child($itag); // Define sources. - $mediagallery->set_source_table('mediagallery', array('id' => backup::VAR_ACTIVITYID)); + $mediagallery->set_source_table('mediagallery', ['id' => backup::VAR_ACTIVITYID]); // All the rest of elements only happen if we are including user info. if ($userinfo) { - $gallery->set_source_table('mediagallery_gallery', array('instanceid' => backup::VAR_PARENTID)); - $item->set_source_table('mediagallery_item', array('galleryid' => backup::VAR_PARENTID)); - $userfeedback->set_source_table('mediagallery_userfeedback', array('itemid' => backup::VAR_PARENTID)); + $gallery->set_source_table('mediagallery_gallery', ['instanceid' => backup::VAR_PARENTID]); + $item->set_source_table('mediagallery_item', ['galleryid' => backup::VAR_PARENTID]); + $userfeedback->set_source_table('mediagallery_userfeedback', ['itemid' => backup::VAR_PARENTID]); if (core_tag_tag::is_enabled('mod_mediagallery', 'mediagallery')) { $ctag->set_source_sql('SELECT t.id, ti.itemid, t.rawname @@ -107,7 +107,7 @@ protected function define_structure() { AND ti.contextid = ?', [ backup_helper::is_sqlparam('mediagallery'), backup_helper::is_sqlparam('mod_mediagallery'), - backup::VAR_CONTEXTID]); + backup::VAR_CONTEXTID, ]); } if (core_tag_tag::is_enabled('mod_mediagallery', 'mediagallery_gallery')) { @@ -119,7 +119,7 @@ protected function define_structure() { AND ti.contextid = ?', [ backup_helper::is_sqlparam('mediagallery_gallery'), backup_helper::is_sqlparam('mod_mediagallery'), - backup::VAR_CONTEXTID]); + backup::VAR_CONTEXTID, ]); } if (core_tag_tag::is_enabled('mod_mediagallery', 'mediagallery_item')) { @@ -131,7 +131,7 @@ protected function define_structure() { AND ti.contextid = ?', [ backup_helper::is_sqlparam('mediagallery_item'), backup_helper::is_sqlparam('mod_mediagallery'), - backup::VAR_CONTEXTID]); + backup::VAR_CONTEXTID, ]); } } diff --git a/backup/moodle2/restore_mediagallery_activity_task.class.php b/backup/moodle2/restore_mediagallery_activity_task.class.php index f62adf7..7a2956f 100644 --- a/backup/moodle2/restore_mediagallery_activity_task.class.php +++ b/backup/moodle2/restore_mediagallery_activity_task.class.php @@ -54,7 +54,7 @@ protected function define_my_steps() { * processed by the link decoder */ public static function define_decode_contents() { - $contents = array(); + $contents = []; return $contents; } @@ -63,7 +63,7 @@ public static function define_decode_contents() { * to the activity to be executed by the link decoder */ public static function define_decode_rules() { - $rules = array(); + $rules = []; $rules[] = new restore_decode_rule('MEDIAGALLERYVIEWBYID', '/mod/mediagallery/view.php?id=$1', 'course_module'); $rules[] = new restore_decode_rule('MEDIAGALLERYINDEX', '/mod/mediagallery/index.php?id=$1', 'course'); @@ -79,7 +79,7 @@ public static function define_decode_rules() { * of {@see \restore_log_rule} objects */ public static function define_restore_log_rules() { - $rules = array(); + $rules = []; $rules[] = new restore_log_rule('mediagallery', 'add', 'view.php?id={course_module}', '{page}'); $rules[] = new restore_log_rule('mediagallery', 'update', 'view.php?id={course_module}', '{page}'); @@ -99,7 +99,7 @@ public static function define_restore_log_rules() { * activity level. All them are rules not linked to any module instance (cmid = 0) */ public static function define_restore_log_rules_for_course() { - $rules = array(); + $rules = []; $rules[] = new restore_log_rule('mediagallery', 'view all', 'index.php?id={course}', null); diff --git a/backup/moodle2/restore_mediagallery_stepslib.php b/backup/moodle2/restore_mediagallery_stepslib.php index 446e16a..1227e25 100644 --- a/backup/moodle2/restore_mediagallery_stepslib.php +++ b/backup/moodle2/restore_mediagallery_stepslib.php @@ -34,7 +34,7 @@ class restore_mediagallery_activity_structure_step extends restore_activity_stru protected function define_structure() { - $paths = array(); + $paths = []; $userinfo = $this->get_setting_value('userinfo'); $mediagallery = new restore_path_element('mediagallery', '/activity/mediagallery'); @@ -179,7 +179,7 @@ protected function after_execute() { // Can't do thumbnail mapping before the item is restored, so we do it here. $mgid = $this->task->get_activityid(); - if ($records = $DB->get_records('mediagallery_gallery', array('instanceid' => $mgid))) { + if ($records = $DB->get_records('mediagallery_gallery', ['instanceid' => $mgid])) { foreach ($records as $record) { if ($record->thumbnail) { $record->thumbnail = $this->get_mappingid('mediagallery_item', $record->thumbnail); diff --git a/classes/base.php b/classes/base.php index cbfff72..853a711 100644 --- a/classes/base.php +++ b/classes/base.php @@ -39,7 +39,7 @@ abstract class base { protected $record; static protected $table; - public function __construct($recordorid, $options = array()) { + public function __construct($recordorid, $options = []) { global $DB; if (empty(static::$table)) { @@ -52,7 +52,7 @@ public function __construct($recordorid, $options = array()) { } $this->record = $recordorid; } else { - $this->record = $DB->get_record(static::$table, array('id' => $recordorid), '*', MUST_EXIST); + $this->record = $DB->get_record(static::$table, ['id' => $recordorid], '*', MUST_EXIST); } $this->options = $options; @@ -81,7 +81,7 @@ public static function create(\stdClass $data) { $class = get_called_class(); $data->id = $DB->insert_record(static::$table, $data); - $record = $DB->get_record(static::$table, array('id' => $data->id)); + $record = $DB->get_record(static::$table, ['id' => $data->id]); // Return an instance of the gallery class. $object = new $class($record); @@ -90,10 +90,10 @@ public static function create(\stdClass $data) { return $object; } - public function delete($options = array()) { + public function delete($options = []) { global $DB; - $DB->delete_records(static::$table, array('id' => $this->record->id)); + $DB->delete_records(static::$table, ['id' => $this->record->id]); \core_tag_tag::remove_all_item_tags('mod_mediagallery', static::$table, $this->id); return true; @@ -156,10 +156,10 @@ public function update($data) { $this->set_tags(); if (empty($data->noevent)) { - $params = array( + $params = [ 'context' => $this->get_context(), 'objectid' => $this->id, - ); + ]; if (isset($data->nosync) && $data->nosync) { $params['other']['nosync'] = true; } @@ -182,7 +182,7 @@ public function is_thebox_creator_or_agent($userid = null) { if (is_null($userid)) { $userid = $USER->id; } else if ($userid != $USER->id) { - $username = $DB->get_field('user', 'username', array('id' => $userid)); + $username = $DB->get_field('user', 'username', ['id' => $userid]); } if ($username == $this->creator || $this->creator == 'z9999999') { diff --git a/classes/collection.php b/classes/collection.php index 2bcf841..b27595f 100644 --- a/classes/collection.php +++ b/classes/collection.php @@ -38,15 +38,15 @@ class collection extends base { public $cm; public $context; - public $options = array( - 'groups' => array(), - ); + public $options = [ + 'groups' => [], + ]; protected $record; protected $submitted = null; static protected $table = 'mediagallery'; private $deleted = false; - public function __construct($recordorid, $options = array()) { + public function __construct($recordorid, $options = []) { global $USER; parent::__construct($recordorid, $options); @@ -79,17 +79,17 @@ public static function create(\stdClass $data) { return new collection($data); } - public function delete($options = array()) { + public function delete($options = []) { global $DB; - $params = array( + $params = [ 'context' => $this->get_context(), 'objectid' => $this->id, - 'other' => array( + 'other' => [ 'modulename' => 'mediagallery', 'instanceid' => $this->id, - ), - ); + ], + ]; if (!empty($options['nosync'])) { $params['other']['nosync'] = true; } @@ -101,7 +101,7 @@ public function delete($options = array()) { JOIN {mediagallery_gallery} g ON g.id = i.galleryid WHERE g.instanceid = ? )"; - $DB->execute($sql, array($this->id)); + $DB->execute($sql, [$this->id]); // We trigger this early so observers can handle external deletion. if (!empty($params['context'])) { @@ -116,9 +116,9 @@ public function delete($options = array()) { FROM {mediagallery_gallery} WHERE instanceid = ? )"; - $DB->execute($sql, array($this->id)); - $DB->delete_records('mediagallery_gallery', array('instanceid' => $this->id)); - $DB->delete_records('mediagallery', array('id' => $this->id)); + $DB->execute($sql, [$this->id]); + $DB->delete_records('mediagallery_gallery', ['instanceid' => $this->id]); + $DB->delete_records('mediagallery', ['id' => $this->id]); return true; } @@ -134,10 +134,10 @@ public function get_my_galleries($userid = null) { $userid = $USER->id; } - $galleries = array(); + $galleries = []; $select = "instanceid = :instanceid AND (userid = :userid"; - $params = array(); + $params = []; if ($this->options['groupmode'] != NOGROUPS) { if (!empty($this->options['groups'])) { list($insql, $params) = $DB->get_in_or_equal(array_keys($this->options['groups']), SQL_PARAMS_NAMED); @@ -149,7 +149,7 @@ public function get_my_galleries($userid = null) { $params['userid'] = $userid; if ($records = $DB->get_records_select('mediagallery_gallery', $select, $params)) { foreach ($records as $record) { - $galleries[$record->id] = new gallery($record, array('collection' => $this)); + $galleries[$record->id] = new gallery($record, ['collection' => $this]); } } @@ -184,10 +184,10 @@ public function get_submitted_galleries() { AND (a.duedate = 0 OR a.duedate < :time OR uf.locked = 1) GROUP BY asub.id, asm.galleryid, asub.assignment, asub.status, asub.attemptnumber, asub.userid ORDER BY asub.assignment ASC, asub.userid, asub.attemptnumber ASC"; - $params = array('collection' => $this->record->id, 'time' => time()); + $params = ['collection' => $this->record->id, 'time' => time()]; if ($results = $DB->get_records_sql($sql, $params)) { - $this->submitted = array(); - $submissions = array(); + $this->submitted = []; + $submissions = []; foreach ($results as $result) { if ($result->status == ASSIGN_SUBMISSION_STATUS_REOPENED) { unset($this->submitted[$submissions[$result->assignment][$result->userid]]); @@ -214,13 +214,13 @@ public function get_submitted_galleries() { */ public function get_visible_galleries() { global $DB, $USER; - $galleries = array(); + $galleries = []; $accessallgroups = has_capability('moodle/site:accessallgroups', $this->context); $viewall = has_capability('mod/mediagallery:viewall', $this->context); $select = "instanceid = :instanceid"; - $params = array(); + $params = []; if ($this->options['groupmode'] == SEPARATEGROUPS && !$accessallgroups && !$viewall) { if (!empty($this->options['groups'])) { list($insql, $params) = $DB->get_in_or_equal(array_keys($this->options['groups']), SQL_PARAMS_NAMED); @@ -239,7 +239,7 @@ public function get_visible_galleries() { ORDER BY gg.id ASC"; if ($records = $DB->get_records_sql($sql, $params)) { foreach ($records as $record) { - $gallery = new gallery($record, array('collection' => $this)); + $gallery = new gallery($record, ['collection' => $this]); if ($viewall || $gallery->user_can_view()) { $galleries[$record->id] = $gallery; } @@ -251,7 +251,7 @@ public function get_visible_galleries() { public function count_galleries() { global $DB; - return $DB->count_records('mediagallery_gallery', array('instanceid' => $this->record->id)); + return $DB->count_records('mediagallery_gallery', ['instanceid' => $this->record->id]); } /** @@ -263,14 +263,14 @@ public function count_galleries() { public function get_galleries($filterbymode = false) { global $DB; - $list = array(); - $params = array('instanceid' => $this->record->id); + $list = []; + $params = ['instanceid' => $this->record->id]; if ($filterbymode) { $params['mode'] = $filterbymode; } $records = $DB->get_records('mediagallery_gallery', $params); foreach ($records as $record) { - $list[$record->id] = new gallery($record, array('collection' => $this)); + $list[$record->id] = new gallery($record, ['collection' => $this]); } return $list; } @@ -280,19 +280,19 @@ public static function get_public_galleries_by_contextid($contextid, $prefix = t $context = \context::instance_by_id($contextid); if (!$coursecontext = $context->get_course_context(false)) { - return array(); + return []; } - $course = $DB->get_record('course', array('id' => $coursecontext->instanceid), '*', MUST_EXIST); + $course = $DB->get_record('course', ['id' => $coursecontext->instanceid], '*', MUST_EXIST); $collections = get_all_instances_in_course('mediagallery', $course); - $collids = array(); + $collids = []; foreach ($collections as $collection) { $collids[] = $collection->id; } if (empty($collids)) { - return array(); + return []; } $concat = $prefix ? $DB->sql_concat('mg.name', "' > '", 'g.name') : 'g.name'; @@ -302,7 +302,7 @@ public static function get_public_galleries_by_contextid($contextid, $prefix = t FROM {mediagallery_gallery} g JOIN {mediagallery} mg on (mg.id = g.instanceid) WHERE instanceid $insql"; - $list = array(); + $list = []; foreach ($DB->get_records_sql($sql, $params) as $record) { $gallery = new gallery($record); if ($gallery->user_can_view()) { @@ -317,13 +317,13 @@ public static function get_my_galleries_by_contextid($contextid) { $context = \context::instance_by_id($contextid); if (!$coursecontext = $context->get_course_context(false)) { - return array(); + return []; } - $course = $DB->get_record('course', array('id' => $coursecontext->instanceid), '*', MUST_EXIST); + $course = $DB->get_record('course', ['id' => $coursecontext->instanceid], '*', MUST_EXIST); $collections = get_all_instances_in_course('mediagallery', $course); - $collids = array(); + $collids = []; $theboxenabled = false; foreach ($collections as $collection) { if (!$theboxenabled && $collection->mode == 'thebox') { @@ -333,7 +333,7 @@ public static function get_my_galleries_by_contextid($contextid) { } if (empty($collids)) { - return array(); + return []; } list($insql, $params) = $DB->get_in_or_equal($collids, SQL_PARAMS_NAMED); @@ -348,7 +348,7 @@ public static function get_my_galleries_by_contextid($contextid) { FROM {mediagallery_gallery} g JOIN {mediagallery} mg on (mg.id = g.instanceid) WHERE instanceid $insql $select"; - $list = array(); + $list = []; foreach ($DB->get_records_sql($sql, $params) as $record) { $gallery = new gallery($record); if ($gallery->user_can_edit(null, true)) { @@ -371,7 +371,7 @@ public function has_submitted() { } $groupselect = ''; - $params = array('collection' => $this->record->id, 'userid' => $USER->id); + $params = ['collection' => $this->record->id, 'userid' => $USER->id]; if ($this->options['groupmode'] != NOGROUPS) { if (!empty($this->options['groups'])) { list($insql, $gparams) = $DB->get_in_or_equal(array_keys($this->options['groups']), SQL_PARAMS_NAMED); @@ -404,7 +404,7 @@ public function get_linked_assignid() { JOIN {assign_plugin_config} apc ON apc.assignment = cm.instance WHERE apc.plugin = 'mediagallery' AND apc.name = 'mediagallery' AND m.name = 'assign' AND ".$DB->sql_compare_text('apc.value')." = ?"; - $params = array($this->record->id); + $params = [$this->record->id]; return $DB->get_field_sql($sql, $params, IGNORE_MULTIPLE); } @@ -475,23 +475,23 @@ public function get_userid_from_logs() { return false; } - $params = array( + $params = [ 'course' => $this->course, 'module' => 'mediagallery', 'action' => 'add', 'cmid' => $this->cm->id, - ); + ]; if ($legacylog = $DB->get_record('log', $params, 'id, userid', IGNORE_MULTIPLE)) { return $legacylog->userid; } // It wasn't in the legacy log table, check the new logstore. - $params = array( + $params = [ 'courseid' => $this->course, 'eventname' => '\core\event\course_module_created', 'contextinstanceid' => $this->cm->id, 'contextlevel' => CONTEXT_MODULE, - ); + ]; if ($standardlog = $DB->get_record('logstore_standard_log', $params, 'id, userid', IGNORE_MULTIPLE)) { return $standardlog->userid; } diff --git a/classes/event/course_module_viewed.php b/classes/event/course_module_viewed.php index 7c0d6b8..a01988a 100644 --- a/classes/event/course_module_viewed.php +++ b/classes/event/course_module_viewed.php @@ -56,7 +56,7 @@ protected function init() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/mediagallery/view.php', array('id' => $this->contextinstanceid)); + return new \moodle_url('/mod/mediagallery/view.php', ['id' => $this->contextinstanceid]); } } diff --git a/classes/event/gallery_created.php b/classes/event/gallery_created.php index d82c2a3..6718f67 100644 --- a/classes/event/gallery_created.php +++ b/classes/event/gallery_created.php @@ -65,7 +65,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/mediagallery/view.php', array('g' => $this->objectid)); + return new \moodle_url('/mod/mediagallery/view.php', ['g' => $this->objectid]); } } diff --git a/classes/event/gallery_deleted.php b/classes/event/gallery_deleted.php index cf120a0..da30688 100644 --- a/classes/event/gallery_deleted.php +++ b/classes/event/gallery_deleted.php @@ -75,7 +75,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/mediagallery/view.php', array('id' => $this->contextinstanceid)); + return new \moodle_url('/mod/mediagallery/view.php', ['id' => $this->contextinstanceid]); } } diff --git a/classes/event/gallery_updated.php b/classes/event/gallery_updated.php index ea1ddf5..77599a7 100644 --- a/classes/event/gallery_updated.php +++ b/classes/event/gallery_updated.php @@ -65,7 +65,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/mediagallery/view.php', array('g' => $this->objectid)); + return new \moodle_url('/mod/mediagallery/view.php', ['g' => $this->objectid]); } } diff --git a/classes/event/gallery_viewed.php b/classes/event/gallery_viewed.php index 1999dd5..2bfcd8b 100644 --- a/classes/event/gallery_viewed.php +++ b/classes/event/gallery_viewed.php @@ -65,7 +65,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/mediagallery/view.php', array('g' => $this->objectid)); + return new \moodle_url('/mod/mediagallery/view.php', ['g' => $this->objectid]); } } diff --git a/classes/event/item_created.php b/classes/event/item_created.php index 399f6f7..fadf8d0 100644 --- a/classes/event/item_created.php +++ b/classes/event/item_created.php @@ -65,7 +65,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/mediagallery/view.php', array('id' => $this->contextinstanceid)); + return new \moodle_url('/mod/mediagallery/view.php', ['id' => $this->contextinstanceid]); } } diff --git a/classes/event/item_deleted.php b/classes/event/item_deleted.php index c3f79f2..403cbb4 100644 --- a/classes/event/item_deleted.php +++ b/classes/event/item_deleted.php @@ -65,7 +65,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/mediagallery/view.php', array('id' => $this->contextinstanceid)); + return new \moodle_url('/mod/mediagallery/view.php', ['id' => $this->contextinstanceid]); } } diff --git a/classes/event/item_updated.php b/classes/event/item_updated.php index 1bf49b3..9ea760a 100644 --- a/classes/event/item_updated.php +++ b/classes/event/item_updated.php @@ -65,7 +65,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/mediagallery/view.php', array('id' => $this->contextinstanceid)); + return new \moodle_url('/mod/mediagallery/view.php', ['id' => $this->contextinstanceid]); } } diff --git a/classes/file_info.php b/classes/file_info.php index 1a7d454..33d6e54 100644 --- a/classes/file_info.php +++ b/classes/file_info.php @@ -65,12 +65,12 @@ public function __construct($browser, $course, $cm, $context, $areas, $filearea) * @return array with keys contextid, filearea, itemid, filepath and filename */ public function get_params() { - return array('contextid' => $this->context->id, - 'component' => 'mod_mediagallery', - 'filearea' => $this->filearea, - 'itemid' => null, - 'filepath' => null, - 'filename' => null); + return ['contextid' => $this->context->id, + 'component' => 'mod_mediagallery', + 'filearea' => $this->filearea, + 'itemid' => null, + 'filepath' => null, + 'filename' => null, ]; } /** @@ -108,7 +108,7 @@ public function get_children() { /** * Help function to return files matching extensions or their count * - * @param string|array $extensions either '*' or array of lowercase extensions, i.e. array('.gif','.jpg') + * @param string|array $extensions either '*' or array of lowercase extensions, i.e. ['.gif','.jpg'] * @param bool|int $countonly if false returns the children, if an int returns just the * count of children but stops counting when $countonly number of children is reached * @param bool $returnemptyfolders if true returns items that don't have matching files inside @@ -117,7 +117,7 @@ public function get_children() { private function get_filtered_children($extensions = '*', $countonly = false, $returnemptyfolders = false) { $galleries = \mod_mediagallery\collection::get_public_galleries_by_contextid($this->context->id, false); - $children = array(); + $children = []; $urlbase = $CFG->wwwroot.'/pluginfile.php'; foreach ($galleries as $id => $name) { $storedfile = new virtual_root_file($this->context->id, 'mod_mediagallery', 'gallery', $id); @@ -140,7 +140,7 @@ private function get_filtered_children($extensions = '*', $countonly = false, $r * Returns list of children which are either files matching the specified extensions * or folders that contain at least one such file. * - * @param string|array $extensions either '*' or array of lowercase extensions, i.e. array('.gif','.jpg') + * @param string|array $extensions either '*' or array of lowercase extensions, i.e. ['.gif','.jpg'] * @return array of file_info instances */ public function get_non_empty_children($extensions = '*') { @@ -151,7 +151,7 @@ public function get_non_empty_children($extensions = '*') { * Returns the number of children which are either files matching the specified extensions * or folders containing at least one such file. * - * @param string|array $extensions for example '*' or array('.gif','.jpg') + * @param string|array $extensions for example '*' or ['.gif','.jpg'] * @param int $limit stop counting after at least $limit non-empty children are found * @return int */ diff --git a/classes/file_info_area_gallery.php b/classes/file_info_area_gallery.php index 72cd957..2a35475 100644 --- a/classes/file_info_area_gallery.php +++ b/classes/file_info_area_gallery.php @@ -49,7 +49,7 @@ public function __construct(file_browser $browser, $context, $storedfile, $urlba * @return array of file_info instances */ public function get_children() { - $result = array(); + $result = []; $items = $this->gallery->get_items(); foreach ($items as $item) { @@ -63,12 +63,12 @@ public function get_children() { * Returns list of children which are either files matching the specified extensions * or folders that contain at least one such file. * - * @param string|array $extensions either '*' or array of lowercase extensions, i.e. array('.gif','.jpg') + * @param string|array $extensions either '*' or array of lowercase extensions, i.e. ['.gif','.jpg'] * @return array of file_info instances */ public function get_non_empty_children($extensions = '*') { $items = $this->gallery->get_items(); - $result = array(); + $result = []; foreach ($items as $item) { $file = $item->get_file(); diff --git a/classes/form/search.php b/classes/form/search.php index 486557c..07c4b64 100644 --- a/classes/form/search.php +++ b/classes/form/search.php @@ -33,12 +33,12 @@ protected function definition() { $mform->addElement('text', 'search', get_string('search')); $mform->setType('search', PARAM_TEXT); - $options = array( + $options = [ \mod_mediagallery\base::TYPE_ALL => get_string('typeall', 'mediagallery'), \mod_mediagallery\base::TYPE_IMAGE => get_string('typeimage', 'mediagallery'), \mod_mediagallery\base::TYPE_VIDEO => get_string('typevideo', 'mediagallery'), \mod_mediagallery\base::TYPE_AUDIO => get_string('typeaudio', 'mediagallery'), - ); + ]; $mform->addElement('select', 'type', get_string('mediatype', 'mediagallery'), $options); // Role select dropdown includes all roles, but using course-specific @@ -51,7 +51,7 @@ protected function definition() { $rolenames = role_fix_names(get_roles_used_in_context($context)); } $mform->addElement('select', 'role', get_string('role'), - array(0 => get_string('all')) + $rolenames); + [0 => get_string('all')] + $rolenames); // Filter by group. $allgroups = groups_get_all_groups($collection->course); @@ -66,7 +66,7 @@ protected function definition() { // Submit button does not use add_action_buttons because that adds // another fieldset which causes the CSS style to break in an unfixable // way due to fieldset quirks. - $group = array(); + $group = []; $group[] = $mform->createElement('submit', 'submitbutton', get_string('filter')); $group[] = $mform->createElement('submit', 'resetbutton', get_string('reset')); $group[] = $mform->createElement('submit', 'exportbutton', get_string('exportascsv', 'mediagallery')); diff --git a/classes/gallery.php b/classes/gallery.php index 7225efa..02b5faf 100644 --- a/classes/gallery.php +++ b/classes/gallery.php @@ -43,7 +43,7 @@ class gallery extends base { protected $items = null; static protected $table = 'mediagallery_gallery'; - public function __construct($recordorid, $options = array()) { + public function __construct($recordorid, $options = []) { if (!empty($options['collection'])) { $this->collection = $options['collection']; unset($options['collection']); @@ -71,7 +71,7 @@ public function can_like() { public function copy($targetid) { global $DB, $USER; - if (!$DB->record_exists('mediagallery', array('id' => $targetid))) { + if (!$DB->record_exists('mediagallery', ['id' => $targetid])) { return false; } // Create a gallery matching this one in the target collection. @@ -92,7 +92,7 @@ public function copy($targetid) { } // Update thumbnail. - $DB->set_field('mediagallery_gallery', 'thumbnail', $thumbnail, array('id' => $newgallery->id)); + $DB->set_field('mediagallery_gallery', 'thumbnail', $thumbnail, ['id' => $newgallery->id]); return true; } @@ -106,10 +106,10 @@ public static function create(\stdClass $data) { } $result = parent::create($data); - $params = array( + $params = [ 'context' => $result->get_collection()->context, 'objectid' => $result->id, - ); + ]; if (!empty($data->nosync)) { $params['other']['nosync'] = true; } @@ -122,15 +122,15 @@ public static function create(\stdClass $data) { return $result; } - public function delete($options = array()) { + public function delete($options = []) { global $DB; $coll = $this->get_collection(); - $params = array( + $params = [ 'context' => $coll->context, 'objectid' => $this->id, - ); + ]; if (!empty($options['nosync'])) { $params['other']['nosync'] = true; } @@ -140,7 +140,7 @@ public function delete($options = array()) { // Delete all items and then the gallery. item::delete_all_by_gallery($this->record->id); - \comment::delete_comments(array('commentarea' => 'gallery', 'itemid' => $this->record->id)); + \comment::delete_comments(['commentarea' => 'gallery', 'itemid' => $this->record->id]); parent::delete(); @@ -153,13 +153,13 @@ public function delete($options = array()) { * @param array $list List of item id's to download. Empty array means all files. * @return void */ - public function download_items(array $list = array()) { + public function download_items(array $list = []) { global $CFG, $DB; // More efficient to load this here. require_once($CFG->libdir.'/filelib.php'); - $filesforzipping = array(); + $filesforzipping = []; $fs = get_file_storage(); $filename = clean_filename('mediagallery-export-'.$this->record->name.'.zip'); @@ -239,7 +239,7 @@ public function get_items() { ORDER BY i.sortorder ASC"; $fs = get_file_storage(); - $filelist = array(); + $filelist = []; $files = $fs->get_area_files($this->get_collection()->context->id, 'mod_mediagallery', 'item', false, 'id', false); foreach ($files as $file) { @@ -254,16 +254,16 @@ public function get_items() { $filelist[$file->get_itemid()]['lowres'] = $file; } - $items = array(); - if ($records = $DB->get_records_sql($sql, array('galleryid' => $this->record->id))) { + $items = []; + if ($records = $DB->get_records_sql($sql, ['galleryid' => $this->record->id])) { $tags = \core_tag_tag::get_items_tags('mod_mediagallery', 'mediagallery_item', array_keys($records)); foreach ($records as $record) { $files = !empty($filelist[$record->id]) ? $filelist[$record->id] : false; - $options = array( + $options = [ 'files' => $files, 'gallery' => $this, - ); + ]; if (!empty($tags[$record->id])) { $options['tags'] = $tags[$record->id]; @@ -296,7 +296,7 @@ public function get_items_by_type($matching = true) { $currentfocus = $this->options['focus']; } - $list = array(); + $list = []; foreach ($this->get_items() as $item) { $matches = false; $type = $item->type(); @@ -322,7 +322,7 @@ public function has_items() { if (!is_null($this->items)) { return !empty($this->items); } - $result = $DB->count_records('mediagallery_item', array('galleryid' => $this->record->id)); + $result = $DB->count_records('mediagallery_item', ['galleryid' => $this->record->id]); return !empty($result); } @@ -333,7 +333,7 @@ public function get_thumbnail() { global $DB, $OUTPUT; $record = false; if (empty($this->record->thumbnail) || - (!$record = $DB->get_record('mediagallery_item', array('id' => $this->record->thumbnail)))) { + (!$record = $DB->get_record('mediagallery_item', ['id' => $this->record->thumbnail]))) { // The thumbnail item got deleted, pick the first item as the new thumbnail. $items = $this->get_items(); if (empty($items)) { @@ -344,21 +344,21 @@ public function get_thumbnail() { $thumbid = $record->id; } if ($this->record->thumbnail != $thumbid) { - $DB->set_field('mediagallery_gallery', 'thumbnail', $thumbid, array('id' => $this->id)); + $DB->set_field('mediagallery_gallery', 'thumbnail', $thumbid, ['id' => $this->id]); } } if (!$record) { return $OUTPUT->image_url('galleryicon', 'mediagallery')->out(false); return null; } - $item = new item($record, array('gallery' => $this)); + $item = new item($record, ['gallery' => $this]); return $item->get_image_url(true); } public function moral_rights_asserted() { global $DB; - $count = $DB->count_records('mediagallery_item', array('galleryid' => $this->record->id, 'moralrights' => 0)); + $count = $DB->count_records('mediagallery_item', ['galleryid' => $this->record->id, 'moralrights' => 0]); return $count == 0; } @@ -379,7 +379,7 @@ public function sync($forcesync = false) { public function update_sortorder($data) { global $DB; $flipped = array_flip($data); - $items = $DB->get_records('mediagallery_item', array('galleryid' => $this->record->id), '', 'id, sortorder'); + $items = $DB->get_records('mediagallery_item', ['galleryid' => $this->record->id], '', 'id, sortorder'); foreach ($items as $item) { if (isset($flipped[$item->id]) && $item->sortorder == $flipped[$item->id]) { unset($flipped[$item->id]); @@ -388,7 +388,7 @@ public function update_sortorder($data) { // TODO: Optimize this. foreach ($flipped as $id => $order) { - $DB->set_field('mediagallery_item', 'sortorder', $order, array('id' => $id)); + $DB->set_field('mediagallery_item', 'sortorder', $order, ['id' => $id]); } return true; } diff --git a/classes/item.php b/classes/item.php index 8a5c114..b37337d 100644 --- a/classes/item.php +++ b/classes/item.php @@ -35,14 +35,14 @@ class item extends base { protected $file = null; protected $lowres = null; protected $thumbnail = null; - protected static $defaultvalues = array( + protected static $defaultvalues = [ 'sortorder' => 1000000, 'display' => 1, 'moralrights' => 1, 'productiondate' => '', - ); + ]; - public function __construct($recordorid, $options = array()) { + public function __construct($recordorid, $options = []) { if (!empty($options['gallery'])) { $this->gallery = $options['gallery']; unset($options['gallery']); @@ -76,24 +76,24 @@ public function copy($targetid) { $fs = get_file_storage(); if ($file = $this->get_file()) { // Item. - $fileinfo = array( + $fileinfo = [ 'contextid' => $newitem->get_context()->id, 'itemid' => $newitem->id, - ); + ]; $fs->create_file_from_storedfile($fileinfo, $file); } if ($file = $this->get_file(true)) { // Thumbnail. - $fileinfo = array( + $fileinfo = [ 'contextid' => $newitem->get_context()->id, 'itemid' => $newitem->id, - ); + ]; $fs->create_file_from_storedfile($fileinfo, $file); } if ($file = $this->get_stored_file_by_type('lowres')) { // Low res version of full image. - $fileinfo = array( + $fileinfo = [ 'contextid' => $newitem->get_context()->id, 'itemid' => $newitem->id, - ); + ]; $fs->create_file_from_storedfile($fileinfo, $file); } return $newitem; @@ -115,13 +115,13 @@ public static function create(\stdClass $data) { $sql = "UPDATE {mediagallery_gallery} SET thumbnail = :item WHERE id = :galleryid"; - $DB->execute($sql, array('item' => $result->id, 'galleryid' => $result->galleryid)); + $DB->execute($sql, ['item' => $result->id, 'galleryid' => $result->galleryid]); } - $params = array( + $params = [ 'context' => $result->get_context(), 'objectid' => $result->id, - ); + ]; if (!empty($data->nosync)) { $params['other']['nosync'] = true; } @@ -132,12 +132,12 @@ public static function create(\stdClass $data) { return $result; } - public static function create_from_archive(gallery $gallery, \stored_file $storedfile, $formdata = array()) { + public static function create_from_archive(gallery $gallery, \stored_file $storedfile, $formdata = []) { global $DB; $context = $gallery->get_collection()->context; $maxitems = $gallery->get_collection()->maxitems; - $count = $DB->count_records('mediagallery_item', array('galleryid' => $gallery->id)); + $count = $DB->count_records('mediagallery_item', ['galleryid' => $gallery->id]); if ($maxitems != 0 && $count >= $maxitems) { return; } @@ -164,15 +164,15 @@ public static function create_from_archive(gallery $gallery, \stored_file $store $data->description = ''; $data->display = 1; - $metafields = array( + $metafields = [ 'moralrights' => 1, 'originalauthor' => '', 'productiondate' => 0, 'medium' => '', 'publisher' => '', 'broadcaster' => '', - 'reference' => '' - ); + 'reference' => '', + ]; foreach ($metafields as $field => $default) { $data->$field = isset($formdata->$field) ? $formdata->$field : $default; } @@ -185,14 +185,14 @@ public static function create_from_archive(gallery $gallery, \stored_file $store $item = self::create($data); // Copy the file into the correct area. - $fileinfo = array( + $fileinfo = [ 'contextid' => $context->id, 'component' => 'mod_mediagallery', 'filearea' => 'item', 'itemid' => $item->id, 'filepath' => '/', - 'filename' => $filename - ); + 'filename' => $filename, + ]; if (!$fs->get_file($context->id, 'mod_mediagallery', 'item', $item->id, '/', $filename)) { $storedfile = $fs->create_file_from_storedfile($fileinfo, $storedfile); } @@ -209,13 +209,13 @@ public static function create_from_archive(gallery $gallery, \stored_file $store * @param array $options * @return bool */ - public function delete($options = array()) { + public function delete($options = []) { global $DB; - $params = array( + $params = [ 'context' => $this->get_context(), 'objectid' => $this->id, - ); + ]; if (!empty($options['nosync'])) { $params['other']['nosync'] = true; } @@ -228,8 +228,8 @@ public function delete($options = array()) { $fs->delete_area_files($this->get_context()->id, 'mod_mediagallery', 'lowres', $this->record->id); $fs->delete_area_files($this->get_context()->id, 'mod_mediagallery', 'thumbnail', $this->record->id); - $DB->delete_records('mediagallery_userfeedback', array('itemid' => $this->record->id)); - \comment::delete_comments(array('commentarea' => 'item', 'itemid' => $this->record->id)); + $DB->delete_records('mediagallery_userfeedback', ['itemid' => $this->record->id]); + \comment::delete_comments(['commentarea' => 'item', 'itemid' => $this->record->id]); return parent::delete(); } @@ -238,7 +238,7 @@ public static function delete_all_by_gallery($galleryid) { global $DB; // Bulk delete files. - if ($itemids = $DB->get_records('mediagallery_item', array('galleryid' => $galleryid), '', 'id')) { + if ($itemids = $DB->get_records('mediagallery_item', ['galleryid' => $galleryid], '', 'id')) { $fs = get_file_storage(); list($insql, $params) = $DB->get_in_or_equal(array_keys($itemids), SQL_PARAMS_NAMED, 'mgi'); @@ -257,8 +257,8 @@ public static function delete_all_by_gallery($galleryid) { FROM {mediagallery_item} WHERE galleryid = :galleryid )"; - $DB->execute($sql, array('galleryid' => $galleryid)); - $DB->delete_records('mediagallery_item', array('galleryid' => $galleryid)); + $DB->execute($sql, ['galleryid' => $galleryid]); + $DB->delete_records('mediagallery_item', ['galleryid' => $galleryid]); return true; } @@ -282,14 +282,14 @@ public function generate_image_by_type($type = 'thumbnail', $force = false, \sto return $newfile; } - $fileinfo = array( + $fileinfo = [ 'contextid' => $this->get_context()->id, 'component' => 'mod_mediagallery', 'filearea' => $type, 'itemid' => $this->record->id, 'userid' => $originalfile->get_userid(), 'filepath' => $originalfile->get_filepath(), - 'filename' => $originalfile->get_filename()); + 'filename' => $originalfile->get_filename(), ]; if ($type == 'thumbnail') { $w = 250; @@ -389,10 +389,10 @@ private function get_image_resized(\stored_file $file = null, $height = 250, $wi } } - $info = array( + $info = [ 'width' => imagesx($image), 'height' => imagesy($image), - ); + ]; $cx = $info['width'] / 2; $cy = $info['height'] / 2; @@ -528,7 +528,7 @@ public function get_metainfo() { public function get_structured_metainfo() { global $DB; - $displayfields = array( + $displayfields = [ 'caption' => get_string('caption', 'mod_mediagallery'), 'description' => get_string('description'), 'originalauthor' => get_string('originalauthor', 'mod_mediagallery'), @@ -540,10 +540,10 @@ public function get_structured_metainfo() { 'moralrightsformatted' => get_string('moralrights', 'mod_mediagallery'), 'copyrightformatted' => get_string('copyright', 'mod_mediagallery'), 'tags' => get_string('tags'), - ); + ]; $info = $this->get_socialinfo(); - $info->fields = array(); + $info->fields = []; $data = clone $this->record; $data->timecreatedformatted = ''; @@ -561,21 +561,21 @@ public function get_structured_metainfo() { } $data->moralrightsformatted = $data->moralrights ? get_string('yes') : get_string('no'); foreach ($displayfields as $key => $displayname) { - $info->fields[] = array( + $info->fields[] = [ 'displayname' => $displayname, 'name' => $key, 'value' => $data->$key, - ); + ]; } - if ($user = $DB->get_record('user', array('id' => $this->record->userid), 'id, firstname, lastname')) { - $linkurl = new \moodle_url('/user/profile.php', array('id' => $this->record->userid)); - $info->fields[] = array( + if ($user = $DB->get_record('user', ['id' => $this->record->userid], 'id, firstname, lastname')) { + $linkurl = new \moodle_url('/user/profile.php', ['id' => $this->record->userid]); + $info->fields[] = [ 'displayname' => get_string('uploader', 'mod_mediagallery'), 'name' => 'owner', 'link' => $linkurl->out(), 'value' => "{$user->firstname} {$user->lastname}", - ); + ]; } return $info; @@ -714,7 +714,7 @@ public function get_image_url_by_type($type = 'item') { public function get_like_count() { global $DB; $select = 'liked = 1 AND itemid = :itemid'; - $count = $DB->count_records_select('mediagallery_userfeedback', $select, array('itemid' => $this->record->id)); + $count = $DB->count_records_select('mediagallery_userfeedback', $select, ['itemid' => $this->record->id]); $count = is_null($count) ? 0 : $count; return $count; } @@ -727,7 +727,7 @@ public function get_socialinfo() { $info->ratings = null; $info->contextid = $this->get_context()->id; if ($this->gallery->can_like()) { - $info->likes = $DB->count_records('mediagallery_userfeedback', array('itemid' => $this->record->id, 'liked' => 1)); + $info->likes = $DB->count_records('mediagallery_userfeedback', ['itemid' => $this->record->id, 'liked' => 1]); $info->likedbyme = false; if ($fb = $this->get_userfeedback()) { @@ -759,7 +759,7 @@ public function get_socialinfo() { public function get_userfeedback() { global $DB, $USER; - return $DB->get_record('mediagallery_userfeedback', array('itemid' => $this->record->id, 'userid' => $USER->id)); + return $DB->get_record('mediagallery_userfeedback', ['itemid' => $this->record->id, 'userid' => $USER->id]); } public function file_icon() { @@ -785,11 +785,11 @@ public function like() { $fb->liked = 1; $DB->update_record('mediagallery_userfeedback', $fb); } else { - $fb = (object) array( + $fb = (object) [ 'itemid' => $this->record->id, 'userid' => $USER->id, 'liked' => 1, - ); + ]; $DB->insert_record('mediagallery_userfeedback', $fb); } return $this->get_like_count(); @@ -813,7 +813,7 @@ public function type($text = false) { return null; } - $videogroups = array('web_video'); + $videogroups = ['web_video']; if (!empty($this->objectid)) { $videogroups[] = 'video'; } @@ -827,15 +827,15 @@ public function type($text = false) { return $text ? 'video' : self::TYPE_VIDEO; } - $texttotype = array( + $texttotype = [ 'audio' => self::TYPE_AUDIO, 'image' => self::TYPE_IMAGE, 'video' => self::TYPE_VIDEO, - ); + ]; if ($mimetype == 'document/unknown' && !empty($this->objectid)) { $ref = $this->file->get_reference_details(); - if (isset($ref->type) && in_array($ref->type, array('audio', 'image', 'video'))) { + if (isset($ref->type) && in_array($ref->type, ['audio', 'image', 'video'])) { return $text ? $ref->type : $texttotype[$ref->type]; } } @@ -869,7 +869,7 @@ public function update($data) { $sql = "UPDATE {mediagallery_gallery} SET thumbnail = :item WHERE id = :galleryid"; - $DB->execute($sql, array('item' => $this->record->id, 'galleryid' => $this->record->galleryid)); + $DB->execute($sql, ['item' => $this->record->id, 'galleryid' => $this->record->galleryid]); } if (!$this->is_thebox_creator_or_agent()) { $data->nosync = true; diff --git a/classes/mcsearch.php b/classes/mcsearch.php index 0f8cc3f..7df410a 100644 --- a/classes/mcsearch.php +++ b/classes/mcsearch.php @@ -45,29 +45,29 @@ public function __construct($params) { public function get_results() { global $DB; - $results = array(); + $results = []; if (is_null($this->params['search'])) { return $this->results = $results; } $fullname = $DB->sql_fullname('u.firstname', 'u.lastname'); - $search = array(); + $search = []; $searchsql = ""; if ($this->params['search']) { - $search = array( + $search = [ $DB->sql_like('i.caption', '?', false, false), $DB->sql_like($fullname, '?', false, false), $DB->sql_like('u.username', '?', false, false), $DB->sql_like('f.filename', '?', false, false), - ); + ]; $searchsql = 'AND ('.implode(' OR ', $search).')'; } - $params = array( + $params = [ $this->params['context']->id, $this->params['collection']->id, - ); + ]; $groupswhere = ''; if ($this->params['group']) { @@ -108,17 +108,17 @@ public function get_results() { WHERE m.id = ? $groupswhere $roleswhere $searchsql"; $grs = $DB->get_recordset_sql($sql, $params); - $gallerys = array(); + $gallerys = []; foreach ($grs as $galleryrecord) { - $gallerys[$galleryrecord->id] = new gallery($galleryrecord, array('collection' => $this->params['collection'])); + $gallerys[$galleryrecord->id] = new gallery($galleryrecord, ['collection' => $this->params['collection']]); } $sql = str_replace('g.*', $select, $sql); $rs = $DB->get_recordset_sql($sql, $params); - $userids = array(); + $userids = []; foreach ($rs as $record) { - $item = new item($record, array('nogallery' => true)); + $item = new item($record, ['nogallery' => true]); if ($this->params['type'] != base::TYPE_ALL && $item->type() != $this->params['type']) { continue; } @@ -142,8 +142,8 @@ public function get_results() { if (isset($roles[$record->userid])) { asort($roles[$record->userid]); } - $record->groups = isset($groups[$record->userid]) ? $groups[$record->userid] : array(); - $record->roles = isset($roles[$record->userid]) ? $roles[$record->userid] : array(); + $record->groups = isset($groups[$record->userid]) ? $groups[$record->userid] : []; + $record->roles = isset($roles[$record->userid]) ? $roles[$record->userid] : []; } return $this->results = $results; @@ -158,10 +158,10 @@ public function get_results() { public function get_groups_for_users($userids) { global $DB; if (empty($userids)) { - return array(); + return []; } - $groups = array(); + $groups = []; list ($insql, $params) = $DB->get_in_or_equal($userids); $sql = "SELECT gm.id, g.name, gm.userid, g.id as groupid @@ -185,10 +185,10 @@ public function get_groups_for_users($userids) { public function get_roles_for_users($userids) { global $DB; if (empty($userids)) { - return array(); + return []; } - $roles = array(); + $roles = []; $context = $this->params['context']; list ($insql, $params) = $DB->get_in_or_equal($userids); @@ -215,21 +215,21 @@ public function get_roles_for_users($userids) { public function download_csv() { $csv = new \csv_export_writer(); $csv->set_filename('mediacollection_search'); - $csv->add_data(array( + $csv->add_data([ get_string('caption', 'mod_mediagallery'), get_string('gallery', 'mod_mediagallery'), get_string('creator', 'mod_mediagallery'), get_string('groups'), get_string('roles'), - )); + ]); foreach ($this->results as $row) { - $csv->add_data(array( + $csv->add_data([ $row->itemcaption, $row->galleryname, $row->creator, implode(', ', $row->groups), implode(', ', $row->roles), - )); + ]); } $csv->download_file(); exit; diff --git a/classes/output/collection/renderable.php b/classes/output/collection/renderable.php index d1e6655..5b663da 100644 --- a/classes/output/collection/renderable.php +++ b/classes/output/collection/renderable.php @@ -19,7 +19,7 @@ class renderable implements \renderable { public $collection; - public $galleries = array(); + public $galleries = []; public $maxreached = true; public $normallycanadd = true; public $readonly = false; @@ -59,7 +59,7 @@ public function __construct(\mod_mediagallery\collection $collection, array $gal require_once($CFG->dirroot.'/mod/assign/locallib.php'); $context = \context_module::instance($this->linkedassigncmid); $cm = get_coursemodule_from_id('assign', $this->linkedassigncmid, 0, false, MUST_EXIST); - $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); + $course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST); $assign = new \assign($context, $cm, $course); $this->submissionsopen = $assign->submissions_open(); @@ -70,7 +70,7 @@ public function __construct(\mod_mediagallery\collection $collection, array $gal $mygalleries = $collection->get_my_galleries(); $this->userorgrouphasgallery = !empty($mygalleries); - foreach (array('id', 'mode', 'thumbnailsperrow', 'thumbnailsperpage') as $opt) { + foreach (['id', 'mode', 'thumbnailsperrow', 'thumbnailsperpage'] as $opt) { if (isset($collection->$opt)) { $this->$opt = $collection->$opt; } diff --git a/classes/output/gallery/renderable.php b/classes/output/gallery/renderable.php index eb907d4..0c59524 100644 --- a/classes/output/gallery/renderable.php +++ b/classes/output/gallery/renderable.php @@ -29,18 +29,18 @@ class renderable implements \renderable { public $mediasizeclass = ''; public $comments = null; public $syncstamp = null; - public $options = array(); + public $options = []; public $nosample = false; public $focus = null; public $galleryview; - public function __construct(\mod_mediagallery\gallery $gallery, $editing = false, $options = array()) { + public function __construct(\mod_mediagallery\gallery $gallery, $editing = false, $options = []) { $this->gallery = $gallery; $this->options = $options; $this->editing = $editing; $this->galleryview = $gallery->get_display_settings()->galleryview; - foreach (array('page', 'comments', 'mediasize', 'syncstamp', 'nosample', 'focus') as $opt) { + foreach (['page', 'comments', 'mediasize', 'syncstamp', 'nosample', 'focus'] as $opt) { if (isset($options[$opt])) { $this->$opt = $options[$opt]; } diff --git a/classes/output/searchresults/renderable.php b/classes/output/searchresults/renderable.php index b6c7de8..78f11c8 100644 --- a/classes/output/searchresults/renderable.php +++ b/classes/output/searchresults/renderable.php @@ -18,7 +18,7 @@ class renderable implements \renderable { - public $results = array(); + public $results = []; public $pageurl; public $totalcount; public $page; diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 15e03a2..bfed43f 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -55,7 +55,7 @@ class provider implements * @param collection $items a reference to the collection to use to store the metadata. * @return collection the updated collection of metadata items. */ - public static function get_metadata(collection $items) : collection { + public static function get_metadata(collection $items): collection { $items->add_database_table( 'mediagallery', @@ -124,7 +124,7 @@ public static function get_metadata(collection $items) : collection { * @param int $userid the userid. * @return contextlist the list of contexts containing user info for the user. */ - public static function get_contexts_for_userid(int $userid) : contextlist { + public static function get_contexts_for_userid(int $userid): contextlist { // Fetch all mediagallery comments. $sql = "SELECT c.id FROM {context} c @@ -185,7 +185,7 @@ public static function export_user_data(approved_contextlist $contextlist) { 'userid1' => $user->id, 'userid2' => $user->id, 'userid3' => $user->id, - 'contextlevel' => CONTEXT_MODULE + 'contextlevel' => CONTEXT_MODULE, ] + $contextparams; $collections = $DB->get_recordset_sql($sql, $params); diff --git a/classes/privacy/subcontext_info.php b/classes/privacy/subcontext_info.php index 6163bfe..1241a41 100644 --- a/classes/privacy/subcontext_info.php +++ b/classes/privacy/subcontext_info.php @@ -25,9 +25,9 @@ namespace mod_mediagallery\privacy; -use \core_privacy\request\approved_contextlist; -use \core_privacy\request\writer; -use \core_privacy\metadata\item_collection; +use core_privacy\request\approved_contextlist; +use core_privacy\request\writer; +use core_privacy\metadata\item_collection; /** * Subcontext helper trait. @@ -42,7 +42,7 @@ trait subcontext_info { * @param \stdClass $gallery The gallery * @return array */ - protected static function get_gallery_area(\stdClass $gallery) : array { + protected static function get_gallery_area(\stdClass $gallery): array { $pathparts = []; if (!empty($discussion->groupname)) { $pathparts[] = get_string('groups'); @@ -67,7 +67,7 @@ protected static function get_gallery_area(\stdClass $gallery) : array { * * @return array */ - protected static function get_item_area() : array { + protected static function get_item_area(): array { $pathparts = [ get_string('areaitem', 'mod_mediagallery'), ]; diff --git a/classes/quickform/limitedurl.php b/classes/quickform/limitedurl.php index cb4ff07..11424e4 100644 --- a/classes/quickform/limitedurl.php +++ b/classes/quickform/limitedurl.php @@ -56,11 +56,11 @@ public function toHtml() { // phpcs:ignore moodle.NamingConventions.ValidFunctio $args->client_id = $clientid; $args->env = 'url'; - $refrepos = repository::get_instances(array( + $refrepos = repository::get_instances([ 'currentcontext' => $PAGE->context, 'return_types' => FILE_EXTERNAL, - )); - $disabled = array(); + ]); + $disabled = []; foreach ($refrepos as $repo) { if (($name = $repo->get_typename()) != $this->_options['repo']) { $disabled[] = $name; @@ -86,9 +86,9 @@ public function toHtml() { // phpcs:ignore moodle.NamingConventions.ValidFunctio $module = [ 'name' => 'form_url', 'fullpath' => '/lib/form/url.js', - 'requires' => ['core_filepicker'] + 'requires' => ['core_filepicker'], ]; - $PAGE->requires->js_init_call('M.form_url.init', array($options), true, $module); + $PAGE->requires->js_init_call('M.form_url.init', [$options], true, $module); return $str; } diff --git a/classes/quickform/uploader.php b/classes/quickform/uploader.php index eaf2c3b..f294a9a 100644 --- a/classes/quickform/uploader.php +++ b/classes/quickform/uploader.php @@ -78,11 +78,11 @@ public function toHtml() { // phpcs:ignore moodle.NamingConventions.ValidFunctio // and which specific repo types we don't want. So here we build a list // of all FILE_REFERENCE supplying repos that aren't thebox to force // it to only display that one. - $refrepos = repository::get_instances(array( + $refrepos = repository::get_instances([ 'currentcontext' => $PAGE->context, 'return_types' => FILE_REFERENCE, - )); - $disabled = array(); + ]); + $disabled = []; foreach ($refrepos as $repo) { if (($name = $repo->get_typename()) != $this->repo) { $disabled[] = $name; @@ -102,9 +102,9 @@ public function toHtml() { // phpcs:ignore moodle.NamingConventions.ValidFunctio 'fullpath' => '/lib/form/filepicker.js', 'requires' => ['core_filepicker', 'node', 'node-event-simulate', 'core_dndupload'], ]; - $PAGE->requires->js_init_call('M.form_filepicker.init', array($fp->options), true, $module); + $PAGE->requires->js_init_call('M.form_filepicker.init', [$fp->options], true, $module); - $nonjsfilepicker = new moodle_url('/repository/draftfiles_manager.php', array( + $nonjsfilepicker = new moodle_url('/repository/draftfiles_manager.php', [ 'env' => 'filepicker', 'action' => 'browse', 'itemid' => $draftitemid, @@ -114,7 +114,7 @@ public function toHtml() { // phpcs:ignore moodle.NamingConventions.ValidFunctio 'ctx_id' => $PAGE->context->id, 'course' => $PAGE->course->id, 'sesskey' => sesskey(), - ) + ] ); // Non js file picker. diff --git a/classes/quickform/uploader_standard.php b/classes/quickform/uploader_standard.php index c01e412..7ab9f55 100644 --- a/classes/quickform/uploader_standard.php +++ b/classes/quickform/uploader_standard.php @@ -53,7 +53,7 @@ public function toHtml() { // phpcs:ignore moodle.NamingConventions.ValidFunctio $args->context = $PAGE->context; $args->buttonname = $elname.'choose'; $args->elementname = $elname; - $args->disable_types = array('thebox'); + $args->disable_types = ['thebox']; $html = $this->_getTabs(); $fp = new file_picker($args); @@ -67,9 +67,9 @@ public function toHtml() { // phpcs:ignore moodle.NamingConventions.ValidFunctio 'fullpath' => '/lib/form/filepicker.js', 'requires' => ['core_filepicker', 'node', 'node-event-simulate', 'core_dndupload'], ]; - $PAGE->requires->js_init_call('M.form_filepicker.init', array($fp->options), true, $module); + $PAGE->requires->js_init_call('M.form_filepicker.init', [$fp->options], true, $module); - $nonjsfilepicker = new moodle_url('/repository/draftfiles_manager.php', array( + $nonjsfilepicker = new moodle_url('/repository/draftfiles_manager.php', [ 'env' => 'filepicker', 'action' => 'browse', 'itemid' => $draftitemid, @@ -79,7 +79,7 @@ public function toHtml() { // phpcs:ignore moodle.NamingConventions.ValidFunctio 'ctx_id' => $PAGE->context->id, 'course' => $PAGE->course->id, 'sesskey' => sesskey(), - ) + ] ); // Non js file picker. diff --git a/classes/search_form.php b/classes/search_form.php index c3c5a64..8257894 100644 --- a/classes/search_form.php +++ b/classes/search_form.php @@ -56,11 +56,11 @@ public function definition() { $mform->addElement('text', 'caption', get_string('caption', 'mediagallery')); $mform->setType('caption', PARAM_TEXT); - $options = array( + $options = [ '' => get_string('choosedots'), 0 => get_string('no'), 1 => get_string('yes'), - ); + ]; $mform->addElement('select', 'moralrights', get_string('moralrights', 'mediagallery'), $options); $mform->addElement('text', 'originalauthor', get_string('originalauthor', 'mediagallery')); diff --git a/classes/viewcontroller.php b/classes/viewcontroller.php index 25b9964..d6341d1 100644 --- a/classes/viewcontroller.php +++ b/classes/viewcontroller.php @@ -28,7 +28,7 @@ class viewcontroller { public $pageurl; public $renderer; - public function __construct($context, $cm, $course, $collection, $gallery, $pageurl, $options = array()) { + public function __construct($context, $cm, $course, $collection, $gallery, $pageurl, $options = []) { global $PAGE; $this->cm = $cm; $this->course = $course; @@ -70,23 +70,23 @@ public function display_action($action) { } public function action_search() { - $urlparams = array( + $urlparams = [ 'search' => optional_param('search', null, PARAM_TEXT), 'group' => optional_param('group', 0, PARAM_INT), 'page' => optional_param('page', 1, PARAM_INT), 'role' => optional_param('role', 0, PARAM_INT), 'type' => optional_param('type', base::TYPE_ALL, PARAM_INT), - ); + ]; if (optional_param('resetbutton', 0, PARAM_ALPHA)) { - redirect(new \moodle_url('/mod/mediagallery/view.php', array('action' => 'search', 'id' => $this->cm->id))); + redirect(new \moodle_url('/mod/mediagallery/view.php', ['action' => 'search', 'id' => $this->cm->id])); } - $params = array_merge($urlparams, array( + $params = array_merge($urlparams, [ 'collection' => $this->collection, 'courseid' => $this->course->id, 'context' => $this->context, - )); + ]); $search = new mcsearch($params); $results = $search->get_results(); @@ -95,8 +95,8 @@ public function action_search() { return $search->download_csv(); }; - $form = new form\search(null, array('context' => $this->context, 'collection' => $this->collection), - 'post', '', array('id' => 'searchform')); + $form = new form\search(null, ['context' => $this->context, 'collection' => $this->collection], + 'post', '', ['id' => 'searchform']); $pageurl = new \moodle_url('/mod/mediagallery/search.php', $urlparams); @@ -108,10 +108,10 @@ public function action_search() { } public function action_viewcollection() { - $params = array( + $params = [ 'context' => $this->context, 'objectid' => $this->collection->id, - ); + ]; $event = event\course_module_viewed::create($params); $event->add_record_snapshot('course_modules', $this->cm); $event->add_record_snapshot('course', $this->course); @@ -129,10 +129,10 @@ public function action_viewcollection() { public function action_viewgallery() { global $DB; $gallery = $this->gallery; - $params = array( + $params = [ 'context' => $this->context, 'objectid' => $this->gallery->id, - ); + ]; $event = event\gallery_viewed::create($params); $event->add_record_snapshot('course_modules', $this->cm); $event->add_record_snapshot('course', $this->course); diff --git a/db/access.php b/db/access.php index bdda0e4..0605271 100644 --- a/db/access.php +++ b/db/access.php @@ -25,72 +25,72 @@ defined('MOODLE_INTERNAL') || die(); -$capabilities = array( +$capabilities = [ - 'mod/mediagallery:addinstance' => array( + 'mod/mediagallery:addinstance' => [ 'riskbitmask' => RISK_XSS, 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'moodle/course:manageactivities' - ), + 'manager' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'moodle/course:manageactivities', + ], - 'mod/mediagallery:comment' => array( + 'mod/mediagallery:comment' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'legacy' => array( + 'legacy' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'student' => CAP_ALLOW - ) - ), + 'student' => CAP_ALLOW, + ], + ], - 'mod/mediagallery:grade' => array( + 'mod/mediagallery:grade' => [ 'riskbitmask' => RISK_XSS, 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], - 'mod/mediagallery:like' => array( + 'mod/mediagallery:like' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'legacy' => array( + 'legacy' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'student' => CAP_ALLOW - ) - ), + 'student' => CAP_ALLOW, + ], + ], - 'mod/mediagallery:manage' => array( + 'mod/mediagallery:manage' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - ), + 'manager' => CAP_ALLOW, + ], + ], - 'mod/mediagallery:viewall' => array( + 'mod/mediagallery:viewall' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - ), + 'manager' => CAP_ALLOW, + ], + ], -); +]; diff --git a/db/log.php b/db/log.php index ebb1ed0..d7eb7c3 100644 --- a/db/log.php +++ b/db/log.php @@ -30,9 +30,9 @@ global $DB; -$logs = array( - array('module' => 'mediagallery', 'action' => 'add', 'mtable' => 'mediagallery', 'field' => 'name'), - array('module' => 'mediagallery', 'action' => 'update', 'mtable' => 'mediagallery', 'field' => 'name'), - array('module' => 'mediagallery', 'action' => 'view', 'mtable' => 'mediagallery', 'field' => 'name'), - array('module' => 'mediagallery', 'action' => 'view all', 'mtable' => 'mediagallery', 'field' => 'name') -); +$logs = [ + ['module' => 'mediagallery', 'action' => 'add', 'mtable' => 'mediagallery', 'field' => 'name'], + ['module' => 'mediagallery', 'action' => 'update', 'mtable' => 'mediagallery', 'field' => 'name'], + ['module' => 'mediagallery', 'action' => 'view', 'mtable' => 'mediagallery', 'field' => 'name'], + ['module' => 'mediagallery', 'action' => 'view all', 'mtable' => 'mediagallery', 'field' => 'name'], +]; diff --git a/db/upgrade.php b/db/upgrade.php index 8b87fde..f1f4eca 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -301,12 +301,12 @@ function xmldb_mediagallery_upgrade($oldversion) { if ($oldversion < 2015011600) { $table = new xmldb_table('mediagallery_item'); - $fields = array(); - $fields = array( + $fields = []; + $fields = [ new xmldb_field('extpath', XMLDB_TYPE_TEXT, null, null, null, null, null, 'objectid'), new xmldb_field('theme_id', XMLDB_TYPE_CHAR, '36', null, null, null, null, 'extpath'), new xmldb_field('copyright_video_id', XMLDB_TYPE_CHAR, '36', null, null, null, null, 'theme_id'), - ); + ]; foreach ($fields as $field) { if (!$dbman->field_exists($table, $field)) { @@ -386,11 +386,11 @@ function xmldb_mediagallery_upgrade($oldversion) { } if ($oldversion < 2015021000) { - $tables = array( + $tables = [ new xmldb_table('mediagallery'), new xmldb_table('mediagallery_gallery'), new xmldb_table('mediagallery_item'), - ); + ]; $field = new xmldb_field('agents', XMLDB_TYPE_TEXT, null, null, null, null, null, 'creator'); foreach ($tables as $table) { diff --git a/export.php b/export.php index 696a9df..d49e0bc 100644 --- a/export.php +++ b/export.php @@ -33,15 +33,15 @@ $gallery = new \mod_mediagallery\gallery($g); $m = $gallery->instanceid; -$mediagallery = $DB->get_record('mediagallery', array('id' => $m), '*', MUST_EXIST); -$course = $DB->get_record('course', array('id' => $mediagallery->course), '*', MUST_EXIST); +$mediagallery = $DB->get_record('mediagallery', ['id' => $m], '*', MUST_EXIST); +$course = $DB->get_record('course', ['id' => $mediagallery->course], '*', MUST_EXIST); $cm = get_coursemodule_from_instance('mediagallery', $mediagallery->id, $course->id, false, MUST_EXIST); require_login($course, true, $cm); $context = context_module::instance($cm->id); -$galleryurl = new moodle_url('/mod/mediagallery/view.php', array('g' => $g, 'editing' => 1)); -$pageurl = new moodle_url('/mod/mediagallery/export.php', array('g' => $g)); +$galleryurl = new moodle_url('/mod/mediagallery/view.php', ['g' => $g, 'editing' => 1]); +$pageurl = new moodle_url('/mod/mediagallery/export.php', ['g' => $g]); $PAGE->set_url($pageurl); $PAGE->set_title(format_string($mediagallery->name)); $PAGE->set_heading(format_string($course->fullname)); @@ -55,11 +55,11 @@ $node = $node->add(format_string(get_string('exportgallery', 'mediagallery')), $pageurl); $node->make_active(); -$mform = new \mod_mediagallery\export_form(null, array('gallery' => $gallery)); +$mform = new \mod_mediagallery\export_form(null, ['gallery' => $gallery]); if ($mform->is_cancelled()) { - redirect(new moodle_url('/mod/mediagallery/view.php', array('g' => $gallery->id, 'editing' => 1))); + redirect(new moodle_url('/mod/mediagallery/view.php', ['g' => $gallery->id, 'editing' => 1])); } else if ($data = $mform->get_data()) { - $list = array(); + $list = []; if (empty($data->completegallery)) { foreach (array_keys((array)$data) as $key) { diff --git a/gallery.php b/gallery.php index ae6d947..8cef6b2 100644 --- a/gallery.php +++ b/gallery.php @@ -41,9 +41,9 @@ $m = $gallery->instanceid; } -$mediagallery = $DB->get_record('mediagallery', array('id' => $m), '*', MUST_EXIST); +$mediagallery = $DB->get_record('mediagallery', ['id' => $m], '*', MUST_EXIST); $mediagallery = new \mod_mediagallery\collection($mediagallery); -$course = $DB->get_record('course', array('id' => $mediagallery->course), '*', MUST_EXIST); +$course = $DB->get_record('course', ['id' => $mediagallery->course], '*', MUST_EXIST); $cm = get_coursemodule_from_instance('mediagallery', $mediagallery->id, $course->id, false, MUST_EXIST); require_login($course, true, $cm); @@ -58,7 +58,7 @@ throw new moodle_exception('errortoomanygalleries', 'mediagallery', '', $maxgalleries); } -$pageurl = new moodle_url('/mod/mediagallery/gallery.php', array('m' => $mediagallery->id)); +$pageurl = new moodle_url('/mod/mediagallery/gallery.php', ['m' => $mediagallery->id]); $PAGE->set_url($pageurl); $PAGE->set_title(format_string($mediagallery->name)); $PAGE->set_heading(format_string($course->fullname)); @@ -72,10 +72,10 @@ $groups = groups_get_all_groups($cm->course, $USER->id, $cm->groupingid); } -$mform = new mod_mediagallery_gallery_form(null, array('mediagallery' => $mediagallery, - 'groups' => $groups, 'groupmode' => $groupmode, 'context' => $context, 'gallery' => $gallery)); +$mform = new mod_mediagallery_gallery_form(null, ['mediagallery' => $mediagallery, + 'groups' => $groups, 'groupmode' => $groupmode, 'context' => $context, 'gallery' => $gallery, ]); if ($mform->is_cancelled()) { - redirect(new moodle_url('/mod/mediagallery/view.php', array('m' => $mediagallery->id, 'editing' => 1))); + redirect(new moodle_url('/mod/mediagallery/view.php', ['m' => $mediagallery->id, 'editing' => 1])); } else if ($data = $mform->get_data()) { if (!isset($data->contributable) || $mediagallery->colltype == 'instructor') { $data->contributable = 0; @@ -103,7 +103,7 @@ } core_tag_tag::set_item_tags('mod_mediagallery', 'mediagallery_gallery', $gallery->id, $context, $data->tags); - redirect(new moodle_url('/mod/mediagallery/view.php', array('g' => $gallery->id, 'editing' => 1))); + redirect(new moodle_url('/mod/mediagallery/view.php', ['g' => $gallery->id, 'editing' => 1])); } else if ($gallery) { if (!$gallery->user_can_edit()) { throw new \moodle_exception('nopermissions', 'error', $pageurl, 'edit gallery'); diff --git a/gallery_form.php b/gallery_form.php index a4259f7..29d67d0 100644 --- a/gallery_form.php +++ b/gallery_form.php @@ -28,7 +28,7 @@ require_once($CFG->libdir.'/formslib.php'); require_once($CFG->dirroot.'/mod/mediagallery/locallib.php'); -use \mod_mediagallery\gallery as gallery; +use mod_mediagallery\gallery as gallery; /** * Module instance settings form @@ -58,7 +58,7 @@ public function definition() { // General settings. $mform->addElement('header', 'general', get_string('general', 'form')); - $mform->addElement('text', 'name', get_string('galleryname', 'mediagallery'), array('size' => '64')); + $mform->addElement('text', 'name', get_string('galleryname', 'mediagallery'), ['size' => '64']); if (!empty($CFG->formatstringstriptags)) { $mform->setType('name', PARAM_TEXT); } else { @@ -70,7 +70,7 @@ public function definition() { if ($groupmode != NOGROUPS || $groupmode === 'aag') { if (count($groups) > 1) { - $opts = array(); + $opts = []; $counts = $mg->get_group_gallery_counts(); foreach ($groups as $group) { $manage = has_capability('mod/mediagallery:manage', $context); @@ -90,10 +90,10 @@ public function definition() { } // Mode. Normal or YT. - $opts = array( + $opts = [ 'standard' => get_string('modestandard', 'mod_mediagallery'), 'youtube' => get_string('modeyoutube', 'mod_mediagallery'), - ); + ]; if (get_config('mediagallery', 'disablestandardgallery') || $mg->mode != 'standard') { unset($opts['standard']); } @@ -116,12 +116,12 @@ public function definition() { // Gallery settings. $mform->addElement('header', 'display', get_string('settingsgallerydisplay', 'mediagallery')); - $options = array( + $options = [ \mod_mediagallery\base::TYPE_ALL => get_string('typeall', 'mediagallery'), \mod_mediagallery\base::TYPE_IMAGE => get_string('typeimage', 'mediagallery'), \mod_mediagallery\base::TYPE_VIDEO => get_string('typevideo', 'mediagallery'), \mod_mediagallery\base::TYPE_AUDIO => get_string('typeaudio', 'mediagallery'), - ); + ]; $mform->addElement('select', 'galleryfocus', get_string('galleryfocus', 'mediagallery'), $options); $mform->addHelpButton('galleryfocus', 'galleryfocus', 'mediagallery'); $mform->setDefault('galleryfocus', $mg->galleryfocus); @@ -130,7 +130,7 @@ public function definition() { $mform->hardFreeze('galleryfocus'); } - $options = array(); + $options = []; if ($mg->grid) { $options[gallery::VIEW_GRID] = get_string('gridview', 'mediagallery'); } @@ -147,13 +147,13 @@ public function definition() { if (!$mg->enforcedefaults) { if (isset($options[gallery::VIEW_GRID])) { - $coloptions = array(0 => get_string('automatic', 'mediagallery'), 1 => 1, 2 => 2, 3 => 3, 4 => 4); + $coloptions = [0 => get_string('automatic', 'mediagallery'), 1 => 1, 2 => 2, 3 => 3, 4 => 4]; $mform->addElement('select', 'gridcolumns', get_string('gridviewcolumns', 'mediagallery'), $coloptions); $mform->disabledIf('gridcolumns', 'galleryview', 'ne', gallery::VIEW_GRID); $mform->setDefault('gridcolumns', $mg->gridcolumns); - $rowoptions = array(0 => get_string('automatic', 'mediagallery'), 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, - 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10); + $rowoptions = [0 => get_string('automatic', 'mediagallery'), 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, + 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, ]; $mform->addElement('select', 'gridrows', get_string('gridviewrows', 'mediagallery'), $rowoptions); $mform->disabledIf('gridrows', 'galleryview', 'ne', gallery::VIEW_GRID); $mform->setDefault('gridrows', $mg->gridrows); @@ -175,12 +175,12 @@ public function definition() { $mform->addElement('date_time_selector', 'visibleinstructor', get_string('visibleinstructor', 'mediagallery'), - array('optional' => true)); + ['optional' => true]); $mform->addHelpButton('visibleinstructor', 'visibleinstructor', 'mediagallery'); $mform->addElement('date_time_selector', 'visibleother', get_string('visibleother', 'mediagallery'), - array('optional' => true)); + ['optional' => true]); $mform->addHelpButton('visibleother', 'visibleother', 'mediagallery'); $mform->setDefault('visibleother', time()); @@ -204,7 +204,7 @@ public function definition() { * @return void */ public function data_preprocessing(&$toform) { - $toform['galleryviewoptions'] = array(); + $toform['galleryviewoptions'] = []; $toform['galleryviewoptions']['carousel'] = $toform['carousel']; $toform['galleryviewoptions']['grid'] = $toform['grid']; } @@ -234,7 +234,7 @@ public function set_data($data) { * @return array List of errors, if any. */ public function validation($data, $files) { - $errors = array(); + $errors = []; $collection = new \mod_mediagallery\collection($data['m']); return $errors; } diff --git a/index.php b/index.php index 1923b63..e17793d 100644 --- a/index.php +++ b/index.php @@ -28,18 +28,18 @@ $id = required_param('id', PARAM_INT); // Course id. -$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST); +$course = $DB->get_record('course', ['id' => $id], '*', MUST_EXIST); $coursecontext = context_course::instance($course->id); require_course_login($course); -$event = \mod_mediagallery\event\course_module_instance_list_viewed::create(array( - 'context' => $coursecontext -)); +$event = \mod_mediagallery\event\course_module_instance_list_viewed::create([ + 'context' => $coursecontext, +]); $event->add_record_snapshot('course', $course); $event->trigger(); -$PAGE->set_url('/mod/mediagallery/index.php', array('id' => $id)); +$PAGE->set_url('/mod/mediagallery/index.php', ['id' => $id]); $PAGE->set_title(format_string($course->fullname)); $PAGE->set_heading(format_string($course->fullname)); $PAGE->set_context($coursecontext); @@ -47,37 +47,37 @@ echo $OUTPUT->header(); if (! $mediagallerys = get_all_instances_in_course('mediagallery', $course)) { - notice(get_string('nomediagallerys', 'mediagallery'), new moodle_url('/course/view.php', array('id' => $course->id))); + notice(get_string('nomediagallerys', 'mediagallery'), new moodle_url('/course/view.php', ['id' => $course->id])); } $table = new html_table(); if ($course->format == 'weeks') { - $table->head = array(get_string('week'), get_string('name')); - $table->align = array('center', 'left'); + $table->head = [get_string('week'), get_string('name')]; + $table->align = ['center', 'left']; } else if ($course->format == 'topics') { - $table->head = array(get_string('topic'), get_string('name')); - $table->align = array('center', 'left', 'left', 'left'); + $table->head = [get_string('topic'), get_string('name')]; + $table->align = ['center', 'left', 'left', 'left']; } else { - $table->head = array(get_string('name')); - $table->align = array('left', 'left', 'left'); + $table->head = [get_string('name')]; + $table->align = ['left', 'left', 'left']; } foreach ($mediagallerys as $mediagallery) { if (!$mediagallery->visible) { $link = html_writer::link( - new moodle_url('/mod/mediagallery/view.php', array('id' => $mediagallery->coursemodule)), + new moodle_url('/mod/mediagallery/view.php', ['id' => $mediagallery->coursemodule]), format_string($mediagallery->name, true), - array('class' => 'dimmed')); + ['class' => 'dimmed']); } else { $link = html_writer::link( - new moodle_url('/mod/mediagallery/view.php', array('id' => $mediagallery->coursemodule)), + new moodle_url('/mod/mediagallery/view.php', ['id' => $mediagallery->coursemodule]), format_string($mediagallery->name, true)); } if ($course->format == 'weeks' || $course->format == 'topics') { - $table->data[] = array($mediagallery->section, $link); + $table->data[] = [$mediagallery->section, $link]; } else { - $table->data[] = array($link); + $table->data[] = [$link]; } } diff --git a/item.php b/item.php index f9fc9c2..80d066a 100644 --- a/item.php +++ b/item.php @@ -49,12 +49,12 @@ $gallery = new \mod_mediagallery\gallery($g); $mediagallery = $gallery->get_collection(); -$course = $DB->get_record('course', array('id' => $mediagallery->course), '*', MUST_EXIST); +$course = $DB->get_record('course', ['id' => $mediagallery->course], '*', MUST_EXIST); $cm = get_coursemodule_from_instance('mediagallery', $mediagallery->id, $course->id, false, MUST_EXIST); require_login($course, true, $cm); $context = context_module::instance($cm->id); -$pageurl = new moodle_url('/mod/mediagallery/item.php', array('g' => $gallery->id)); +$pageurl = new moodle_url('/mod/mediagallery/item.php', ['g' => $gallery->id]); if (!$gallery->user_can_contribute()) { throw new \moodle_exception('nopermissions', 'error', $pageurl, 'edit gallery'); } @@ -66,7 +66,7 @@ $PAGE->add_body_class('mediagallery-mode-'.$gallery->mode); if ($gallery) { - $pageurl = new moodle_url('/mod/mediagallery/view.php', array('g' => $g)); + $pageurl = new moodle_url('/mod/mediagallery/view.php', ['g' => $g]); $navnode = $PAGE->navigation->find($cm->id, navigation_node::TYPE_ACTIVITY); if (empty($navnode)) { @@ -80,12 +80,12 @@ $formclass = $bulk ? 'mod_mediagallery_item_bulk_form' : 'mod_mediagallery_item_form'; $mform = new $formclass(null, - array('gallery' => $gallery, 'firstitem' => !$gallery->has_items(), 'item' => $item)); + ['gallery' => $gallery, 'firstitem' => !$gallery->has_items(), 'item' => $item]); $fs = get_file_storage(); if ($mform->is_cancelled()) { - redirect(new moodle_url('/mod/mediagallery/view.php', array('g' => $gallery->id, 'editing' => 1))); + redirect(new moodle_url('/mod/mediagallery/view.php', ['g' => $gallery->id, 'editing' => 1])); } else if ($data = $mform->get_data()) { if ($bulk) { $draftid = file_get_submitted_draft_itemid('content'); @@ -121,21 +121,21 @@ $item->generate_image_by_type('lowres', $regenthumb, $storedfile); $item->generate_image_by_type('thumbnail', $regenthumb, $storedfile); } - $params = array( + $params = [ 'context' => $context, 'objectid' => $item->id, - 'other' => array( + 'other' => [ 'copyright_id' => $data->copyright_id, 'theme_id' => $data->theme_id, - ), - ); + ], + ]; $event = \mod_mediagallery\event\item_updated::create($params); $event->add_record_snapshot('mediagallery_item', $item->get_record()); $event->trigger(); } } - redirect(new moodle_url('/mod/mediagallery/view.php', array('g' => $gallery->id, 'editing' => 1))); + redirect(new moodle_url('/mod/mediagallery/view.php', ['g' => $gallery->id, 'editing' => 1])); } else if ($item) { $data = $item->get_record(); @@ -145,19 +145,19 @@ $draftitemidthumb = file_get_submitted_draft_itemid('customthumbnail'); file_prepare_draft_area($draftitemidthumb, $context->id, 'mod_mediagallery', 'thumbnail', empty($data->id) ? null : $data->id, - array('subdirs' => 0), empty($data->customthumbnail) ? '' : $data->customthumbnail); + ['subdirs' => 0], empty($data->customthumbnail) ? '' : $data->customthumbnail); $data->customthumbnail = $draftitemidthumb; $draftideditor = file_get_submitted_draft_itemid('description'); $currenttext = file_prepare_draft_area($draftideditor, $context->id, 'mod_mediagallery', 'description', empty($data->id) ? null : $data->id, - array('subdirs' => 0), empty($data->description) ? '' : $data->description); + ['subdirs' => 0], empty($data->description) ? '' : $data->description); $data->content = $draftitemid; - $data->description = array('text' => $currenttext, + $data->description = ['text' => $currenttext, 'format' => editors_get_preferred_format(), - 'itemid' => $draftideditor); + 'itemid' => $draftideditor, ]; $data->tags = core_tag_tag::get_item_tags_array('mod_mediagallery', 'mediagallery_item', $item->id); $mform->set_data($data); diff --git a/item_bulk_form.php b/item_bulk_form.php index e2a71e9..c36a988 100644 --- a/item_bulk_form.php +++ b/item_bulk_form.php @@ -49,7 +49,7 @@ public function definition() { $mform->addElement('header', 'general', get_string('addbulkitems', 'mediagallery')); $mform->addElement('static', 'filecheck', '', get_string('contentbulkheader', 'mediagallery')); - $options = array('maxbytes' => $gallery->get_collection()->maxbytes, 'accepted_types' => array('application/zip')); + $options = ['maxbytes' => $gallery->get_collection()->maxbytes, 'accepted_types' => ['application/zip']]; $mform->addElement('filepicker', 'content', get_string('content', 'mediagallery'), '0', $options); $mform->addHelpButton('content', 'contentbulk', 'mediagallery'); $mform->addRule('content', null, 'required', null, 'client'); diff --git a/item_form.php b/item_form.php index d146dba..7a06fc4 100644 --- a/item_form.php +++ b/item_form.php @@ -52,16 +52,16 @@ public function definition() { // General settings. $mform->addElement('header', 'general', get_string('general', 'form')); - $mform->addElement('text', 'caption', get_string('caption', 'mediagallery'), array('size' => '64')); + $mform->addElement('text', 'caption', get_string('caption', 'mediagallery'), ['size' => '64']); $mform->setType('caption', PARAM_TEXT); $mform->addRule('caption', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $mform->addHelpButton('caption', 'caption', 'mediagallery'); - $options = array( + $options = [ 'collapsed' => true, 'maxfiles' => 0, 'return_types' => null, - ); + ]; $mform->addElement('editor', 'description', get_string('description'), null, $options); $mform->addElement('selectyesno', 'display', get_string('itemdisplay', 'mediagallery')); @@ -81,19 +81,19 @@ public function definition() { $mform->addHelpButton('content', 'content', 'mediagallery'); $fpoptions = mediagallery_filepicker_options($gallery); - $fpoptions['accepted_types'] = array('web_image'); + $fpoptions['accepted_types'] = ['web_image']; $fpoptions['return_types'] = FILE_INTERNAL; $mform->addElement('filepicker', 'customthumbnail', get_string('thumbnail', 'mediagallery'), '0', $fpoptions); $mform->addHelpButton('customthumbnail', 'thumbnail', 'mediagallery'); } else if ($gallery->mode == 'youtube') { - $mform->addElement('limitedurl', 'externalurl', get_string('youtubeurl', 'mediagallery'), array('size' => '60'), - array('usefilepicker' => true, 'repo' => 'youtube')); + $mform->addElement('limitedurl', 'externalurl', get_string('youtubeurl', 'mediagallery'), ['size' => '60'], + ['usefilepicker' => true, 'repo' => 'youtube']); $mform->setType('externalurl', PARAM_TEXT); $mform->addHelpButton('externalurl', 'externalurl', 'mediagallery'); } else if ($gallery->mode == 'thebox') { if (empty($item->objectid)) { $mform->addElement('uploader', 'content', get_string('content', 'mediagallery'), '0', - array('maxfiles' => 1, 'return_types' => FILE_REFERENCE, 'repo' => 'thebox')); + ['maxfiles' => 1, 'return_types' => FILE_REFERENCE, 'repo' => 'thebox']); $mform->addHelpButton('content', 'content', 'mediagallery'); } else { $mform->removeElement('filecheck'); @@ -153,7 +153,7 @@ public function definition() { public function validation($data, $files) { global $CFG; $errors = parent::validation($data, $files); - $info = isset($data['content']) ? file_get_draft_area_info($data['content']) : array('filecount' => 0); + $info = isset($data['content']) ? file_get_draft_area_info($data['content']) : ['filecount' => 0]; $url = isset($data['externalurl']) ? trim($data['externalurl']) : ''; if (empty($data['externalurl']) && $info['filecount'] == 0 && empty($data['objectid'])) { diff --git a/jquery/plugins.php b/jquery/plugins.php index a937ed6..1293ba6 100644 --- a/jquery/plugins.php +++ b/jquery/plugins.php @@ -25,9 +25,9 @@ defined('MOODLE_INTERNAL') || die(); -$plugins = array( - 'jcarousel' => array('files' => array( +$plugins = [ + 'jcarousel' => ['files' => [ 'jcarousel/jquery.jcarousel.v2.min.js', - ) - ), -); + ], + ], +]; diff --git a/lib.php b/lib.php index b533584..280540f 100644 --- a/lib.php +++ b/lib.php @@ -174,7 +174,7 @@ function mediagallery_formfield_transform(stdClass $mediagallery) { function mediagallery_delete_instance($id) { global $DB; - if (! $mediagallery = $DB->get_record('mediagallery', array('id' => $id))) { + if (! $mediagallery = $DB->get_record('mediagallery', ['id' => $id])) { return false; } @@ -283,7 +283,7 @@ function mediagallery_cron () { * @return array */ function mediagallery_get_extra_capabilities() { - return array(); + return []; } // Gradebook API. @@ -357,12 +357,12 @@ function mediagallery_update_grades(stdClass $mediagallery, $userid = 0) { * @return array of [(string)filearea] => (string)description */ function mediagallery_get_file_areas($course, $cm, $context) { - return array( + return [ 'gallery' => new lang_string('areagallery', 'mod_mediagallery'), 'item' => new lang_string('areaitem', 'mod_mediagallery'), 'lowres' => new lang_string('arealowres', 'mod_mediagallery'), 'thumbnail' => new lang_string('areathumbnail', 'mod_mediagallery'), - ); + ]; } /** @@ -435,7 +435,7 @@ function mediagallery_get_file_info($browser, $areas, $course, $cm, $context, $f * @param bool $forcedownload whether or not force download * @param array $options additional options affecting the file serving */ -function mediagallery_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload, array $options=array()) { +function mediagallery_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload, array $options=[]) { global $DB, $CFG; if ($context->contextlevel != CONTEXT_MODULE) { @@ -493,7 +493,7 @@ function mediagallery_comment_validate($commentparam) { * @return array */ function mediagallery_comment_permissions($args) { - return array('post' => true, 'view' => true); + return ['post' => true, 'view' => true]; } /** diff --git a/locallib.php b/locallib.php index 9714ddc..0c1973d 100644 --- a/locallib.php +++ b/locallib.php @@ -45,12 +45,12 @@ * @return array */ function mediagallery_filepicker_options($gallery) { - $pickeroptions = array( + $pickeroptions = [ 'maxbytes' => $gallery->get_collection()->maxbytes, 'maxfiles' => 1, 'return_types' => FILE_INTERNAL | FILE_REFERENCE, 'subdirs' => false, - ); + ]; return $pickeroptions; } @@ -63,7 +63,7 @@ function mediagallery_filepicker_options($gallery) { * @return array List of mediagallery's. */ function mediagallery_get_sample_targets($course, $gallery) { - $list = array(); + $list = []; $modinfo = get_fast_modinfo($course); foreach ($modinfo->get_instances_of('mediagallery') as $mgid => $cm) { if (!$cm->uservisible) { @@ -99,7 +99,7 @@ function mediagallery_appears_valid_url($url) { */ function mediagallery_get_file_storage_usage() { global $DB; - $usagedata = array('course' => array(), 'total' => 0); + $usagedata = ['course' => [], 'total' => 0]; $sql = "SELECT c.id, c.fullname, c.category, f.contenthash, f.filesize FROM {course_modules} cm @@ -108,7 +108,7 @@ function mediagallery_get_file_storage_usage() { JOIN {files} f ON f.contextid = cx.id WHERE f.component = 'mod_mediagallery' ORDER BY f.id ASC"; - $seen = array(); + $seen = []; if ($result = $DB->get_recordset_sql($sql)) { foreach ($result as $record) { if (isset($seen[$record->contenthash])) { @@ -116,12 +116,12 @@ function mediagallery_get_file_storage_usage() { } $seen[$record->contenthash] = true; if (!isset($usagedata['course'][$record->id])) { - $usagedata['course'][$record->id] = (object)array( + $usagedata['course'][$record->id] = (object)[ 'id' => $record->id, 'fullname' => $record->fullname, 'category' => $record->category, 'sum' => 0, - ); + ]; } $usagedata['course'][$record->id]->sum += $record->filesize; } @@ -150,7 +150,7 @@ function mediagallery_get_file_storage_usage() { */ function mediagallery_get_readable_collections($courses) { $instances = get_all_instances_in_courses('mediagallery', $courses); - $list = array(); + $list = []; foreach ($instances as $instance) { $instance->cm = $instance->coursemodule; $list[$instance->id] = new \mod_mediagallery\collection($instance); @@ -175,15 +175,15 @@ function mediagallery_search_items($searchterms, $courses, $limitfrom = 0, $limi $collections = mediagallery_get_readable_collections($courses); if (count($collections) == 0) { - return array(false, 0); + return [false, 0]; } - $fullaccess = array(); - $where = array(); - $params = array(); + $fullaccess = []; + $where = []; + $params = []; foreach ($collections as $collectionid => $collection) { - $select = array(); + $select = []; $cm = $collection->cm; $context = $collection->context; @@ -256,7 +256,7 @@ function mediagallery_search_items($searchterms, $courses, $limitfrom = 0, $limi $totalcount = $DB->count_records_sql($countsql, $params); $records = $DB->get_records_sql($searchsql, $params, $limitfrom, $limitnum); - return array($records, $totalcount); + return [$records, $totalcount]; } /** @@ -274,7 +274,7 @@ function mediagallery_generate_search_sql($parsetree) { $notregexp = $DB->sql_regex(false); } - $params = array(); + $params = []; $ntokens = count($parsetree); if ($ntokens == 0) { @@ -283,7 +283,7 @@ function mediagallery_generate_search_sql($parsetree) { $sqlstring = ''; - $fields = array('caption', 'originalauthor', 'moralrights', 'medium', 'publisher', 'collection', 'name'); + $fields = ['caption', 'originalauthor', 'moralrights', 'medium', 'publisher', 'collection', 'name']; for ($i = 0; $i < $ntokens; $i++) { if ($i > 0) { // We have more than one clause, need to tack on AND. @@ -337,7 +337,7 @@ function mediagallery_generate_search_sql($parsetree) { $sqlstring .= ")"; } - return array($sqlstring, $params); + return [$sqlstring, $params]; } @@ -358,7 +358,7 @@ function mediagallery_add_metainfo_fields(&$mform) { $mform->addHelpButton('originalauthor', 'originalauthor', 'mediagallery'); $mform->addElement('date_selector', 'productiondate', get_string('productiondate', 'mediagallery'), - array('optional' => true, 'startyear' => 0)); + ['optional' => true, 'startyear' => 0]); $mform->addHelpButton('productiondate', 'productiondate', 'mediagallery'); $mform->addElement('text', 'medium', get_string('medium', 'mediagallery')); @@ -415,8 +415,8 @@ function mod_mediagallery_get_tagged_collections($tag, $exclusivemode = false, $ AND cm.deletioninprogress = 0 AND mc.id %ITEMFILTER% AND c.id %COURSEFILTER%"; - $params = array('itemtype' => 'mediagallery', 'tagid' => $tag->id, 'component' => 'mod_mediagallery', - 'coursemodulecontextlevel' => CONTEXT_MODULE); + $params = ['itemtype' => 'mediagallery', 'tagid' => $tag->id, 'component' => 'mod_mediagallery', + 'coursemodulecontextlevel' => CONTEXT_MODULE, ]; if ($ctx) { $context = $ctx ? context::instance_by_id($ctx) : context_system::instance(); @@ -470,14 +470,14 @@ function mod_mediagallery_get_tagged_collections($tag, $exclusivemode = false, $ context_helper::preload_from_record($item); $modinfo = get_fast_modinfo($item->courseid); $cm = $modinfo->get_cm($item->cmid); - $pageurl = new moodle_url('/mod/mediagallery/view.php', array('m' => $item->id)); - $pagename = format_string($item->name, true, array('context' => context_module::instance($item->cmid))); + $pageurl = new moodle_url('/mod/mediagallery/view.php', ['m' => $item->id]); + $pagename = format_string($item->name, true, ['context' => context_module::instance($item->cmid)]); $pagename = html_writer::link($pageurl, $pagename); $courseurl = course_get_url($item->courseid, $cm->sectionnum); $cmname = html_writer::link($cm->url, $cm->get_formatted_name()); - $coursename = format_string($item->fullname, true, array('context' => context_course::instance($item->courseid))); + $coursename = format_string($item->fullname, true, ['context' => context_course::instance($item->courseid)]); $coursename = html_writer::link($courseurl, $coursename); - $icon = html_writer::link($pageurl, html_writer::empty_tag('img', array('src' => $cm->get_icon_url()))); + $icon = html_writer::link($pageurl, html_writer::empty_tag('img', ['src' => $cm->get_icon_url()])); $tagfeed->add($icon, $pagename, $cmname.'
'.$coursename); } @@ -523,8 +523,8 @@ function mod_mediagallery_get_tagged_galleries($tag, $exclusivemode = false, $fr AND cm.deletioninprogress = 0 AND mg.id %ITEMFILTER% AND c.id %COURSEFILTER%"; - $params = array('itemtype' => 'mediagallery_gallery', 'tagid' => $tag->id, 'component' => 'mod_mediagallery', - 'coursemodulecontextlevel' => CONTEXT_MODULE); + $params = ['itemtype' => 'mediagallery_gallery', 'tagid' => $tag->id, 'component' => 'mod_mediagallery', + 'coursemodulecontextlevel' => CONTEXT_MODULE, ]; if ($ctx) { $context = $ctx ? context::instance_by_id($ctx) : context_system::instance(); @@ -580,14 +580,14 @@ function mod_mediagallery_get_tagged_galleries($tag, $exclusivemode = false, $fr context_helper::preload_from_record($item); $modinfo = get_fast_modinfo($item->courseid); $cm = $modinfo->get_cm($item->cmid); - $pageurl = new moodle_url('/mod/mediagallery/view.php', array('g' => $item->id)); - $pagename = format_string($item->name, true, array('context' => context_module::instance($item->cmid))); + $pageurl = new moodle_url('/mod/mediagallery/view.php', ['g' => $item->id]); + $pagename = format_string($item->name, true, ['context' => context_module::instance($item->cmid)]); $pagename = html_writer::link($pageurl, $pagename); $courseurl = course_get_url($item->courseid, $cm->sectionnum); $cmname = html_writer::link($cm->url, $cm->get_formatted_name()); - $coursename = format_string($item->fullname, true, array('context' => context_course::instance($item->courseid))); + $coursename = format_string($item->fullname, true, ['context' => context_course::instance($item->courseid)]); $coursename = html_writer::link($courseurl, $coursename); - $icon = html_writer::link($pageurl, html_writer::empty_tag('img', array('src' => $cm->get_icon_url()))); + $icon = html_writer::link($pageurl, html_writer::empty_tag('img', ['src' => $cm->get_icon_url()])); $tagfeed->add($icon, $pagename, $cmname.'
'.$coursename); } @@ -635,8 +635,8 @@ function mod_mediagallery_get_tagged_items($tag, $exclusivemode = false, $fromct AND cm.deletioninprogress = 0 AND mi.id %ITEMFILTER% AND c.id %COURSEFILTER%"; - $params = array('itemtype' => 'mediagallery_item', 'tagid' => $tag->id, 'component' => 'mod_mediagallery', - 'coursemodulecontextlevel' => CONTEXT_MODULE); + $params = ['itemtype' => 'mediagallery_item', 'tagid' => $tag->id, 'component' => 'mod_mediagallery', + 'coursemodulecontextlevel' => CONTEXT_MODULE, ]; if ($ctx) { $context = $ctx ? context::instance_by_id($ctx) : context_system::instance(); @@ -691,14 +691,14 @@ function mod_mediagallery_get_tagged_items($tag, $exclusivemode = false, $fromct context_helper::preload_from_record($item); $modinfo = get_fast_modinfo($item->courseid); $cm = $modinfo->get_cm($item->cmid); - $pageurl = new moodle_url('/mod/mediagallery/view.php', array('g' => $item->galleryid)); - $pagename = format_string($item->caption, true, array('context' => context_module::instance($item->cmid))); + $pageurl = new moodle_url('/mod/mediagallery/view.php', ['g' => $item->galleryid]); + $pagename = format_string($item->caption, true, ['context' => context_module::instance($item->cmid)]); $pagename = html_writer::link($pageurl, $pagename); $courseurl = course_get_url($item->courseid, $cm->sectionnum); $cmname = html_writer::link($cm->url, $cm->get_formatted_name()); - $coursename = format_string($item->fullname, true, array('context' => context_course::instance($item->courseid))); + $coursename = format_string($item->fullname, true, ['context' => context_course::instance($item->courseid)]); $coursename = html_writer::link($courseurl, $coursename); - $icon = html_writer::link($pageurl, html_writer::empty_tag('img', array('src' => $cm->get_icon_url()))); + $icon = html_writer::link($pageurl, html_writer::empty_tag('img', ['src' => $cm->get_icon_url()])); $tagfeed->add($icon, $pagename, $cmname.'
'.$coursename); } diff --git a/mod_form.php b/mod_form.php index f706d89..969a1fb 100644 --- a/mod_form.php +++ b/mod_form.php @@ -69,7 +69,7 @@ public function definition() { // General settings. $mform->addElement('header', 'general', get_string('general', 'form')); - $mform->addElement('text', 'name', get_string('mediagalleryname', 'mediagallery'), array('size' => '64')); + $mform->addElement('text', 'name', get_string('mediagalleryname', 'mediagallery'), ['size' => '64']); if (!empty($CFG->formatstringstriptags)) { $mform->setType('name', PARAM_TEXT); } else { @@ -80,9 +80,9 @@ public function definition() { $mform->addHelpButton('name', 'mediagalleryname', 'mediagallery'); $this->standard_intro_elements(); - $opts = array( + $opts = [ 'standard' => get_string('modestandard', 'mod_mediagallery'), - ); + ]; if (!empty($config->disablestandardgallery) && (empty($this->_instance) || $this->current->mode == 'thebox') && count($opts) > 1) { unset($opts['standard']); @@ -99,13 +99,13 @@ public function definition() { $mform->disabledIf('mode', 'instance', 'neq', '' ); } - $options = array( + $options = [ 'instructor' => get_string('colltypeinstructor', 'mediagallery'), 'single' => get_string('colltypesingle', 'mediagallery'), 'contributed' => get_string('colltypecontributed', 'mediagallery'), 'assignment' => get_string('colltypeassignment', 'mediagallery'), 'peerreviewed' => get_string('colltypepeerreviewed', 'mediagallery'), - ); + ]; $mform->addElement('select', 'colltype', get_string('colltype', 'mediagallery'), $options); $mform->addHelpButton('colltype', 'colltype', 'mediagallery'); @@ -115,8 +115,8 @@ public function definition() { $mform->addElement('select', 'maxbytes', get_string('maxbytes', 'mediagallery'), $options); $mform->setDefault('maxbytes', $config->maxbytes); - $numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 100); - $options = array_merge(array(0 => get_string('unlimited')), $numbers); + $numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 100]; + $options = array_merge([0 => get_string('unlimited')], $numbers); $mform->addElement('select', 'maxitems', get_string('maxitems', 'mediagallery'), $options); $mform->setType('maxitems', PARAM_INT); $mform->setDefault('maxitems', 0); @@ -124,7 +124,7 @@ public function definition() { $mform->disabledIf('maxitems', 'colltype', 'eq', 'instructor'); $mform->disabledIf('maxitems', 'colltype', 'eq', 'single'); - $options = array( + $options = [ 0 => get_string('unlimited'), '-1' => 0, 1 => 1, @@ -142,7 +142,7 @@ public function definition() { 40 => 40, 50 => 50, 100 => 100, - ); + ]; $mform->addElement('select', 'maxgalleries', get_string('maxgalleries', 'mediagallery'), $options); $mform->setType('maxgalleries', PARAM_INT); $mform->setDefault('maxgalleries', 1); @@ -163,31 +163,31 @@ public function definition() { // Display settings. $mform->addElement('header', 'display', get_string('settingsdisplay', 'mediagallery')); - $options = array( + $options = [ 0 => get_string('showall', 'mediagallery'), 10 => 10, 25 => 25, 50 => 50, 100 => 100, 200 => 200, - ); + ]; $mform->addElement('select', 'thumbnailsperpage', get_string('thumbnailsperpage', 'mediagallery'), $options); - $options = array(2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6); + $options = [2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6]; $mform->addElement('select', 'thumbnailsperrow', get_string('thumbnailsperrow', 'mediagallery'), $options); $mform->addElement('selectyesno', 'displayfullcaption', get_string('displayfullcaption', 'mediagallery')); - $options = array( + $options = [ \mod_mediagallery\base::POS_BOTTOM => get_string('bottom', 'mediagallery'), \mod_mediagallery\base::POS_TOP => get_string('top', 'mediagallery'), - ); + ]; $mform->addElement('select', 'captionposition', get_string('captionposition', 'mediagallery'), $options); // Gallery settings. $mform->addElement('header', 'display', get_string('settingsgallery', 'mediagallery')); - $typeoptgroup = array(); + $typeoptgroup = []; $typeoptgroup[] = $mform->createElement('radio', 'focus', '', get_string('typeall', 'mediagallery'), \mod_mediagallery\base::TYPE_ALL); $typeoptgroup[] = $mform->createElement('radio', 'focus', '', @@ -200,21 +200,21 @@ public function definition() { $mform->addHelpButton('gallerytypeoptions', 'galleryfocus', 'mediagallery'); $mform->addRule('gallerytypeoptions', null, 'required', null, 'client'); - $viewoptgroup = array(); + $viewoptgroup = []; $viewoptgroup[] = $mform->createElement('checkbox', 'carousel', '', get_string('carousel', 'mediagallery')); $viewoptgroup[] = $mform->createElement('checkbox', 'grid', '', get_string('gridview', 'mediagallery')); $mform->addGroup($viewoptgroup, 'galleryviewoptions', get_string('galleryviewoptions', 'mediagallery')); $mform->addHelpButton('galleryviewoptions', 'galleryviewoptions', 'mediagallery'); $mform->addRule('galleryviewoptions', null, 'required', null, 'client'); - $options = array(0 => get_string('automatic', 'mediagallery'), 1 => 1, 2 => 2, 3 => 3, 4 => 4); + $options = [0 => get_string('automatic', 'mediagallery'), 1 => 1, 2 => 2, 3 => 3, 4 => 4]; $mform->addElement('select', 'gridcolumns', get_string('gridviewcolumns', 'mediagallery'), $options); $mform->addHelpButton('gridcolumns', 'gridviewcolumns', 'mediagallery'); $mform->disabledIf('gridcolumns', 'galleryviewoptions[grid]', 'notchecked'); $mform->setDefault('gridcolumns', 0); - $options = array(0 => get_string('automatic', 'mediagallery'), 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, - 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10); + $options = [0 => get_string('automatic', 'mediagallery'), 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, + 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, ]; $mform->addElement('select', 'gridrows', get_string('gridviewrows', 'mediagallery'), $options); $mform->addHelpButton('gridrows', 'gridviewrows', 'mediagallery'); $mform->disabledIf('gridrows', 'galleryviewoptions[grid]', 'notchecked'); @@ -227,9 +227,9 @@ public function definition() { $mform->addElement('header', 'display', get_string('settingsavailability', 'mediagallery')); $mform->addElement('date_time_selector', 'readonlyfrom', get_string('readonlyfrom', 'mediagallery'), - array('optional' => true)); + ['optional' => true]); $mform->addElement('date_time_selector', 'readonlyto', get_string('readonlyto', 'mediagallery'), - array('optional' => true)); + ['optional' => true]); if ($CFG->enableavailability) { $mform->addElement('static', 'restrictavailableinfo', '', get_string('restrictavailableinfo', 'mediagallery')); } @@ -249,11 +249,11 @@ public function definition() { * @return void */ public function data_preprocessing(&$toform) { - $toform['galleryviewoptions'] = array(); + $toform['galleryviewoptions'] = []; $toform['galleryviewoptions']['carousel'] = isset($toform['carousel']) ? $toform['carousel'] : 1; $toform['galleryviewoptions']['grid'] = isset($toform['grid']) ? $toform['grid'] : ''; - $toform['gallerytypeoptions'] = array(); + $toform['gallerytypeoptions'] = []; $toform['gallerytypeoptions']['focus'] = \mod_mediagallery\base::TYPE_IMAGE; if (isset($toform['galleryfocus'])) { $toform['gallerytypeoptions']['focus'] = $toform['galleryfocus']; diff --git a/renderer.php b/renderer.php index 6d7d9f5..8529ae0 100644 --- a/renderer.php +++ b/renderer.php @@ -25,12 +25,12 @@ defined('MOODLE_INTERNAL') || die(); -use \mod_mediagallery\collection, - \mod_mediagallery\gallery, - \mod_mediagallery\item, - \mod_mediagallery\base as mcbase; -use \mod_mediagallery\output\collection\renderable as rencollection; -use \mod_mediagallery\output\gallery\renderable as rengallery; +use mod_mediagallery\collection, + mod_mediagallery\gallery, + mod_mediagallery\item, + mod_mediagallery\base as mcbase; +use mod_mediagallery\output\collection\renderable as rencollection; +use mod_mediagallery\output\gallery\renderable as rengallery; /** * Main renderer. @@ -73,19 +73,19 @@ public function view_header($controller) { $this->page->requires->css('/mod/mediagallery/css/fontawesome.min.css?1667793614'); $this->page->requires->js('/mod/mediagallery/js/screenfull.min.js'); $this->page->requires->yui_module('moodle-mod_mediagallery-base', 'M.mod_mediagallery.base.init', - array( + [ $controller->course->id, $controller->collection->id, $controller->options['viewcontrols'], $controller->options['editing'], - $galleryid, $jsoptions)); + $galleryid, $jsoptions, ]); if (!$controller->options['editing'] && $controller->options['action'] == 'viewgallery') { $this->setup_mediabox($controller->collection, $controller->gallery); } $this->page->requires->jquery(); - $jsstrs = array('confirmgallerydelete', 'confirmitemdelete', 'deletegallery', + $jsstrs = ['confirmgallerydelete', 'confirmitemdelete', 'deletegallery', 'deleteitem', 'like', 'likedby', 'comments', 'unlike', 'others', 'other', 'addsamplegallery', 'mediagallery', 'information', 'caption', 'moralrights', 'originalauthor', 'productiondate', 'medium', 'collection', @@ -96,20 +96,20 @@ public function view_header($controller) { 'deleteorremovegallery', 'deleteorremovegallerywarn', 'deleteorremoveitem', 'deleteorremoveitemwarn', 'removecollectionconfirm', 'removegalleryconfirm', 'removeitemconfirm', - 'youmusttypedelete', 'copyright', 'mediainformation'); + 'youmusttypedelete', 'copyright', 'mediainformation', ]; $this->page->requires->strings_for_js($jsstrs, 'mod_mediagallery'); - $this->page->requires->strings_for_js(array( + $this->page->requires->strings_for_js([ 'move', 'add', 'description', 'no', 'yes', 'group', 'fullnameuser', 'username', 'next', 'previous', 'submit', - ), 'moodle'); + ], 'moodle'); $this->page->requires->string_for_js('thisdirection', 'core_langconfig'); $canedit = $controller->gallery && $controller->gallery->user_can_contribute(); if ($controller->gallery && $canedit) { if (!$controller->options['editing']) { - $url = new moodle_url('/mod/mediagallery/view.php', array('g' => $controller->gallery->id, 'editing' => 1)); + $url = new moodle_url('/mod/mediagallery/view.php', ['g' => $controller->gallery->id, 'editing' => 1]); $this->page->set_button($this->output->single_button($url, get_string('turneditingon', 'core', 'get'))); } else { - $url = new moodle_url('/mod/mediagallery/view.php', array('g' => $controller->gallery->id)); + $url = new moodle_url('/mod/mediagallery/view.php', ['g' => $controller->gallery->id]); $this->page->set_button($this->output->single_button($url, get_string('turneditingoff', 'core', 'get'))); $this->page->requires->yui_module('moodle-mod_mediagallery-dragdrop', 'M.mod_mediagallery.dragdrop.init'); } @@ -125,20 +125,20 @@ public function view_header($controller) { * @return void */ protected function setup_mediabox($collection, $gallery) { - $mediaboxparams = array( + $mediaboxparams = [ 'metainfouri' => (new moodle_url('/mod/mediagallery/rest.php'))->out(), - 'metainfodata' => array( + 'metainfodata' => [ 'sesskey' => sesskey(), 'm' => $collection->id, 'class' => 'item', - ), - ); + ], + ]; if ($gallery) { $mediaboxparams['enablecomments'] = $gallery->can_comment(); $mediaboxparams['enablelikes'] = $gallery->can_like(); } $this->page->requires->yui_module('moodle-mod_mediagallery-mediabox', 'M.mod_mediagallery.init_mediabox', - array($mediaboxparams)); + [$mediaboxparams]); } /** @@ -153,7 +153,7 @@ public function render_collection(rencollection $renderable) { $rowopen = false; $count = 0; - $o = html_writer::start_tag('div', array('class' => 'gallery_list')); + $o = html_writer::start_tag('div', ['class' => 'gallery_list']); foreach ($renderable->galleries as $gallery) { if ($renderable->thumbnailsperrow > 0 && $column > $renderable->thumbnailsperrow) { // Row complete. @@ -163,7 +163,7 @@ public function render_collection(rencollection $renderable) { $row++; } if ($column == 1) { - $o .= html_writer::start_tag('div', array('class' => 'row clearfix')); + $o .= html_writer::start_tag('div', ['class' => 'row clearfix']); $rowopen = true; } if ($renderable->thumbnailsperpage > 0 && $count >= $renderable->thumbnailsperpage) { @@ -198,25 +198,25 @@ public function render_collection(rencollection $renderable) { public function gallery_list_item($gallery) { global $COURSE, $USER; $o = html_writer::start_tag('div', - array('class' => 'gallery_list_item', 'data-title' => $gallery->name, 'data-id' => $gallery->id)); + ['class' => 'gallery_list_item', 'data-title' => $gallery->name, 'data-id' => $gallery->id]); - $url = new moodle_url('/mod/mediagallery/view.php', array('g' => $gallery->id)); - $img = html_writer::empty_tag('img', array('src' => $gallery->get_thumbnail())); + $url = new moodle_url('/mod/mediagallery/view.php', ['g' => $gallery->id]); + $img = html_writer::empty_tag('img', ['src' => $gallery->get_thumbnail()]); $link = html_writer::link($url, $img); - $o .= html_writer::tag('div', $link, array('class' => 'gthumbnail')); - $o .= html_writer::start_tag('div', array('class' => 'title')); + $o .= html_writer::tag('div', $link, ['class' => 'gthumbnail']); + $o .= html_writer::start_tag('div', ['class' => 'title']); $heading = format_string($gallery->name); $o .= $this->output->heading($heading, 6); $o .= html_writer::tag('span', $heading, ['class' => 'tooltiptext']); $o .= html_writer::end_tag('div'); - $o .= html_writer::start_tag('div', array('class' => 'controls')); + $o .= html_writer::start_tag('div', ['class' => 'controls']); $this->page->requires->yui_module('moodle-mod_mediagallery-base', 'M.mod_mediagallery.base.add_gallery_info_modal', - array($COURSE->id, $gallery->get_metainfo()), null, true); - $url = new moodle_url('/mod/mediagallery/gallery.php', array('g' => $gallery->id, 'action' => 'info')); + [$COURSE->id, $gallery->get_metainfo()], null, true); + $url = new moodle_url('/mod/mediagallery/gallery.php', ['g' => $gallery->id, 'action' => 'info']); $o .= $this->output->action_icon($url, new pix_icon('i/info', get_string('information', 'mediagallery')), null, - array('class' => 'action-icon info')); + ['class' => 'action-icon info']); $actions = $this->gallery_list_item_actions($gallery); $o .= $this->action_menu($actions); @@ -233,15 +233,15 @@ public function gallery_list_item($gallery) { * @return string[] */ public function gallery_list_item_actions($gallery) { - $actions = array(); + $actions = []; if ($gallery->user_can_edit()) { - $url = new moodle_url('/mod/mediagallery/view.php', array('g' => $gallery->id, 'editing' => 1)); + $url = new moodle_url('/mod/mediagallery/view.php', ['g' => $gallery->id, 'editing' => 1]); $actions['edit'] = $this->iconlink(get_string('editgallery', 'mediagallery'), $url, 'pencil-square-o', '', true); } if ($gallery->user_can_remove()) { - $url = new moodle_url('/mod/mediagallery/gallery.php', array('g' => $gallery->id, 'action' => 'delete')); + $url = new moodle_url('/mod/mediagallery/gallery.php', ['g' => $gallery->id, 'action' => 'delete']); $isowner = $gallery->is_thebox_creator_or_agent() ? ' owner' : ''; $actions['delete'] = $this->iconlink(get_string('deletegallery', 'mediagallery'), $url, 'trash-o', "delete$isowner", true); @@ -290,14 +290,14 @@ public function gallery_heading(gallery $gallery) { * @return string */ private function focus_selector($currentfocus) { - $options = array( + $options = [ mcbase::TYPE_ALL => get_string('typeall', 'mediagallery'), mcbase::TYPE_IMAGE => get_string('typeimage', 'mediagallery'), mcbase::TYPE_VIDEO => get_string('typevideo', 'mediagallery'), mcbase::TYPE_AUDIO => get_string('typeaudio', 'mediagallery'), - ); + ]; - $select = new single_select($this->page->url, 'focus', $options, $currentfocus, array()); + $select = new single_select($this->page->url, 'focus', $options, $currentfocus, []); $select->label = get_string('galleryfocus', 'mod_mediagallery'); $select->method = 'get'; return html_writer::div($this->output->render($select), 'focus_selector'); @@ -311,13 +311,13 @@ private function focus_selector($currentfocus) { * @return string */ private function mediasize_selector($currentsize = rengallery::MEDIASIZE_MD) { - $options = array( + $options = [ rengallery::MEDIASIZE_SM => get_string('mediasizesm', 'mediagallery'), rengallery::MEDIASIZE_MD => get_string('mediasizemd', 'mediagallery'), rengallery::MEDIASIZE_LG => get_string('mediasizelg', 'mediagallery'), - ); + ]; $label = html_writer::label(get_string('mediasize', 'mod_mediagallery'), 'mediasize'); - $select = html_writer::select($options, 'mediasize', $currentsize, array()); + $select = html_writer::select($options, 'mediasize', $currentsize, []); return html_writer::div($label.$select, 'mediasize_selector'); } @@ -338,10 +338,10 @@ public function render_gallery(rengallery $renderable) { $class = ' no'; $pix = 'i/invalid'; } - $indicator = html_writer::empty_tag('img', array('src' => $this->output->image_url($pix))); - $o .= html_writer::tag('div', $indicator, array('class' => 'moralrights'.$class)); - $link = html_writer::link('#', get_string('sample', 'mediagallery'), array('id' => 'mg_sample')); - $o .= html_writer::tag('div', $link, array('class' => 'moralrights_title')); + $indicator = html_writer::empty_tag('img', ['src' => $this->output->image_url($pix)]); + $o .= html_writer::tag('div', $indicator, ['class' => 'moralrights'.$class]); + $link = html_writer::link('#', get_string('sample', 'mediagallery'), ['id' => 'mg_sample']); + $o .= html_writer::tag('div', $link, ['class' => 'moralrights_title']); } if ($gallery->mode != 'youtube' && !$renderable->editing) { @@ -380,7 +380,7 @@ public function render_gallery(rengallery $renderable) { } // If the user normally could edit, but can't currently due to read-only time or submission, display export link. if ($gallery->user_can_edit(null, true) && !$gallery->user_can_edit()) { - $exporturl = new moodle_url('/mod/mediagallery/export.php', array('g' => $gallery->id)); + $exporturl = new moodle_url('/mod/mediagallery/export.php', ['g' => $gallery->id]); $o .= html_writer::div(html_writer::link($exporturl, get_string('exportgallery', 'mediagallery')), 'exportlink'); } $o .= html_writer::div('', 'clearfix'); @@ -395,7 +395,7 @@ public function render_gallery(rengallery $renderable) { * @return string */ protected function gallery_viewing_page(rengallery $renderable) { - $o = html_writer::start_tag('div', array('class' => 'gallery'.$renderable->mediasizeclass)); + $o = html_writer::start_tag('div', ['class' => 'gallery'.$renderable->mediasizeclass]); $items = $renderable->gallery->get_items(); if (empty($items)) { $o .= get_string('noitemsadded', 'mediagallery'); @@ -418,7 +418,7 @@ protected function gallery_viewing_page(rengallery $renderable) { * @param gallery $gallery The gallery to display. */ public function gallery_editing_page(gallery $gallery) { - $o = html_writer::start_tag('div', array('class' => 'gallery_items editing')); + $o = html_writer::start_tag('div', ['class' => 'gallery_items editing']); foreach ($gallery->get_items() as $item) { $o .= $this->item_editing($item, $gallery); } @@ -448,20 +448,20 @@ public function collection_editing_actions(rencollection $renderable) { * @return array A list of actions. */ public function collection_editing_actions_list(rencollection $renderable) { - $links = array(); + $links = []; if ($renderable->normallycanadd && !$renderable->readonly) { if ($renderable->maxreached) { $links['maxgalleries'] = $this->iconlink(get_string('maxgalleriesreached', 'mediagallery'), null); } else { - $url = new moodle_url('/mod/mediagallery/gallery.php', array('m' => $renderable->id)); + $url = new moodle_url('/mod/mediagallery/gallery.php', ['m' => $renderable->id]); $links['addgallery'] = $this->iconlink(get_string('addagallery', 'mediagallery'), $url, 'plus'); } } if ($renderable->linkedassigncmid && $renderable->userorgrouphasgallery) { $url = new moodle_url('/mod/assign/view.php', - array('id' => $renderable->linkedassigncmid, 'action' => 'editsubmission')); + ['id' => $renderable->linkedassigncmid, 'action' => 'editsubmission']); if ($renderable->submissionsopen) { $str = $renderable->hassubmitted ? 'assignedit' : 'assignsubmit'; $links['submitassign'] = $this->iconlink(get_string($str, 'mediagallery'), $url, 'check-square'); @@ -471,7 +471,7 @@ public function collection_editing_actions_list(rencollection $renderable) { } } - $url = new moodle_url('/mod/mediagallery/view.php', array('id' => $this->page->context->instanceid, 'action' => 'search')); + $url = new moodle_url('/mod/mediagallery/view.php', ['id' => $this->page->context->instanceid, 'action' => 'search']); $links['search'] = $this->iconlink(get_string('search', 'mediagallery'), $url, 'search'); return $links; @@ -512,7 +512,7 @@ public function last_synced($timestamp) { public function gallery_editing_actions(gallery $gallery) { $actions = $this->gallery_editing_actions_list($gallery); - $o = html_writer::start_tag('div', array('class' => 'actions')); + $o = html_writer::start_tag('div', ['class' => 'actions']); $o .= implode('   ', $actions); $o .= html_writer::end_tag('div'); @@ -526,12 +526,12 @@ public function gallery_editing_actions(gallery $gallery) { * @return array A list of actions. */ protected function gallery_editing_actions_list($gallery) { - $additemurl = new moodle_url('/mod/mediagallery/item.php', array('g' => $gallery->id)); - $addbulkitemurl = new moodle_url('/mod/mediagallery/item.php', array('g' => $gallery->id, 'bulk' => 1)); - $viewurl = new moodle_url('/mod/mediagallery/view.php', array('g' => $gallery->id)); - $editurl = new moodle_url('/mod/mediagallery/gallery.php', array('g' => $gallery->id)); - $exporturl = new moodle_url('/mod/mediagallery/export.php', array('g' => $gallery->id)); - $actions = array(); + $additemurl = new moodle_url('/mod/mediagallery/item.php', ['g' => $gallery->id]); + $addbulkitemurl = new moodle_url('/mod/mediagallery/item.php', ['g' => $gallery->id, 'bulk' => 1]); + $viewurl = new moodle_url('/mod/mediagallery/view.php', ['g' => $gallery->id]); + $editurl = new moodle_url('/mod/mediagallery/gallery.php', ['g' => $gallery->id]); + $exporturl = new moodle_url('/mod/mediagallery/export.php', ['g' => $gallery->id]); + $actions = []; $maxitems = $gallery->get_collection()->maxitems; if ($maxitems == 0 || count($gallery->get_items()) < $maxitems) { @@ -566,13 +566,13 @@ protected function gallery_editing_actions_list($gallery) { protected function iconlink($text, $link = null, $fa = null, $linkclass = '', $actionmenu = false) { $o = ''; if ($fa) { - $icon = html_writer::tag('i', '', array('class' => 'mgfa mgfa-fw mgfa-lg mgfa-'.$fa)); + $icon = html_writer::tag('i', '', ['class' => 'mgfa mgfa-fw mgfa-lg mgfa-'.$fa]); } if ($link) { $class = $actionmenu ? 'action-menu' : 'maction'; $linkclass = trim($linkclass.' '.$class); - $o = html_writer::link($link, $icon.$text, array('class' => $linkclass)); + $o = html_writer::link($link, $icon.$text, ['class' => $linkclass]); } else { $o = html_writer::span($text); } @@ -588,26 +588,26 @@ protected function iconlink($text, $link = null, $fa = null, $linkclass = '', $a */ public function item_editing(item $item, $gallery) { global $USER; - $o = html_writer::start_tag('div', array('class' => 'item', 'data-id' => $item->id, 'data-title' => $item->caption)); + $o = html_writer::start_tag('div', ['class' => 'item', 'data-id' => $item->id, 'data-title' => $item->caption]); - $img = html_writer::empty_tag('img', array('src' => $item->get_image_url_by_type('thumbnail'))); + $img = html_writer::empty_tag('img', ['src' => $item->get_image_url_by_type('thumbnail')]); $link = html_writer::link(null, $img); - $o .= html_writer::tag('div', $link, array('class' => 'gthumbnail')); - $o .= html_writer::start_tag('div', array('class' => 'title')); + $o .= html_writer::tag('div', $link, ['class' => 'gthumbnail']); + $o .= html_writer::start_tag('div', ['class' => 'title']); $heading = format_string($item->caption); $o .= $this->output->heading($heading, 6); $o .= html_writer::tag('span', $heading, ['class' => 'tooltiptext']); $o .= html_writer::end_tag('div'); - $o .= html_writer::start_tag('div', array('class' => 'controls')); + $o .= html_writer::start_tag('div', ['class' => 'controls']); $metainfo = $item->get_metainfo(); $metainfo->tags = $this->tag_list($metainfo->tags, '', 'item-tags'); $this->page->requires->yui_module('moodle-mod_mediagallery-base', 'M.mod_mediagallery.base.add_item_info_modal', - array($metainfo), null, true); - $url = new moodle_url('/mod/mediagallery/item.php', array('i' => $item->id, 'action' => 'info')); + [$metainfo], null, true); + $url = new moodle_url('/mod/mediagallery/item.php', ['i' => $item->id, 'action' => 'info']); $o .= $this->output->action_icon($url, new pix_icon('i/info', get_string('information', 'mediagallery')), null, - array('class' => 'action-icon info')); + ['class' => 'action-icon info']); $actions = $this->item_editing_actions_list($item, $gallery); $o .= $this->action_menu($actions); @@ -626,13 +626,13 @@ public function item_editing(item $item, $gallery) { * @return array A list of actions. */ protected function item_editing_actions_list($item, $gallery) { - $actions = array(); + $actions = []; $type = $item->type(true); $boxcreatoragent = $gallery->get_collection()->mode == 'thebox' && ($gallery->is_thebox_creator_or_agent() || $gallery->get_collection()->is_thebox_creator_or_agent()); if ($item->user_can_edit() || $boxcreatoragent) { - $url = new moodle_url('/mod/mediagallery/item.php', array('i' => $item->id)); + $url = new moodle_url('/mod/mediagallery/item.php', ['i' => $item->id]); $str = is_null($type) ? 'edititem' : 'edititemtype'; $actions['edit'] = $this->iconlink(get_string($str, 'mediagallery', $type), $url, 'pencil-square-o', "edit", true); @@ -640,7 +640,7 @@ protected function item_editing_actions_list($item, $gallery) { $isowner = $item->is_thebox_creator_or_agent() ? ' owner' : ''; if (($gallery->mode != 'thebox' && $item->user_can_remove()) || $gallery->is_thebox_creator_or_agent()) { - $url = new moodle_url('/mod/mediagallery/item.php', array('i' => $item->id, 'action' => 'delete')); + $url = new moodle_url('/mod/mediagallery/item.php', ['i' => $item->id, 'action' => 'delete']); $str = is_null($type) ? 'deleteitem' : 'deleteitemtype'; $actions['delete'] = $this->iconlink(get_string($str, 'mediagallery', $type), $url, 'trash-o', "delete$isowner", true); @@ -662,7 +662,7 @@ protected function list_other_items($items, $gallery) { if (!$item->display) { continue; } - $image = $this->output->pix_icon($item->file_icon(), $item->caption, 'moodle', array('class' => 'icon')); + $image = $this->output->pix_icon($item->file_icon(), $item->caption, 'moodle', ['class' => 'icon']); if ($gallery->mode != 'thebox' || $item->thebox_processed()) { $entry = html_writer::link($item->get_embed_url(), $image.$item->caption); } else { @@ -682,20 +682,20 @@ protected function list_other_items($items, $gallery) { * @param array $options * @return string */ - public function view_carousel(gallery $gallery, array $options = array()) { - $o = html_writer::start_tag('div', array('class' => 'jcarousel-wrapper')); + public function view_carousel(gallery $gallery, array $options = []) { + $o = html_writer::start_tag('div', ['class' => 'jcarousel-wrapper']); $o .= html_writer::start_tag('div', - array('class' => 'jcarousel type_'.$gallery->type(true), 'data-jcarousel' => 'true', 'data-wrap' => 'circular')); + ['class' => 'jcarousel type_'.$gallery->type(true), 'data-jcarousel' => 'true', 'data-wrap' => 'circular']); $o .= html_writer::start_tag('ul'); foreach ($gallery->get_items_by_type() as $item) { if (!$item->display) { continue; } - $itemhtml = html_writer::empty_tag('img', array('src' => $item->get_image_url_by_type('thumbnail'))); + $itemhtml = html_writer::empty_tag('img', ['src' => $item->get_image_url_by_type('thumbnail')]); $attribs = $this->linkattribs($gallery, $item); if (!empty($options['filter'])) { - $attribs['href'] = new moodle_url('/mod/mediagallery/view.php', array('g' => $gallery->id)); + $attribs['href'] = new moodle_url('/mod/mediagallery/view.php', ['g' => $gallery->id]); } else { $attribs['href'] = $item->get_image_url_by_type('lowres'); } @@ -704,18 +704,18 @@ public function view_carousel(gallery $gallery, array $options = array()) { $o .= html_writer::end_tag('ul'); $o .= html_writer::end_tag('div'); - $o .= html_writer::tag('a', '‹', array('data-jcarousel-control' => 'true', 'data-target' => '-=1', - 'href' => '#', 'class' => 'jcarousel-control-prev')); - $o .= html_writer::tag('a', '›', array('data-jcarousel-control' => 'true', 'data-target' => '+=1', - 'href' => '#', 'class' => 'jcarousel-control-next')); - $o .= html_writer::tag('p', '', array('data-jcarouselpagination' => 'true', 'class' => 'jcarousel-pagination')); + $o .= html_writer::tag('a', '‹', ['data-jcarousel-control' => 'true', 'data-target' => '-=1', + 'href' => '#', 'class' => 'jcarousel-control-prev', ]); + $o .= html_writer::tag('a', '›', ['data-jcarousel-control' => 'true', 'data-target' => '+=1', + 'href' => '#', 'class' => 'jcarousel-control-next', ]); + $o .= html_writer::tag('p', '', ['data-jcarouselpagination' => 'true', 'class' => 'jcarousel-pagination']); $o .= html_writer::end_tag('div'); // For whatever reason, including the JS earlier doesn't work. - $o .= html_writer::tag('script', '', array( + $o .= html_writer::tag('script', '', [ 'type' => 'text/javascript', 'src' => new moodle_url('/theme/jquery.php/mod_mediagallery/jcarousel/jquery.jcarousel.v2.js'), - )); + ]); return $o; } @@ -740,7 +740,7 @@ public function embed_html($item) { protected function linkattribs($gallery, $item) { $type = $item->type(); $player = $type == mcbase::TYPE_AUDIO || ($type == mcbase::TYPE_VIDEO && $item->externalurl == '') ? $type : 1; - $attribs = array( + $attribs = [ 'data-mediabox' => 'gallery_'.$gallery->id, 'title' => $item->caption, 'data-id' => $item->id, @@ -748,7 +748,7 @@ protected function linkattribs($gallery, $item) { 'data-player' => $player, 'data-url' => $item->get_embed_url(), 'data-objectid' => $item->objectid, - ); + ]; return $attribs; } @@ -788,7 +788,7 @@ protected function view_grid(gallery $gallery, array $options) { $row++; } if ($column == 1) { - $o .= html_writer::start_tag('div', array('class' => 'grid_row clearfix')); + $o .= html_writer::start_tag('div', ['class' => 'grid_row clearfix']); $rowopen = true; } if ($row > $view->gridrows && $view->gridrows != 0) { @@ -796,15 +796,15 @@ protected function view_grid(gallery $gallery, array $options) { break; } - $url = new moodle_url('/mod/mediagallery/item.php', array('i' => $item->id, 'action' => 'info')); + $url = new moodle_url('/mod/mediagallery/item.php', ['i' => $item->id, 'action' => 'info']); $infoicon = html_writer::tag('div', $this->output->action_icon($url, new pix_icon('i/info', get_string('information', 'mediagallery')), null, - array('class' => 'action-icon info')), - array('class' => 'info') + ['class' => 'action-icon info']), + ['class' => 'info'] ); - $caption = html_writer::tag('div', $infoicon.$item->caption, array('class' => 'caption')); - $img = html_writer::empty_tag('img', array('src' => $item->get_image_url_by_type('thumbnail'))); + $caption = html_writer::tag('div', $infoicon.$item->caption, ['class' => 'caption']); + $img = html_writer::empty_tag('img', ['src' => $item->get_image_url_by_type('thumbnail')]); $linkattribs = $this->linkattribs($gallery, $item); $link = html_writer::link($item->get_image_url_by_type('lowres'), $img, $linkattribs); @@ -812,18 +812,18 @@ protected function view_grid(gallery $gallery, array $options) { if ($cappos == mcbase::POS_TOP) { $itemframe .= $caption; } - $itemframe .= html_writer::tag('div', $link, array('class' => 'item-thumb')); + $itemframe .= html_writer::tag('div', $link, ['class' => 'item-thumb']); if ($cappos == mcbase::POS_BOTTOM) { $itemframe .= $caption; } - $itemframe = html_writer::tag('div', $itemframe, array('class' => 'item-wrapper')); + $itemframe = html_writer::tag('div', $itemframe, ['class' => 'item-wrapper']); - $o .= html_writer::tag('div', $itemframe, array('class' => 'item grid_item', 'data-id' => $item->id, - 'data-title' => $item->caption, 'id' => 'gallery_item_'.$item->id)); + $o .= html_writer::tag('div', $itemframe, ['class' => 'item grid_item', 'data-id' => $item->id, + 'data-title' => $item->caption, 'id' => 'gallery_item_'.$item->id, ]); $metainfo = $item->get_metainfo(); $metainfo->tags = $this->tag_list($metainfo->tags, '', 'item-tags'); $this->page->requires->yui_module('moodle-mod_mediagallery-base', 'M.mod_mediagallery.base.add_item_info_modal', - array($metainfo), null, true); + [$metainfo], null, true); $column++; } @@ -832,7 +832,7 @@ protected function view_grid(gallery $gallery, array $options) { } $count = count($items); if ($count > $perpage && $perpage != 0) { - $url = new moodle_url('/mod/mediagallery/view.php', array('g' => $gallery->id, 'page' => $options['page'])); + $url = new moodle_url('/mod/mediagallery/view.php', ['g' => $gallery->id, 'page' => $options['page']]); $o .= $this->output->paging_bar($count, $options['page'], $perpage, $url); } @@ -871,13 +871,13 @@ public function render_searchresults($renderable) { $t = new html_table(); $row = new html_table_row(); - $fields = array( + $fields = [ get_string('caption', 'mod_mediagallery'), get_string('gallery', 'mod_mediagallery'), get_string('creator', 'mod_mediagallery'), get_string('groups'), get_string('roles'), - ); + ]; foreach ($fields as $field) { $headercell = new html_table_cell($field); @@ -888,14 +888,14 @@ public function render_searchresults($renderable) { $t->data[] = $row; foreach ($renderable->results as $results) { - $row = array(); + $row = []; $row[] = new html_table_cell($results->itemcaption); - $url = new moodle_url('/mod/mediagallery/view.php', array('g' => $results->galleryid)); + $url = new moodle_url('/mod/mediagallery/view.php', ['g' => $results->galleryid]); $gallery = html_writer::link($url, $results->galleryname); $row[] = new html_table_cell($gallery); - $url = new moodle_url('/user/view.php', array('id' => $results->userid, 'course' => $this->page->course->id)); + $url = new moodle_url('/user/view.php', ['id' => $results->userid, 'course' => $this->page->course->id]); $user = html_writer::link($url, $results->creator); $row[] = new html_table_cell($user); @@ -932,9 +932,9 @@ public function search_results($items, $totalcount, $page, $perpage) { $counts->to = $totalcount; } $o = get_string('searchdisplayxtoyofzresults', 'mediagallery', $counts); - $o .= html_writer::start_tag('ol', array('start' => $counts->from)); + $o .= html_writer::start_tag('ol', ['start' => $counts->from]); foreach ($items as $item) { - $url = new moodle_url('/mod/mediagallery/view.php', array('g' => $item->galleryid)); + $url = new moodle_url('/mod/mediagallery/view.php', ['g' => $item->galleryid]); $text = html_writer::link($url, $item->caption); $o .= html_writer::tag('li', $text); } @@ -967,7 +967,7 @@ public function storage_report($usagedata) { $o .= $catname; $o .= html_writer::start_tag('ul'); foreach ($usagedata['category'][$catid] as $courseid) { - $link = html_writer::link(new moodle_url('/course/view.php', array('id' => $courseid)), + $link = html_writer::link(new moodle_url('/course/view.php', ['id' => $courseid]), $usagedata['course'][$courseid]->fullname); $entry = $link.' : '.$this->convert_size($usagedata['course'][$courseid]->sum); $o .= html_writer::tag('li', $entry); @@ -1023,11 +1023,11 @@ public function gallery_list_item_actions($gallery) { $actions = parent::gallery_list_item_actions($gallery); if ($gallery->mode == 'standard' && $gallery->user_can_edit()) { - $exporturl = new moodle_url('/mod/mediagallery/export.php', array('g' => $gallery->id)); + $exporturl = new moodle_url('/mod/mediagallery/export.php', ['g' => $gallery->id]); $actions['export'] = $this->iconlink(get_string('exportgallery', 'mediagallery'), $exporturl, 'share', '', true); } - $order = array_flip(array('edit', 'export', 'delete')); + $order = array_flip(['edit', 'export', 'delete']); uksort($actions, function($a, $b) use ($order) { return $order[$a] - $order[$b]; }); diff --git a/rest.php b/rest.php index 711c3f3..dd84309 100644 --- a/rest.php +++ b/rest.php @@ -34,10 +34,10 @@ $action = optional_param('action', null, PARAM_ALPHAEXT); $data = optional_param_array('data', null, PARAM_RAW); -$PAGE->set_url('/mod/mediagallery/rest.php', array('id' => $id, 'class' => $class, 'm' => $m)); +$PAGE->set_url('/mod/mediagallery/rest.php', ['id' => $id, 'class' => $class, 'm' => $m]); -$mediagallery = $DB->get_record('mediagallery', array('id' => $m), '*', MUST_EXIST); -$course = $DB->get_record('course', array('id' => $mediagallery->course), '*', MUST_EXIST); +$mediagallery = $DB->get_record('mediagallery', ['id' => $m], '*', MUST_EXIST); +$course = $DB->get_record('course', ['id' => $mediagallery->course], '*', MUST_EXIST); $cm = get_coursemodule_from_instance('mediagallery', $mediagallery->id, $course->id, false, MUST_EXIST); require_login($course, false, $cm); diff --git a/search.php b/search.php index 1f34c27..624e20f 100644 --- a/search.php +++ b/search.php @@ -43,16 +43,16 @@ $perpage = optional_param('perpage', 10, PARAM_INT); $showform = optional_param('showform', 0, PARAM_INT); -$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); +$course = $DB->get_record('course', ['id' => $courseid], '*', MUST_EXIST); require_login($course); $context = context_course::instance($courseid); $PAGE->set_context($context); -$pageurl = new moodle_url('/mod/mediagallery/search.php', array('id' => $course->id)); +$pageurl = new moodle_url('/mod/mediagallery/search.php', ['id' => $course->id]); $pageurl->param('courseonly', $courseonly); -$data = array(); +$data = []; if (empty($searchstring)) { if (!empty($search)) { @@ -106,8 +106,8 @@ $node->make_active(); $results = false; -$mform = new search_form(null, array('course' => $course)); -$mform->set_data(array('search' => $search, 'moralrights' => $moralrights)); +$mform = new search_form(null, ['course' => $course]); +$mform->set_data(['search' => $search, 'moralrights' => $moralrights]); $searchterms = explode(' ', $searchstring); @@ -121,7 +121,7 @@ if (empty($searchstring)) { $items = false; } else { - $courses = array($course->id => $course); + $courses = [$course->id => $course]; list($items, $totalcount) = mediagallery_search_items($searchterms, $courses, $page * $perpage, $perpage); } if (!$items) { diff --git a/tests/base_test.php b/tests/base_test.php index 55f04b4..a63cd0a 100644 --- a/tests/base_test.php +++ b/tests/base_test.php @@ -44,12 +44,12 @@ class base_test extends \advanced_testcase { /** * @var array List of teacher records. */ - protected $teachers = array(); + protected $teachers = []; /** * @var array List of student records. */ - protected $students = array(); + protected $students = []; /** * Setup function - we will create a course and add a mediagallery instance to it. @@ -65,12 +65,12 @@ protected function setUp(): void { $student1 = $this->getDataGenerator()->create_user(); $student2 = $this->getDataGenerator()->create_user(); - $editingteacherrole = $DB->get_record('role', array('shortname' => 'editingteacher')); + $editingteacherrole = $DB->get_record('role', ['shortname' => 'editingteacher']); $this->getDataGenerator()->enrol_user($teacher1->id, $this->course->id, $editingteacherrole->id); - $studentrole = $DB->get_record('role', array('shortname' => 'student')); + $studentrole = $DB->get_record('role', ['shortname' => 'student']); $this->getDataGenerator()->enrol_user($student1->id, $this->course->id, $studentrole->id); @@ -83,8 +83,8 @@ protected function setUp(): void { $this->students[] = $student2; } - public function test_collection_read_only() { - $options = array('colltype' => 'instructor', 'course' => $this->course->id); + public function test_collection_read_only(): void { + $options = ['colltype' => 'instructor', 'course' => $this->course->id]; $record = $this->getDataGenerator()->create_module('mediagallery', $options); // Test instructor can write to an instructor collection and students can't. @@ -95,20 +95,20 @@ public function test_collection_read_only() { $this->assertTrue($collection->is_read_only()); // Students can write when its not an instructor collection. - $options = array('colltype' => 'contributed', 'course' => $this->course->id); + $options = ['colltype' => 'contributed', 'course' => $this->course->id]; $record = $this->getDataGenerator()->create_module('mediagallery', $options); $contributed = new \mod_mediagallery\collection($record); $this->assertFalse($contributed->is_read_only()); } - public function test_gallery_access_permissions() { - $options = array('colltype' => 'contributed', 'course' => $this->course->id); + public function test_gallery_access_permissions(): void { + $options = ['colltype' => 'contributed', 'course' => $this->course->id]; $record = $this->getDataGenerator()->create_module('mediagallery', $options); $collection = new \mod_mediagallery\collection($record); // Contributed mode. Users can see each others galleries. self::setUser($this->students[0]); - $record = array('name' => 'Test gallery', 'instanceid' => $collection->id); + $record = ['name' => 'Test gallery', 'instanceid' => $collection->id]; $gallery = self::getDataGenerator()->get_plugin_generator('mod_mediagallery')->create_gallery($record); $mygals = $collection->get_my_galleries(); @@ -129,10 +129,10 @@ public function test_gallery_access_permissions() { $teaid = $this->teachers[0]->id; $stuid1 = $this->students[0]->id; $stuid2 = $this->students[1]->id; - $record = array('name' => 'Test gallery', - 'instanceid' => $collection->id, - 'contributable' => 1, - 'userid' => $this->students[0]->id); + $record = ['name' => 'Test gallery', + 'instanceid' => $collection->id, + 'contributable' => 1, + 'userid' => $this->students[0]->id, ]; $gallery = $generator->create_gallery($record); $this->assertTrue($gallery->user_can_edit($stuid1)); @@ -140,9 +140,9 @@ public function test_gallery_access_permissions() { $this->assertTrue($gallery->user_can_contribute($stuid1)); $this->assertTrue($gallery->user_can_contribute($stuid2)); - $record = array('galleryid' => $gallery->id, 'userid' => $stuid1); + $record = ['galleryid' => $gallery->id, 'userid' => $stuid1]; $item1 = $generator->create_item($record); - $record = array('galleryid' => $gallery->id, 'userid' => $stuid2); + $record = ['galleryid' => $gallery->id, 'userid' => $stuid2]; $item2 = $generator->create_item($record); // Stuid1 owns the gallery and the item. So stuid2 can do nothing to @@ -166,10 +166,10 @@ public function test_gallery_access_permissions() { $this->assertFalse($item2->user_can_remove($stuid1)); // Flag off. - $record = array('name' => 'Test gallery', - 'instanceid' => $collection->id, - 'contributable' => 0, - 'userid' => $this->students[0]->id); + $record = ['name' => 'Test gallery', + 'instanceid' => $collection->id, + 'contributable' => 0, + 'userid' => $this->students[0]->id, ]; $gallery = $generator->create_gallery($record); $this->assertTrue($gallery->user_can_edit($stuid1)); diff --git a/tests/collection_test.php b/tests/collection_test.php index 2dfb2a4..9e30428 100644 --- a/tests/collection_test.php +++ b/tests/collection_test.php @@ -42,12 +42,12 @@ class collection_test extends \advanced_testcase { /** * @var array List of teacher records. */ - protected $teachers = array(); + protected $teachers = []; /** * @var array List of student records. */ - protected $students = array(); + protected $students = []; /** * Setup function - we will create a course and add a mediagallery instance to it. @@ -63,12 +63,12 @@ protected function setUp(): void { $student1 = $this->getDataGenerator()->create_user(); $student2 = $this->getDataGenerator()->create_user(); - $editingteacherrole = $DB->get_record('role', array('shortname' => 'editingteacher')); + $editingteacherrole = $DB->get_record('role', ['shortname' => 'editingteacher']); $this->getDataGenerator()->enrol_user($teacher1->id, $this->course->id, $editingteacherrole->id); - $studentrole = $DB->get_record('role', array('shortname' => 'student')); + $studentrole = $DB->get_record('role', ['shortname' => 'student']); $this->getDataGenerator()->enrol_user($student1->id, $this->course->id, $studentrole->id); @@ -81,46 +81,46 @@ protected function setUp(): void { $this->students[] = $student2; } - public function test_user_can_add_children() { + public function test_user_can_add_children(): void { $options = [ 'colltype' => 'contributed', 'course' => $this->course->id, 'groupmode' => VISIBLEGROUPS, - 'maxgalleries' => 1 + 'maxgalleries' => 1, ]; $record = $this->getDataGenerator()->create_module('mediagallery', $options); $collection = new \mod_mediagallery\collection($record); - $group1 = $this->getDataGenerator()->create_group(array('courseid' => $this->course->id)); - $group2 = $this->getDataGenerator()->create_group(array('courseid' => $this->course->id)); - $this->getDataGenerator()->create_group_member((object)array('groupid' => $group1, 'userid' => $this->students[0]->id)); - $this->getDataGenerator()->create_group_member((object)array('groupid' => $group2, 'userid' => $this->students[0]->id)); - $this->getDataGenerator()->create_group_member((object)array('groupid' => $group2, 'userid' => $this->students[1]->id)); + $group1 = $this->getDataGenerator()->create_group(['courseid' => $this->course->id]); + $group2 = $this->getDataGenerator()->create_group(['courseid' => $this->course->id]); + $this->getDataGenerator()->create_group_member((object)['groupid' => $group1, 'userid' => $this->students[0]->id]); + $this->getDataGenerator()->create_group_member((object)['groupid' => $group2, 'userid' => $this->students[0]->id]); + $this->getDataGenerator()->create_group_member((object)['groupid' => $group2, 'userid' => $this->students[1]->id]); $this->assertTrue($collection->user_can_add_children($this->students[0]->id)); $this->assertTrue($collection->user_can_add_children($this->students[1]->id)); $generator = self::getDataGenerator()->get_plugin_generator('mod_mediagallery'); - $record = array( + $record = [ 'name' => 'Test gallery G1', 'instanceid' => $collection->id, 'contributable' => 1, 'userid' => $this->students[0]->id, 'groupid' => $group1->id, - ); + ]; $generator->create_gallery($record); // Limit is one per group, as both are in group2 which has no gallery yet, they should both still be able to add. $this->assertTrue($collection->user_can_add_children($this->students[0]->id)); $this->assertTrue($collection->user_can_add_children($this->students[1]->id)); - $record = array( + $record = [ 'name' => 'Test gallery G2', 'instanceid' => $collection->id, 'contributable' => 1, 'userid' => $this->students[0]->id, 'groupid' => $group2->id, - ); + ]; $generator->create_gallery($record); // Now that group2 has a gallery, neither should be able to add a new gallery. @@ -128,7 +128,7 @@ public function test_user_can_add_children() { $this->assertFalse($collection->user_can_add_children($this->students[1]->id)); // Now test with a non-groupmode collection. - $options = array('colltype' => 'contributed', 'course' => $this->course->id, 'groupmode' => NOGROUPS, 'maxgalleries' => 1); + $options = ['colltype' => 'contributed', 'course' => $this->course->id, 'groupmode' => NOGROUPS, 'maxgalleries' => 1]; $record = $this->getDataGenerator()->create_module('mediagallery', $options); $collection = new \mod_mediagallery\collection($record); @@ -136,12 +136,12 @@ public function test_user_can_add_children() { $this->assertTrue($collection->user_can_add_children($this->students[1]->id)); $generator = self::getDataGenerator()->get_plugin_generator('mod_mediagallery'); - $record = array( + $record = [ 'name' => 'Test gallery G1', 'instanceid' => $collection->id, 'contributable' => 1, 'userid' => $this->students[0]->id, - ); + ]; $generator->create_gallery($record); // Limit is one per user, not in groupmode so groups don't matter. diff --git a/tests/generator/lib.php b/tests/generator/lib.php index 1a0d6fc..c606dad 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -55,7 +55,7 @@ public function create_instance($record = null, array $options = null) { throw new coding_exception('module generator requires $record->course'); } - $defaultsettings = array( + $defaultsettings = [ 'name' => get_string('pluginname', 'mediagallery').' '.$i, 'intro' => 'Test mediagallery ' . $i, 'introformat' => FORMAT_MOODLE, @@ -66,7 +66,7 @@ public function create_instance($record = null, array $options = null) { 'captionposition' => 0, 'colltype' => 'contributed', 'galleryfocus' => 1, - 'galleryviewoptions' => array('carousel' => 1), + 'galleryviewoptions' => ['carousel' => 1], 'gridrows' => 2, 'gridcolumns' => 3, 'enforcedefauls' => 0, @@ -75,7 +75,7 @@ public function create_instance($record = null, array $options = null) { 'mode' => 'standard', 'contributable' => 0, 'maxgalleries' => 0, - ); + ]; $defaultsettings['gallerytypeoptions']['focus'] = 1; foreach ($defaultsettings as $name => $value) { @@ -97,14 +97,14 @@ public function create_gallery($record = null) { global $CFG, $USER; $record = (object)(array)$record; - $defaults = array( + $defaults = [ 'groupid' => 0, 'galleryfocus' => \mod_mediagallery\base::TYPE_IMAGE, 'galleryview' => \mod_mediagallery\gallery::VIEW_GRID, 'userid' => $USER->id, 'mode' => 'standard', 'tags' => '', - ); + ]; if (!isset($record->instanceid)) { throw new coding_exception('instanceid must be present in $record'); @@ -132,11 +132,11 @@ public function create_item($record = null) { global $CFG, $USER; $record = (object)(array)$record; - $defaults = array( + $defaults = [ 'caption' => '', 'userid' => $USER->id, 'tags' => '', - ); + ]; if (!isset($record->galleryid)) { throw new coding_exception('galleryid must be present in $record'); diff --git a/tests/privacy_test.php b/tests/privacy_test.php index d1324d9..2e9cad3 100644 --- a/tests/privacy_test.php +++ b/tests/privacy_test.php @@ -62,26 +62,26 @@ private function create_users($count) { } private function create_gallery($cm, $user) { - $record = array( + $record = [ 'name' => 'Test gallery '.$cm->id.'_'.$user->id, 'instanceid' => $cm->id, 'contributable' => 1, 'userid' => $user->id, - ); + ]; return self::getDataGenerator() ->get_plugin_generator('mod_mediagallery')->create_gallery($record); } private function create_item($gallery, $user) { - $record = array( + $record = [ 'galleryid' => $gallery->id, 'userid' => $user->id, - ); + ]; return self::getDataGenerator() ->get_plugin_generator('mod_mediagallery')->create_item($record); } - public function test_get_contexts_for_userid() { + public function test_get_contexts_for_userid(): void { $dg = $this->getDataGenerator(); $c1 = $dg->create_course(); @@ -125,7 +125,7 @@ public function test_get_contexts_for_userid() { $this->assertTrue(in_array(\context_module::instance($cm2b->cmid)->id, $contextids)); } - public function test_delete_data_for_all_users_in_context() { + public function test_delete_data_for_all_users_in_context(): void { global $DB; $dg = $this->getDataGenerator(); @@ -142,7 +142,7 @@ public function test_delete_data_for_all_users_in_context() { $this->assertFalse($DB->record_exists('mediagallery_gallery', ['userid' => $users[1]->id, 'instanceid' => $cm1b->id])); } - public function test_delete_data_for_user() { + public function test_delete_data_for_user(): void { global $DB; $dg = $this->getDataGenerator(); $fs = get_file_storage(); @@ -180,7 +180,7 @@ public function test_delete_data_for_user() { $this->assertTrue($DB->record_exists('mediagallery_gallery', ['userid' => $users[1]->id, 'instanceid' => $cm1b->id])); } - public function test_export_data_for_user() { + public function test_export_data_for_user(): void { global $DB; $dg = $this->getDataGenerator(); $fs = get_file_storage(); diff --git a/view.php b/view.php index 56ea2e2..881f422 100644 --- a/view.php +++ b/view.php @@ -40,14 +40,14 @@ $mediasize = get_user_preferences('mod_mediagallery_mediasize', \mod_mediagallery\output\gallery\renderable::MEDIASIZE_MD); -$options = array( +$options = [ 'focus' => $focus, 'mediasize' => $mediasize, 'editing' => $editing, 'page' => $page, 'action' => $action, 'viewcontrols' => $viewcontrols, -); +]; if ($g) { $gallery = new \mod_mediagallery\gallery($g, $options); $gallery->sync($forcesync); @@ -55,15 +55,15 @@ $m = $gallery->instanceid; $options['viewcontrols'] = 'item'; $mediagallery = $gallery->get_collection(); - $course = $DB->get_record('course', array('id' => $mediagallery->course), '*', MUST_EXIST); + $course = $DB->get_record('course', ['id' => $mediagallery->course], '*', MUST_EXIST); $cm = $mediagallery->cm; } else if ($id) { $cm = get_coursemodule_from_id('mediagallery', $id, 0, false, MUST_EXIST); - $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); + $course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST); $mediagallery = new \mod_mediagallery\collection($cm->instance); } else if ($m) { $mediagallery = new \mod_mediagallery\collection($m); - $course = $DB->get_record('course', array('id' => $mediagallery->course), '*', MUST_EXIST); + $course = $DB->get_record('course', ['id' => $mediagallery->course], '*', MUST_EXIST); $cm = get_coursemodule_from_instance('mediagallery', $mediagallery->id, $course->id, false, MUST_EXIST); } else { throw new \moodle_exception('missingparameter'); @@ -75,7 +75,7 @@ switch($mediagallery->count_galleries()) { case 0: // Redirect to adding a gallery. - redirect(new moodle_url('/mod/mediagallery/gallery.php', array('m' => $mediagallery->id))); + redirect(new moodle_url('/mod/mediagallery/gallery.php', ['m' => $mediagallery->id])); break; case 1: $galleries = $mediagallery->get_visible_galleries(); @@ -115,13 +115,13 @@ if ($gallery) { - $pageurl = new moodle_url('/mod/mediagallery/view.php', array('g' => $g, 'page' => $page)); + $pageurl = new moodle_url('/mod/mediagallery/view.php', ['g' => $g, 'page' => $page]); if ($options['editing']) { $pageurl->param('editing', true); } } else { - $pageurl = new moodle_url('/mod/mediagallery/view.php', array('id' => $cm->id)); + $pageurl = new moodle_url('/mod/mediagallery/view.php', ['id' => $cm->id]); } $PAGE->set_url($pageurl);