Example #1
0
function taoview_print_artefacts($artefacts, $viewtype, $tagfilter, $userfilter, $sort, $page, $perpage)
{
    global $CFG, $USER;
    //get scale
    $scale = get_record("scale", "name", 'TAO: Stars');
    $artefacts = taoview_get_paginated_results($artefacts, $page, $perpage);
    foreach ($artefacts as $artefact) {
        if ($perpage <= 0) {
            //not a great way to paginate.
            break;
        }
        echo '<div class="taoview">';
        if (!empty($artefact['thumbnail'])) {
            echo '<div class="taoview-thumb"><img src="' . $artefact['thumbnail'] . '"></div>';
        }
        echo '<div class="taoview-download"><a href="' . $artefact['download'] . '" target="_blank">' . $artefact['name'] . '</a></div>';
        if (!empty($artefact['uploader'])) {
            $user = get_record('user', 'username', $artefact['uploader']);
            if (!empty($user)) {
                echo '<div class="taoview-user">' . get_string('submittedby', 'local') . ': <a href="' . $CFG->wwwroot . '/local/mahara/taoview' . $viewtype . '.php?tag=' . $tagfilter . '&filteruser='******'uploader'] . '&sort=' . $sort . '">' . fullname($user) . '</a></div>';
            }
        }
        if (!empty($artefact['ctime'])) {
            echo '<div class="taoview-date">' . $artefact['ctime'] . '</div>';
        }
        if (!empty($artefact['description'])) {
            echo '<div class="taoview-desc">' . $artefact['description'] . '</div>';
        }
        if (!empty($artefact['tags']) && is_array($artefact['tags'])) {
            echo '<div class="taoview-tags">' . get_string('tags') . ': ';
            foreach ($artefact['tags'] as $tag) {
                echo '<a href="' . $CFG->wwwroot . '/local/mahara/taoview' . $viewtype . '.php?tag=' . $tag . '&sort=' . $sort . '">' . $tag . '</a>, ';
            }
            echo '</div>';
        }
        //now do ratings stuff
        echo '<div class="ratings">';
        $possiblevalues = make_grades_menu(-$scale->id);
        echo '<span class="taoviewratingtext">';
        tao_print_ratings($artefact['id'], $possiblevalues);
        echo '</span>';
        if (!empty($user) && $user->id != $USER->id && !isguest()) {
            tao_print_rating_menu($artefact['id'], $USER->id, $possiblevalues);
        }
        echo '</div>';
        //end of ratings stuff
        if (!empty($artefact['page'])) {
            echo '<div class="taoview-page"><a href="' . $artefact['page'] . '">' . get_string('moreinfo', 'local') . '</a></div>';
        }
        echo '</div>';
        $perpage--;
    }
    if (!empty($artefacts) && !isguest()) {
        echo "<div class=\"boxaligncenter\"><input id=\"taoviewratingsubmit\" type=\"submit\" value=\"" . get_string("sendinratings", "local") . "\" />";
        if (ajaxenabled()) {
            /// AJAX enabled, standard submission form
            $rate_ajax_config_settings = array("pixpath" => $CFG->pixpath, "wwwroot" => $CFG->wwwroot, "sesskey" => sesskey());
            echo "<script type=\"text/javascript\">//<![CDATA[\n" . "var rate_ajax_config = " . json_encode($rate_ajax_config_settings) . ";\n" . "init_rate_ajax();\n" . "//]]></script>\n";
        }
        //print_scale_menu_helpbutton(SITEID, $scale); //no help file written yet.
        echo "</div>";
    }
}
Example #2
0
/// Calculate scale values
$scale_values = make_grades_menu(-$scale->id);
/// Check rate is valid for for that forum scale values
if (!array_key_exists($rate, $scale_values) && $rate != FORUM_UNSET_POST_RATING) {
    print_error('invalidrate', 'local');
}
/// Everything ready, process rate
if ($oldrating = get_record('taoview_ratings', 'userid', $USER->id, 'artefactid', $artefactid)) {
    if ($rate != $oldrating->rating) {
        $oldrating->rating = $rate;
        $oldrating->time = time();
        if (!update_record('taoview_ratings', $oldrating)) {
            error("Could not update an old rating ({$artefact->id} = {$rate})");
        }
    }
    /// Inserting rate
} else {
    $newrating = new object();
    $newrating->userid = $USER->id;
    $newrating->time = time();
    $newrating->artefactid = $artefactid;
    $newrating->rating = $rate;
    if (!insert_record('taoview_ratings', $newrating)) {
        print_error('cannotinsertrate', 'error', '', (object) array('id' => $artefactid, 'rating' => $rate));
    }
}
$rateinfo = tao_print_ratings($artefactid, $scale_values, true);
/// Calculate response
$response['status'] = 'Ok';
$response['message'] = $rateinfo;
echo json_encode($response);