Skip to content

Commit bc3ba3b

Browse files
committed
Code style updates
1 parent 9c5e0c6 commit bc3ba3b

25 files changed

Lines changed: 378 additions & 281 deletions

_course_changenumsections.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
* @since Moodle 2.3
3030
*/
3131

32-
require_once(__DIR__.'/../../../config.php'); // CHANGED.
33-
require_once($CFG->dirroot.'/course/lib.php');
34-
require_once(__DIR__.'/locallib.php');
32+
require_once(__DIR__ . '/../../../config.php'); // CHANGED.
33+
require_once($CFG->dirroot . '/course/lib.php');
34+
require_once(__DIR__ . '/locallib.php');
3535
// ADDED LINE ABOVE: For function format_multitopic_course_create_section .
3636

3737
$courseid = required_param('courseid', PARAM_INT);
@@ -105,15 +105,14 @@
105105
// Overwriting returnurl to be consistent with block below even though we never get here.
106106
$returnurl = course_get_url($course);
107107
$returnurl->set_anchor('changenumsections');
108-
109108
} else if (course_get_format($course)->uses_sections() && $insertsection !== null) {
110109
if (true) {
111110
// CHANGED: Usually Moodle would not check for the capability to move sections when adding a section to the end.
112111
// Since "the end" seems a less meaningful distinction for a heirarchy than for a list, this special case is omitted.
113112
require_capability('moodle/course:movesections', \context_course::instance($course->id));
114113
}
115114
$sections = [];
116-
for ($i = 0; $i < max($numsections, 1); $i ++) {
115+
for ($i = 0; $i < max($numsections, 1); $i++) {
117116
$sections[] = format_multitopic_course_create_section($course, $insertsection);
118117
// CHANGED LINE ABOVE: Use custom method, and send section info, not section number.
119118
}

_course_editsection.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@
5656
$cancelurl = course_get_url($course, $sectioninfo); // CHANGED: Ignore $sectionreturn.
5757
if (course_can_delete_section($course, $sectioninfo)) {
5858
$confirm = optional_param('confirm', false, PARAM_BOOL) && confirm_sesskey();
59-
if (!$confirm && optional_param('sesskey', null, PARAM_RAW) !== null &&
60-
empty($sectioninfo->summary) && empty($sectioninfo->sequence) && confirm_sesskey()) {
59+
if (
60+
!$confirm && optional_param('sesskey', null, PARAM_RAW) !== null &&
61+
empty($sectioninfo->summary) && empty($sectioninfo->sequence) && confirm_sesskey()
62+
) {
6163
// Do not ask for confirmation if section is empty and sesskey is already provided.
6264
$confirm = true;
6365
}
@@ -90,8 +92,12 @@
9092
// CHANGED LINE ABOVE: Custom script.
9193
$formcontinue = new \single_button($deleteurl, get_string('delete'));
9294
$formcancel = new \single_button($cancelurl, get_string('cancel'), 'get');
93-
echo $OUTPUT->confirm(get_string('confirmdeletesection', '',
94-
get_section_name($course, $sectioninfo)), $formcontinue, $formcancel);
95+
echo $OUTPUT->confirm(
96+
get_string('confirmdeletesection', '',
97+
get_section_name($course, $sectioninfo)),
98+
$formcontinue,
99+
$formcancel
100+
);
95101
echo $OUTPUT->box_end();
96102
echo $OUTPUT->footer();
97103
exit;
@@ -148,8 +154,10 @@
148154
if (isset($data->level) && ($data->level != $sectioninfoextra->levelsan) && ($sectioninfo->section > 0)) {
149155
// If the level was changed, update the section info properties relevant to generating the URL.
150156
// This is a hack to avoid recalculating section properties. TODO: Remove?
151-
if (($sectioninfoextra->levelsan < FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC)
152-
&& ($data->level >= FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC)) {
157+
if (
158+
($sectioninfoextra->levelsan < FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC)
159+
&& ($data->level >= FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC)
160+
) {
153161
// If the section was changed to Topic level, the former previous page will be the new parent page.
154162
$sectioninfoextra->parentid = $sectioninfoextra->prevpageid;
155163
}

_course_view.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
require_once($CFG->libdir . '/completionlib.php');
3232

3333
if (true) { // ADDED: To pass indentation style check.
34-
3534
$id = optional_param('id', 0, PARAM_INT);
3635
$name = optional_param('name', '', PARAM_TEXT);
3736
$edit = optional_param('edit', -1, PARAM_BOOL);
@@ -127,8 +126,10 @@
127126

128127
// Switchrole - sanity check in cost-order...
129128
$resetuserallowedediting = false;
130-
if ($switchrole > 0 && confirm_sesskey() &&
131-
has_capability('moodle/role:switchroles', $context)) {
129+
if (
130+
$switchrole > 0 && confirm_sesskey() &&
131+
has_capability('moodle/role:switchroles', $context)
132+
) {
132133
// Is this role assignable in this context?
133134
// Inquiring minds want to know...
134135
$aroles = get_switchable_roles($context);
@@ -256,10 +257,12 @@
256257
// END CHANGED.
257258
}
258259

259-
if (!empty($section) && !empty($dest) &&
260-
has_capability('moodle/course:movesections', $context) &&
261-
(has_capability('moodle/course:update', $context) || !isset($dest->level)) &&
262-
confirm_sesskey()) { // CHANGED: Use $dest, check capability for level.
260+
if (
261+
!empty($section) && !empty($dest) &&
262+
has_capability('moodle/course:movesections', $context) &&
263+
(has_capability('moodle/course:update', $context) || !isset($dest->level)) &&
264+
confirm_sesskey()
265+
) { // CHANGED: Use $dest, check capability for level.
263266
// TODO: Is this the correct capability?
264267
$destsection = $dest; // CHANGED: Use section info with ID instead of num.
265268
try { // CHANGED: Use try/catch instead of return false.
@@ -300,8 +303,13 @@
300303
if ($section && $section->section > 0 && course_format_uses_sections($course->format)) { // CHANGED: Dereference section num.
301304
$sectionname = get_string('sectionname', "format_$course->format");
302305
$sectiontitle = get_section_name($course, $section);
303-
$PAGE->set_title(get_string('coursesectiontitle', 'moodle',
304-
['course' => $course->fullname, 'sectiontitle' => $sectiontitle, 'sectionname' => $sectionname]));
306+
$PAGE->set_title(
307+
get_string(
308+
'coursesectiontitle',
309+
'moodle',
310+
['course' => $course->fullname, 'sectiontitle' => $sectiontitle, 'sectionname' => $sectionname]
311+
)
312+
);
305313
} else {
306314
$PAGE->set_title(get_string('coursetitle', 'moodle', ['course' => $course->fullname]));
307315
}
@@ -310,7 +318,6 @@
310318
echo $OUTPUT->header();
311319

312320
if ($USER->editing == 1) {
313-
314321
// MDL-65321 The backup libraries are quite heavy, only require the bare minimum.
315322
require_once($CFG->dirroot . '/backup/util/helper/async_helper.class.php');
316323

@@ -365,5 +372,4 @@
365372
}
366373

367374
echo $OUTPUT->footer();
368-
369375
}

backup/moodle2/restore_format_multitopic_plugin.class.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3737
*/
3838
class restore_format_multitopic_plugin extends restore_format_plugin {
39-
4039
/**
4140
* Creates a dummy path element in order to be able to execute code after restore.
4241
*
@@ -54,7 +53,6 @@ public function define_course_plugin_structure() {
5453
* @return void
5554
*/
5655
public function process_dummy_course() {
57-
5856
}
5957

6058
/**
@@ -89,6 +87,5 @@ public function after_restore_course() {
8987
)",
9088
[$this->step->get_task()->get_courseid()]
9189
);
92-
9390
}
9491
}

classes/coursecontentheaderfooter.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ public function __construct(\moodle_page $page, int $pos) {
4949
// Based on lib/outputrenderers.php function activity_navigation .
5050

5151
// First we should check if we want to add navigation.
52-
if (($page->pagelayout == 'incourse' || $page->pagelayout == 'frametop')
53-
&& $page->context->contextlevel == CONTEXT_MODULE
54-
&& !$page->cm->is_stealth()) {
52+
if (
53+
($page->pagelayout == 'incourse' || $page->pagelayout == 'frametop')
54+
&& $page->context->contextlevel == CONTEXT_MODULE
55+
&& !$page->cm->is_stealth()
56+
) {
5557
$course = $page->cm->get_course();
5658
$section = new \stdClass();
5759
$section->id = $page->cm->section;
@@ -92,5 +94,4 @@ public function output(): string {
9294

9395
return $o;
9496
}
95-
9697
}

classes/courseformat/stateactions.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3838
*/
3939
class stateactions extends \core_courseformat\stateactions {
40-
4140
/**
4241
* Move course sections to another location in the same course.
4342
*
@@ -80,10 +79,12 @@ public function section_move(
8079
foreach ($ids as $id) {
8180
$originextra = $allsectionsextra[$id];
8281
$origins[] = $originextra;
83-
for ($originsubextra = $originextra; /* ... */
84-
$originsubextra && ($originsubextra->id == $originextra->id
85-
|| $originsubextra->levelsan > $originextra->levelsan); /* ... */
86-
$originsubextra = $originsubextra->nextanyid ? $allsectionsextra[$originsubextra->nextanyid] : null) {
82+
for (
83+
$originsubextra = $originextra; /* ... */
84+
$originsubextra && ($originsubextra->id == $originextra->id
85+
|| $originsubextra->levelsan > $originextra->levelsan); /* ... */
86+
$originsubextra = $originsubextra->nextanyid ? $allsectionsextra[$originsubextra->nextanyid] : null
87+
) {
8788
$subids[] = $originsubextra->id;
8889
}
8990
}
@@ -158,10 +159,12 @@ public function section_move_after(
158159
foreach ($ids as $id) {
159160
$originextra = $allsectionsextra[$id];
160161
$origins[] = $originextra;
161-
for ($originsubextra = $originextra; /* ... */
162-
$originsubextra && ($originsubextra->id == $originextra->id
163-
|| $originsubextra->levelsan > $originextra->levelsan); /* ... */
164-
$originsubextra = $originsubextra->nextanyid ? $allsectionsextra[$originsubextra->nextanyid] : null) {
162+
for (
163+
$originsubextra = $originextra; /* ... */
164+
$originsubextra && ($originsubextra->id == $originextra->id
165+
|| $originsubextra->levelsan > $originextra->levelsan); /* ... */
166+
$originsubextra = $originsubextra->nextanyid ? $allsectionsextra[$originsubextra->nextanyid] : null
167+
) {
165168
$subids[] = $originsubextra->id;
166169
}
167170
}
@@ -231,10 +234,12 @@ public function fmt_section_move_into(
231234
foreach ($ids as $id) {
232235
$originextra = $allsectionsextra[$id];
233236
$origins[] = $originextra;
234-
for ($originsubextra = $originextra; /* ... */
235-
$originsubextra && ($originsubextra->id == $originextra->id
236-
|| $originsubextra->levelsan > $originextra->levelsan); /* ... */
237-
$originsubextra = $originsubextra->nextanyid ? $allsectionsextra[$originsubextra->nextanyid] : null) {
237+
for (
238+
$originsubextra = $originextra; /* ... */
239+
$originsubextra && ($originsubextra->id == $originextra->id
240+
|| $originsubextra->levelsan > $originextra->levelsan); /* ... */
241+
$originsubextra = $originsubextra->nextanyid ? $allsectionsextra[$originsubextra->nextanyid] : null
242+
) {
238243
$subids[] = $originsubextra->id;
239244
}
240245
}
@@ -300,5 +305,4 @@ protected function set_section_visibility(
300305
}
301306
$this->section_state($updates, $course, $ids);
302307
}
303-
304308
}

classes/courseheader.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,17 @@ public function __construct(\stdClass $course) {
7272
$filename = $file->get_filename();
7373
$filenameextpos = strrpos($filename, '.');
7474
if ($filenameextpos) {
75-
$url = \moodle_url::make_file_url('/pluginfile.php' ,
76-
'/' . $file->get_contextid() . '/course/overviewfiles' .
77-
$file->get_filepath() . $filename);
75+
$url = \moodle_url::make_file_url(
76+
'/pluginfile.php',
77+
'/' . $file->get_contextid() . '/course/overviewfiles' . $file->get_filepath() . $filename
78+
);
7879
$this->imageurl = $url;
7980
$this->imagename = substr($filename, 0, $filenameextpos);
8081
$this->authorwithurl = $file->get_author();
8182
$this->licencecode = $file->get_license();
8283
break;
8384
}
8485
}
85-
8686
}
8787

8888
/**
@@ -113,5 +113,4 @@ public function output(): string {
113113

114114
return $o;
115115
}
116-
117116
}

classes/global_navigation_wrapper.php

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected function generate_sections_and_activities(\stdClass $course): array {
111111
}
112112
foreach ($modinfo->sections[$section->section] as $cmid) {
113113
$cm = $modinfo->cms[$cmid];
114-
$activity = new \stdClass;
114+
$activity = new \stdClass();
115115
$activity->id = $cm->id;
116116
$activity->course = $course->id;
117117
$activity->sectionid = $section->id; // CHANGED: Use section ID instead of number.
@@ -154,15 +154,18 @@ public function load_generic_course_sections(\stdClass $course, \navigation_node
154154
global $CFG, $SITE; // CHANGED: Removed $DB and $USER.
155155
require_once($CFG->dirroot . '/course/lib.php');
156156

157-
list($sections, $activities) = $this->generate_sections_and_activities($course);
157+
[$sections, $activities] = $this->generate_sections_and_activities($course);
158158

159159
$navigationsections = [];
160160
// ADDED.
161161
// Navigation node at level n.
162162
// This is a list of the navigation nodes currently at each level,
163163
// from the node for the course, down to the node we're currently working on.
164-
$nodeln = array_fill(FORMAT_MULTITOPIC_SECTION_LEVEL_ROOT,
165-
FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC - FORMAT_MULTITOPIC_SECTION_LEVEL_ROOT + 1, $coursenode);
164+
$nodeln = array_fill(
165+
FORMAT_MULTITOPIC_SECTION_LEVEL_ROOT,
166+
FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC - FORMAT_MULTITOPIC_SECTION_LEVEL_ROOT + 1,
167+
$coursenode
168+
);
166169
// The navigation node we're currently working on.
167170
$sectionnode = $coursenode;
168171
// Extra navigation node ID counter.
@@ -172,7 +175,6 @@ public function load_generic_course_sections(\stdClass $course, \navigation_node
172175
$extraid = -1;
173176
// END ADDED.
174177
foreach ($sections as $sectionid => $section) {
175-
176178
// Delegated sections should be added from the activity node.
177179
if (isset($section->component) && $section->component) {
178180
continue;
@@ -183,11 +185,13 @@ public function load_generic_course_sections(\stdClass $course, \navigation_node
183185
if ($course->id == $SITE->id) {
184186
$this->load_section_activities($coursenode, $section, $activities); // CHANGED: Pass section info rather than num.
185187
} else {
186-
if (!(($section->section == 0) || $section->uservisible && course_get_format($course)->is_section_visible($section))
187-
|| (!$this->innershowemptysections &&
188-
!$section->hasactivites && !$sectionextra->hassubsections
188+
if (
189+
!(($section->section == 0) || $section->uservisible && course_get_format($course)->is_section_visible($section))
190+
|| (!$this->innershowemptysections
191+
&& !$section->hasactivites && !$sectionextra->hassubsections
189192
&& $this->inner->includesectionnum !== $section->section // TODO: Remove?
190-
&& $this->innerincludesectionid !== $section->id)) {
193+
&& $this->innerincludesectionid !== $section->id)
194+
) {
191195
// CHANGED ABOVE: Use sanitised visibility, check for subsections, and use section ID.
192196
continue;
193197
}
@@ -207,10 +211,17 @@ public function load_generic_course_sections(\stdClass $course, \navigation_node
207211
for ($level = $firstlevel; $level <= $lastlevel; $level++) {
208212
$parentnode = $nodeln[$level - 1]; // ADDED.
209213
$nodeid = ($level == $lastlevel) ? $sectionid : $extraid--; // ADDED.
210-
$sectionnode = $parentnode->add($sectionname, $url, \navigation_node::TYPE_SECTION,
211-
null, $nodeid,
212-
new \pix_icon($sectionextra->levelsan < FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC ? 'i/section'
213-
: 'e/bullet_list', ''));
214+
$sectionnode = $parentnode->add(
215+
$sectionname,
216+
$url,
217+
\navigation_node::TYPE_SECTION,
218+
null,
219+
$nodeid,
220+
new \pix_icon(
221+
$sectionextra->levelsan < FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC ? 'i/section' : 'e/bullet_list',
222+
''
223+
)
224+
);
214225
// CHANGED ABOVE: Attach to parentnode with nodeid as defined above, and use a list icon for topic sections.
215226
$sectionnode->nodetype = \navigation_node::NODETYPE_BRANCH;
216227
$sectionnode->hidden = (!$section->visible || !$section->available) && ($section->section != 0);
@@ -223,16 +234,17 @@ public function load_generic_course_sections(\stdClass $course, \navigation_node
223234
$nodeln[$level] = $sectionnode;
224235
}
225236

226-
if ($this->inner->includesectionnum !== false && $this->inner->includesectionnum == $section->section
227-
|| isset($this->innerincludesectionid) && $this->innerincludesectionid == $section->id
228-
|| $sectionextra->hassubsections) {
237+
if (
238+
$this->inner->includesectionnum !== false && $this->inner->includesectionnum == $section->section
239+
|| isset($this->innerincludesectionid) && $this->innerincludesectionid == $section->id
240+
|| $sectionextra->hassubsections
241+
) {
229242
// CHANGED ABOVE: Use section ID.
230243
// Also check for subsections, because activities might not get loaded otherwise.
231244
$this->load_section_activities($sectionnode, $section, $activities);
232245
}
233246
$navigationsections[$sectionid] = $section;
234247
// END CHANGED.
235-
236248
}
237249
}
238250
return $navigationsections;
@@ -247,8 +259,12 @@ public function load_generic_course_sections(\stdClass $course, \navigation_node
247259
* @param \stdClass|null $course The course object the section and activities relate to.
248260
* @return array Array of activity nodes
249261
*/
250-
protected function load_section_activities(\navigation_node $sectionnode, \section_info $section, array $activities,
251-
?\stdClass $course = null): array {
262+
protected function load_section_activities(
263+
\navigation_node $sectionnode,
264+
\section_info $section,
265+
array $activities,
266+
?\stdClass $course = null
267+
): array {
252268
// CHANGED ABOVE: Use section info instead of number.
253269
global $CFG, $SITE;
254270
// A static counter for JS function naming.
@@ -315,7 +331,6 @@ protected function load_section_activities(\navigation_node $sectionnode, \secti
315331
}
316332

317333
// REMOVED function load_stealth_activity - class end .
318-
319334
}
320335

321336
// REMOVED class global_navigation_for_ajax - end .

0 commit comments

Comments
 (0)