protected function process_enrollments(&$courselist) { global $DB; // Locate and annotate any courses that have existing. // Enrollments. $strhasenrollments = get_string('hasenrollments', 'block_iomad_company_admin'); $strsharedhasenrollments = get_string('sharedhasenrollments', 'block_iomad_company_admin'); foreach ($courselist as $id => $course) { if ($DB->get_record_sql("SELECT id\n FROM {iomad_courses}\n WHERE courseid={$id}\n AND shared = 0")) { // Deal with own courses. $context = context_course::instance($id); if (count_enrolled_users($context) > 0) { $courselist[$id]->hasenrollments = true; $courselist[$id]->fullname = "<span class=\"hasenrollments\">\n {$course->fullname} ({$strhasenrollments})</span>"; $this->hasenrollments = true; } } if ($DB->get_record_sql("SELECT id\n FROM {iomad_courses}\n WHERE courseid={$id}\n AND shared = 2")) { // Deal with closed shared courses. if ($companygroup = company::get_company_group($this->companyid, $id)) { if ($DB->get_records('groups_members', array('groupid' => $companygroup->id))) { $courselist[$id]->hasenrollments = true; $courselist[$id]->fullname = "<span class=\"hasenrollments\">\n {$course->fullname} ({$strsharedhasenrollments})</span>"; $this->hasenrollments = true; } } } } }
public function take_from_form_data($formdata) { global $DB, $USER; // TODO: WARNING - $formdata is unclean - comes from direct $_POST - ideally needs a rewrite but we do some cleaning below. $statuses = implode(',', array_keys((array) $this->get_statuses())); $now = time(); $sesslog = array(); $formdata = (array) $formdata; foreach ($formdata as $key => $value) { if (substr($key, 0, 4) == 'user') { $sid = substr($key, 4); if (!(is_numeric($sid) && is_numeric($value))) { // Sanity check on $sid and $value. print_error('nonnumericid', 'attendance'); } $sesslog[$sid] = new stdClass(); $sesslog[$sid]->studentid = $sid; // We check is_numeric on this above. $sesslog[$sid]->statusid = $value; // We check is_numeric on this above. $sesslog[$sid]->statusset = $statuses; $sesslog[$sid]->remarks = array_key_exists('remarks' . $sid, $formdata) ? clean_param($formdata['remarks' . $sid], PARAM_TEXT) : ''; $sesslog[$sid]->sessionid = $this->pageparams->sessionid; $sesslog[$sid]->timetaken = $now; $sesslog[$sid]->takenby = $USER->id; } } $dbsesslog = $this->get_session_log($this->pageparams->sessionid); foreach ($sesslog as $log) { if ($log->statusid) { if (array_key_exists($log->studentid, $dbsesslog)) { $log->id = $dbsesslog[$log->studentid]->id; $DB->update_record('attendance_log', $log); } else { $DB->insert_record('attendance_log', $log, false); } } } $session = $this->get_session_info($this->pageparams->sessionid); $session->lasttaken = $now; $session->lasttakenby = $USER->id; $DB->update_record('attendance_sessions', $session); if ($this->grade != 0) { $this->update_users_grade(array_keys($sesslog)); } // Create url for link in log screen. $params = array('sessionid' => $this->pageparams->sessionid, 'grouptype' => $this->pageparams->grouptype); $event = \mod_attendance\event\attendance_taken::create(array('objectid' => $this->id, 'context' => $this->context, 'other' => $params)); $event->add_record_snapshot('course_modules', $this->cm); $event->add_record_snapshot('attendance_sessions', $session); $event->trigger(); $group = 0; if ($this->pageparams->grouptype != self::SESSION_COMMON) { $group = $this->pageparams->grouptype; } else { if ($this->pageparams->group) { $group = $this->pageparams->group; } } $totalusers = count_enrolled_users(context_module::instance($this->cm->id), 'mod/attendance:canbelisted', $group); $usersperpage = $this->pageparams->perpage; if (!empty($this->pageparams->page) && $this->pageparams->page && $totalusers && $usersperpage) { $numberofpages = ceil($totalusers / $usersperpage); if ($this->pageparams->page < $numberofpages) { $params['page'] = $this->pageparams->page + 1; redirect($this->url_take($params), get_string('moreattendance', 'attendance')); } } redirect($this->url_manage(), get_string('attendancesuccess', 'attendance')); }
/** * Print course participants. Called by message_print_contact_selector() * @param object $context the course context * @param int $courseid the course ID * @param string $contactselecturl the url to send the user to when a contact's name is clicked * @param bool $showactionlinks show action links (add/remove contact etc) next to the users * @param string $titletodisplay Optionally specify a title to display above the participants * @param int $page if there are so many users listed that they have to be split into pages what page are we viewing * @param object $user2 the user $user1 is talking to. They will be highlighted if they appear in the list of participants * @return void */ function message_print_participants($context, $courseid, $contactselecturl=null, $showactionlinks=true, $titletodisplay=null, $page=0, $user2=null) { global $DB, $USER, $PAGE, $OUTPUT; if (empty($titletodisplay)) { $titletodisplay = get_string('participants'); } $countparticipants = count_enrolled_users($context); $participants = get_enrolled_users($context, '', 0, 'u.*', '', $page*MESSAGE_CONTACTS_PER_PAGE, MESSAGE_CONTACTS_PER_PAGE); $pagingbar = new paging_bar($countparticipants, $page, MESSAGE_CONTACTS_PER_PAGE, $PAGE->url, 'page'); echo $OUTPUT->render($pagingbar); echo html_writer::start_tag('table', array('id' => 'message_participants', 'class' => 'boxaligncenter', 'cellspacing' => '2', 'cellpadding' => '0', 'border' => '0')); echo html_writer::start_tag('tr'); echo html_writer::tag('td', $titletodisplay, array('colspan' => 3, 'class' => 'heading')); echo html_writer::end_tag('tr'); //todo these need to come from somewhere if the course participants list is to show users with unread messages $iscontact = true; $isblocked = false; foreach ($participants as $participant) { if ($participant->id != $USER->id) { $participant->messagecount = 0;//todo it would be nice if the course participant could report new messages message_print_contactlist_user($participant, $iscontact, $isblocked, $contactselecturl, $showactionlinks, $user2); } } echo html_writer::end_tag('table'); }
/** * Print course participants. Called by message_print_contact_selector() * * @param object $context the course context * @param int $courseid the course ID * @param string $contactselecturl the url to send the user to when a contact's name is clicked * @param bool $showactionlinks show action links (add/remove contact etc) next to the users * @param string $titletodisplay Optionally specify a title to display above the participants * @param int $page if there are so many users listed that they have to be split into pages what page are we viewing * @param object $user2 the user $user1 is talking to. They will be highlighted if they appear in the list of participants * @return void */ function message_print_participants($context, $courseid, $contactselecturl=null, $showactionlinks=true, $titletodisplay=null, $page=0, $user2=null) { global $DB, $USER, $PAGE, $OUTPUT; if (empty($titletodisplay)) { $titletodisplay = get_string('participants'); } $countparticipants = count_enrolled_users($context); list($esql, $params) = get_enrolled_sql($context); $params['mcuserid'] = $USER->id; $ufields = user_picture::fields('u'); $sql = "SELECT $ufields, mc.id as contactlistid, mc.blocked FROM {user} u JOIN ($esql) je ON je.id = u.id LEFT JOIN {message_contacts} mc ON mc.contactid = u.id AND mc.userid = :mcuserid WHERE u.deleted = 0"; $participants = $DB->get_records_sql($sql, $params, $page * MESSAGE_CONTACTS_PER_PAGE, MESSAGE_CONTACTS_PER_PAGE); $pagingbar = new paging_bar($countparticipants, $page, MESSAGE_CONTACTS_PER_PAGE, $PAGE->url, 'page'); $pagingbar->maxdisplay = 4; echo $OUTPUT->render($pagingbar); echo html_writer::start_tag('div', array('id' => 'message_participants', 'class' => 'boxaligncenter')); echo html_writer::tag('div' , $titletodisplay, array('class' => 'heading')); $users = ''; foreach ($participants as $participant) { if ($participant->id != $USER->id) { $iscontact = false; $isblocked = false; if ( $participant->contactlistid ) { if ($participant->blocked == 0) { // Is contact. Is not blocked. $iscontact = true; $isblocked = false; } else { // Is blocked. $iscontact = false; $isblocked = true; } } $participant->messagecount = 0;//todo it would be nice if the course participant could report new messages $content = message_print_contactlist_user($participant, $iscontact, $isblocked, $contactselecturl, $showactionlinks, $user2); $users .= html_writer::tag('li', $content); } } if (strlen($users) > 0) { echo html_writer::tag('ul', $users, array('id' => 'message-courseparticipants', 'class' => 'message-contacts')); } echo html_writer::end_tag('div'); }
/** * Load a count of users enrolled in the current course with the specified permission and group (0 for no group) * * @param int $currentgroup * @return int number of matching users */ public function count_participants($currentgroup) { return count_enrolled_users($this->context, "mod/assign:submit", $currentgroup); }
/** * Get total participant count for specific courseid. * * @param $courseid * @param $modname the name of the module, used to build a capability check * @return int */ public static function course_participant_count($courseid, $modname = null) { static $participantcount = array(); // Incorporate the modname in the static cache index. $idx = $courseid . $modname; if (!isset($participantcount[$idx])) { // Use the modname to determine the best capability. switch ($modname) { case 'assign': $capability = 'mod/assign:submit'; break; case 'quiz': $capability = 'mod/quiz:attempt'; break; case 'choice': $capability = 'mod/choice:choose'; break; case 'feedback': $capability = 'mod/feedback:complete'; break; default: // If no modname is specified, assume a count of all users is required $capability = ''; } $context = \context_course::instance($courseid); $onlyactive = true; $enrolled = count_enrolled_users($context, $capability, null, $onlyactive); $participantcount[$idx] = $enrolled; } return $participantcount[$idx]; }
/** * Get total participant count for specific courseid. * * @param $courseid * @return int */ public static function course_participant_count($courseid) { static $participantcount = array(); if (!isset($participantcount[$courseid])) { $context = \context_course::instance($courseid); $onlyactive = true; $capability = 'mod/assign:submit'; $enrolled = count_enrolled_users($context, $capability, null, $onlyactive); $participantcount[$courseid] = $enrolled; } return $participantcount[$courseid]; }
/** * returns object with information about registrations/queues for each group * (optional with userdata) * if $user == 0 no userdata is returned * else if $user == null data about $USERs registrations/queues is added * else data about $userids registrations/queues is added * * @param int $userid id of user for whom data should be added * or 0 (=$USER) or null (=no userdata) * @return object object containing information about active groups */ public function get_registration_stats($userid = null) { global $USER, $DB; $return = new stdClass(); $return->group_places = 0; $return->free_places = 0; $return->occupied_places = 0; $return->users = 0; $return->registered = array(); $return->queued = array(); $return->queued_users = 0; $return->reg_users = 0; switch ($userid) { case null: $userid = $USER->id; default: $groups = $this->get_active_groups(false, false); break; case 0: $groups = $this->get_active_groups(); } foreach ($groups as $group) { $group = $this->get_active_groups(true, true, $group->agrpid, $group->id); $group = current($group); if ($this->grouptool->use_size) { $return->group_places += $group->grpsize; } $return->occupied_places += count($group->registered); if ($userid != 0) { $regrank = $this->get_rank_in_queue($group->registered, $userid); if (!empty($regrank)) { $regdata = new stdClass(); $regdata->rank = $regrank; $regdata->grpname = $group->name; $regdata->agrpid = $group->agrpid; reset($group->registered); do { $current = current($group->registered); $regdata->timestamp = $current->timestamp; next($group->registered); } while ($current->userid != $userid); $regdata->id = $group->id; $return->registered[] = $regdata; } $queuerank = $this->get_rank_in_queue($group->queued, $userid); if (!empty($queuerank)) { $queuedata = new stdClass(); $queuedata->rank = $queuerank; $queuedata->grpname = $group->name; $queuedata->agrpid = $group->agrpid; reset($group->queued); do { $current = current($group->queued); $queuedata->timestamp = $current->timestamp; next($group->queued); } while ($current->userid != $userid); $queuedata->id = $group->id; $return->queued[] = $queuedata; } } } $return->free_places = $this->grouptool->use_size ? $return->group_places - $return->occupied_places : null; $return->users = count_enrolled_users($this->context, 'mod/grouptool:register'); $agrps = $DB->get_records('grouptool_agrps', array('grouptoolid' => $this->cm->instance, 'active' => 1)); if (is_array($agrps) && count($agrps) >= 1) { $agrpids = array_keys($agrps); list($inorequal, $params) = $DB->get_in_or_equal($agrpids); $sql = "SELECT count(DISTINCT userid)\n FROM {grouptool_registered}\n WHERE modified_by >= 0 AND agrpid " . $inorequal; $return->reg_users = $DB->count_records_sql($sql, $params); $sql = "SELECT count(DISTINCT userid)\n FROM {grouptool_queued}\n WHERE agrpid " . $inorequal; $return->queued_users = $DB->count_records_sql($sql, $params); } else { $return->reg_users = 0; } $return->notreg_users = $return->users - $return->reg_users; return $return; }
/** * Displays the core ("index") page for the Paper Copy report. */ protected function display_index() { global $OUTPUT; //calculate the class's enrollment; this determines the default number of papercopies to create $enrollment = count_enrolled_users($this->context); //output the header for "mass upload grades" echo $OUTPUT->heading(get_string('massuploadattempts', 'quiz_papercopy')); $mform = new quiz_papercopy_import_form($this->cm->id); $mform->display(); //output the header for "create paper copies" echo $OUTPUT->heading(get_string('createcopies', 'quiz_papercopy')); $mform = new quiz_papercopy_create_form($this->cm->id, $enrollment); $mform->display(); //output the batch display view echo $OUTPUT->heading(get_string('modifyattempts', 'quiz_papercopy')); echo html_writer::empty_tag('br'); echo $this->display_batches(); return true; }
foreach ($json as $n => $data) { if ($data['help']) { $users[$answer->id_user]->help++; } elseif ($data['content'] == $solutions[$answer->id_cue]->json[$n]) { $users[$answer->id_user]->success++; } elseif ($data['content'] != '') { $users[$answer->id_user]->error++; } } } } // Add the users to the table foreach ($users as $user) { // For each user add data $table->data[] = array(html_writer::link(new moodle_url('/mod/elang/view.php', array('id' => $cm->id, 'id_user' => $user->id)), sprintf(get_string('studentformatname', 'elang'), $user->firstname, $user->lastname)), $user->email, $user->success, $user->help, $user->error, $count - $user->success - $user->help - $user->error); } // Define alignments $table->align = array(null, null, 'right', 'right', 'right', 'right'); // Output the table echo html_writer::table($table); if ($perpage > 0) { // Output the pagination echo $OUTPUT->paging_bar(count_enrolled_users($context, 'mod/elang:isinreport', $id_group), $page, $perpage, new moodle_url('/mod/elang/view.php', array('id' => $cm->id))); } // Displays the form $mform->display(); // Finish the page. echo $OUTPUT->footer(); } die; }
private function construct_take_controls(attendance_take_data $takedata) { global $CFG; $controls = ''; $group = 0; if ($takedata->pageparams->grouptype != attendance::SESSION_COMMON) { $group = $takedata->pageparams->grouptype; } else { if ($takedata->pageparams->group) { $group = $takedata->pageparams->group; } } if (!empty($CFG->enablegroupmembersonly) and $takedata->cm->groupmembersonly) { if ($group == 0) { $groups = array_keys(groups_get_all_groups($takedata->cm->course, 0, $takedata->cm->groupingid, 'g.id')); } else { $groups = $group; } $users = get_users_by_capability(context_module::instance($takedata->cm->id), 'mod/attendance:canbelisted', 'u.id, u.firstname, u.lastname, u.email', '', '', '', $groups, '', false, true); $totalusers = count($users); } else { $totalusers = count_enrolled_users(context_module::instance($takedata->cm->id), 'mod/attendance:canbelisted', $group); } $usersperpage = $takedata->pageparams->perpage; if (!empty($takedata->pageparams->page) && $takedata->pageparams->page && $totalusers && $usersperpage) { $controls .= html_writer::empty_tag('br'); $numberofpages = ceil($totalusers / $usersperpage); if ($takedata->pageparams->page > 1) { $controls .= html_writer::link($takedata->url(array('page' => $takedata->pageparams->page - 1)), $this->output->larrow()); } $controls .= html_writer::tag('span', "Page {$takedata->pageparams->page} of {$numberofpages}", array('class' => 'attbtn')); if ($takedata->pageparams->page < $numberofpages) { $controls .= html_writer::link($takedata->url(array('page' => $takedata->pageparams->page + 1, 'perpage' => $takedata->pageparams->perpage)), $this->output->rarrow()); } } if ($takedata->pageparams->grouptype == attendance::SESSION_COMMON and ($takedata->groupmode == VISIBLEGROUPS or $takedata->groupmode and $takedata->perm->can_access_all_groups())) { $controls .= groups_print_activity_menu($takedata->cm, $takedata->url(), true); } $controls .= html_writer::empty_tag('br'); $options = array(att_take_page_params::SORTED_LIST => get_string('sortedlist', 'attendance'), att_take_page_params::SORTED_GRID => get_string('sortedgrid', 'attendance')); $select = new single_select($takedata->url(), 'viewmode', $options, $takedata->pageparams->viewmode, null); $select->set_label(get_string('viewmode', 'attendance')); $select->class = 'singleselect inline'; $controls .= $this->output->render($select); if ($takedata->pageparams->viewmode == att_take_page_params::SORTED_LIST) { $options = array(0 => get_string('donotusepaging', 'attendance'), get_config('attendance', 'resultsperpage') => get_config('attendance', 'resultsperpage')); $select = new single_select($takedata->url(), 'perpage', $options, $takedata->pageparams->perpage, null); $select->class = 'singleselect inline'; $controls .= $this->output->render($select); } if ($takedata->pageparams->viewmode == att_take_page_params::SORTED_GRID) { $options = array(1 => '1 ' . get_string('column', 'attendance'), '2 ' . get_string('columns', 'attendance'), '3 ' . get_string('columns', 'attendance'), '4 ' . get_string('columns', 'attendance'), '5 ' . get_string('columns', 'attendance'), '6 ' . get_string('columns', 'attendance'), '7 ' . get_string('columns', 'attendance'), '8 ' . get_string('columns', 'attendance'), '9 ' . get_string('columns', 'attendance'), '10 ' . get_string('columns', 'attendance')); $select = new single_select($takedata->url(), 'gridcols', $options, $takedata->pageparams->gridcols, null); $select->class = 'singleselect inline'; $controls .= $this->output->render($select); } if (count($takedata->sessions4copy) > 0) { $controls .= html_writer::empty_tag('br'); $controls .= html_writer::empty_tag('br'); $options = array(); foreach ($takedata->sessions4copy as $sess) { $start = userdate($sess->sessdate, get_string('strftimehm', 'attendance')); $end = $sess->duration ? ' - ' . userdate($sess->sessdate + $sess->duration, get_string('strftimehm', 'attendance')) : ''; $options[$sess->id] = $start . $end; } $select = new single_select($takedata->url(array(), array('copyfrom')), 'copyfrom', $options); $select->set_label(get_string('copyfrom', 'attendance')); $select->class = 'singleselect inline'; $controls .= $this->output->render($select); } return $controls; }
function message_print_participants($context, $courseid, $contactselecturl = null, $showactionlinks = true, $titletodisplay = null, $page = 0, $user2 = null) { global $DB, $USER, $PAGE, $OUTPUT; $countparticipants = count_enrolled_users($context); $participants = get_enrolled_users($context, '', 0, 'u.*', '', $page * MESSAGE_CONTACTS_PER_PAGE, MESSAGE_CONTACTS_PER_PAGE); $pagingbar = new paging_bar($countparticipants, $page, MESSAGE_CONTACTS_PER_PAGE, $PAGE->url, 'page'); echo $OUTPUT->render($pagingbar); echo '<table id="message_participants" class="boxaligncenter" cellspacing="2" cellpadding="0" border="0">'; if (!empty($titletodisplay)) { echo "<tr><td colspan='3' class='heading'>{$titletodisplay}</td></tr>"; } if (empty($titletodisplay)) { echo '<tr><td colspan="3" class="heading">'; echo get_string('participants'); echo '</td></tr>'; } //todo these need to come from somewhere if the course participants list is to show users with unread messages $iscontact = true; $isblocked = false; foreach ($participants as $participant) { if ($participant->id != $USER->id) { $participant->messagecount = 0; //todo it would be nice if the course participant could report new messages message_print_contactlist_user($participant, $iscontact, $isblocked, $contactselecturl, $showactionlinks, $user2); } } //$participants->close(); echo '</table>'; }
/** * Create new users, enrol them in default courses, assert that each default * course has the new users. */ public function test_enrol_default_courses() { // Make the dummy course a default course. set_config('courseids', $this->dummycourse->id, 'local_defaultcourses'); // Try to enrol users (none) in the default course. dc_enrol_default_courses(); // How many enrolments are there? $initialenrolcount = count_enrolled_users($this->dummycoursecontext); // Expected: no enrolments. $this->assertEquals(0, $initialenrolcount); // Create three dummy users. $this->user = $this->getDataGenerator()->create_user(array('email' => '*****@*****.**', 'username' => 'dctestuser')); $this->user2 = $this->getDataGenerator()->create_user(array('email' => '*****@*****.**', 'username' => 'dctestuser2')); $this->user3 = $this->getDataGenerator()->create_user(array('email' => '*****@*****.**', 'username' => 'dctestuser3')); // Try again to enrol users (three) in the default course. dc_enrol_default_courses(); // How many enrolments are there now? $subsequentenrolcount = count_enrolled_users($this->dummycoursecontext); // Expected: three enrolments. $this->assertEquals(3, $subsequentenrolcount); }
protected function get_qubaids_condition() { $where = "quiza.quiz = :mangrquizid AND\n quiza.preview = 0 AND\n quiza.state = :statefinished"; $params = array('mangrquizid' => $this->cm->instance, 'statefinished' => quiz_attempt::FINISHED); $usersjoin = ''; $currentgroup = groups_get_activity_group($this->cm, true); $enrolleduserscount = count_enrolled_users($this->context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), $currentgroup); if ($currentgroup) { $userssql = get_enrolled_sql($this->context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), $currentgroup); if ($enrolleduserscount < 1) { $where .= ' AND quiza.userid = 0'; } else { $usersjoin = "JOIN ({$userssql[0]}) AS enr ON quiza.userid = enr.id"; $params += $userssql[1]; } } return new qubaid_join("{quiz_attempts} quiza {$usersjoin} ", 'quiza.uniqueid', $where, $params); }
public static function get_course_info($courseID) { global $DB; console . log("in course_info. CourseID: " + $courseID); //check parameters $params = self::validate_parameters(self::get_course_info_parameters(), array('courseID' => $courseID)); // now security checks $coursecontext = context_course::instance($params['courseID']); self::validate_context($coursecontext); //Is the user allowes to use this web service? //require_capability('moodle/site:viewparticipants', $context); // is the user normaly allowed to see all participants of the course require_capability('tool/supporter:get_course_info', $coursecontext); // is the user coursecreator, manager, teacher, editingteacher $select = "SELECT c.id, c.shortname, c.fullname, c.visible, cat.name AS fb, (SELECT name FROM {course_categories} WHERE id = cat.parent) AS semester FROM {course} c, {course_categories} cat WHERE c.category = cat.id AND c.id = '{$courseID}'"; $courseDetails = $DB->get_record_sql($select); $courseDetails = (array) $courseDetails; $courseDetails['enrolledUsers'] = count_enrolled_users($coursecontext, $withcapability = '', $groupid = '0'); $roles = array(); $roleList = get_all_roles($coursecontext); // array('moodle/legacy:student', 'moodle/legacy:teacher', 'moodle/legacy:editingteacher', 'moodle/legacy:coursecreator'); $count = count_role_users([1, 2, 3, 4, 5, 6, 7], $coursecontext); print_r($roleList); echo "count"; print_r($count); foreach ($roleList as $r) { if ($r->coursealias != NULL) { $roleName = $r->coursealias; } else { $roleName = $r->shortname; } $roleNumber = count_role_users($r->id, $coursecontext); //$roleNumber = count_enrolled_users($coursecontext, $withcapability = $role, $groupid = 0); if ($roleNumber != 0) { $roles[] = ['roleName' => $roleName, 'roleNumber' => $roleNumber]; } } $users_raw = get_enrolled_users($coursecontext, $withcapability = '', $groupid = 0, $userfields = 'u.id,u.username,u.firstname, u.lastname', $orderby = '', $limitfrom = 0, $limitnum = 0); $users = array(); foreach ($users_raw as $u) { $users[] = (array) $u; } $activities = array(); $modules = get_array_of_activities($courseID); foreach ($modules as $mo) { $section = get_section_name($courseID, $mo->section); $activity = ['section' => $section, 'activity' => $mo->mod, 'name' => $mo->name, 'visible' => $mo->visible]; $activities[] = $activity; } $data = ['courseDetails' => $courseDetails, 'roles' => $roles, 'users' => $users, 'activities' => $activities]; return $data; }
/** * This is a standard Moodle module that prints out a summary of all activities of this kind in the My Moodle page for a user * * @param object $courses * @param object $htmlarray * @global type $USER * @global type $CFG * @global type $DB * @global type $OUTPUT * @return bool success */ function turnitintooltwo_print_overview($courses, &$htmlarray) { global $USER, $CFG, $DB, $OUTPUT; if (empty($courses) || !is_array($courses) || count($courses) == 0) { return array(); } if (!($turnitintooltwos = get_all_instances_in_courses('turnitintooltwo', $courses))) { return; } $submissioncount = array(); foreach ($turnitintooltwos as $key => $turnitintooltwo) { $turnitintooltwoassignment = new turnitintooltwo_assignment($turnitintooltwo->id, $turnitintooltwo); $parts = $turnitintooltwoassignment->get_parts(false); $cm = get_coursemodule_from_id('turnitintooltwo', $turnitintooltwo->coursemodule); $context = context_module::instance($cm->id); $partsarray = array(); $grader = has_capability('mod/turnitintooltwo:grade', $context); if ($grader) { $submissionsquery = $DB->get_records_select('turnitintooltwo_submissions', 'turnitintooltwoid = ? GROUP BY id, submission_part, submission_grade, submission_gmimaged', array($turnitintooltwo->id), '', 'id, submission_part, submission_grade, submission_gmimaged'); foreach ($submissionsquery as $submission) { if (!isset($submissioncount[$submission->submission_part])) { $submissioncount[$submission->submission_part] = array('graded' => 0, 'submitted' => 0); } if ($submission->submission_grade != 'NULL' and $submission->submission_gmimaged == 1) { $submissioncount[$submission->submission_part]['graded']++; } $submissioncount[$submission->submission_part]['submitted']++; } } foreach ($parts as $part) { if (!isset($submissioncount[$part->id])) { $submissioncount[$part->id] = array('graded' => 0, 'submitted' => 0); } $partsarray[$part->id]['name'] = $part->partname; $partsarray[$part->id]['dtdue'] = $part->dtdue; if ($grader) { // If user is a grader. $numsubmissions = $submissioncount[$part->id]['submitted']; $graded = $submissioncount[$part->id]['graded']; $input = new stdClass(); $input->submitted = $numsubmissions; $input->graded = $graded; $input->total = count_enrolled_users($context, 'mod/turnitintooltwo:submit', 0); $input->gplural = $graded != 1 ? 's' : ''; $partsarray[$part->id]['status'] = get_string('tutorstatus', 'turnitintooltwo', $input); } else { // If user is a student. $submission = $turnitintooltwoassignment->get_submissions($cm, $part->id, $USER->id, 1); if (!empty($submission[$part->id][$USER->id])) { $input = new stdClass(); $input->modified = userdate($submission[$part->id][$USER->id]->submission_modified, get_string('strftimedatetimeshort', 'langconfig')); $input->objectid = $submission[$part->id][$USER->id]->submission_objectid; $partsarray[$part->id]['status'] = get_string('studentstatus', 'turnitintooltwo', $input); } else { $partsarray[$part->id]['status'] = get_string('nosubmissions', 'turnitintooltwo'); } } } $attributes["class"] = $turnitintooltwo->visible ? "" : "dimmed"; $attributes["title"] = get_string('modulename', 'turnitintooltwo'); $assignmentlink = html_writer::link($CFG->wwwroot . "/mod/turnitintooltwo/view.php?id=" . $turnitintooltwo->coursemodule, $turnitintooltwo->name, $attributes); $partsblock = ""; foreach ($partsarray as $thispart) { $partstr = $thispart['name'] . ' - ' . get_string('dtdue', 'turnitintooltwo') . ': ' . userdate($thispart['dtdue'], get_string('strftimedatetimeshort', 'langconfig'), $USER->timezone); $partsblock .= $OUTPUT->box($OUTPUT->box($partstr, 'bold') . $OUTPUT->box($thispart['status'], 'italic'), 'info'); } $str = html_writer::tag('div', html_writer::tag('div', get_string('modulename', 'turnitintooltwo') . ": " . $assignmentlink . $partsblock, array('class' => 'name')), array('class' => 'turnitintooltwo overview')); if (empty($htmlarray[$turnitintooltwo->course]['turnitintooltwo'])) { $htmlarray[$turnitintooltwo->course]['turnitintooltwo'] = $str; } else { $htmlarray[$turnitintooltwo->course]['turnitintooltwo'] .= $str; } } }