Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1222
Línea 22... Línea 22...
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
23
 */
Línea 24... Línea 24...
24
 
24
 
25
require_once('../../config.php');
25
require_once('../../config.php');
26
require_once('lib.php');
26
require_once('lib.php');
Línea 27... Línea 27...
27
require_once($CFG->libdir.'/completionlib.php');
27
require_once($CFG->libdir . '/completionlib.php');
28
 
28
 
29
$reply   = optional_param('reply', 0, PARAM_INT);
29
$reply   = optional_param('reply', 0, PARAM_INT);
30
$forum   = optional_param('forum', 0, PARAM_INT);
30
$forum   = optional_param('forum', 0, PARAM_INT);
Línea 143... Línea 143...
143
        if (!isguestuser()) {
143
        if (!isguestuser()) {
144
            if (!is_enrolled($coursecontext)) {
144
            if (!is_enrolled($coursecontext)) {
145
                if (enrol_selfenrol_available($course->id)) {
145
                if (enrol_selfenrol_available($course->id)) {
146
                    $SESSION->wantsurl = qualified_me();
146
                    $SESSION->wantsurl = qualified_me();
147
                    $SESSION->enrolcancel = get_local_referer(false);
147
                    $SESSION->enrolcancel = get_local_referer(false);
-
 
148
                    redirect(
148
                    redirect(new moodle_url('/enrol/index.php', array('id' => $course->id,
149
                        new moodle_url('/enrol/index.php', array(
-
 
150
                            'id' => $course->id,
149
                        'returnurl' => '/mod/forum/view.php?f=' . $forum->id)),
151
                            'returnurl' => '/mod/forum/view.php?f=' . $forum->id
-
 
152
                        )),
150
                        get_string('youneedtoenrol'));
153
                        get_string('youneedtoenrol')
-
 
154
                    );
151
                }
155
                }
152
            }
156
            }
153
        }
157
        }
154
        throw new \moodle_exception('nopostforum', 'forum');
158
        throw new \moodle_exception('nopostforum', 'forum');
155
    }
159
    }
Línea 156... Línea 160...
156
 
160
 
157
    if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $modcontext)) {
161
    if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $modcontext)) {
158
        redirect(
162
        redirect(
159
                $urlfactory->get_course_url_from_forum($forumentity),
163
            $urlfactory->get_course_url_from_forum($forumentity),
160
                get_string('activityiscurrentlyhidden'),
164
            get_string('activityiscurrentlyhidden'),
161
                null,
165
            null,
162
                \core\output\notification::NOTIFY_ERROR
166
            \core\output\notification::NOTIFY_ERROR
163
            );
167
        );
Línea 164... Línea 168...
164
    }
168
    }
Línea 165... Línea 169...
165
 
169
 
Línea 177... Línea 181...
177
    $post->messagetrust  = 0;
181
    $post->messagetrust  = 0;
178
    $post->groupid = $groupid;
182
    $post->groupid = $groupid;
Línea 179... Línea 183...
179
 
183
 
180
    // Unsetting this will allow the correct return URL to be calculated later.
184
    // Unsetting this will allow the correct return URL to be calculated later.
181
    unset($SESSION->fromdiscussion);
-
 
182
 
185
    unset($SESSION->fromdiscussion);
