Browse Source

Use correct prefix on function names.

MOODLE_29_STABLE
Dan Marsden 9 years ago
parent
commit
78e8697039
  1. 2
      add_form.php
  2. 12
      classes/structure.php
  3. 6
      lib.php
  4. 26
      locallib.php
  5. 16
      renderables.php
  6. 10
      renderhelpers.php
  7. 2
      update_form.php

2
add_form.php

@ -109,7 +109,7 @@ class mod_attendance_add_form extends moodleform {
if ($maxstatusset > 0) { if ($maxstatusset > 0) {
$opts = array(); $opts = array();
for ($i = 0; $i <= $maxstatusset; $i++) { for ($i = 0; $i <= $maxstatusset; $i++) {
$opts[$i] = att_get_setname($this->_customdata['att']->id, $i); $opts[$i] = attendance_get_setname($this->_customdata['att']->id, $i);
} }
$mform->addElement('select', 'statusset', get_string('usestatusset', 'mod_attendance'), $opts); $mform->addElement('select', 'statusset', get_string('usestatusset', 'mod_attendance'), $opts);
} else { } else {

12
classes/structure.php

@ -696,8 +696,8 @@ class mod_attendance_structure {
$sessioninfo = $this->get_session_info($this->pageparams->sessionid); $sessioninfo = $this->get_session_info($this->pageparams->sessionid);
$statusset = $sessioninfo->statusset; $statusset = $sessioninfo->statusset;
} }
$this->statuses = att_get_statuses($this->id, $onlyvisible, $statusset); $this->statuses = attendance_get_statuses($this->id, $onlyvisible, $statusset);
$this->allstatuses = att_get_statuses($this->id, $onlyvisible); $this->allstatuses = attendance_get_statuses($this->id, $onlyvisible);
} }
// Return all sets, if requested. // Return all sets, if requested.
@ -757,10 +757,10 @@ class mod_attendance_structure {
public function get_user_taken_sessions_count($userid) { public function get_user_taken_sessions_count($userid) {
if (!array_key_exists($userid, $this->usertakensesscount)) { if (!array_key_exists($userid, $this->usertakensesscount)) {
if (!empty($this->pageparams->startdate) && !empty($this->pageparams->enddate)) { if (!empty($this->pageparams->startdate) && !empty($this->pageparams->enddate)) {
$this->usertakensesscount[$userid] = att_get_user_taken_sessions_count($this->id, $this->course->startdate, $this->usertakensesscount[$userid] = attendance_get_user_taken_sessions_count($this->id, $this->course->startdate,
$userid, $this->cm, $this->pageparams->startdate, $this->pageparams->enddate); $userid, $this->cm, $this->pageparams->startdate, $this->pageparams->enddate);
} else { } else {
$this->usertakensesscount[$userid] = att_get_user_taken_sessions_count($this->id, $this->course->startdate, $this->usertakensesscount[$userid] = attendance_get_user_taken_sessions_count($this->id, $this->course->startdate,
$userid, $this->cm); $userid, $this->cm);
} }
} }
@ -842,7 +842,7 @@ class mod_attendance_structure {
* @return type * @return type
*/ */
public function get_user_grade($userid, array $filters = null) { public function get_user_grade($userid, array $filters = null) {
return att_get_user_grade($this->get_user_statuses_stat($userid, $filters), $this->get_statuses(true, true)); return attendance_get_user_grade($this->get_user_statuses_stat($userid, $filters), $this->get_statuses(true, true));
} }
// For getting sessions count implemented simplest method - taken sessions. // For getting sessions count implemented simplest method - taken sessions.
@ -853,7 +853,7 @@ class mod_attendance_structure {
// While implementing those methods we need recalculate grades of all users // While implementing those methods we need recalculate grades of all users
// on session adding. // on session adding.
public function get_user_max_grade($userid) { public function get_user_max_grade($userid) {
return att_get_user_max_grade($this->get_user_taken_sessions_count($userid), $this->get_statuses(true, true)); return attendance_get_user_max_grade($this->get_user_taken_sessions_count($userid), $this->get_statuses(true, true));
} }
public function update_users_grade($userids) { public function update_users_grade($userids) {

6
lib.php

@ -227,10 +227,10 @@ function attendance_user_outline($course, $user, $mod, $attendance) {
$result->time = 0; $result->time = 0;
} }
if (has_capability('mod/attendance:canbelisted', $mod->context, $user->id)) { if (has_capability('mod/attendance:canbelisted', $mod->context, $user->id)) {
$statuses = att_get_statuses($attendance->id); $statuses = attendance_get_statuses($attendance->id);
$grade = att_get_user_grade(att_get_user_statuses_stat($attendance->id, $course->startdate, $grade = attendance_get_user_grade(attendance_get_user_statuses_stat($attendance->id, $course->startdate,
$user->id, $mod), $statuses); $user->id, $mod), $statuses);
$maxgrade = att_get_user_max_grade(att_get_user_taken_sessions_count($attendance->id, $course->startdate, $maxgrade = attendance_get_user_max_grade(attendance_get_user_taken_sessions_count($attendance->id, $course->startdate,
$user->id, $mod), $statuses); $user->id, $mod), $statuses);
$result->info = $grade.' / '.$maxgrade; $result->info = $grade.' / '.$maxgrade;

26
locallib.php

@ -37,7 +37,7 @@ define('ATT_VIEW_NOTPRESENT', 6);
define('ATT_SORT_LASTNAME', 1); define('ATT_SORT_LASTNAME', 1);
define('ATT_SORT_FIRSTNAME', 2); define('ATT_SORT_FIRSTNAME', 2);
function att_get_statuses($attid, $onlyvisible=true, $statusset = -1) { function attendance_get_statuses($attid, $onlyvisible=true, $statusset = -1) {
global $DB; global $DB;
// Set selector. // Set selector.
@ -67,10 +67,10 @@ function att_get_statuses($attid, $onlyvisible=true, $statusset = -1) {
* @param bool $includevalues * @param bool $includevalues
* @return string * @return string
*/ */
function att_get_setname($attid, $statusset, $includevalues = true) { function attendance_get_setname($attid, $statusset, $includevalues = true) {
$statusname = get_string('statusset', 'mod_attendance', $statusset + 1); $statusname = get_string('statusset', 'mod_attendance', $statusset + 1);
if ($includevalues) { if ($includevalues) {
$statuses = att_get_statuses($attid, true, $statusset); $statuses = attendance_get_statuses($attid, true, $statusset);
$statusesout = array(); $statusesout = array();
foreach ($statuses as $status) { foreach ($statuses as $status) {
$statusesout[] = $status->acronym; $statusesout[] = $status->acronym;
@ -88,7 +88,7 @@ function att_get_setname($attid, $statusset, $includevalues = true) {
return $statusname; return $statusname;
} }
function att_get_user_taken_sessions_count($attid, $coursestartdate, $userid, $coursemodule, $startdate = '', $enddate = '') { function attendance_get_user_taken_sessions_count($attid, $coursestartdate, $userid, $coursemodule, $startdate = '', $enddate = '') {
global $DB, $COURSE; global $DB, $COURSE;
$groupmode = groups_get_activity_groupmode($coursemodule, $COURSE); $groupmode = groups_get_activity_groupmode($coursemodule, $COURSE);
if (!empty($groupmode)) { if (!empty($groupmode)) {
@ -123,7 +123,7 @@ function att_get_user_taken_sessions_count($attid, $coursestartdate, $userid, $c
return $DB->count_records_sql($qry, $params); return $DB->count_records_sql($qry, $params);
} }
function att_get_user_statuses_stat($attid, $coursestartdate, $userid, $coursemodule) { function attendance_get_user_statuses_stat($attid, $coursestartdate, $userid, $coursemodule) {
global $DB, $COURSE; global $DB, $COURSE;
$groupmode = groups_get_activity_groupmode($coursemodule, $COURSE); $groupmode = groups_get_activity_groupmode($coursemodule, $COURSE);
if (!empty($groupmode)) { if (!empty($groupmode)) {
@ -154,7 +154,7 @@ function att_get_user_statuses_stat($attid, $coursestartdate, $userid, $coursemo
return $DB->get_records_sql($qry, $params); return $DB->get_records_sql($qry, $params);
} }
function att_get_user_grade($userstatusesstat, $statuses) { function attendance_get_user_grade($userstatusesstat, $statuses) {
$sum = 0; $sum = 0;
foreach ($userstatusesstat as $stat) { foreach ($userstatusesstat as $stat) {
$sum += $stat->stcnt * $statuses[$stat->statusid]->grade; $sum += $stat->stcnt * $statuses[$stat->statusid]->grade;
@ -163,12 +163,12 @@ function att_get_user_grade($userstatusesstat, $statuses) {
return $sum; return $sum;
} }
function att_get_user_max_grade($sesscount, $statuses) { function attendance_get_user_max_grade($sesscount, $statuses) {
reset($statuses); reset($statuses);
return current($statuses)->grade * $sesscount; return current($statuses)->grade * $sesscount;
} }
function att_get_user_courses_attendances($userid) { function attendance_get_user_courses_attendances($userid) {
global $DB; global $DB;
$usercourses = enrol_get_users_courses($userid); $usercourses = enrol_get_users_courses($userid);
@ -219,7 +219,7 @@ function attendance_update_all_users_grades(mod_attendance_structure $attendance
if (!empty($attgrades->items[0]) and !empty($attgrades->items[0]->grades)) { if (!empty($attgrades->items[0]) and !empty($attgrades->items[0]->grades)) {
$usergrades = $attgrades->items[0]->grades; $usergrades = $attgrades->items[0]->grades;
} }
$statuses = att_get_statuses($attendance->id); $statuses = attendance_get_statuses($attendance->id);
foreach ($usergrades as $userid => $existinggrade) { foreach ($usergrades as $userid => $existinggrade) {
if (is_null($existinggrade->grade)) { if (is_null($existinggrade->grade)) {
// Don't update grades where one doesn't exist yet. // Don't update grades where one doesn't exist yet.
@ -227,10 +227,10 @@ function attendance_update_all_users_grades(mod_attendance_structure $attendance
} }
$grade = new stdClass; $grade = new stdClass;
$grade->userid = $userid; $grade->userid = $userid;
$userstatusesstat = att_get_user_statuses_stat($attendance->id, $course->startdate, $userid, $coursemodule); $userstatusesstat = attendance_get_user_statuses_stat($attendance->id, $course->startdate, $userid, $coursemodule);
$usertakensesscount = att_get_user_taken_sessions_count($attendance->id, $course->startdate, $userid, $coursemodule); $usertakensesscount = attendance_get_user_taken_sessions_count($attendance->id, $course->startdate, $userid, $coursemodule);
$usergrade = att_get_user_grade($userstatusesstat, $statuses); $usergrade = attendance_get_user_grade($userstatusesstat, $statuses);
$usermaxgrade = att_get_user_max_grade($usertakensesscount, $statuses); $usermaxgrade = attendance_get_user_max_grade($usertakensesscount, $statuses);
$grade->rawgrade = attendance_calc_user_grade_fraction($usergrade, $usermaxgrade) * $attendance->grade; $grade->rawgrade = attendance_calc_user_grade_fraction($usergrade, $usermaxgrade) * $attendance->grade;
$grades[$userid] = $grade; $grades[$userid] = $grade;
} }

16
renderables.php

@ -387,7 +387,7 @@ class attendance_user_data implements renderable {
$this->groups = groups_get_all_groups($att->course->id); $this->groups = groups_get_all_groups($att->course->id);
} else { } else {
$this->coursesatts = att_get_user_courses_attendances($userid); $this->coursesatts = attendance_get_user_courses_attendances($userid);
$this->statuses = array(); $this->statuses = array();
$this->stat = array(); $this->stat = array();
$this->gradable = array(); $this->gradable = array();
@ -399,9 +399,9 @@ class attendance_user_data implements renderable {
unset($this->courseatts[$atid]); unset($this->courseatts[$atid]);
continue; continue;
} }
$statuses = att_get_statuses($ca->attid); $statuses = attendance_get_statuses($ca->attid);
$usertakensessionscount = att_get_user_taken_sessions_count($ca->attid, $ca->coursestartdate, $userid, $att->cm); $usertakensessionscount = attendance_get_user_taken_sessions_count($ca->attid, $ca->coursestartdate, $userid, $att->cm);
$userstatusesstat = att_get_user_statuses_stat($ca->attid, $ca->coursestartdate, $userid, $att->cm); $userstatusesstat = attendance_get_user_statuses_stat($ca->attid, $ca->coursestartdate, $userid, $att->cm);
$this->statuses[$ca->attid] = $statuses; $this->statuses[$ca->attid] = $statuses;
@ -411,13 +411,13 @@ class attendance_user_data implements renderable {
$this->gradable[$ca->attid] = $ca->attgrade > 0; $this->gradable[$ca->attid] = $ca->attgrade > 0;
if ($this->gradable[$ca->attid]) { if ($this->gradable[$ca->attid]) {
$this->grade[$ca->attid] = att_get_user_grade($userstatusesstat, $statuses); $this->grade[$ca->attid] = attendance_get_user_grade($userstatusesstat, $statuses);
// For getting sessions count implemented simplest method - taken sessions. // For getting sessions count implemented simplest method - taken sessions.
// It can have error if users don't have attendance info for some sessions. // It can have error if users don't have attendance info for some sessions.
// In the future we can implement another methods: // In the future we can implement another methods:
// * all sessions between user start enrolment date and now; // * all sessions between user start enrolment date and now;
// * all sessions between user start and end enrolment date. // * all sessions between user start and end enrolment date.
$this->maxgrade[$ca->attid] = att_get_user_max_grade($usertakensessionscount, $statuses); $this->maxgrade[$ca->attid] = attendance_get_user_max_grade($usertakensessionscount, $statuses);
} else { } else {
// For more comfortable and universal work with arrays. // For more comfortable and universal work with arrays.
$this->grade[$ca->attid] = null; $this->grade[$ca->attid] = null;
@ -498,7 +498,7 @@ class attendance_report_data implements renderable {
$this->decimalpoints = $CFG->grade_decimalpoints; $this->decimalpoints = $CFG->grade_decimalpoints;
} }
$maxgrade = att_get_user_max_grade(count($this->sessions), $this->statuses); $maxgrade = attendance_get_user_max_grade(count($this->sessions), $this->statuses);
foreach ($this->users as $key => $user) { foreach ($this->users as $key => $user) {
$grade = 0; $grade = 0;
@ -595,7 +595,7 @@ class attendance_set_selector implements renderable {
} }
public function get_status_name($statusset) { public function get_status_name($statusset) {
return att_get_setname($this->att->id, $statusset, true); return attendance_get_setname($this->att->id, $statusset, true);
} }
} }

10
renderhelpers.php

@ -270,13 +270,13 @@ function construct_user_data_stat($stat, $statuses, $gradable, $grade, $maxgrade
function construct_full_user_stat_html_table($attendance, $course, $user, $coursemodule) { function construct_full_user_stat_html_table($attendance, $course, $user, $coursemodule) {
global $CFG; global $CFG;
$gradeable = $attendance->grade > 0; $gradeable = $attendance->grade > 0;
$statuses = att_get_statuses($attendance->id); $statuses = attendance_get_statuses($attendance->id);
$userstatusesstat = att_get_user_statuses_stat($attendance->id, $course->startdate, $user->id, $coursemodule); $userstatusesstat = attendance_get_user_statuses_stat($attendance->id, $course->startdate, $user->id, $coursemodule);
$stat['completed'] = att_get_user_taken_sessions_count($attendance->id, $course->startdate, $user->id, $coursemodule); $stat['completed'] = attendance_get_user_taken_sessions_count($attendance->id, $course->startdate, $user->id, $coursemodule);
$stat['statuses'] = $userstatusesstat; $stat['statuses'] = $userstatusesstat;
if ($gradeable) { if ($gradeable) {
$grade = att_get_user_grade($userstatusesstat, $statuses); $grade = attendance_get_user_grade($userstatusesstat, $statuses);
$maxgrade = att_get_user_max_grade(att_get_user_taken_sessions_count($attendance->id, $course->startdate, $maxgrade = attendance_get_user_max_grade(attendance_get_user_taken_sessions_count($attendance->id, $course->startdate,
$user->id, $coursemodule), $statuses); $user->id, $coursemodule), $statuses);
if (!$decimalpoints = grade_get_setting($course->id, 'decimalpoints')) { if (!$decimalpoints = grade_get_setting($course->id, 'decimalpoints')) {
$decimalpoints = $CFG->grade_decimalpoints; $decimalpoints = $CFG->grade_decimalpoints;

2
update_form.php

@ -86,7 +86,7 @@ class mod_attendance_update_form extends moodleform {
$maxstatusset = attendance_get_max_statusset($this->_customdata['att']->id); $maxstatusset = attendance_get_max_statusset($this->_customdata['att']->id);
if ($maxstatusset > 0) { if ($maxstatusset > 0) {
$mform->addElement('static', 'statusset', get_string('usestatusset', 'mod_attendance'), $mform->addElement('static', 'statusset', get_string('usestatusset', 'mod_attendance'),
att_get_setname($this->_customdata['att']->id, $sess->statusset)); attendance_get_setname($this->_customdata['att']->id, $sess->statusset));
} }
$mform->addElement('editor', 'sdescription', get_string('description', 'attendance'), $mform->addElement('editor', 'sdescription', get_string('description', 'attendance'),

Loading…
Cancel
Save