Skip to content

Commit 1243d4c

Browse files
committed
Coding guideline fixes.
1 parent deb566e commit 1243d4c

12 files changed

+35
-38
lines changed

classes/conversation.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function close() {
153153
throw new \moodle_exception('cannotclosedraftconversation', 'dialogue');
154154
}
155155
// Permission check.
156-
$canclose = (($this->_authorid == $USER->id) or has_capability('mod/dialogue:closeany', $context));
156+
$canclose = (($this->_authorid == $USER->id) || has_capability('mod/dialogue:closeany', $context));
157157
if (!$canclose) {
158158
throw new \moodle_exception('nopermissiontoclose', 'dialogue');
159159
}
@@ -187,7 +187,7 @@ public function delete() {
187187
return true;
188188
}
189189
// Permission to delete conversation.
190-
$candelete = ((has_capability('mod/dialogue:delete', $context) and $USER->id == $this->_authorid) or
190+
$candelete = ((has_capability('mod/dialogue:delete', $context) && $USER->id == $this->_authorid) ||
191191
has_capability('mod/dialogue:deleteany', $context));
192192

193193
if (!$candelete) {
@@ -315,7 +315,7 @@ public function initialise_form() {
315315
// Set bulk open bulk.
316316
$bulkopenrule = $this->bulkopenrule; // Insure loaded by using magic.
317317

318-
if (!empty($bulkopenrule) and has_capability('mod/dialogue:bulkopenrulecreate', $context)) {
318+
if (!empty($bulkopenrule) && has_capability('mod/dialogue:bulkopenrulecreate', $context)) {
319319
// Format for option item e.g. course-1, group-1.
320320
$groupinformation = $bulkopenrule['type'] . '-' . $bulkopenrule['sourceid'];
321321
$form->set_data(array('groupinformation' => $groupinformation));
@@ -339,7 +339,7 @@ public function initialise_form() {
339339
// Set attachments.
340340
$form->set_data(array('attachments[itemid]' => $this->_attachmentsdraftid));
341341
// Remove any unecessary buttons.
342-
if (($USER->id != $this->author->id) or is_null($this->conversationid)) {
342+
if (($USER->id != $this->author->id) || is_null($this->conversationid)) {
343343
$form->remove_from_group('trash', 'actionbuttongroup');
344344
}
345345
// Attach initialised form to conversation class and return.
@@ -470,7 +470,7 @@ public function save() {
470470
global $DB, $USER;
471471

472472
$admin = get_admin(); // Possible cronjob.
473-
if ($USER->id != $admin->id and $USER->id != $this->_authorid) {
473+
if ($USER->id != $admin->id && $USER->id != $this->_authorid) {
474474
throw new \moodle_exception("This conversation doesn't belong to you!");
475475
}
476476

@@ -651,8 +651,8 @@ public function send() {
651651
$cm = $this->dialogue->cm;
652652
$course = $this->dialogue->course;
653653

654-
$incomplete = ((empty($this->_bulkopenrule) and empty($this->_participants)) or
655-
empty($this->_subject) or empty($this->_body));
654+
$incomplete = ((empty($this->_bulkopenrule) && empty($this->_participants)) ||
655+
empty($this->_subject) || empty($this->_body));
656656

657657
if ($incomplete) {
658658
throw new \moodle_exception("incompleteconversation", 'mod_dialogue');
@@ -682,7 +682,7 @@ protected function set_bulk_open_rule($type = null, $sourceid = null, $includefu
682682
/* Must have type (course, group) and sourceid (course->id, group->id) to
683683
* be a rule, else is empty.
684684
*/
685-
if (!is_null($type) and !is_null($sourceid)) {
685+
if (!is_null($type) && !is_null($sourceid)) {
686686
$rule['type'] = (string) $type;
687687
$rule['sourceid'] = (int) $sourceid;
688688
$rule['includefuturemembers'] = (int) $includefuturemembers;

classes/local/course_enrolment_manager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class course_enrolment_manager extends \course_enrolment_manager {
3838
* boolean moreusers True if there are still more users, otherwise is False.
3939
*/
4040
public function search_users_with_groups(string $search = '', bool $searchanywhere = false, int $page = 0, int $perpage = 25,
41-
array $groups) {
41+
array $groups = []) {
4242
global $DB;
4343

4444
[$ufields, $joins, $params, $wherecondition] = $this->get_basic_search_conditions($search, $searchanywhere);

classes/message.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function delete() {
133133
return true;
134134
}
135135
// Permission to delete conversation.
136-
$candelete = ((has_capability('mod/dialogue:delete', $context) and $USER->id == $this->_authorid) or
136+
$candelete = ((has_capability('mod/dialogue:delete', $context) && $USER->id == $this->_authorid) ||
137137
has_capability('mod/dialogue:deleteany', $context));
138138

139139
if (!$candelete) {
@@ -326,7 +326,7 @@ public function set_body($body, $format, $itemid = null) {
326326
$this->_body = $body;
327327
$this->_bodyformat = $format;
328328

329-
if ($format == FORMAT_HTML and isset($itemid)) {
329+
if ($format == FORMAT_HTML && isset($itemid)) {
330330
$this->_bodydraftid = $itemid;
331331
$this->_body = file_rewrite_urls_to_pluginfile($this->_body, $this->_bodydraftid);
332332
}
@@ -372,7 +372,7 @@ public function save() {
372372
global $DB, $USER;
373373

374374
$admin = get_admin(); // Possible cronjob.
375-
if ($USER->id != $admin->id and $USER->id != $this->_authorid) {
375+
if ($USER->id != $admin->id && $USER->id != $this->_authorid) {
376376
throw new \moodle_exception("This doesn't belong to you!");
377377
}
378378

classes/reply.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ public function initialise_form() {
125125
}
126126

127127
// Remove any unecessary buttons.
128-
if (($USER->id != $this->author->id) or is_null($this->messageid)) {
128+
if (($USER->id != $this->author->id) || is_null($this->messageid)) {
129129
$form->remove_from_group('delete', 'actionbuttongroup');
130130
}
131131

132132
// Remove any unecessary buttons.
133-
if (($USER->id != $this->author->id) or is_null($this->messageid)) {
133+
if (($USER->id != $this->author->id) || is_null($this->messageid)) {
134134
$form->remove_from_group('trash', 'actionbuttongroup');
135135
}
136136

@@ -168,7 +168,7 @@ public function send() {
168168
$conversationid = $this->conversation->conversationid;
169169

170170
// Check permission.
171-
if ($USER->id != $this->_authorid or !has_capability('mod/dialogue:reply', $context)) {
171+
if ($USER->id != $this->_authorid || !has_capability('mod/dialogue:reply', $context)) {
172172
throw new \moodle_exception("This doesn't belong to you!");
173173
}
174174

classes/search/activity.php

-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
namespace mod_dialogue\search;
2727

28-
defined('MOODLE_INTERNAL') || die();
29-
3028
/**
3129
* Search area for mod_dialogue activities.
3230
*

classes/search/conversations.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
namespace mod_dialogue\search;
2727

28-
defined('MOODLE_INTERNAL') || die();
29-
3028
/**
3129
* Search area for mod_dialogue conversatoins and messages.
3230
*
@@ -96,7 +94,7 @@ public function get_document($record, $options = array()) {
9694
$doc->set('owneruserid', \core_search\manager::NO_OWNER_ID);
9795
$doc->set('modified', $record->timemodified);
9896

99-
// // Check if this document should be considered new.
97+
// Check if this document should be considered new.
10098
if (isset($options['lastindexedtime']) && ($options['lastindexedtime'] < $record->timemodified)) {
10199
// If the document was created after the last index time, it must be new.
102100
$doc->set_is_new(true);
@@ -157,7 +155,8 @@ public function get_doc_url(\core_search\document $doc) {
157155
public function get_context_url(\core_search\document $doc) {
158156
$context = \context::instance_by_id($doc->get('contextid'));
159157
$entry = $this->get_dialogue_conversations($doc->get('itemid'));
160-
return new \moodle_url('/mod/dialogue/conversation.php', array('id' => $context->instanceid, 'action' => 'view', 'conversationid' => $entry->messageid));
158+
return new \moodle_url('/mod/dialogue/conversation.php',
159+
['id' => $context->instanceid, 'action' => 'view', 'conversationid' => $entry->messageid]);
161160
}
162161

163162
/**
@@ -213,4 +212,4 @@ public function attach_files($doc) {
213212
}
214213
}
215214

216-
}
215+
}

conversation.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
$dialogue = new \mod_dialogue\dialogue($cm, $course, $activityrecord);
5959
$conversation = new \mod_dialogue\conversation($dialogue, $conversationid);
6060

61-
if ($action == 'create' or $action == 'edit') {
61+
if ($action == 'create' || $action == 'edit') {
6262
require_capability('mod/dialogue:open', $context);
6363
$form = $conversation->initialise_form();
6464
if ($form->is_submitted()) {
@@ -156,13 +156,13 @@
156156
}
157157

158158
if ($conversation->state == \mod_dialogue\dialogue::STATE_BULK_AUTOMATED) {
159-
if (!has_capability('mod/dialogue:bulkopenruleeditany', $context) and $conversation->author->id != $USER->id) {
159+
if (!has_capability('mod/dialogue:bulkopenruleeditany', $context) && $conversation->author->id != $USER->id) {
160160
throw new moodle_exception('nopermission');
161161
}
162162
}
163163

164-
if ($conversation->state == \mod_dialogue\dialogue::STATE_OPEN or $conversation->state == \mod_dialogue\dialogue::STATE_CLOSED) {
165-
if (!has_capability('mod/dialogue:viewany', $context) and !$conversation->is_participant()) {
164+
if ($conversation->state == \mod_dialogue\dialogue::STATE_OPEN || $conversation->state == \mod_dialogue\dialogue::STATE_CLOSED) {
165+
if (!has_capability('mod/dialogue:viewany', $context) && !$conversation->is_participant()) {
166166
throw new moodle_exception('nopermission');
167167
}
168168
}
@@ -181,11 +181,11 @@
181181
}
182182

183183
// Output reply form if meets criteria.
184-
$hasreplycapability = (has_capability('mod/dialogue:reply', $context) or
184+
$hasreplycapability = (has_capability('mod/dialogue:reply', $context) ||
185185
has_capability('mod/dialogue:replyany', $context));
186186

187187
// Conversation is open and user can reply... then output reply form.
188-
if ($hasreplycapability and $conversation->state == \mod_dialogue\dialogue::STATE_OPEN) {
188+
if ($hasreplycapability && $conversation->state == \mod_dialogue\dialogue::STATE_OPEN) {
189189
$reply = $conversation->reply();
190190
$form = $reply->initialise_form();
191191
$form->display();

formlib.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected function definition() {
4848
$mform->setType('body', PARAM_RAW);
4949

5050
// Maxattachments = 0 = No attachments at all.
51-
if (!get_config('dialogue', 'maxattachments') or !empty($PAGE->activityrecord->maxattachments)) {
51+
if (!get_config('dialogue', 'maxattachments') || !empty($PAGE->activityrecord->maxattachments)) {
5252
$mform->addElement('filemanager', 'attachments[itemid]',
5353
get_string('attachments', 'dialogue'), null, self::attachment_options());
5454
}

lang/en/dialogue.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
$string['runsuntil'] = 'Runs until ';
184184
$string['savedraft'] = 'Save draft';
185185
$string['search:activity'] = 'Dialogue - activity information';
186-
$string['search:conversations'] = 'Dialogue - conversation and message information';
186+
$string['search:conversations'] = 'Dialogue - conversation and message information';
187187
$string['searchpotentials'] = ' Search potentials...';
188188
$string['second'] = 'second';
189189
$string['seconds'] = 'seconds';

lib.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ function dialogue_can_track_dialogue($user = false) {
402402
}
403403

404404
// Dont allow guests to track.
405-
if (isguestuser($user) or empty($user->id)) {
405+
if (isguestuser($user) || empty($user->id)) {
406406
return false;
407407
}
408408

@@ -451,7 +451,7 @@ function dialogue_pluginfile($course, $cm, $context, $filearea, $args, $forcedow
451451
$fs = get_file_storage();
452452
$relativepath = implode('/', $args);
453453
$fullpath = "/$context->id/mod_dialogue/$filearea/$itemid/$relativepath";
454-
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
454+
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) || $file->is_directory()) {
455455
return false;
456456
}
457457

locallib.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ function dialogue_cm_unread_total(\mod_dialogue\dialogue $dialogue) {
207207

208208
// Get user's total unread count for a dialogue.
209209
$record = (array) $DB->get_record_sql($sql, $params);
210-
if (isset($record['unread']) and $record['unread'] > 0) {
210+
if (isset($record['unread']) && $record['unread'] > 0) {
211211
return (int) $record['unread'];
212212
}
213213
return 0;
@@ -329,7 +329,7 @@ function dialogue_generate_summary_line($subject, $body, $bodyformat, $length =
329329
$body = html_to_text($body, 0, false);
330330

331331
$diff = $length - (strlen($subject) + strlen($separator));
332-
if (\core_text::strlen($subject) > $length or ! $diff) {
332+
if (\core_text::strlen($subject) > $length || ! $diff) {
333333
return html_writer::tag('strong', shorten_text($subject, $length));
334334
}
335335

renderer.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function render_conversation(mod_dialogue\conversation $conversation) {
8686
$html .= html_writer::start_tag('ul', array('class' => "message-actions pull-right"));
8787

8888
if ($conversation->state == \mod_dialogue\dialogue::STATE_OPEN) {
89-
$canclose = ((has_capability('mod/dialogue:close', $context) and $USER->id == $conversation->author->id) or
89+
$canclose = ((has_capability('mod/dialogue:close', $context) && $USER->id == $conversation->author->id) ||
9090
has_capability('mod/dialogue:closeany', $context));
9191

9292
if ($canclose) {
@@ -101,7 +101,7 @@ public function render_conversation(mod_dialogue\conversation $conversation) {
101101
}
102102
}
103103

104-
$candelete = ((has_capability('mod/dialogue:delete', $context) and $USER->id == $conversation->author->id) or
104+
$candelete = ((has_capability('mod/dialogue:delete', $context) && $USER->id == $conversation->author->id) ||
105105
has_capability('mod/dialogue:deleteany', $context));
106106

107107
if ($candelete) {
@@ -244,7 +244,7 @@ public function conversation_listing(\mod_dialogue\conversations $conversations)
244244
$html .= html_writer::tag('td', fullname($displayuser));
245245
}
246246

247-
if (isset($record->subject) and isset($record->body)) {
247+
if (isset($record->subject) && isset($record->body)) {
248248
$subject = empty($record->subject) ? get_string('nosubject', 'dialogue') : $record->subject;
249249
$summaryline = dialogue_generate_summary_line($subject, $record->body, $record->bodyformat);
250250
$html .= html_writer::start_tag('td');
@@ -616,7 +616,7 @@ public function tab_navigation(\mod_dialogue\dialogue $dialogue) {
616616
$html .= html_writer::link($viewurl, get_string('viewconversations', 'dialogue'));
617617
$html .= html_writer::end_tag('li');
618618
// Experimental: link conversation by role listing.
619-
if (!empty($config->viewconversationsbyrole) and has_capability('mod/dialogue:viewbyrole', $context)) {
619+
if (!empty($config->viewconversationsbyrole) && has_capability('mod/dialogue:viewbyrole', $context)) {
620620
$active = ($currentpage == 'viewconversationsbyrole') ? array('class' => 'active') : array();
621621
$html .= html_writer::start_tag('li', $active);
622622
$viewurl = new moodle_url('viewconversationsbyrole.php', array('id' => $cm->id));

0 commit comments

Comments
 (0)