183
} else if (!empty($reply)) {
186
} else if (!empty($reply)) {
Línea 184... Línea 187...
184
    // User is writing a new reply.
187
    // User is writing a new reply.
185
 
188
 
Línea 216... Línea 219...
216
    if (!$capabilitymanager->can_reply_to_post($USER, $discussionentity, $parententity)) {
219
    if (!$capabilitymanager->can_reply_to_post($USER, $discussionentity, $parententity)) {
217
        if (!isguestuser()) {
220
        if (!isguestuser()) {
218
            if (!is_enrolled($coursecontext)) {  // User is a guest here!
221
            if (!is_enrolled($coursecontext)) {  // User is a guest here!
219
                $SESSION->wantsurl = qualified_me();
222
                $SESSION->wantsurl = qualified_me();
220
                $SESSION->enrolcancel = get_local_referer(false);
223
                $SESSION->enrolcancel = get_local_referer(false);
-
 
224
                redirect(
221
                redirect(new moodle_url('/enrol/index.php', array('id' => $course->id,
225
                    new moodle_url('/enrol/index.php', array(
-
 
226
                        'id' => $course->id,
222
                    'returnurl' => '/mod/forum/view.php?f=' . $forum->id)),
227
                        'returnurl' => '/mod/forum/view.php?f=' . $forum->id
-
 
228
                    )),
223
                    get_string('youneedtoenrol'));
229
                    get_string('youneedtoenrol')
-
 
230
                );
224
            }
231
            }
Línea 225... Línea 232...
225
 
232
 
226
            // The forum has been locked. Just redirect back to the discussion page.
233
            // The forum has been locked. Just redirect back to the discussion page.
227
            if (forum_discussion_is_locked($forum, $discussion)) {
234
            if (forum_discussion_is_locked($forum, $discussion)) {
Línea 282... Línea 289...
282
 
289
 
Línea 283... Línea 290...
283
    $post->groupid = ($discussion->groupid == -1) ? 0 : $discussion->groupid;
290
    $post->groupid = ($discussion->groupid == -1) ? 0 : $discussion->groupid;
284
 
291
 
285
    $strre = get_string('re', 'forum');
292
    $strre = get_string('re', 'forum');
286
    if (!(substr($post->subject, 0, strlen($strre)) == $strre)) {
293
    if (!(substr($post->subject, 0, strlen($strre)) == $strre)) {
Línea 287... Línea 294...
287
        $post->subject = $strre.' '.$post->subject;
294
        $post->subject = $strre . ' ' . $post->subject;
288
    }
295
    }
289
 
-
 
290
    // Unsetting this will allow the correct return URL to be calculated later.
296
 
291
    unset($SESSION->fromdiscussion);
297
    // Unsetting this will allow the correct return URL to be calculated later.
Línea 292... Línea 298...
292
 
298
    unset($SESSION->fromdiscussion);
293
} else if (!empty($edit)) {
299
} else if (!empty($edit)) {
Línea 326... Línea 332...
326
 
332
 
Línea 327... Línea 333...
327
    $PAGE->set_cm($cm, $course, $forum);
333
    $PAGE->set_cm($cm, $course, $forum);
328
 
334
 
329
    if (!($forum->type == 'news' && !$post->parent && $discussion->timestart > time())) {
335
    if (!($forum->type == 'news' && !$post->parent && $discussion->timestart > time())) {
-
 
336
        if (((time() - $post->created) > $CFG->maxeditingtime) and
330
        if (((time() - $post->created) > $CFG->maxeditingtime) and
337
            !has_capability('mod/forum:editanypost', $modcontext)
331
            !has_capability('mod/forum:editanypost', $modcontext)) {
338
        ) {
332
            throw new \moodle_exception('maxtimehaspassed', 'forum', '', format_time($CFG->maxeditingtime));
339
            throw new \moodle_exception('maxtimehaspassed', 'forum', '', format_time($CFG->maxeditingtime));
333
        }
340
        }
334
    }
341
    }
-
 
342
    if (($post->userid <> $USER->id) and
335
    if (($post->userid <> $USER->id) and
343
        !has_capability('mod/forum:editanypost', $modcontext)
336
        !has_capability('mod/forum:editanypost', $modcontext)) {
344
    ) {
Línea 337... Línea 345...
337
        throw new \moodle_exception('cannoteditposts', 'forum');
345
        throw new \moodle_exception('cannoteditposts', 'forum');
338
    }
346
    }
Línea 348... Línea 356...
348
 
356
 
Línea 349... Línea 357...
349
    $post = trusttext_pre_edit($post, 'message', $modcontext);
357
    $post = trusttext_pre_edit($post, 'message', $modcontext);
350
 
358
 
351
    // Unsetting this will allow the correct return URL to be calculated later.
-
 
352
    unset($SESSION->fromdiscussion);
359
    // Unsetting this will allow the correct return URL to be calculated later.
353
 
360
    unset($SESSION->fromdiscussion);
Línea 354... Línea 361...
354
} else if (!empty($delete)) {
361
} else if (!empty($delete)) {
355
    // User is deleting a post.
362
    // User is deleting a post.
Línea 375... Línea 382...
375
    $modcontext = $forumentity->get_context();
382
    $modcontext = $forumentity->get_context();
Línea 376... Línea 383...
376
 
383
 
Línea 377... Línea 384...
377
    require_login($course, false, $cm);
384
    require_login($course, false, $cm);
-
 
385
 
-
 
386
    $replycount = $postvault->get_reply_count_for_post_id_in_discussion_id(
378
 
387
        $USER,
-
 
388
        $postentity->get_id(),
-
 
389
        $discussionentity->get_id(),
Línea 379... Línea 390...
379
    $replycount = $postvault->get_reply_count_for_post_id_in_discussion_id(
390
        true
380
        $USER, $postentity->get_id(), $discussionentity->get_id(), true);
391
    );
381
 
392
 
Línea 431... Línea 442...
431
                $e->getMessage(),
442
                $e->getMessage(),
432
                null,
443
                null,
433
                \core\output\notification::NOTIFY_ERROR
444
                \core\output\notification::NOTIFY_ERROR
434
            );
445
            );
435
        }
446
        }
436
 
-
 
437
    } else {
447
    } else {
Línea 438... Línea 448...
438
 
448
 
439
        if (!$capabilitymanager->can_delete_post($USER, $discussionentity, $postentity)) {
449
        if (!$capabilitymanager->can_delete_post($USER, $discussionentity, $postentity)) {
440
            redirect(
450
            redirect(
441
                    $urlfactory->get_discussion_view_url_from_discussion($discussionentity),
451
                $urlfactory->get_discussion_view_url_from_discussion($discussionentity),
442
                    get_string('cannotdeletepost', 'forum'),
452
                get_string('cannotdeletepost', 'forum'),
443
                    null,
453
                null,
444
                    \core\output\notification::NOTIFY_ERROR
454
                \core\output\notification::NOTIFY_ERROR
445
                );
455
            );
Línea 446... Línea 456...
446
        }
456
        }
447
 
457
 
Línea 457... Línea 467...
457
        $PAGE->activityheader->disable();
467
        $PAGE->activityheader->disable();
Línea 458... Línea 468...
458
 
468
 
459
        if ($replycount) {
469
        if ($replycount) {
460
            if (!has_capability('mod/forum:deleteanypost', $modcontext)) {
470
            if (!has_capability('mod/forum:deleteanypost', $modcontext)) {
461
                redirect(
471
                redirect(
462
                        forum_go_back_to($urlfactory->get_view_post_url_from_post($postentity)),
472
                    forum_go_back_to($urlfactory->get_view_post_url_from_post($postentity)),
463
                        get_string('couldnotdeletereplies', 'forum'),
473
                    get_string('couldnotdeletereplies', 'forum'),
464
                        null,
474
                    null,
465
                        \core\output\notification::NOTIFY_ERROR
475
                    \core\output\notification::NOTIFY_ERROR
466
                    );
476
                );
Línea 467... Línea 477...
467
            }
477
            }
468
 
478
 
469
            echo $OUTPUT->header();
479
            echo $OUTPUT->header();
470
            if (!$PAGE->has_secondary_navigation()) {
480
            if (!$PAGE->has_secondary_navigation()) {
-
 
481
                echo $OUTPUT->heading(format_string($forum->name), 2);
471
                echo $OUTPUT->heading(format_string($forum->name), 2);
482
            }
472
            }
483
            echo $OUTPUT->confirm(
473
            echo $OUTPUT->confirm(get_string("deletesureplural", "forum", $replycount + 1),
484
                get_string("deletesureplural", "forum", $replycount + 1),
-
 
485
                "post.php?delete=$delete&confirm=$delete",
Línea 474... Línea 486...
474
                "post.php?delete=$delete&confirm=$delete",
486
                $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $post->discussion . '#p' . $post->id
475
                $CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'#p'.$post->id);
487
            );
476
 
488
 
477
            $postentities = [$postentity];
489
            $postentities = [$postentity];
478
            if (empty($post->edit)) {
490
            if (empty($post->edit)) {
479
                $postvault = $vaultfactory->get_post_vault();
491
                $postvault = $vaultfactory->get_post_vault();
480
                $replies = $postvault->get_replies_to_post(
492
                $replies = $postvault->get_replies_to_post(
481
                        $USER,
493
                    $USER,
482
                        $postentity,
494
                    $postentity,
483
                        // Note: All replies are fetched here as the user has deleteanypost.
495
                    // Note: All replies are fetched here as the user has deleteanypost.
484
                        true,
496
                    true,
485
                        'created ASC'
497
                    'created ASC'
Línea 486... Línea 498...
486
                    );
498
                );
487
                $postentities = array_merge($postentities, $replies);
499
                $postentities = array_merge($postentities, $replies);
Línea 493... Línea 505...
493
        } else {
505
        } else {
494
            echo $OUTPUT->header();
506
            echo $OUTPUT->header();
495
            if (!$PAGE->has_secondary_navigation()) {
507
            if (!$PAGE->has_secondary_navigation()) {
496
                echo $OUTPUT->heading(format_string($forum->name), 2);
508
                echo $OUTPUT->heading(format_string($forum->name), 2);
497
            }
509
            }
-
 
510
            echo $OUTPUT->confirm(
498
            echo $OUTPUT->confirm(get_string("deletesure", "forum", $replycount),
511
                get_string("deletesure", "forum", $replycount),
499
                "post.php?delete=$delete&confirm=$delete",
512
                "post.php?delete=$delete&confirm=$delete",
500
                $CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'#p'.$post->id);
513
                $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $post->discussion . '#p' . $post->id
-
 
514
            );
Línea 501... Línea 515...
501
 
515
 
502
            $rendererfactory = mod_forum\local\container::get_renderer_factory();
516
            $rendererfactory = mod_forum\local\container::get_renderer_factory();
503
            $postsrenderer = $rendererfactory->get_single_discussion_posts_renderer(null, true);
517
            $postsrenderer = $rendererfactory->get_single_discussion_posts_renderer(null, true);
504
            echo $postsrenderer->render($USER, [$forumentity], [$discussionentity], [$postentity]);
518
            echo $postsrenderer->render($USER, [$forumentity], [$discussionentity], [$postentity]);
505
        }
-
 
506
 
519
        }
507
    }
520
    }
508
    echo $OUTPUT->footer();
521
    echo $OUTPUT->footer();
509
    die;
-
 
510
 
522
    die;
511
} else if (!empty($prune)) {
523
} else if (!empty($prune)) {
Línea 512... Línea 524...
512
    // Pruning.
524
    // Pruning.
513
 
525
 
Línea 538... Línea 550...
538
        throw new \moodle_exception('invalidcoursemodule');
550
        throw new \moodle_exception('invalidcoursemodule');
539
    }
551
    }
Línea 540... Línea 552...
540
 
552
 
541
    if (!$postentity->has_parent()) {
553
    if (!$postentity->has_parent()) {
542
        redirect(
554
        redirect(
543
                $urlfactory->get_discussion_view_url_from_discussion($discussionentity),
555
            $urlfactory->get_discussion_view_url_from_discussion($discussionentity),
544
                get_string('alreadyfirstpost', 'forum'),
556
            get_string('alreadyfirstpost', 'forum'),
545
                null,
557
            null,
546
                \core\output\notification::NOTIFY_ERROR
558
            \core\output\notification::NOTIFY_ERROR
547
            );
559
        );
548
    }
560
    }
549
    if (!$capabilitymanager->can_split_post($USER, $discussionentity, $postentity)) {
561
    if (!$capabilitymanager->can_split_post($USER, $discussionentity, $postentity)) {
550
        redirect(
562
        redirect(
551
                $urlfactory->get_discussion_view_url_from_discussion($discussionentity),
563
            $urlfactory->get_discussion_view_url_from_discussion($discussionentity),
552
                get_string('cannotsplit', 'forum'),
564
            get_string('cannotsplit', 'forum'),
553
                null,
565
            null,
554
                \core\output\notification::NOTIFY_ERROR
566
            \core\output\notification::NOTIFY_ERROR
555
            );
567
        );
Línea 556... Línea 568...
556
    }
568
    }
557
 
569
 
558
    $PAGE->set_cm($cm);
570
    $PAGE->set_cm($cm);
Línea 638... Línea 650...
638
        // Display the prune form.
650
        // Display the prune form.
639
        $course = $DB->get_record('course', array('id' => $forum->course));
651
        $course = $DB->get_record('course', array('id' => $forum->course));
640
        $subjectstr = format_string($post->subject, true);
652
        $subjectstr = format_string($post->subject, true);
641
        $PAGE->navbar->add($subjectstr, new moodle_url('/mod/forum/discuss.php', array('d' => $discussion->id)));
653
        $PAGE->navbar->add($subjectstr, new moodle_url('/mod/forum/discuss.php', array('d' => $discussion->id)));
642
        $PAGE->navbar->add(get_string("prunediscussion", "forum"));
654
        $PAGE->navbar->add(get_string("prunediscussion", "forum"));
643
        $PAGE->set_title(format_string($discussion->name).": ".format_string($post->subject));
655
        $PAGE->set_title(format_string($discussion->name) . ": " . format_string($post->subject));
644
        $PAGE->set_heading($course->fullname);
656
        $PAGE->set_heading($course->fullname);
645
        echo $OUTPUT->header();
657
        echo $OUTPUT->header();
646
        if (!$PAGE->has_secondary_navigation()) {
658
        if (!$PAGE->has_secondary_navigation()) {
647
            echo $OUTPUT->heading(format_string($forum->name), 2);
659
            echo $OUTPUT->heading(format_string($forum->name), 2);
648
        }
660
        }
Línea 660... Línea 672...
660
 
672
 
661
    echo $OUTPUT->footer();
673
    echo $OUTPUT->footer();
662
    die;
674
    die;
663
} else {
675
} else {
664
    throw new \moodle_exception('unknowaction');
-
 
665
 
676
    throw new \moodle_exception('unknowaction');
Línea 666... Línea 677...
666
}
677
}
Línea 667... Línea 678...
667
 
