Ejemplo n.º 1
0
 /**
  * Output substantive / bookmark toggles
  *
  * @param stdClass $post The post to add flags to
  * @param $cm
  * @param int $discussion id of parent discussion
  * @param bool $reply is this the first post in a thread or a reply
  * @throws coding_exception
  * @return array
  * @author Mark Nielsen
  */
 public function post_get_flags($post, $cm, $discussion, $reply = false)
 {
     global $PAGE, $CFG;
     $context = context_module::instance($cm->id);
     if (!local::cached_has_capability('mod/hsuforum:viewflags', $context)) {
         return array();
     }
     if (!property_exists($post, 'flags')) {
         throw new coding_exception('The post\'s flags property must be set');
     }
     require_once __DIR__ . '/lib/flag.php';
     $flaglib = new hsuforum_lib_flag();
     $canedit = local::cached_has_capability('mod/hsuforum:editanypost', $context);
     $returnurl = $this->return_url($cm->id, $discussion);
     $flaghtml = array();
     $forum = hsuforum_get_cm_forum($cm);
     foreach ($flaglib->get_flags() as $flag) {
         // Skip bookmark flagging if switched off at forum level or if global kill switch set.
         if ($flag == 'bookmark') {
             if ($forum->showbookmark === '0') {
                 continue;
             }
         }
         // Skip substantive flagging if switched off at forum level or if global kill switch set.
         if ($flag == 'substantive') {
             if ($forum->showsubstantive === '0') {
                 continue;
             }
         }
         $isflagged = $flaglib->is_flagged($post->flags, $flag);
         $url = new moodle_url('/mod/hsuforum/route.php', array('contextid' => $context->id, 'action' => 'flag', 'returnurl' => $returnurl, 'postid' => $post->id, 'flag' => $flag, 'sesskey' => sesskey()));
         // Create appropriate area described by.
         $describedby = $reply ? 'thread-title-' . $discussion : 'hsuforum-post-' . $post->id;
         // Create toggle element.
         $flaghtml[$flag] = $this->toggle_element($flag, $describedby, $url, $isflagged, $canedit, array('class' => 'hsuforum_flag'));
     }
     return $flaghtml;
 }