/** * @todo Documenting this function */ function stampcoll_user_complete($course, $user, $mod, $stampcoll) { global $USER; $context = get_context_instance(CONTEXT_MODULE, $mod->id); if ($USER->id == $user->id) { if (!has_capability('mod/stampcoll:viewownstamps', $context)) { echo get_string('notallowedtoviewstamps', 'stampcoll'); return true; } } else { if (!has_capability('mod/stampcoll:viewotherstamps', $context)) { echo get_string('notallowedtoviewstamps', 'stampcoll'); return true; } } if (!($allstamps = stampcoll_get_stamps($stampcoll->id))) { // no stamps yet in this instance echo get_string('nostampscollected', "stampcoll"); return true; } $userstamps = array(); foreach ($allstamps as $s) { if ($s->userid == $user->id) { $userstamps[] = $s; } } unset($allstamps); unset($s); if (empty($userstamps)) { echo get_string('nostampscollected', 'stampcoll'); } else { echo get_string('numberofcollectedstamps', 'stampcoll', count($userstamps)); echo '<div class="stamppictures">'; foreach ($userstamps as $s) { echo stampcoll_stamp($s, $stampcoll->image); } echo '</div>'; unset($s); } }
case 'own': $currenttab = 'viewown'; break; default: $currenttab = 'view'; break; } include dirname(__FILE__) . '/tabs.php'; /// Print activity introduction (description) if (in_array($currenttab, array('view', 'viewown')) and !empty($stampcoll->text)) { print_box(format_text($stampcoll->text), 'generalbox', 'intro'); } if (!$cap_viewsomestamps) { notice(get_string('notallowedtoviewstamps', 'stampcoll'), $CFG->wwwroot . "/course/view.php?id={$course->id}"); } $allstamps = stampcoll_get_stamps($stampcoll->id) or $allstamps = array(); if (empty($allstamps) && !$stampcoll->displayzero) { notice(get_string('nostampsincollection', 'stampcoll'), $CFG->wwwroot . "/course/view.php?id={$course->id}"); } /// Re-sort all stamps into "by-user-array" $userstamps = array(); foreach ($allstamps as $s) { if ($s->userid == $USER->id && !$cap_viewownstamps) { continue; } if ($s->userid != $USER->id && !$cap_viewotherstamps) { continue; } $userstamps[$s->userid][] = $s; } unset($allstamps);
} else { $table->head = array(get_string('name'), get_string('numberofstamps', 'stampcoll')); $table->align = array('left', 'left'); } } $currentsection = ''; foreach ($stampcolls as $stampcoll) { if (!($cm = get_coursemodule_from_instance('stampcoll', $stampcoll->id))) { error('Course Module ID was incorrect'); } $context = get_context_instance(CONTEXT_MODULE, $cm->id); include dirname(__FILE__) . '/caps.php'; if (!$cap_viewsomestamps) { $count_mystamps = get_string('notallowedtoviewstamps', 'stampcoll'); } else { if (!($allstamps = stampcoll_get_stamps($stampcoll->id))) { $allstamps = array(); } $count_totalstamps = count($allstamps); $count_mystamps = 0; foreach ($allstamps as $s) { if ($s->userid == $USER->id) { $count_mystamps++; } } unset($allstamps); unset($s); } $printsection = ''; if ($stampcoll->section !== $currentsection) { if ($stampcoll->section) {