678
 
Línea 674... Línea 685...
674
    throw new \moodle_exception('noguest');
685
    throw new \moodle_exception('noguest');
675
}
686
}
Línea 676... Línea 687...
676
 
687
 
677
$thresholdwarning = forum_check_throttling($forum, $cm);
688
$thresholdwarning = forum_check_throttling($forum, $cm);
678
$mformpost = new mod_forum_post_form('post.php', [
689
$mformpost = new mod_forum_post_form('post.php', [
679
        'course' => $course,
690
    'course' => $course,
680
        'cm' => $cm,
691
    'cm' => $cm,
681
        'coursecontext' => $coursecontext,
692
    'coursecontext' => $coursecontext,
682
        'modcontext' => $modcontext,
693
    'modcontext' => $modcontext,
683
        'forum' => $forum,
694
    'forum' => $forum,
684
        'post' => $post,
695
    'post' => $post,
685
        'subscribe' => \mod_forum\subscriptions::is_subscribed($USER->id, $forum, null, $cm),
696
    'subscribe' => \mod_forum\subscriptions::is_subscribed($USER->id, $forum, null, $cm),
686
        'thresholdwarning' => $thresholdwarning,
697
    'thresholdwarning' => $thresholdwarning,
687
        'edit' => $edit,
698
    'edit' => $edit,
688
        'canreplyprivately' => $canreplyprivately,
699
    'canreplyprivately' => $canreplyprivately,
Línea 689... Línea 700...
689
    ], 'post', '', array('id' => 'mformforum'));
700
], 'post', '', array('id' => 'mformforum'));
690
 
