Skip to content

Commit

Permalink
Code style
Browse files Browse the repository at this point in the history
  • Loading branch information
davidherney committed May 20, 2024
1 parent 6f227a4 commit 32f444b
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 63 deletions.
10 changes: 4 additions & 6 deletions backup/moodle2/backup_format_menutopic_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* @since 2.3
* @package format_menutopic
* @copyright 2012 David Herney Bernal - cirano
* @copyright 2012 David Herney - cirano
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

Expand All @@ -28,7 +28,7 @@
*
* @package format_menutopic
* @category backup
* @copyright 2012 David Herney Bernal - cirano
* @copyright 2012 David Herney - cirano
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_format_menutopic_plugin extends backup_format_plugin {
Expand All @@ -47,13 +47,11 @@ protected function define_course_plugin_structure() {
$plugin->add_child($pluginwrapper);

// Set up fromat's own structure and add to wrapper.
$menutopic = new backup_nested_element('menutopic', array('id'), array(
'config', 'css', 'js', 'html', 'tree'));
$menutopic = new backup_nested_element('menutopic', ['id'], ['config', 'css', 'js', 'html', 'tree']);
$pluginwrapper->add_child($menutopic);

// Use database to get source.
$menutopic->set_source_table('format_menutopic',
array('course' => backup::VAR_COURSEID));
$menutopic->set_source_table('format_menutopic', ['course' => backup::VAR_COURSEID]);

return $plugin;
}
Expand Down
11 changes: 5 additions & 6 deletions backup/moodle2/restore_format_menutopic_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* @since 2.3
* @package format_menutopic
* @copyright 2012 David Herney Bernal - cirano
* @copyright 2012 David Herney - cirano
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

Expand All @@ -28,7 +28,7 @@
*
* @package format_menutopic
* @category backup
* @copyright 2012 David Herney Bernal - cirano
* @copyright 2012 David Herney - cirano
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_format_menutopic_plugin extends restore_format_plugin {
Expand All @@ -37,7 +37,7 @@ class restore_format_menutopic_plugin extends restore_format_plugin {
* Returns the course format information to attach to course element.
*/
protected function define_course_plugin_structure() {
$paths = array();
$paths = [];

// Because of using get_recommended_name() it is able to find the
// correct path just by using the part inside the element name (which
Expand Down Expand Up @@ -65,11 +65,10 @@ public function process_menutopic($data) {
$data->course = $this->task->get_courseid();

// See if there is an existing record for this course.
$existingid = $DB->get_field('format_menutopic', 'id',
array('course' => $data->course));
$existingid = $DB->get_field('format_menutopic', 'id', ['course' => $data->course]);
if ($existingid) {
$data->id = $existingid;
$DB->update_record('format_menutopic', data);
$DB->update_record('format_menutopic', $data);
} else {
$DB->insert_record('format_menutopic', $data);
}
Expand Down
4 changes: 2 additions & 2 deletions classes/forms/csstemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class csstemplate extends \moodleform {
* Defines the form fields.
*/
public function definition() {
global $USER, $CFG, $course;
global $course;

$csscode = '';

Expand All @@ -50,7 +50,7 @@ public function definition() {
$mform->addElement('header', 'general', get_string('csstemplate_editmenu_title', 'format_menutopic'));
$mform->addHelpButton('general', 'csstemplate', 'format_menutopic');

$mform->addElement('textarea', 'csscode', get_string('csscode', 'format_menutopic'), array('rows' => '20', 'cols' => '65'));
$mform->addElement('textarea', 'csscode', get_string('csscode', 'format_menutopic'), ['rows' => '20', 'cols' => '65']);
$mform->setType('csscode', PARAM_RAW);
$mform->setDefault('csscode', $csscode);

Expand Down
4 changes: 2 additions & 2 deletions classes/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function remove_topic($section, $onlyhide = false, $removetopic = true) {
* @param int $section The linked section
* @return array of object
*/
public function get_topics($section) : ?array {
public function get_topics($section): ?array {

$topics = [];
foreach ($this->menuitems as $key => $item) {
Expand All @@ -141,7 +141,7 @@ public function get_topics($section) : ?array {
* @param int $courseid The course id.
* @return array of object.
*/
public function get_list(int $courseid) : array {
public function get_list(int $courseid): array {

$menutree = [];

Expand Down
4 changes: 2 additions & 2 deletions classes/menuitem.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function __construct(string $url, string $title) {
* @param int $level Submenu level.
* @return void
*/
public function loadsubtopics(array $subtopics, int $level = 0) : void {
public function loadsubtopics(array $subtopics, int $level = 0): void {

$this->submenu->level = $level;

Expand Down Expand Up @@ -156,7 +156,7 @@ public function get_submenu() {
*
* @return void
*/
public function clean_submenu() : void {
public function clean_submenu(): void {
$this->submenu = new \format_menutopic\menu();
}

Expand Down
6 changes: 3 additions & 3 deletions classes/output/courseformat/content/section.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ class section extends section_base {
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output typically, the renderer that's calling this function
* @param \renderer_base $output typically, the renderer that's calling this function
* @return array data context for a mustache template
*/
public function export_for_template(\renderer_base $output): stdClass {
global $USER, $PAGE;
global $PAGE;

$format = $this->format;
$course = $format->get_course();
Expand All @@ -63,7 +63,7 @@ public function export_for_template(\renderer_base $output): stdClass {
'summary' => $summary->export_for_template($output),
'highlightedlabel' => $format->get_section_highlighted_name(),
'sitehome' => $course->id == SITEID,
'editing' => $PAGE->user_is_editing()
'editing' => $PAGE->user_is_editing(),
];

$haspartials = [];
Expand Down
2 changes: 1 addition & 1 deletion classes/output/courseformat/content/section/summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private function replace_resources(section_info $section) {
$this->tplstringsearch = $instancename;

$newsummary = preg_replace_callback("/(\[\[)(([<][^>]*>)*)((" . preg_quote($this->tplstringsearch, '/') .
")(:?))([^\]]*)\]\]/i", array($this, "replace_tag_in_expresion"), $summary);
")(:?))([^\]]*)\]\]/i", [$this, "replace_tag_in_expresion"], $summary);

if ($newsummary != $summary) {
$this->format->tplcmsused[] = $modnumber;
Expand Down
14 changes: 7 additions & 7 deletions classes/output/edition.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Contains the default content output class.
*
* @package format_menutopic
* @copyright 2022 David Herney Bernal - cirano. https://bambuco.co
* @copyright 2022 David Herney - cirano. https://bambuco.co
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

Expand All @@ -32,7 +32,7 @@
* Base class to render the configuration forms.
*
* @package format_menutopic
* @copyright 2022 David Herney Bernal - cirano. https://bambuco.co
* @copyright 2022 David Herney - cirano. https://bambuco.co
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class edition implements renderable, templatable {
Expand Down Expand Up @@ -71,15 +71,15 @@ public function get_template_name(renderer_base $renderer): string {
* @return array Context variables for the template
*/
public function export_for_template(renderer_base $output) {
global $CFG, $USER, $DB, $format;
global $CFG, $DB, $format;

$msgs = [];

$displaysection = \format_menutopic::$displaysection;

if (!($formatdata = $DB->get_record('format_menutopic', ['course' => $this->course->id]))) {
$formatdata = new \stdClass();
$formatdata->course = $course->id;
$formatdata->course = $this->course->id;

if (!($formatdata->id = $DB->insert_record('format_menutopic', $formatdata))) {
debugging('Not is possible save the course format data in menutopic format.', DEBUG_DEVELOPER);
Expand Down Expand Up @@ -140,12 +140,12 @@ public function export_for_template(renderer_base $output) {
if (!$DB->update_record('format_menutopic', $formatdata)) {
$msgs[] = (object)[
'type' => 'error',
'message' => get_string('notsaved', 'format_menutopic')
'message' => get_string('notsaved', 'format_menutopic'),
];
} else {
$msgs[] = (object)[
'type' => 'success',
'message' => get_string('savecorrect', 'format_menutopic')
'message' => get_string('savecorrect', 'format_menutopic'),
];
}
}
Expand Down Expand Up @@ -183,7 +183,7 @@ public function export_for_template(renderer_base $output) {
'hasmsgs' => count($msgs) > 0,
'msgs' => $msgs,
'styleboots' => true,
'darkstyle' => true
'darkstyle' => true,
];

if ($displaysection >= 0) {
Expand Down
66 changes: 34 additions & 32 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,62 +380,62 @@ public function course_format_options($foreditform = false) {
static $courseformatoptions = false;
if ($courseformatoptions === false) {
$courseconfig = get_config('moodlecourse');
$courseformatoptions = array(
'numsections' => array(
$courseformatoptions = [
'numsections' => [
'default' => $courseconfig->numsections,
'type' => PARAM_INT
),
'hiddensections' => array(
'type' => PARAM_INT,
],
'hiddensections' => [
'default' => $courseconfig->hiddensections,
'type' => PARAM_INT
),
'coursedisplay' => array(
'type' => PARAM_INT,
],
'coursedisplay' => [
'default' => $courseconfig->coursedisplay,
'type' => PARAM_INT
),
);
'type' => PARAM_INT,
],
];
}
if ($foreditform && !isset($courseformatoptions['coursedisplay']['label'])) {
$courseconfig = get_config('moodlecourse');
$max = $courseconfig->maxsections;
if (!isset($max) || !is_numeric($max)) {
$max = 52;
}
$sectionmenu = array();
$sectionmenu = [];
for ($i = 0; $i <= $max; $i++) {
$sectionmenu[$i] = "$i";
}
$courseformatoptionsedit = array(
'numsections' => array(
$courseformatoptionsedit = [
'numsections' => [
'label' => new lang_string('numberweeks'),
'element_type' => 'select',
'element_attributes' => array($sectionmenu),
),
'hiddensections' => array(
'element_attributes' => [$sectionmenu],
],
'hiddensections' => [
'label' => new lang_string('hiddensections'),
'help' => 'hiddensections',
'help_component' => 'moodle',
'element_type' => 'select',
'element_attributes' => array(
array(
'element_attributes' => [
[
0 => new lang_string('hiddensectionscollapsed'),
1 => new lang_string('hiddensectionsinvisible')
)
),
),
'coursedisplay' => array(
1 => new lang_string('hiddensectionsinvisible'),
],
],
],
'coursedisplay' => [
'label' => new lang_string('coursedisplay', 'format_menutopic'),
'element_type' => 'select',
'element_attributes' => array(
array(
'element_attributes' => [
[
COURSE_DISPLAY_SINGLEPAGE => new lang_string('coursedisplay_single', 'format_menutopic'),
COURSE_DISPLAY_MULTIPAGE => new lang_string('coursedisplay_multi', 'format_menutopic')
)
),
COURSE_DISPLAY_MULTIPAGE => new lang_string('coursedisplay_multi', 'format_menutopic'),
],
],
'help' => 'coursedisplay',
'help_component' => 'format_menutopic',
)
);
],
];
$courseformatoptions = array_merge_recursive($courseformatoptions, $courseformatoptionsedit);
}
return $courseformatoptions;
Expand Down Expand Up @@ -485,6 +485,8 @@ public function create_edit_form_elements(&$mform, $forsection = false) {
* @return bool whether there were any changes to the options values
*/
public function update_course_format_options($data, $oldcourse = null) {
global $DB;

if ($oldcourse !== null) {
$data = (array)$data;
$oldcourse = (array)$oldcourse;
Expand All @@ -497,7 +499,7 @@ public function update_course_format_options($data, $oldcourse = null) {
// If previous format does not have the field 'numsections' and $data['numsections'] is not set,
// we fill it with the maximum section number from the DB.
$maxsection = $DB->get_field_sql('SELECT max(section) from {course_sections} WHERE course = ?',
array($this->courseid));
[$this->courseid]);
if ($maxsection) {
// If there are no sections, or just default 0-section, 'numsections' will be set to default.
$data['numsections'] = $maxsection;
Expand Down
2 changes: 1 addition & 1 deletion settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
$fields = [
\format_menutopic::STYLE_BOOTS => new lang_string('style_boots', 'format_menutopic'),
\format_menutopic::STYLE_BOOTSDARK => new lang_string('style_bootsdark', 'format_menutopic'),
\format_menutopic::STYLE_BASIC => new lang_string('style_basic', 'format_menutopic')
\format_menutopic::STYLE_BASIC => new lang_string('style_basic', 'format_menutopic'),
];
$settings->add(new admin_setting_configselect('format_menutopic/globalstyle',
get_string('globalstyle', 'format_menutopic'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{
"activityname": "Course announcements",
"hascompletion": true,
"uservisible": true,
"uservisible": false,
"isautomatic": true,
"showmanualcompletion": true,
"completiondetails": [
Expand Down

0 comments on commit 32f444b

Please sign in to comment.