Proyectos de Subversion Moodle

Rev

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

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