701
 
691
$draftitemid = file_get_submitted_draft_itemid('attachments');
702
$draftitemid = file_get_submitted_draft_itemid('attachments');
692
$postid = empty($post->id) ? null : $post->id;
703
$postid = empty($post->id) ? null : $post->id;
Línea 697... Línea 708...
697
 
708
 
698
if ($USER->id != $post->userid) {   // Not the original author, so add a message to the end.
709
if ($USER->id != $post->userid) {   // Not the original author, so add a message to the end.
699
    $data = new stdClass();
710
    $data = new stdClass();
700
    $data->date = userdate($post->created);
711
    $data->date = userdate($post->created);
701
    if ($post->messageformat == FORMAT_HTML) {
712
    if ($post->messageformat == FORMAT_HTML) {
702
        $data->name = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$USER->id.'&course='.$post->course.'">'.
713
        $data->name = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $USER->id . '&course=' . $post->course . '">' .
703
            fullname($USER).'</a>';
-
 
704
        $post->message .= '<p><span class="edited">('.get_string('editedby', 'forum', $data).')</span></p>';
714
            fullname($USER) . '</a>';
705
    } else {
715
    } else {
706
        $data->name = fullname($USER);
-
 
707
        $post->message .= "\n\n(".get_string('editedby', 'forum', $data).')';
716
        $data->name = fullname($USER);
708
    }
717
    }
709
    unset($data);
718
    unset($data);
Línea 710... Línea 719...
710
}
719
}
Línea 746... Línea 755...
746
        'discussion' => $post->discussion,
