Example #1
0
 if (!$post->parent) {
     print_error('alreadyfirstpost', 'hsuforum');
 }
 if (!($cm = get_coursemodule_from_instance("hsuforum", $forum->id, $forum->course))) {
     // For the logs
     print_error('invalidcoursemodule');
 } else {
     $modcontext = context_module::instance($cm->id);
 }
 if (!has_capability('mod/hsuforum:splitdiscussions', $modcontext)) {
     print_error('cannotsplit', 'hsuforum');
 }
 if (!empty($name) && confirm_sesskey()) {
     // User has confirmed the prune
     // Make sure post name does not go beyond 255 chars.
     $name = \mod_hsuforum\local::shorten_post_name($name);
     $newdiscussion = new stdClass();
     $newdiscussion->course = $discussion->course;
     $newdiscussion->forum = $discussion->forum;
     $newdiscussion->name = $name;
     $newdiscussion->firstpost = $post->id;
     $newdiscussion->userid = $discussion->userid;
     $newdiscussion->groupid = $discussion->groupid;
     $newdiscussion->assessed = $discussion->assessed;
     $newdiscussion->usermodified = $post->userid;
     $newdiscussion->timestart = $discussion->timestart;
     $newdiscussion->timeend = $discussion->timeend;
     $newid = $DB->insert_record('hsuforum_discussions', $newdiscussion);
     $newpost = new stdClass();
     $newpost->id = $post->id;
     $newpost->parent = 0;
Example #2
0
/**
 * Given a user, return post user that is ready for display (EG:
 * anonymous is enforced as well as highlighting)
 *
 * @param object $user
 * @param object $post
 * @param object $forum
 * @param context_module $context
 * @return stdClass
 */
function hsuforum_get_postuser($user, $post, $forum, context_module $context)
{
    static $cache = [];
    if (empty($forum->anonymous) or !empty($post->reveal)) {
        if (isset($cache[$user->id])) {
            return $cache[$user->id];
        }
    }
    $postuser = hsuforum_anonymize_user($user, $forum, $post);
    if (property_exists($user, 'picture')) {
        $postuser->user_picture = new user_picture($postuser);
        $postuser->user_picture->courseid = $forum->course;
        $postuser->user_picture->link = !hsuforum_is_anonymous_user($postuser);
    }
    $postuser->fullname = fullname($postuser, \mod_hsuforum\local::cached_has_capability('moodle/site:viewfullnames', $context));
    if (empty($forum->anonymous) or !empty($post->reveal)) {
        $cache[$user->id] = $postuser;
    }
    return $postuser;
}
 /**
  * @param stdClass $post
  * @param stdClass $discussion
  * @param stdClass $cm
  * @param bool $canreply
  * @return array
  * @throws coding_exception
  * @author Mark Nielsen
  */
 public function post_get_commands($post, $discussion, $cm, $canreply)
 {
     global $CFG, $USER;
     $discussionlink = new moodle_url('/mod/hsuforum/discuss.php', array('d' => $post->discussion));
     $ownpost = (isloggedin() and $post->userid == $USER->id);
     $commands = array();
     if (!property_exists($post, 'privatereply')) {
         throw new coding_exception('Must set post\'s privatereply property!');
     }
     $forum = hsuforum_get_cm_forum($cm);
     if ($canreply and empty($post->privatereply)) {
         $postuser = hsuforum_extract_postuser($post, $forum, context_module::instance($cm->id));
         $replytitle = get_string('replybuttontitle', 'hsuforum', strip_tags($postuser->fullname));
         $commands['reply'] = html_writer::link(new moodle_url('/mod/hsuforum/post.php', array('reply' => $post->id)), get_string('reply', 'hsuforum'), array('title' => $replytitle, 'class' => 'hsuforum-reply-link btn btn-default'));
     }
     // Hack for allow to edit news posts those are not displayed yet until they are displayed
     $age = time() - $post->created;
     if (!$post->parent && $forum->type == 'news' && $discussion->timestart > time()) {
         $age = 0;
     }
     if ($ownpost && $age < $CFG->maxeditingtime || local::cached_has_capability('mod/hsuforum:editanypost', context_module::instance($cm->id))) {
         $commands['edit'] = html_writer::link(new moodle_url('/mod/hsuforum/post.php', array('edit' => $post->id)), get_string('edit', 'hsuforum'));
     }
     if ($ownpost && $age < $CFG->maxeditingtime && local::cached_has_capability('mod/hsuforum:deleteownpost', context_module::instance($cm->id)) || local::cached_has_capability('mod/hsuforum:deleteanypost', context_module::instance($cm->id))) {
         $commands['delete'] = html_writer::link(new moodle_url('/mod/hsuforum/post.php', array('delete' => $post->id)), get_string('delete', 'hsuforum'));
     }
     if (local::cached_has_capability('mod/hsuforum:splitdiscussions', context_module::instance($cm->id)) && $post->parent && !$post->privatereply && $forum->type != 'single') {
         $commands['split'] = html_writer::link(new moodle_url('/mod/hsuforum/post.php', array('prune' => $post->id)), get_string('prune', 'hsuforum'), array('title' => get_string('pruneheading', 'hsuforum')));
     }
     if ($CFG->enableportfolios && empty($forum->anonymous) && (local::cached_has_capability('mod/hsuforum:exportpost', context_module::instance($cm->id)) || $ownpost && local::cached_has_capability('mod/hsuforum:exportownpost', context_module::instance($cm->id)))) {
         require_once $CFG->libdir . '/portfoliolib.php';
         $button = new portfolio_add_button();
         $button->set_callback_options('hsuforum_portfolio_caller', array('postid' => $post->id), 'mod_hsuforum');
         list($attachments, $attachedimages) = hsuforum_print_attachments($post, $cm, 'separateimages');
         if (empty($attachments)) {
             $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML);
         } else {
             $button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
         }
         $porfoliohtml = $button->to_html(PORTFOLIO_ADD_TEXT_LINK);
         if (!empty($porfoliohtml)) {
             $commands['portfolio'] = $porfoliohtml;
         }
     }
     $rating = $this->post_rating($post);
     if (!empty($rating)) {
         $commands['rating'] = $rating;
     }
     return $commands;
 }
        $button = '&nbsp;';
        $buttonextraclass = ' noavailable';
    }
    echo html_writer::tag('div', $button, array('class' => 'discussioncontrol exporttoportfolio' . $buttonextraclass));
}
if ($course->format != 'singleactivity' && $forum->type != 'single' && local::cached_has_capability('mod/hsuforum:movediscussions', $modcontext)) {
    echo '<div class="discussioncontrol movediscussion">';
    // Popup menu to move discussions to other forums. The discussion in a
    // single discussion forum can't be moved.
    $modinfo = get_fast_modinfo($course);
    if (isset($modinfo->instances['hsuforum'])) {
        $forummenu = array();
        // Check forum types and eliminate simple discussions.
        $forumcheck = $DB->get_records('hsuforum', array('course' => $course->id), '', 'id, type');
        foreach ($modinfo->instances['hsuforum'] as $forumcm) {
            if (!$forumcm->uservisible || !local::cached_has_capability('mod/hsuforum:startdiscussion', context_module::instance($forumcm->id))) {
                continue;
            }
            $section = $forumcm->sectionnum;
            $sectionname = get_section_name($course, $section);
            if (empty($forummenu[$section])) {
                $forummenu[$section] = array($sectionname => array());
            }
            $forumidcompare = $forumcm->instance != $forum->id;
            $forumtypecheck = $forumcheck[$forumcm->instance]->type !== 'single';
            if ($forumidcompare and $forumtypecheck) {
                $url = "/mod/hsuforum/discuss.php?d={$discussion->id}&move={$forumcm->instance}&sesskey=" . sesskey();
                $forummenu[$section][$sectionname][$url] = format_string($forumcm->name);
            }
        }
    }
 /**
  * Creates the post object to be saved.
  *
  * @param object $discussion
  * @param object $parent The parent post
  * @param \context_module $context
  * @param array $options These override default post values, EG: set the post message with this
  * @return \stdClass
  */
 public function create_post_object($discussion, $parent, $context, array $options = array())
 {
     $post = new \stdClass();
     $post->course = $discussion->course;
     $post->forum = $discussion->forum;
     $post->discussion = $discussion->id;
     $post->parent = $parent->id;
     $post->reveal = 0;
     $post->privatereply = 0;
     $post->mailnow = 0;
     $post->subject = $parent->subject;
     $post->attachment = '';
     $post->message = '';
     $post->messageformat = FORMAT_MOODLE;
     $post->messagetrust = trusttext_trusted($context);
     $post->itemid = 0;
     // For text editor stuffs.
     $post->groupid = $discussion->groupid == -1 ? 0 : $discussion->groupid;
     $post->flags = null;
     $strre = get_string('re', 'hsuforum');
     if (!(\core_text::substr($post->subject, 0, \core_text::strlen($strre)) == $strre)) {
         $post->subject = $strre . ' ' . $post->subject;
     }
     // Make sure post subject does not go beyond 255 chars.
     $post->subject = \mod_hsuforum\local::shorten_post_name($post->subject);
     foreach ($options as $name => $value) {
         if (property_exists($post, $name)) {
             $post->{$name} = $value;
         }
     }
     return $post;
 }