Esempio n. 1
0
        }
        /// and finally print the entry.
        if (glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook, 1, $displayformat, $ratings)) {
            $ratingsmenuused = true;
        }
        $entriesshown++;
    }
}
if (!$entriesshown) {
    echo $OUTPUT->box(get_string("noentries", "glossary"), "generalbox boxaligncenter boxwidthwide");
}
if ($ratingsmenuused) {
    echo "<div class=\"boxaligncenter\"><input type=\"submit\" value=\"" . get_string("sendinratings", "glossary") . "\" />";
    if ($glossary->scale < 0) {
        if ($scale = $DB->get_record("scale", array("id" => abs($glossary->scale)))) {
            echo $OUTPUT->help_button(help_button::make_scale_menu($course->id, $scale));
        }
    }
    echo "</div>";
}
if (!empty($formsent)) {
    // close the form properly if used
    echo "</div>";
    echo "</form>";
}
if ($paging) {
    echo '<hr />';
    echo '<div class="paging">';
    echo $paging;
    echo '</div>';
}
Esempio n. 2
0
/**
 * Prints a help button about a scale
 *
 * @deprecated since Moodle 2.0
 *
 * @global object
 * @param id $courseid
 * @param object $scale
 * @param boolean $return If set to true returns rather than echo's
 * @return string|bool Depending on value of $return
 */
function print_scale_menu_helpbutton($courseid, $scale, $return = false)
{
    // debugging('print_scale_menu_helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_button($scaleselect).');
    global $OUTPUT;
    $output = $OUTPUT->help_button(help_button::make_scale_menu($courseid, $scale));
    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}
Esempio n. 3
0
/**
 * @global object
 * @global object
 * @uses CONTEXT_MODULE
 * @uses FORUM_MODE_FLATNEWEST
 * @uses FORUM_MODE_FLATOLDEST
 * @uses FORUM_MODE_THREADED
 * @uses FORUM_MODE_NESTED
 * @param object $course
 * @param object $cm
 * @param object $forum
 * @param object $discussion
 * @param object $post
 * @param object $mode
 * @param mixed $canreply
 * @param bool $cancreate
 */
function forum_print_discussion($course, $cm, $forum, $discussion, $post, $mode, $canreply = NULL, $canrate = false)
{
    global $USER, $CFG, $DB, $PAGE, $OUTPUT;
    if (!empty($USER->id)) {
        $ownpost = $USER->id == $post->userid;
    } else {
        $ownpost = false;
    }
    $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
    if ($canreply === NULL) {
        $reply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext);
    } else {
        $reply = $canreply;
    }
    // $cm holds general cache for forum functions
    $cm->cache = new object();
    $cm->cache->groups = groups_get_all_groups($course->id, 0, $cm->groupingid);
    $cm->cache->usersgroups = array();
    $posters = array();
    // preload all posts - TODO: improve...
    if ($mode == FORUM_MODE_FLATNEWEST) {
        $sort = "p.created DESC";
    } else {
        $sort = "p.created ASC";
    }
    $forumtracked = forum_tp_is_tracked($forum);
    $posts = forum_get_all_discussion_posts($discussion->id, $sort, $forumtracked);
    $post = $posts[$post->id];
    foreach ($posts as $pid => $p) {
        $posters[$p->userid] = $p->userid;
    }
    // preload all groups of ppl that posted in this discussion
    if ($postersgroups = groups_get_all_groups($course->id, $posters, $cm->groupingid, 'gm.id, gm.groupid, gm.userid')) {
        foreach ($postersgroups as $pg) {
            if (!isset($cm->cache->usersgroups[$pg->userid])) {
                $cm->cache->usersgroups[$pg->userid] = array();
            }
            $cm->cache->usersgroups[$pg->userid][$pg->groupid] = $pg->groupid;
        }
        unset($postersgroups);
    }
    $ratings = NULL;
    $ratingsmenuused = false;
    $ratingsformused = false;
    if ($forum->assessed and isloggedin()) {
        if ($scale = make_grades_menu($forum->scale)) {
            $ratings = new object();
            $ratings->scale = $scale;
            $ratings->assesstimestart = $forum->assesstimestart;
            $ratings->assesstimefinish = $forum->assesstimefinish;
            $ratings->allow = $canrate;
            if ($ratings->allow) {
                echo '<form id="form" method="post" action="rate.php">';
                echo '<div class="ratingform">';
                echo '<input type="hidden" name="forumid" value="' . $forum->id . '" />';
                $ratingsformused = true;
            }
            // preload all ratings - one query only and minimal memory
            $cm->cache->ratings = array();
            $cm->cache->myratings = array();
            if ($postratings = forum_get_all_discussion_ratings($discussion)) {
                foreach ($postratings as $pr) {
                    if (!isset($cm->cache->ratings[$pr->postid])) {
                        $cm->cache->ratings[$pr->postid] = array();
                    }
                    $cm->cache->ratings[$pr->postid][$pr->id] = $pr->rating;
                    if ($pr->userid == $USER->id) {
                        $cm->cache->myratings[$pr->postid] = $pr->rating;
                    }
                }
                unset($postratings);
            }
        }
    }
    $post->forum = $forum->id;
    // Add the forum id to the post object, later used by forum_print_post
    $post->forumtype = $forum->type;
    $post->subject = format_string($post->subject);
    $postread = !empty($post->postread);
    if (forum_print_post($post, $discussion, $forum, $cm, $course, $ownpost, $reply, false, $ratings, '', '', $postread, true, $forumtracked)) {
        $ratingsmenuused = true;
    }
    switch ($mode) {
        case FORUM_MODE_FLATOLDEST:
        case FORUM_MODE_FLATNEWEST:
        default:
            if (forum_print_posts_flat($course, $cm, $forum, $discussion, $post, $mode, $ratings, $reply, $forumtracked, $posts)) {
                $ratingsmenuused = true;
            }
            break;
        case FORUM_MODE_THREADED:
            if (forum_print_posts_threaded($course, $cm, $forum, $discussion, $post, 0, $ratings, $reply, $forumtracked, $posts)) {
                $ratingsmenuused = true;
            }
            break;
        case FORUM_MODE_NESTED:
            if (forum_print_posts_nested($course, $cm, $forum, $discussion, $post, $ratings, $reply, $forumtracked, $posts)) {
                $ratingsmenuused = true;
            }
            break;
    }
    if ($ratingsformused) {
        if ($ratingsmenuused) {
            echo '<div class="ratingsubmit">';
            echo '<input type="submit" id="forumpostratingsubmit" value="' . get_string('sendinratings', 'forum') . '" />';
            if (ajaxenabled() && !empty($CFG->forum_ajaxrating)) {
                /// AJAX enabled, standard submission form
                $PAGE->requires->js_function_call('add_menu_listeners', array($OUTPUT->old_icon_url('i/loading_small')))->on_dom_ready();
            }
            if ($forum->scale < 0) {
                if ($scale = $DB->get_record("scale", array("id" => abs($forum->scale)))) {
                    echo $OUTPUT->help_button(help_button::make_scale_menu($course->id, $scale));
                }
            }
            echo '</div>';
        }
        echo '</div>';
        echo '</form>';
    }
}