755
        'discussion' => $post->discussion,
747
        'course' => $course->id,
756
        'course' => $course->id,
748
        'isprivatereply' => $post->isprivatereply ?? false
757
        'isprivatereply' => $post->isprivatereply ?? false
749
    ) +
758
    ) +
Línea 750... Línea 759...
750
 
759
 
Línea 751... Línea 760...
751
    $pageparams +
760
        $pageparams +
Línea 752... Línea 761...
752
 
761
 
Línea 753... Línea 762...
753
    (isset($post->format) ? array('format' => $post->format) : array()) +
762
        (isset($post->format) ? array('format' => $post->format) : array()) +
Línea 754... Línea 763...
754
 
763
 
Línea 755... Línea 764...
755
    (isset($discussion->timestart) ? array('timestart' => $discussion->timestart) : array()) +
764
        (isset($discussion->timestart) ? array('timestart' => $discussion->timestart) : array()) +
Línea 756... Línea 765...
756
 
765
 
757
    (isset($discussion->timeend) ? array('timeend' => $discussion->timeend) : array()) +
766
        (isset($discussion->timeend) ? array('timeend' => $discussion->timeend) : array()) +
Línea 758... Línea 767...
758
 
767
 
759
    (isset($discussion->pinned) ? array('pinned' => $discussion->pinned) : array()) +
