Skip to content

Commit

Permalink
Coding guideline fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
danmarsden committed Apr 22, 2024
1 parent deb566e commit 1243d4c
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 38 deletions.
16 changes: 8 additions & 8 deletions classes/conversation.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function close() {
throw new \moodle_exception('cannotclosedraftconversation', 'dialogue');
}
// Permission check.
$canclose = (($this->_authorid == $USER->id) or has_capability('mod/dialogue:closeany', $context));
$canclose = (($this->_authorid == $USER->id) || has_capability('mod/dialogue:closeany', $context));
if (!$canclose) {
throw new \moodle_exception('nopermissiontoclose', 'dialogue');
}
Expand Down Expand Up @@ -187,7 +187,7 @@ public function delete() {
return true;
}
// Permission to delete conversation.
$candelete = ((has_capability('mod/dialogue:delete', $context) and $USER->id == $this->_authorid) or
$candelete = ((has_capability('mod/dialogue:delete', $context) && $USER->id == $this->_authorid) ||
has_capability('mod/dialogue:deleteany', $context));

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

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

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

Expand Down Expand Up @@ -651,8 +651,8 @@ public function send() {
$cm = $this->dialogue->cm;
$course = $this->dialogue->course;

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

if ($incomplete) {
throw new \moodle_exception("incompleteconversation", 'mod_dialogue');
Expand Down Expand Up @@ -682,7 +682,7 @@ protected function set_bulk_open_rule($type = null, $sourceid = null, $includefu
/* Must have type (course, group) and sourceid (course->id, group->id) to
* be a rule, else is empty.
*/
if (!is_null($type) and !is_null($sourceid)) {
if (!is_null($type) && !is_null($sourceid)) {
$rule['type'] = (string) $type;
$rule['sourceid'] = (int) $sourceid;
$rule['includefuturemembers'] = (int) $includefuturemembers;
Expand Down
2 changes: 1 addition & 1 deletion classes/local/course_enrolment_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class course_enrolment_manager extends \course_enrolment_manager {
* boolean moreusers True if there are still more users, otherwise is False.
*/
public function search_users_with_groups(string $search = '', bool $searchanywhere = false, int $page = 0, int $perpage = 25,
array $groups) {
array $groups = []) {
global $DB;

[$ufields, $joins, $params, $wherecondition] = $this->get_basic_search_conditions($search, $searchanywhere);
Expand Down
6 changes: 3 additions & 3 deletions classes/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function delete() {
return true;
}
// Permission to delete conversation.
$candelete = ((has_capability('mod/dialogue:delete', $context) and $USER->id == $this->_authorid) or
$candelete = ((has_capability('mod/dialogue:delete', $context) && $USER->id == $this->_authorid) ||
has_capability('mod/dialogue:deleteany', $context));

if (!$candelete) {
Expand Down Expand Up @@ -326,7 +326,7 @@ public function set_body($body, $format, $itemid = null) {
$this->_body = $body;
$this->_bodyformat = $format;

if ($format == FORMAT_HTML and isset($itemid)) {
if ($format == FORMAT_HTML && isset($itemid)) {
$this->_bodydraftid = $itemid;
$this->_body = file_rewrite_urls_to_pluginfile($this->_body, $this->_bodydraftid);
}
Expand Down Expand Up @@ -372,7 +372,7 @@ public function save() {
global $DB, $USER;

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

Expand Down
6 changes: 3 additions & 3 deletions classes/reply.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ public function initialise_form() {
}

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

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

Expand Down Expand Up @@ -168,7 +168,7 @@ public function send() {
$conversationid = $this->conversation->conversationid;

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

Expand Down
2 changes: 0 additions & 2 deletions classes/search/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

namespace mod_dialogue\search;

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

/**
* Search area for mod_dialogue activities.
*
Expand Down
9 changes: 4 additions & 5 deletions classes/search/conversations.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

namespace mod_dialogue\search;

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

/**
* Search area for mod_dialogue conversatoins and messages.
*
Expand Down Expand Up @@ -96,7 +94,7 @@ public function get_document($record, $options = array()) {
$doc->set('owneruserid', \core_search\manager::NO_OWNER_ID);
$doc->set('modified', $record->timemodified);

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

/**
Expand Down Expand Up @@ -213,4 +212,4 @@ public function attach_files($doc) {
}
}

}
}
12 changes: 6 additions & 6 deletions conversation.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
$dialogue = new \mod_dialogue\dialogue($cm, $course, $activityrecord);
$conversation = new \mod_dialogue\conversation($dialogue, $conversationid);

if ($action == 'create' or $action == 'edit') {
if ($action == 'create' || $action == 'edit') {
require_capability('mod/dialogue:open', $context);
$form = $conversation->initialise_form();
if ($form->is_submitted()) {
Expand Down Expand Up @@ -156,13 +156,13 @@
}

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

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

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

// Conversation is open and user can reply... then output reply form.
if ($hasreplycapability and $conversation->state == \mod_dialogue\dialogue::STATE_OPEN) {
if ($hasreplycapability && $conversation->state == \mod_dialogue\dialogue::STATE_OPEN) {
$reply = $conversation->reply();
$form = $reply->initialise_form();
$form->display();
Expand Down
2 changes: 1 addition & 1 deletion formlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function definition() {
$mform->setType('body', PARAM_RAW);

// Maxattachments = 0 = No attachments at all.
if (!get_config('dialogue', 'maxattachments') or !empty($PAGE->activityrecord->maxattachments)) {
if (!get_config('dialogue', 'maxattachments') || !empty($PAGE->activityrecord->maxattachments)) {
$mform->addElement('filemanager', 'attachments[itemid]',
get_string('attachments', 'dialogue'), null, self::attachment_options());
}
Expand Down
2 changes: 1 addition & 1 deletion lang/en/dialogue.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
$string['runsuntil'] = 'Runs until ';
$string['savedraft'] = 'Save draft';
$string['search:activity'] = 'Dialogue - activity information';
$string['search:conversations'] = 'Dialogue - conversation and message information';
$string['search:conversations'] = 'Dialogue - conversation and message information';
$string['searchpotentials'] = ' Search potentials...';
$string['second'] = 'second';
$string['seconds'] = 'seconds';
Expand Down
4 changes: 2 additions & 2 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ function dialogue_can_track_dialogue($user = false) {
}

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

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

Expand Down
4 changes: 2 additions & 2 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function dialogue_cm_unread_total(\mod_dialogue\dialogue $dialogue) {

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

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

Expand Down
8 changes: 4 additions & 4 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function render_conversation(mod_dialogue\conversation $conversation) {
$html .= html_writer::start_tag('ul', array('class' => "message-actions pull-right"));

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

if ($canclose) {
Expand All @@ -101,7 +101,7 @@ public function render_conversation(mod_dialogue\conversation $conversation) {
}
}

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

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

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

0 comments on commit 1243d4c

Please sign in to comment.