function taoview_sort_artefacts($artefacts, $viewtype, $tagfilter = '', $userfilter = '', $sort = '') { global $CFG; $returnartefacts = array(); $ratings = array(); echo ' <div class="sortby">' . get_string('sortby', 'local') . ': '; if (empty($sort) || $sort == 'date') { echo get_string('date') . ' | <a href="' . $CFG->wwwroot . '/local/mahara/taoview' . $viewtype . '.php?tag=' . $tagfilter . '&filteruser='******'&sort=rating">' . get_string('rating', 'local') . '</a>'; return $artefacts; } elseif ($sort == 'rating') { echo '<a href="' . $CFG->wwwroot . '/local/mahara/taoview' . $viewtype . '.php?tag=' . $tagfilter . '&filteruser='******'">' . get_string('date') . '</a> | ' . get_string('rating', 'local'); $scale = get_record("scale", "name", 'TAO: Stars'); $scalevars = explode(',', $scale->scale); $possiblevalues = array(); //use values instead of the scale so we can order them! $i = 1; foreach ($scalevars as $sc) { $possiblevalues[$i] = $i; $i++; } echo '<div class="ratings">'; foreach ($artefacts as $aid => $artefact) { $ratings[$aid] = tao_get_ratings_mean($artefact['id'], $possiblevalues); } arsort($ratings); foreach ($ratings as $id => $rat) { $returnartefacts[] = $artefacts[$id]; } } echo '</div>'; return $returnartefacts; }
function tao_print_ratings($artefactid, $possiblevalues, $return = false) { $str = get_string('rating', 'local') . ': ' . tao_get_ratings_mean($artefactid, $possiblevalues); if ($return) { return $str; } echo $str; }