768
        (isset($discussion->pinned) ? array('pinned' => $discussion->pinned) : array()) +
760
 
769
 
Línea 808... Línea 817...
808
        $fromform->id = $fromform->edit;
817
        $fromform->id = $fromform->edit;
809
        $message = '';
818
        $message = '';
Línea 810... Línea 819...
810
 
819
 
811
        if (!$capabilitymanager->can_edit_post($USER, $discussionentity, $postentity)) {
820
        if (!$capabilitymanager->can_edit_post($USER, $discussionentity, $postentity)) {
812
            redirect(
821
            redirect(
813
                    $urlfactory->get_view_post_url_from_post($postentity),
822
                $urlfactory->get_view_post_url_from_post($postentity),
814
                    get_string('cannotupdatepost', 'forum'),
823
                get_string('cannotupdatepost', 'forum'),
815
                    null,
824
                null,
816
                    \core\output\notification::ERROR
825
                \core\output\notification::ERROR
817
                );
826
            );
Línea 818... Línea 827...
818
        }
827
        }
819
 
828
 
820
        if (isset($fromform->groupinfo) && $capabilitymanager->can_move_discussions($USER)) {
829
        if (isset($fromform->groupinfo) && $capabilitymanager->can_move_discussions($USER)) {
821
            // If the user has access to all groups and they are changing the group, then update the post.
830
            // If the user has access to all groups and they are changing the group, then update the post.
822
            if (empty($fromform->groupinfo)) {
831
            if (empty($fromform->groupinfo)) {
Línea 823... Línea 832...
823
                $fromform->groupinfo = -1;
832
                $fromform->groupinfo = -1;
824
            }
833
            }
825
 
834
 
826
            if (!$capabilitymanager->can_create_discussions($USER, $fromform->groupinfo)) {
835
            if (!$capabilitymanager->can_create_discussions($USER, $fromform->groupinfo)) {
827
                redirect(
836
                redirect(
828
                        $urlfactory->get_view_post_url_from_post($postentity),
837
                    $urlfactory->get_view_post_url_from_post($postentity),
829
                        get_string('cannotupdatepost', 'forum'),
838
                    get_string('cannotupdatepost', 'forum'),
830
                        null,
839
                    null,
Línea 831... Línea 840...
831
                        \core\output\notification::ERROR
840
                    \core\output\notification::ERROR
832
                    );
841
                );
833
            }
842
            }
Línea 875... Línea 884...
875
            forum_go_back_to($discussionurl),
884
            forum_go_back_to($discussionurl),
876
            $message . $subscribemessage,
885
            $message . $subscribemessage,
877
            null,
886
            null,
878
            \core\output\notification::NOTIFY_SUCCESS
887
            \core\output\notification::NOTIFY_SUCCESS
879
        );
888
        );
