Exemplo n.º 1
0
/**
 * @global object
 * @param object $post
 * @param bool $children
 * @return int
 */
function quora_count_replies($post, $children = true)
{
    global $DB;
    $count = 0;
    if ($children) {
        if ($childposts = $DB->get_records('quora_posts', array('parent' => $post->id))) {
            foreach ($childposts as $childpost) {
                $count++;
                // For this child
                $count += quora_count_replies($childpost, true);
            }
        }
    } else {
        $count += $DB->count_records('quora_posts', array('parent' => $post->id));
    }
    return $count;
}
Exemplo n.º 2
0
 }
 if (!($quora = $DB->get_record("quora", array("id" => $discussion->quora)))) {
     print_error('invalidquoraid', 'quora');
 }
 if (!($cm = get_coursemodule_from_instance("quora", $quora->id, $quora->course))) {
     print_error('invalidcoursemodule');
 }
 if (!($course = $DB->get_record('course', array('id' => $quora->course)))) {
     print_error('invalidcourseid');
 }
 require_login($course, false, $cm);
 $modcontext = context_module::instance($cm->id);
 if (!($post->userid == $USER->id && has_capability('mod/quora:deleteownpost', $modcontext) || has_capability('mod/quora:deleteanypost', $modcontext))) {
     print_error('cannotdeletepost', 'quora');
 }
 $replycount = quora_count_replies($post);
 if (!empty($confirm) && confirm_sesskey()) {
     // User has confirmed the delete
     //check user capability to delete post.
     $timepassed = time() - $post->created;
     if ($timepassed > $CFG->maxeditingtime && !has_capability('mod/quora:deleteanypost', $modcontext)) {
         print_error("cannotdeletepost", "quora", quora_go_back_to("discuss.php?d={$post->discussion}"));
     }
     if ($post->totalscore) {
         notice(get_string('couldnotdeleteratings', 'rating'), quora_go_back_to("discuss.php?d={$post->discussion}"));
     } else {
         if ($replycount && !has_capability('mod/quora:deleteanypost', $modcontext)) {
             print_error("couldnotdeletereplies", "quora", quora_go_back_to("discuss.php?d={$post->discussion}"));
         } else {
             if (!$post->parent) {
                 // post is a discussion topic as well, so delete discussion