示例#1
0
文件: view.php 项目: r007/PMoodle
        }
        /// and finally print the entry.
        if (glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook, 1, $displayformat, $ratings)) {
            $ratingsmenuused = true;
        }
        $entriesshown++;
    }
}
if (!$entriesshown) {
    print_simple_box('<div style="text-align:center">' . get_string("noentries", "glossary") . '</div>', "center", "95%");
}
if ($ratingsmenuused) {
    echo "<div class=\"boxaligncenter\"><input type=\"submit\" value=\"" . get_string("sendinratings", "glossary") . "\" />";
    if ($glossary->scale < 0) {
        if ($scale = get_record("scale", "id", abs($glossary->scale))) {
            print_scale_menu_helpbutton($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>';
}
示例#2
0
function data_print_ratings($data, $record)
{
    global $USER;
    $cm = get_coursemodule_from_instance('data', $data->id);
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    if ($data->assessed and !empty($USER->id) and (has_capability('mod/data:rate', $context) or has_capability('mod/data:viewrating', $context) or data_isowner($record->id))) {
        if ($ratingsscale = make_grades_menu($data->scale)) {
            $ratingsmenuused = false;
            echo '<div class="ratings" style="text-align:center">';
            echo '<form id="form" method="post" action="rate.php">';
            echo '<input type="hidden" name="dataid" value="' . $data->id . '" />';
            if (has_capability('mod/data:rate', $context) and !data_isowner($record->id)) {
                data_print_ratings_mean($record->id, $ratingsscale, has_capability('mod/data:viewrating', $context));
                echo '&nbsp;';
                data_print_rating_menu($record->id, $USER->id, $ratingsscale);
                $ratingsmenuused = true;
            } else {
                data_print_ratings_mean($record->id, $ratingsscale, true);
            }
            if ($data->scale < 0) {
                if ($scale = get_record('scale', 'id', abs($data->scale))) {
                    print_scale_menu_helpbutton($data->course, $scale);
                }
            }
            if ($ratingsmenuused) {
                echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
                echo '<input type="submit" value="' . get_string('sendinratings', 'data') . '" />';
            }
            echo '</form>';
            echo '</div>';
        }
    }
}
示例#3
0
文件: lib.php 项目: r007/PMoodle
/**
 *
 */
function forum_print_discussion($course, $cm, $forum, $discussion, $post, $mode, $canreply = NULL, $canrate = false)
{
    global $USER, $CFG;
    if (!empty($USER->id)) {
        $ownpost = $USER->id == $post->userid;
    } else {
        $ownpost = false;
    }
    if ($canreply === NULL) {
        $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
        $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 ($ratings->scale = make_grades_menu($forum->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" value="' . get_string('sendinratings', 'forum') . '" />';
            if ($forum->scale < 0) {
                if ($scale = get_record("scale", "id", abs($forum->scale))) {
                    print_scale_menu_helpbutton($course->id, $scale);
                }
            }
            echo '</div>';
        }
        echo '</div>';
        echo '</form>';
    }
}
示例#4
0
/**
 * 
 */
function forum_print_discussion($course, $forum, $discussion, $post, $mode, $canreply = NULL, $canrate = false)
{
    global $USER, $CFG;
    if (!empty($USER->id)) {
        $ownpost = $USER->id == $post->userid;
    } else {
        $ownpost = false;
    }
    if ($canreply === NULL) {
        $reply = forum_user_can_post($forum);
    } else {
        $reply = $canreply;
    }
    $ratings = NULL;
    $ratingsmenuused = false;
    $ratingsformused = false;
    if ($forum->assessed and !empty($USER->id)) {
        if ($ratings->scale = make_grades_menu($forum->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;
            }
        }
    }
    $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);
    if (forum_tp_can_track_forums($forum)) {
        if ($forumtracked = forum_tp_is_tracked($forum)) {
            $user_read_array = forum_tp_get_discussion_read_records($USER->id, $post->discussion);
        } else {
            $user_read_array = array();
        }
    } else {
        $forumtracked = false;
        $user_read_array = array();
    }
    if (empty($post->modcontext)) {
        // Have to generate it, which is expensive!  Should always be set.
        if (empty($post->forum)) {
            $discussion = get_record('forum_discussions', 'id', $post->discussion);
            $post->forum = $discussion->forum;
        }
        if (!($cm = get_coursemodule_from_instance('forum', $post->forum))) {
            error('Course Module ID was incorrect');
        }
        $post->modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
    }
    if (forum_print_post($post, $course->id, $ownpost, $reply, $link = false, $ratings, '', '', !$forumtracked || isset($user_read_array[$post->id]) || forum_tp_is_post_old($post))) {
        $ratingsmenuused = true;
    }
    switch ($mode) {
        case FORUM_MODE_FLATOLDEST:
        case FORUM_MODE_FLATNEWEST:
        default:
            if (forum_print_posts_flat($post->discussion, $course->id, $mode, $ratings, $reply, $user_read_array, $post->forum, $post->modcontext)) {
                $ratingsmenuused = true;
            }
            break;
        case FORUM_MODE_THREADED:
            if (forum_print_posts_threaded($post->id, $course->id, 0, $ratings, $reply, $user_read_array, $post->forum, $post->modcontext)) {
                $ratingsmenuused = true;
            }
            break;
        case FORUM_MODE_NESTED:
            if (forum_print_posts_nested($post->id, $course->id, $ratings, $reply, $user_read_array, $post->forum, $post->modcontext)) {
                $ratingsmenuused = true;
            }
            break;
    }
    if ($ratingsformused) {
        if ($ratingsmenuused) {
            echo '<div class="ratingsubmit">';
            echo '<input type="submit" value="' . get_string('sendinratings', 'forum') . '" />';
            if ($forum->scale < 0) {
                if ($scale = get_record("scale", "id", abs($forum->scale))) {
                    print_scale_menu_helpbutton($course->id, $scale);
                }
            }
            echo '</div>';
        }
        echo '</div>';
        echo '</form>';
    }
}