880
 
-
 
881
    } else if ($fromform->discussion) {
889
    } else if ($fromform->discussion) {
882
        // Adding a new post to an existing discussion
890
        // Adding a new post to an existing discussion
883
        // Before we add this we must check that the user will not exceed the blocking threshold.
891
        // Before we add this we must check that the user will not exceed the blocking threshold.
884
        forum_check_blocking_threshold($thresholdwarning);
892
        forum_check_blocking_threshold($thresholdwarning);
Línea 893... Línea 901...
893
            $subscribemessage = forum_post_subscription($fromform, $forum, $discussion);
901
            $subscribemessage = forum_post_subscription($fromform, $forum, $discussion);
Línea 894... Línea 902...
894
 
902
 
895
            if (!empty($fromform->mailnow)) {
903
            if (!empty($fromform->mailnow)) {
896
                $message .= get_string("postmailnow", "forum");
904
                $message .= get_string("postmailnow", "forum");
897
            } else {
905
            } else {
898
                $message .= '<p>'.get_string("postaddedsuccess", "forum") . '</p>';
906
                $message .= '<p>' . get_string("postaddedsuccess", "forum") . '</p>';
899
                $message .= '<p>'.get_string("postaddedtimeleft", "forum", format_time($CFG->maxeditingtime)) . '</p>';
907
                $message .= '<p>' . get_string("postaddedtimeleft", "forum", format_time($CFG->maxeditingtime)) . '</p>';
Línea 900... Línea 908...
900
            }
908
            }
901
 
909
 
902
            if ($forum->type == 'single') {
910
            if ($forum->type == 'single') {
Línea 921... Línea 929...
921
            $event->add_record_snapshot('forum_discussions', $discussion);
929
            $event->add_record_snapshot('forum_discussions', $discussion);
922
            $event->trigger();
930
            $event->trigger();
Línea 923... Línea 931...
923
 
931
 
924
            // Update completion state.
932
            // Update completion state.
-
 
933
            $completion = new completion_info($course);
925
            $completion = new completion_info($course);
934
            if (
926
            if ($completion->is_enabled($cm) &&
935
                $completion->is_enabled($cm) &&
-
 
936
                ($forum->completionreplies || $forum->completionposts)
927
                ($forum->completionreplies || $forum->completionposts)) {
937
            ) {
928
                $completion->update_state($cm, COMPLETION_COMPLETE);
938
                $completion->update_state($cm, COMPLETION_COMPLETE);
Línea 929... Línea 939...
929
            }
939
            }
930
 
940
 
931
            redirect(
941
            redirect(
932
                forum_go_back_to($discussionurl),
942
                forum_go_back_to($discussionurl),
933
                $message . $subscribemessage,
943
                $message . $subscribemessage,
934
                null,
944
                null,
935
                \core\output\notification::NOTIFY_SUCCESS
-
 
936
            );
945
                \core\output\notification::NOTIFY_SUCCESS
937
 
946
            );
938
        } else {
947
        } else {
939
            throw new \moodle_exception("couldnotadd", "forum", $errordestination);
948
            throw new \moodle_exception("couldnotadd", "forum", $errordestination);
940
        }
-
 
941
        exit;
949
        }
942
 
950
        exit;
943
    } else {
951
    } else {
944
        // Adding a new discussion.
952
        // Adding a new discussion.
Línea 1015... Línea 1023...
1015
                $event->trigger();
1023
                $event->trigger();
Línea 1016... Línea 1024...
1016
 
1024
 
1017
                if ($fromform->mailnow) {
1025
                if ($fromform->mailnow) {
1018
                    $message .= get_string("postmailnow", "forum");
1026
                    $message .= get_string("postmailnow", "forum");
1019
                } else {
1027
                } else {
1020
                    $message .= '<p>'.get_string("postaddedsuccess", "forum") . '</p>';
1028
                    $message .= '<p>' . get_string("postaddedsuccess", "forum") . '</p>';
1021
                    $message .= '<p>'.get_string("postaddedtimeleft", "forum", format_time($CFG->maxeditingtime)) . '</p>';
1029
                    $message .= '<p>' . get_string("postaddedtimeleft", "forum", format_time($CFG->maxeditingtime)) . '</p>';
Línea 1022... Línea 1030...
1022
                }
1030
                }
1023
 
1031
 
1024
                $subscribemessage = forum_post_subscription($fromform, $forum, $discussion);
1032
                $subscribemessage = forum_post_subscription($fromform, $forum, $discussion);
1025
            } else {
1033
            } else {
1026
                throw new \moodle_exception("couldnotadd", "forum", $errordestination);
1034
                throw new \moodle_exception("couldnotadd", "forum", $errordestination);
Línea 1027... Línea 1035...
1027
            }
