Skip to content

Commit 7fe2ba9

Browse files
committed
code cleaning
1 parent c7dedfa commit 7fe2ba9

File tree

11 files changed

+56
-162
lines changed

11 files changed

+56
-162
lines changed

classes/discussion/discussion.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public function moodleoverflow_add_discussion($prepost) {
233233
'context' => $prepost->modulecontext,
234234
'objectid' => $this->id,
235235
];
236-
// TODO: check if the event functions.
236+
// LEARNWEB-TODO: check if the event functions.
237237
$event = \mod_moodleoverflow\event\discussion_viewed::create($params);
238238
$event->trigger();
239239

classes/post/post.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use mod_moodleoverflow\review;
3232
use mod_moodleoverflow\readtracking;
3333
use mod_moodleoverflow\discussion\discussion;
34+
use moodle_exception;
3435

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

@@ -680,7 +681,7 @@ private function build_db_object() {
680681
return $dbobject;
681682
}
682683

683-
/*
684+
/**
684685
* Count all replies of a post.
685686
*
686687
* @param bool $onlyreviewed Whether to count only reviewed posts.
@@ -710,7 +711,7 @@ public function moodleoverflow_count_replies($onlyreviewed) {
710711
*/
711712
private function existence_check() {
712713
if (empty($this->id) || $this->id == false || $this->id == null) {
713-
throw new \moodle_exception('noexistingpost', 'moodleoverflow');
714+
throw new moodle_exception('noexistingpost', 'moodleoverflow');
714715
}
715716
return true;
716717
}

classes/post/post_control.php

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@
2828
// Import namespace from the locallib, needs a check later which namespaces are really needed.
2929
use mod_moodleoverflow\anonymous;
3030
use mod_moodleoverflow\capabilities;
31+
use mod_moodleoverflow\event\discussion_created;
32+
use mod_moodleoverflow\event\post_created;
33+
use mod_moodleoverflow\event\post_updated;
3134
use mod_moodleoverflow\review;
3235

3336
use mod_moodleoverflow\post\post;
3437
use mod_moodleoverflow\discussion\discussion;
38+
use mod_moodleoverflow\subscriptions;
3539
use moodle_exception;
3640

