Skip to content

Commit af53432

Browse files
committed
codestyling updated
1 parent f1c3179 commit af53432

File tree

6 files changed

+53
-56
lines changed

6 files changed

+53
-56
lines changed

classes/task/send_daily_mail.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public function execute() {
4848
mtrace('No daily mail to send.');
4949
return;
5050
}
51-
foreach($users as $user) {
52-
$userdata = $DB->get_records('moodleoverflow_mail_info', array('userid' => $user->userid), 'courseid, forumid'); //order by courseid
51+
foreach ($users as $user) {
52+
$userdata = $DB->get_records('moodleoverflow_mail_info', array('userid' => $user->userid), 'courseid, forumid'); // order by courseid
5353
$mail = array();
54-
foreach($userdata as $row) {
54+
foreach ($userdata as $row) {
5555
$currentcourse = $DB->get_record('course', array('id' => $row->courseid), 'fullname');
5656
$currentforum = $DB->get_record('moodleoverflow', array('id' => $row->forumid), 'name');
5757
$discussion = $DB->get_record('moodleoverflow_discussions', array('id' => $row->forumdiscussionid), 'name');
@@ -60,16 +60,16 @@ public function execute() {
6060
'currentforum' => $currentforum->name,
6161
'discussion' => $discussion->name,
6262
'unreadposts' => $unreadposts));
63-
array_push($mail,$string);
63+
array_push($mail, $string);
6464
}
6565
$message = implode('<br>', $mail);
6666
// mtrace($message);.
6767
// send message to user.
6868
$userto = $DB->get_record('user', array('id' => $user->userid));
6969
$from = \core_user::get_noreply_user();
7070
$subject = get_string('tasksenddailymail', 'mod_moodleoverflow');
71-
72-
email_to_user($userto,$from, $subject,$message);
71+
72+
email_to_user($userto, $from, $subject, $message);
7373
}
7474
}
75-
}
75+
}

db/tasks.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@
5151
// Clean old read records.
5252
array(
5353
'classname' => 'mod_moodleoverflow\task\send_daily_mail',
54-
'blocking' => 0,
55-
'minute' => '0',
56-
'hour' => '17',
57-
'day' => '*',
58-
'month' => '*',
54+
'blocking' => 0,
55+
'minute' => '0',
56+
'hour' => '17',
57+
'day' => '*',
58+
'month' => '*',
5959
'dayofweek' => '*'
6060
)
6161
);

db/upgrade.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ function xmldb_moodleoverflow_upgrade($oldversion) {
246246
upgrade_mod_savepoint(true, 2022110700, 'moodleoverflow');
247247
}
248248