1035
            }
1028
        }
1036
        }
-
 
1037
 
1029
 
1038
        // Update completion status.
1030
        // Update completion status.
1039
        $completion = new completion_info($course);
-
 
1040
        if (
1031
        $completion = new completion_info($course);
1041
            $completion->is_enabled($cm) &&
1032
        if ($completion->is_enabled($cm) &&
1042
            ($forum->completiondiscussions || $forum->completionposts)
Línea 1033... Línea 1043...
1033
            ($forum->completiondiscussions || $forum->completionposts)) {
1043
        ) {
1034
            $completion->update_state($cm, COMPLETION_COMPLETE);
1044
            $completion->update_state($cm, COMPLETION_COMPLETE);
Línea 1137... Línea 1147...
1137
    $postentities = [$parententity];
1147
    $postentities = [$parententity];
Línea 1138... Línea 1148...
1138
 
1148
 
1139
    if (empty($post->edit)) {
1149
    if (empty($post->edit)) {
1140
        if ('qanda' != $forumentity->get_type() || forum_user_can_see_discussion($forum, $discussion, $modcontext)) {
1150
        if ('qanda' != $forumentity->get_type() || forum_user_can_see_discussion($forum, $discussion, $modcontext)) {
1141
            $replies = $postvault->get_replies_to_post(
1151
            $replies = $postvault->get_replies_to_post(
1142
                    $USER,
1152
                $USER,
1143
                    $parententity,
1153
                $parententity,
1144
                    $capabilitymanager->can_view_any_private_reply($USER),
1154
                $capabilitymanager->can_view_any_private_reply($USER),
1145
                    'created ASC'
1155
                'created ASC'
1146
                );
1156
            );
1147
            $postentities = array_merge($postentities, $replies);
1157
            $postentities = array_merge($postentities, $replies);
1148
        }
1158
        }
Línea 1149... Línea 1159...
1149
    }
1159
    }
Línea 1153... Línea 1163...
1153
    echo $postsrenderer->render($USER, [$forumentity], [$discussionentity], $postentities);
1163
    echo $postsrenderer->render($USER, [$forumentity], [$discussionentity], $postentities);
1154
}
1164
}
Línea 1155... Línea 1165...
1155
 
1165
 
1156
// Call print disclosure for enabled plagiarism plugins.
1166
// Call print disclosure for enabled plagiarism plugins.
1157
if (!empty($CFG->enableplagiarism)) {
1167
if (!empty($CFG->enableplagiarism)) {
1158
    require_once($CFG->libdir.'/plagiarismlib.php');
1168
    require_once($CFG->libdir . '/plagiarismlib.php');
1159
    echo plagiarism_print_disclosure($cm->id);
1169
    echo plagiarism_print_disclosure($cm->id);
Línea 1160... Línea 1170...
1160
}
1170
}
1161
 
1171