3741
defined('MOODLE_INTERNAL') || die();
@@ -284,7 +288,7 @@ private function build_prepost_reply($replypostid) {
284288
$this->prepost->subject = $strre . ' ' . $this->prepost->subject;
285289
}
286290
} else {
287-
// TODO: remove this else branch when support for php version 7.4 ends.
291+
// LEARNWEB-TODO: remove this else branch when support for php version 7.4 ends.
288292
if (!(substr($this->prepost->subject, 0, strlen($strre)) == $strre)) {
289293
$this->prepost->subject = $strre . ' ' . $this->prepost->subject;
290294
}
@@ -371,6 +375,13 @@ private function build_prepost_delete($deletepostid) {
371375

372376
// Execute Functions.
373377

378+
/**
379+
* Executes the creation of a new discussion.
380+
*
381+
* @param object $form The results from the post_form.
382+
* @param string $errordestination The URL to redirect to in case of an error.
383+
* @throws moodle_exception if the discussion could not be added.
384+
*/
374385
private function execute_create($form, $errordestination) {
375386
global $USER;
376387
// Check if the user is allowed to post.
@@ -400,13 +411,13 @@ private function execute_create($form, $errordestination) {
400411

401412
// Trigger the discussion created event.
402413
$params = ['context' => $this->info->modulecontext, 'objectid' => $discussion->get_id()];
403-
$event = \mod_moodleoverflow\event\discussion_created::create($params);
414+
$event = discussion_created::create($params);
404415
$event->trigger();
405416

406417
// Subscribe to this thread.
407418
// Please be aware that in future the use of get_db_object() should be replaced with only $this->info->discussion,
408419
// as the subscription class should be refactored with the new way of working with posts.
409-
\mod_moodleoverflow\subscriptions::moodleoverflow_post_subscription($form, $this->info->moodleoverflow,
420+
subscriptions::moodleoverflow_post_subscription($form, $this->info->moodleoverflow,
410421
$discussion->get_db_object(),
411422
$this->info->modulecontext);
412423

@@ -415,6 +426,13 @@ private function execute_create($form, $errordestination) {
415426
redirect(moodleoverflow_go_back_to($redirectto->out()), $redirectmessage, null, \core\output\notification::NOTIFY_SUCCESS);
416427
}
417428

429+
/**
430+
* Executes the reply to an existing post.
431+
*
432+
* @param object $form The results from the post_form.
433+
* @param string $errordestination The URL to redirect to in case of an error.
434+
* @throws moodle_exception if the reply could not be added.
435+
*/
418436
private function execute_reply($form, $errordestination) {
419437
// Check if the user has the capability to write a reply.
420438
$this->check_user_can_create_reply();
@@ -443,13 +461,13 @@ private function execute_reply($form, $errordestination) {
443461
'moodleoverflowid' => $this->prepost->moodleoverflowid,
444462
],
445463
];
446-
$event = \mod_moodleoverflow\event\post_created::create($params);
464+
$event = post_created::create($params);
447465
$event->trigger();
448466

449467
// Subscribe to this thread.
450468
// Please be aware that in future the use of build_db_object() should be replaced with only $this->info->discussion,
451469
// as the subscription class should be refactored with the new way of working with posts.
452-
\mod_moodleoverflow\subscriptions::moodleoverflow_post_subscription($form, $this->info->moodleoverflow,
470+
subscriptions::moodleoverflow_post_subscription($form, $this->info->moodleoverflow,
453471
$this->info->discussion->get_db_object(),
454472
$this->info->modulecontext);
455473

@@ -460,6 +478,13 @@ private function execute_reply($form, $errordestination) {
460478

461479
}
462480

481+
/**
482+
* Executes the edit of an existing post.
483+
*
484+
* @param object $form The results from the post_form.
485+
* @param string $errordestination The URL to redirect to in case of an error.
486+
* @throws moodle_exception if the post could not be updated.
487+
*/
463488
private function execute_edit($form, $errordestination) {
464489
global $USER, $DB;
465490
// Check if the user has the capability to edit his post.
@@ -496,7 +521,7 @@ private function execute_edit($form, $errordestination) {
496521
],
497522
'relateduserid' => $this->prepost->userid == $USER->id ? $this->prepost->userid : null,
498523
];
499-
$event = \mod_moodleoverflow\event\post_updated::create($params);
524+
$event = post_updated::create($params);
500525
$event->trigger();
501526

502527
// Define the location to redirect the user after successfully editing.
@@ -505,6 +530,11 @@ private function execute_edit($form, $errordestination) {
505530
redirect(moodleoverflow_go_back_to($redirectto->out()), $redirectmessage, null, \core\output\notification::NOTIFY_SUCCESS);
506531
}
507532

533+
/**
534+
* Executes the deletion of a post.
535+
*
536+
* @throws moodle_exception if the post could not be deleted.
537+
*/
508538
public function execute_delete() {
509539
$this->check_interaction('delete');
510540

classes/subscriptions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ public static function unsubscribe_user($userid, $moodleoverflow, $context, $use
764764
/**
765765
* Subscribes the user to the specified discussion.
766766
*
767-
* TODO: Refactor this function to the new way of working with discussion and posts.
767+
* LEARNWEB-TODO: Refactor this function to the new way of working with discussion and posts.
768768
* @param int $userid The user ID
769769
* @param stdClass $discussion The discussion record
770770
* @param context_module $context The module context
@@ -989,7 +989,7 @@ public static function moodleoverflow_get_subscribe_link($moodleoverflow, $conte
989989
/**
990990
* Given a new post, subscribes the user to the thread the post was posted in.
991991
*
992-
* TODO: Refactor this function to the new way of working with discussion and posts.
992+
* LEARNWEB-TODO: Refactor this function to the new way of working with discussion and posts.
993993
* @param object $fromform The submitted form
994994
* @param stdClass $moodleoverflow The moodleoverflow record
995995
* @param stdClass $discussion The discussion record

externallib.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
*/
4141
class mod_moodleoverflow_external extends external_api {
4242

43-
// TODO: Adapt the functions to the new way of working with posts.
43+
// LEARNWEB-TODO: Adapt the functions to the new way of working with posts.
4444
/**
4545
* Returns description of method parameters
4646
* @return external_function_parameters

lang/en/moodleoverflow.php

Lines changed: 1 addition & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -227,146 +227,7 @@
227227
$string['moodleoverflow:reviewpost'] = 'Review (approve or reject) posts';
228228
$string['moodleoverflow:startdiscussion'] = 'Start a discussion';
229229
$string['moodleoverflow:viewanyrating'] = 'View total ratings that anyone received';
230-
<<<<<<< HEAD
231-
232-
// Strings for the view.php.
233-
$string['noviewdiscussionspermission'] = 'You do not have the permission to view discussions in this forum';
234-
$string['lastpost'] = 'Last post';
235-
236-
// Strings for the locallib.php.
237-
$string['addanewdiscussion'] = 'Add a new discussion topic';
238-
$string['seeuserstats'] = 'View user statistics';
239-
$string['nodiscussions'] = 'There are no discussion topics yet in this forum.';
240-
$string['markallread_forum'] = 'Mark all posts as read';
241-
$string['markallread'] = 'Mark all posts in this discussion as read';
242-
$string['delete'] = 'Delete';
243-
$string['parent'] = 'Show parent';
244-
$string['markread'] = 'Mark read';
245-
$string['markunread'] = 'Mark unread';
246-
$string['permalink'] = 'Permalink';
247-
$string['postbyuser'] = '{$a->post} by {$a->user}';
248-
$string['bynameondate'] = 'by {$a->name} ({$a->rating}) - {$a->date}';
249-
$string['bynameondatenorating'] = 'by {$a->name} - {$a->date}';
250-
$string['deletesure'] = 'Are you sure you want to delete this post?';
251-
$string['deletesureplural'] = 'Are you sure you want to delete this post and all replies? ({$a} posts)';
252-
$string['amount_unread_posts_in_discussion'] = 'There are {$a} unread posts in this discussion.';
253-
254-
// Strings for the settings.php.
255-
$string['configmanydiscussions'] = 'Maximum number of discussions shown in a Moodleoverflow instance per page';
256-
$string['manydiscussions'] = 'Discussions per page';
257-
$string['maxattachmentsize'] = 'Maximum attachment size';
258-
$string['maxattachmentsize_help'] = 'This setting specifies the largest size of file that can be attached to a forum post.';
259-
$string['configmaxbytes'] = 'Default maximum size for all forum attachments on the site (subject to course limits and other local settings)';
260-
$string['maxattachments'] = 'Maximum number of attachments';
261-
$string['maxattachments_help'] = 'This setting specifies the maximum number of files that can be attached to a forum post.';
262-
$string['configmaxattachments'] = 'Default maximum number of attachments allowed per post.';
263-
$string['maxeditingtime'] = 'Maximum amount of time during which a post can be edited by its owner (sec)';
264-
$string['configmaxeditingtime'] = 'Default maximum seconds are 3600 (= one hour). Regarding editing posts, please also consider the <a href="#admin-reviewpossibleaftertime">"Review possible after" setting</a> for moderated forums.';
265-
$string['configoldpostdays'] = 'Number of days old any post is considered read.';
266-
$string['oldpostdays'] = 'Read after days';
267-
$string['trackingoff'] = 'Off';
268-
$string['trackingon'] = 'Forced';
269-
$string['trackingoptional'] = 'Optional';
270-
$string['trackingtype'] = 'Read tracking';
271-
$string['configtrackingtype'] = 'Default setting for read tracking.';
272-
$string['trackmoodleoverflow'] = 'Track unread posts';
273-
$string['configtrackmoodleoverflow'] = 'Set to \'yes\' if you want to track read/unread for each user.';
274-
$string['forcedreadtracking'] = 'Allow forced read tracking';
275-
$string['configforcedreadtracking'] = 'Allows Moodleoverflows to be set to forced read tracking. Will result in decreased performance for some users, particularly on courses with many moodleoverflows and posts. When off, any moodleoverflows previously set to Forced are treated as optional.';
276-
$string['cleanreadtime'] = 'Mark old posts as read hour';
277-
$string['configcleanreadtime'] = 'The hour of the day to clean old posts from the \'read\' table.';
278-
$string['allowdisablerating'] = 'Allow teachers to disable rating and reputation';
279-
$string['configallowdisablerating'] = 'Set to \'yes\' if you want to give teachers the ability to disable rating and reputation.';
280-
281-
$string['votescalevote'] = 'Reputation: Vote.';
282-
$string['configvotescalevote'] = 'The amount of reputation voting gives.';
283-
$string['votescaledownvote'] = 'Reputation: Downvote';
284-
$string['configvotescaledownvote'] = 'The amount of reputation a downvote for your post gives.';
285-
$string['votescaleupvote'] = 'Reputation: Upvote';
286-
$string['configvotescaleupvote'] = 'The amount of reputation an upvote for your post gives.';
287-
$string['votescalesolved'] = 'Reputation: Solution';
288-
$string['configvotescalesolved'] = 'The amount of reputation a mark as solution on your post gives.';
289-
$string['votescalehelpful'] = 'Reputation: Helpful';
290-
$string['configvotescalehelpful'] = 'The amount of reputation a mark as helpful on your post gives.';
291-
$string['reputationnotnegative'] = 'Reputation just positive?';
292-
$string['configreputationnotnegative'] = 'Prohibits the users reputation being negative.';
293-
$string['allowcoursereputation'] = 'Sum reputation within a course.';
294-
$string['configallowcoursereputation'] = 'Allow to sum the reputation of all instances of the current course?';
295-
$string['maxmailingtime'] = 'Maximal mailing time';
296-
$string['configmaxmailingtime'] = 'Posts older than this number of hours will not be mailed to the users. This will help to avoid problems where the cron has not been running for a long time.';
297-
298-
// Strings for the post.php environment.
299-
$string['invalidmoodleoverflowid'] = 'Forum ID was incorrect';
300-
$string['invalidparentpostid'] = 'Parent post ID was incorrect';
301-
$string['notpartofdiscussion'] = 'This post is not part of a discussion!';
302-
$string['noguestpost'] = 'Sorry, guests are not allowed to post.';
303-
$string['nopostmoodleoverflow'] = 'Sorry, you are not allowed to post to this forum.';
304-
$string['yourreply'] = 'Your reply';
305-
$string['re'] = 'Re:';
306-
$string['invalidpostid'] = 'Invalid post ID - {$a}';
307-
$string['cannotfindparentpost'] = 'Could not find top parent of post {$a}';
308-
$string['edit'] = 'Edit';
309-
$string['cannotreply'] = 'You cannot reply to this post';
310-
$string['cannotcreatediscussion'] = 'Could not create new discussion';
311-
$string['couldnotadd'] = 'Could not add your post due to an unknown error';
312-
$string['postaddedsuccess'] = 'Your post was successfully added.';
313-
$string['postaddedtimeleft'] = 'You have {$a} to edit it if you want to make any changes.';
314-
$string['cannotupdatepost'] = 'You can not update this post';
315-
$string['couldnotupdate'] = 'Could not update your post due to an unknown error';
316-
$string['editedpostupdated'] = '{$a}\'s post was updated';
317-
$string['postupdated'] = 'Your post was updated';
318-
$string['editedby'] = 'Edited by {$a->name} on {$a->date}';
319-
$string['cannotdeletepost'] = 'You can\'t delete this post!';
320-
$string['couldnotdeletereplies'] = 'Sorry, that cannot be deleted as people have already responded to it';
321-
$string['errorwhiledelete'] = 'An error occurred while deleting record.';
322-
$string['couldnotdeletereplies'] = 'Sorry, that cannot be deleted as people have already responded to it';
323-
$string['noexistingpost'] = 'Post does not exists, needs to be created first';
324-
$string['noexistingdiscussion'] = 'Discussion does not exists, needs to be created first';
325-
$string['notallpostsavailable'] = 'This Discussion does not have all of its posts, this could lead to errors!';
326-
$string['missingformattachments'] = 'This functions requires data that was not submitted.';
327-
$string['unexpectedinteractionerror'] = 'An unexpected error occured, please try again';
328-
329-
// String for the classes/post/post_control.php.
330-
$string['wronginteraction'] = 'Wrong interaction detected, please choose the right function';
331-
332-
// Strings for the classes/mod_form.php.
333-
$string['subject'] = 'Subject';
334-
$string['reply'] = 'Comment';
335-
$string['replyfirst'] = 'Answer';
336-
$string['message'] = 'Message';
337-
$string['discussionsubscription'] = 'Discussion subscription';
338-
$string['discussionsubscription_help'] = 'Subscribing to a discussion means you will receive notifications of new posts to that discussion.';
339-
$string['posttomoodleoverflow'] = 'Post to forum';
340-
$string['posts'] = 'Posts';
341-
$string['erroremptysubject'] = 'Post subject cannot be empty.';
342-
$string['erroremptymessage'] = 'Post message cannot be empty';
343-
$string['yournewtopic'] = 'Your new discussion topic';
344-
345-
// Strings for the classes/ratings.php.
346-
$string['postnotexist'] = 'Requested post does not exist';
347-
$string['noratemoodleoverflow'] = 'Sorry, you are not allowed to vote in this forum.';
348-
$string['configallowratingchange'] = 'Can a user change its ratings?';
349-
$string['allowratingchange'] = 'Allow rating changes';
350-
$string['configpreferteachersmark'] = 'The answer marked as solution by a course owner are prioritized over the answer marked as helpful by the starter of the discussion.';
351-
$string['preferteachersmark'] = 'Prefer course owners\' marks?';
352-
$string['noratingchangeallowed'] = 'You are not allowed to change your ratings.';
353-
$string['invalidratingid'] = 'The submitted rating is neither an upvote nor a downvote.';
354-
$string['notstartuser'] = 'Only the user who started the discussion can mark an answer as helpful.';
355-
$string['notteacher'] = 'Only course owners can do this.';
356-
$string['ratingtoold'] = 'Ratings can only be changed within 30 minutes after the first vote. ';
357-
$string['postnotpartofdiscussion'] = 'Post does not exist in this discussion, please check the parameter';
358-
359-
// Strings for the discussion.php.
360-
$string['invaliddiscussionid'] = 'Discussion ID was incorrect';
361-
$string['notexists'] = 'Discussion no longer exists';
362-
$string['discussionname'] = 'Discussion name';
363-
$string['discussionlocked'] = 'This discussion has been locked so you can no longer reply to it.';
364-
$string['hiddenmoodleoverflowpost'] = 'Hidden forum post';
365-
$string['moodleoverflowsubjecthidden'] = 'Subject (hidden)';
366-
367-
=======
368230
$string['moodleoverflow:viewdiscussion'] = 'View discussion';
369-
>>>>>>> 0702bd3437f0d25ebe364a04cb0149f0ca79f0e2
370231
$string['moodleoverflowauthorhidden'] = 'Author (hidden)';
371232
$string['moodleoverflowbodyhidden'] = 'This post cannot be viewed by you, probably because you have not posted in the discussion, the maximum editing time hasn\'t passed yet, the discussion has not started or the discussion has expired.';
372233
$string['moodleoverflowfieldset'] = 'Custom example fieldset';
@@ -410,9 +271,7 @@
410271
$string['postaddedtimeleft'] = 'You have {$a} to edit it if you want to make any changes.';
411272
$string['postbyuser'] = '{$a->post} by {$a->user}';
412273
$string['postincontext'] = 'See this post in context';
413-
$string['postmailinfolink'] = 'This is a copy of a message posted in {$a->coursename}.
414-
415-
To reply click on this link: {$a->replylink}';
274+
$string['postmailinfolink'] = 'This is a copy of a message posted in {$a->coursename}. To reply click on this link: {$a->replylink}';
416275
$string['postmailsubject'] = '{$a->courseshortname}: {$a->subject}';
417276
$string['postnotexist'] = 'Requested post does not exist';
418277
$string['posts'] = 'Posts';

lib.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3030
*/
3131

32-
// TODO: Adapt functions to the new way of working with posts and discussions (Replace the post/discussion functions).
32+
// LEARNWEB-TODO: Adapt functions to the new way of working with posts and discussions (Replace the post/discussion functions).
3333
use core\context\course;
3434

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

0 commit comments

Comments
 (0)