249-
if($oldversion < 2023022400) {
250-
//Table for information of digest mail.
249+
if ($oldversion < 2023022400) {
250+
// Table for information of digest mail.
251251
$table = new xmldb_table('moodleoverflow_mail_info');
252252

253253
// Adding fields to table moodleoverflow_mail_info.
@@ -257,7 +257,7 @@ function xmldb_moodleoverflow_upgrade($oldversion) {
257257
$table->add_field('forumid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
258258
$table->add_field('forumdiscussionid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
259259
$table->add_field('numberofposts', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
260-
260+
261261
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
262262
$table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
263263
$table->add_key('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
@@ -271,6 +271,6 @@ function xmldb_moodleoverflow_upgrade($oldversion) {
271271

272272
// Moodleoverflow savepoint reached.
273273
upgrade_mod_savepoint(true, 2023022400, 'moodleoverflow');
274-
}
274+
}
275275
return true;
276276
}

lib.php

+12-15
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ function moodleoverflow_send_mails() {
733733
$errorcount[$postid] = 0;
734734
}
735735
}
736-
736+
737737
// Send mails to the users with information about the posts.
738738
if ($users && $posts) {
739739
// Send one mail to every user.
@@ -762,37 +762,34 @@ function moodleoverflow_send_mails() {
762762

763763
// Loop through all posts of this users.
764764
foreach ($posts as $postid => $post) {
765-
766765

767766
// Initiate variables for the post.
768767
$discussion = $discussions[$post->discussion];
769768
$moodleoverflow = $moodleoverflows[$discussion->moodleoverflow];
770769
$course = $courses[$moodleoverflow->course];
771770
$cm =& $coursemodules[$moodleoverflow->id];
772771

773-
/**
774-
* Check if user wants a resume
775-
* in this case: make a new dataset in "moodleoverflow_mail_info" to save the posts data
776-
* Dataset from moodleoverflow_mail_info will be send later in a mail
777-
*/
772+
// Check if user wants a resume.
773+
// in this case: make a new dataset in "moodleoverflow_mail_info" to save the posts data.
774+
// Dataset from moodleoverflow_mail_info will be send later in a mail.
778775
$usermailsetting = $userto->maildigest;
779-
if($usermailsetting != 0) {
776+
if ($usermailsetting != 0) {
780777
$dataobject = new stdClass();
781778
$dataobject->userid = $userto->id;
782779
$dataobject->courseid = $course->id;
783780
$dataobject->forumid = $moodleoverflow->id;
784781
$dataobject->forumdiscussionid = $discussion->id;
785-
$record = $DB->get_record('moodleoverflow_mail_info', array( 'userid' => $dataobject->userid,
786-
'courseid' => $dataobject->courseid,
787-
'forumid' => $dataobject->forumid,
788-
'forumdiscussionid' => $dataobject->forumdiscussionid), 'numberofposts, id');
789-
if(is_object($record)) {
782+
$record = $DB->get_record('moodleoverflow_mail_info', array('userid' => $dataobject->userid,
783+
'courseid' => $dataobject->courseid,
784+
'forumid' => $dataobject->forumid,
785+
'forumdiscussionid' => $dataobject->forumdiscussionid),
786+
'numberofposts, id');
787+
if (is_object($record)) {
790788
$dataset = $record;
791789
$dataobject->numberofposts = $dataset->numberofposts + 1;
792790
$dataobject->id = $dataset->id;
793791
$DB->update_record('moodleoverflow_mail_info', $dataobject);
794-
}
795-
else {
792+
} else {
796793
$dataobject->numberofposts = 1;
797794
$DB->insert_record('moodleoverflow_mail_info', $dataobject);
798795
}

tests/dailymail_test.php

+24-24
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@
3131
global $CFG;
3232
require_once($CFG->dirroot . '/mod/moodleoverflow/lib.php');
3333

34-
class mod_moodleoverflow_dailymail_test extends \advanced_testcase {
35-
34+
class dailymail_test extends \advanced_testcase {
35+
3636
private $sink;
3737
private $messagesink;
3838
private $course;
3939
private $user;
4040
private $moodleoverflow;
4141
private $discussion;
42-
42+
4343
/**
4444
* Test setUp.
4545
*/
@@ -55,8 +55,8 @@ public function setUp(): void {
5555

5656
// Create a new course with a moodleoverflow forum.
5757
$this->course = $this->getDataGenerator()->create_course();
58-
$location = array('course' => $this->course->id,'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE);
59-
$this->moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow',$location);
58+
$location = array('course' => $this->course->id, 'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE);
59+
$this->moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $location);
6060

6161
}
6262

@@ -77,7 +77,7 @@ public function helper_create_user_and_discussion($maildigest) {
7777
$this->user = $this->getDataGenerator()->create_user(array('firstname' => 'Tamaro', 'maildigest' => $maildigest));
7878
$this->getDataGenerator()->enrol_user($this->user->id, $this->course->id, 'student');
7979

80-
//Create a new discussion and post within the moodleoverflow.
80+
// Create a new discussion and post within the moodleoverflow.
8181
$generator = $this->getDataGenerator()->get_plugin_generator('mod_moodleoverflow');
8282
$this->discussion = $generator->post_to_forum($this->moodleoverflow, $this->user);
8383
}
@@ -94,7 +94,7 @@ private function run_send_daily_mail() {
9494
ob_end_clean();
9595
return $output;
9696
}
97-
97+
9898
/**
9999
* Run the send mails task.
100100
* @return false|string
@@ -118,11 +118,11 @@ public function test_mail_delivery() {
118118
$this->helper_create_user_and_discussion('1');
119119

120120
// Send a mail and test if the mail was sent.
121-
122-
$this->run_send_mails(); //content2
123-
$this->run_send_daily_mail(); //content
121+
122+
$this->run_send_mails(); // content2
123+
$this->run_send_daily_mail(); // content
124124
$messages = $this->sink->count();
125-
125+
126126
$this->assertEquals(1, $messages);
127127
}
128128

@@ -132,22 +132,22 @@ public function test_content_of_mail_delivery() {
132132
// Creat Users with maildigest = on.
133133
$this->helper_create_user_and_discussion('1');
134134

135-
//send the mails and count the messages.
135+
// send the mails and count the messages.
136136
$this->run_send_mails();
137137
$content = $this->run_send_daily_mail();
138138
$messages = $this->sink->count();
139-
140-
//Build the text that the mail should have.
141-
//Text structure: $string['digestunreadpost'] = 'Course: {$a->currentcourse} -> {$a->currentforum}, Topic: {$a->discussion} has {$a->unreadposts} unread posts.';.
139+
140+
// Build the text that the mail should have.
141+
// Text structure: $string['digestunreadpost'] = 'Course: {$a->currentcourse} -> {$a->currentforum}, Topic: {$a->discussion} has {$a->unreadposts} unread posts.';.
142142
$currentcourse = $this->course->fullname;
143143
$currentforum = $this->moodleoverflow->name;
144144
$currentdiscussion = $this->discussion[0]->name;
145-
$text = 'Course: ' . $currentcourse . ' -> ' . $currentforum . ', Topic: ' . $currentdiscussion . ' has ' . $messages . ' unread posts.';
146-
$content = str_replace("\r\n","",$content);
147-
$text = str_replace("\r\n","",$text);
148-
149-
//$this->assertisInt(0, strcmp($text, $content)); //strcmp compares 2 strings and retuns 0 if equal
150-
//$this->assertEquals($text, $content);
145+
$text = 'Course: ' . $currentcourse . ' -> ' . $currentforum . ', Topic: ' . $currentdiscussion . ' has ' . $messages . ' unread posts.';
146+
$content = str_replace("\r\n", "", $content);
147+
$text = str_replace("\r\n", "", $text);
148+
149+
// $this->assertisInt(0, strcmp($text, $content)); //strcmp compares 2 strings and retuns 0 if equal
150+
// $this->assertEquals($text, $content);
151151
$this->assertStringContainsString($text, $content);
152152
}
153153

@@ -160,7 +160,7 @@ public function test_mail_not_send() {
160160
$this->run_send_mails();
161161
$this->run_send_daily_mail();
162162
$messages = $this->sink->count();
163-
164-
$this->assertEquals(0,$messages);
163+
164+
$this->assertEquals(0, $messages);
165165
}
166-
}
166+
}

version.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
defined('MOODLE_INTERNAL') || die();
2929

3030
$plugin->component = 'mod_moodleoverflow';
31-
$plugin->version = 2023022401;
31+
$plugin->version = 2023022404;
3232
$plugin->release = 'v4.1-r1';
3333
$plugin->requires = 2020061500; // Requires Moodle 3.9+.
3434
$plugin->maturity = MATURITY_STABLE;

0 commit comments

Comments
 (0)