From e91283a339865dc24234e4a98e962b9b9e3ec7fe Mon Sep 17 00:00:00 2001 From: Chris Stones Date: Thu, 17 Nov 2011 15:12:54 -0800 Subject: [PATCH] Appending prefixes to non prefixed functions and defines --- lib.php | 6 +-- locallib.php | 94 +++++++++++++++++++++++------------------------ manage.php | 2 +- preferences.php | 2 +- renderables.php | 26 ++++++------- renderer.php | 2 +- renderhelpers.php | 6 +-- 7 files changed, 69 insertions(+), 69 deletions(-) diff --git a/lib.php b/lib.php index 5a9a205..38f81ee 100644 --- a/lib.php +++ b/lib.php @@ -179,9 +179,9 @@ function attforblock_user_outline($course, $user, $mod, $attforblock) { else $result->time = 0; if (has_capability('mod/attforblock:canbelisted', $mod->context, $user->id)) { - $statuses = get_statuses($attforblock->id); - $grade = get_user_grade(get_user_statuses_stat($attforblock->id, $course->startdate, $user->id), $statuses); - $maxgrade = get_user_max_grade(get_user_taken_sessions_count($attforblock->id, $course->startdate, $user->id), $statuses); + $statuses = att_get_statuses($attforblock->id); + $grade = att_get_user_grade(get_user_statuses_stat($attforblock->id, $course->startdate, $user->id), $statuses); + $maxgrade = att_get_user_max_grade(get_user_taken_sessions_count($attforblock->id, $course->startdate, $user->id), $statuses); $result->info = $grade.' / '.$maxgrade; } diff --git a/locallib.php b/locallib.php index 5aab43d..4fcf604 100644 --- a/locallib.php +++ b/locallib.php @@ -6,14 +6,14 @@ require_once($CFG->libdir . '/gradelib.php'); require_once(dirname(__FILE__).'/renderhelpers.php'); -define('VIEW_DAYS', 1); -define('VIEW_WEEKS', 2); -define('VIEW_MONTHS', 3); -define('VIEW_ALLPAST', 4); -define('VIEW_ALL', 5); +define('ATT_VIEW_DAYS', 1); +define('ATT_VIEW_WEEKS', 2); +define('ATT_VIEW_MONTHS', 3); +define('ATT_VIEW_ALLPAST', 4); +define('ATT_VIEW_ALL', 5); -define('SORT_LASTNAME', 1); -define('SORT_FIRSTNAME', 2); +define('ATT_SORT_LASTNAME', 1); +define('ATT_SORT_FIRSTNAME', 2); class attforblock_permissions { private $canview; @@ -139,7 +139,7 @@ class att_page_with_filter_controls { public $selectortype = self::SELECTOR_NONE; - protected $defaultview = VIEW_WEEKS; + protected $defaultview = ATT_VIEW_WEEKS; private $cm; @@ -193,23 +193,23 @@ public function init_start_end_date() { $year = $date['year']; switch ($this->view) { - case VIEW_DAYS: + case ATT_VIEW_DAYS: $this->startdate = make_timestamp($year, $mon, $mday); $this->enddate = make_timestamp($year, $mon, $mday + 1); break; - case VIEW_WEEKS: + case ATT_VIEW_WEEKS: $this->startdate = make_timestamp($year, $mon, $mday - $wday); $this->enddate = make_timestamp($year, $mon, $mday + 7 - $wday) - 1; break; - case VIEW_MONTHS: + case ATT_VIEW_MONTHS: $this->startdate = make_timestamp($year, $mon); $this->enddate = make_timestamp($year, $mon + 1); break; - case VIEW_ALLPAST: + case ATT_VIEW_ALLPAST: $this->startdate = 1; $this->enddate = time(); break; - case VIEW_ALL: + case ATT_VIEW_ALL: $this->startdate = 0; $this->enddate = 0; break; @@ -317,7 +317,7 @@ class att_view_page_params extends att_page_with_filter_controls { public $mode; public function __construct() { - $this->defaultview = VIEW_MONTHS; + $this->defaultview = ATT_VIEW_MONTHS; } public function get_significant_params() { @@ -370,7 +370,7 @@ class att_take_page_params { public function init() { if (!isset($this->group)) $this->group = 0; - if (!isset($this->sort)) $this->sort = SORT_LASTNAME; + if (!isset($this->sort)) $this->sort = ATT_SORT_LASTNAME; $this->init_view_mode(); $this->init_gridcols(); } @@ -399,7 +399,7 @@ public function get_significant_params() { $params['sessionid'] = $this->sessionid; $params['grouptype'] = $this->grouptype; if ($this->group) $params['group'] = $this->group; - if ($this->sort != SORT_LASTNAME) $params['sort'] = $this->sort; + if ($this->sort != ATT_SORT_LASTNAME) $params['sort'] = $this->sort; if (isset($this->copyfrom)) $params['copyfrom'] = $this->copyfrom; return $params; @@ -418,14 +418,14 @@ public function init($cm) { parent::init($cm); if (!isset($this->group)) $this->group = $this->get_current_sesstype() > 0 ? $this->get_current_sesstype() : 0; - if (!isset($this->sort)) $this->sort = SORT_LASTNAME; + if (!isset($this->sort)) $this->sort = ATT_SORT_LASTNAME; } public function get_significant_params() { $params = array(); //if ($this->group) $params['group'] = $this->group; - if ($this->sort != SORT_LASTNAME) $params['sort'] = $this->sort; + if ($this->sort != ATT_SORT_LASTNAME) $params['sort'] = $this->sort; return $params; } @@ -759,7 +759,7 @@ public function update_session_from_form_data($formdata, $sessionid) { public function take_from_form_data($formdata) { global $DB, $USER; - $statuses = implode(',', array_keys( (array)$this->get_statuses() )); + $statuses = implode(',', array_keys( (array)$this->att_get_statuses() )); $now = time(); $sesslog = array(); $formdata = (array)$formdata; @@ -815,7 +815,7 @@ public function get_users($groupid = 0) { //fields we need from the user table $userfields = user_picture::fields('u').',u.username'; - if (isset($this->pageparams->sort) and ($this->pageparams->sort == SORT_FIRSTNAME)) { + if (isset($this->pageparams->sort) and ($this->pageparams->sort == ATT_SORT_FIRSTNAME)) { $orderby = "u.firstname ASC, u.lastname ASC"; } else { @@ -870,11 +870,11 @@ public function get_user($userid) { return $user; } - public function get_statuses($onlyvisible = true) { + public function att_get_statuses($onlyvisible = true) { global $DB; if (!isset($this->statuses)) { - $this->statuses = get_statuses($this->id, $onlyvisible); + $this->statuses = att_get_statuses($this->id, $onlyvisible); } return $this->statuses; @@ -925,22 +925,22 @@ public function get_user_stat($userid) { global $DB; $ret = array(); - $ret['completed'] = $this->get_user_taken_sessions_count($userid); - $ret['statuses'] = $this->get_user_statuses_stat($userid); + $ret['completed'] = $this->att_get_user_taken_sessions_count($userid); + $ret['statuses'] = $this->att_get_user_statuses_stat($userid); return $ret; } - public function get_user_taken_sessions_count($userid) { + public function att_get_user_taken_sessions_count($userid) { global $DB; if (!array_key_exists($userid, $this->usertakensesscount)) - $this->usertakensesscount[$userid] = get_user_taken_sessions_count($this->id, $this->course->startdate, $userid); + $this->usertakensesscount[$userid] = att_get_user_taken_sessions_count($this->id, $this->course->startdate, $userid); return $this->usertakensesscount[$userid]; } - public function get_user_statuses_stat($userid) { + public function att_get_user_statuses_stat($userid) { global $DB; if (!array_key_exists($userid, $this->userstatusesstat)) { @@ -963,8 +963,8 @@ public function get_user_statuses_stat($userid) { return $this->userstatusesstat[$userid]; } - public function get_user_grade($userid) { - return get_user_grade($this->get_user_statuses_stat($userid), $this->get_statuses()); + public function att_get_user_grade($userid) { + return att_get_user_grade($this->att_get_user_statuses_stat($userid), $this->att_get_statuses()); } // For getting sessions count implemented simplest method - taken sessions. @@ -974,8 +974,8 @@ public function get_user_grade($userid) { // * all sessions between user start and end enrolment date. // While implementing those methods we need recalculate grades of all users // on session adding - public function get_user_max_grade($userid) { - return get_user_max_grade($this->get_user_taken_sessions_count($userid), $this->get_statuses()); + public function att_get_user_max_grade($userid) { + return att_get_user_max_grade($this->att_get_user_taken_sessions_count($userid), $this->att_get_statuses()); } public function update_users_grade($userids) { @@ -983,7 +983,7 @@ public function update_users_grade($userids) { foreach ($userids as $userid) { $grades[$userid]->userid = $userid; - $grades[$userid]->rawgrade = calc_user_grade_percent($this->get_user_grade($userid), $this->get_user_max_grade($userid)); + $grades[$userid]->rawgrade = att_calc_user_grade_percent($this->att_get_user_grade($userid), $this->att_get_user_max_grade($userid)); } return grade_update('mod/attforblock', $this->course->id, 'mod', 'attforblock', @@ -1152,13 +1152,13 @@ public function log($action, moodle_url $url = null, $info = null) { $info = $this->id; } - $logurl = log_convert_url($url); + $logurl = att_log_convert_url($url); add_to_log($this->course->id, 'attforblock', $action, $logurl, $info, $this->cm->id); } } -function get_statuses($attid, $onlyvisible=true) { +function att_get_statuses($attid, $onlyvisible=true) { global $DB; if ($onlyvisible) { @@ -1170,7 +1170,7 @@ function get_statuses($attid, $onlyvisible=true) { return $statuses; } -function get_user_taken_sessions_count($attid, $coursestartdate, $userid) { +function att_get_user_taken_sessions_count($attid, $coursestartdate, $userid) { global $DB; $qry = "SELECT count(*) as cnt @@ -1188,7 +1188,7 @@ function get_user_taken_sessions_count($attid, $coursestartdate, $userid) { return $DB->count_records_sql($qry, $params); } -function get_user_statuses_stat($attid, $coursestartdate, $userid) { +function att_get_user_statuses_stat($attid, $coursestartdate, $userid) { global $DB; $qry = "SELECT al.statusid, count(al.statusid) AS stcnt @@ -1207,7 +1207,7 @@ function get_user_statuses_stat($attid, $coursestartdate, $userid) { return $DB->get_records_sql($qry, $params); } -function get_user_grade($userstatusesstat, $statuses) { +function att_get_user_grade($userstatusesstat, $statuses) { $sum = 0; foreach ($userstatusesstat as $stat) { $sum += $stat->stcnt * $statuses[$stat->statusid]->grade; @@ -1216,12 +1216,12 @@ function get_user_grade($userstatusesstat, $statuses) { return $sum; } -function get_user_max_grade($sesscount, $statuses) { +function att_get_user_max_grade($sesscount, $statuses) { reset($statuses); return current($statuses)->grade * $sesscount; } -function get_user_courses_attendances($userid) { +function att_get_user_courses_attendances($userid) { global $DB; $usercourses = enrol_get_users_courses($userid); @@ -1241,39 +1241,39 @@ function get_user_courses_attendances($userid) { return $DB->get_records_sql($sql, $params); } -function calc_user_grade_percent($grade, $maxgrade) { +function att_calc_user_grade_percent($grade, $maxgrade) { if ($maxgrade == 0) return 0; else return $grade / $maxgrade * 100; } -function update_all_users_grades($attid, $course, $context) { +function att_update_all_users_grades($attid, $course, $context) { global $COURSE; $grades = array(); $userids = array_keys(get_enrolled_users($context, 'mod/attforblock:canbelisted', 0, 'u.id')); - $statuses = get_statuses($attid); + $statuses = att_get_statuses($attid); foreach ($userids as $userid) { $grades[$userid]->userid = $userid; - $userstatusesstat = get_user_statuses_stat($attid, $course->startdate, $userid); - $usertakensesscount = get_user_taken_sessions_count($attid, $course->startdate, $userid); - $grades[$userid]->rawgrade = calc_user_grade_percent(get_user_grade($userstatusesstat, $statuses), get_user_max_grade($usertakensesscount, $statuses)); + $userstatusesstat = att_get_user_statuses_stat($attid, $course->startdate, $userid); + $usertakensesscount = att_get_user_taken_sessions_count($attid, $course->startdate, $userid); + $grades[$userid]->rawgrade = att_calc_user_grade_percent(att_get_user_grade($userstatusesstat, $statuses), att_get_user_max_grade($usertakensesscount, $statuses)); } return grade_update('mod/attforblock', $course->id, 'mod', 'attforblock', $attid, 0, $grades); } -function has_logs_for_status($statusid) { +function att_has_logs_for_status($statusid) { global $DB; return $DB->count_records('attendance_log', array('statusid'=> $statusid)) > 0; } -function log_convert_url(moodle_url $fullurl) { +function att_log_convert_url(moodle_url $fullurl) { static $baseurl; if (!isset($baseurl)) { diff --git a/manage.php b/manage.php index 532842e..1e5bfc1 100644 --- a/manage.php +++ b/manage.php @@ -43,7 +43,7 @@ } elseif ($size > 1) { $att->curdate = $today; //temporally set $view for single access to page from block - $att->$view = VIEW_DAYS; + $att->$view = ATT_VIEW_DAYS; } } diff --git a/preferences.php b/preferences.php index e1009c8..864c2d0 100644 --- a/preferences.php +++ b/preferences.php @@ -53,7 +53,7 @@ redirect($att->url_preferences(), get_string('statusdeleted','attforblock')); } - $statuses = $att->get_statuses(); + $statuses = $att->att_get_statuses(); $status = $statuses[$att->pageparams->statusid]; $message = get_string('deletecheckfull', '', get_string('variable', 'attforblock')); $message .= str_repeat(html_writer::empty_tag('br'), 2); diff --git a/renderables.php b/renderables.php index a546ec2..1b652a4 100644 --- a/renderables.php +++ b/renderables.php @@ -113,7 +113,7 @@ public function __construct(attforblock $att) { $year = $date['year']; switch ($this->pageparams->view) { - case VIEW_DAYS: + case ATT_VIEW_DAYS: $format = get_string('strftimedm', 'attforblock'); $this->prevcur = make_timestamp($year, $mon, $mday - 1); $this->nextcur = make_timestamp($year, $mon, $mday + 1); @@ -256,7 +256,7 @@ public function __construct(attforblock $att) { $this->groupmode = $att->get_group_mode(); $this->cm = $att->cm; - $this->statuses = $att->get_statuses(); + $this->statuses = $att->att_get_statuses(); $this->sessioninfo = $att->get_session_info($att->pageparams->sessionid); $this->updatemode = $this->sessioninfo->lasttaken > 0; @@ -336,14 +336,14 @@ public function __construct(attforblock $att, $userid) { } if ($this->pageparams->mode == att_view_page_params::MODE_THIS_COURSE) { - $this->statuses = $att->get_statuses(); + $this->statuses = $att->att_get_statuses(); $this->stat = $att->get_user_stat($userid); $this->gradable = $att->grade > 0; if ($this->gradable) { - $this->grade = $att->get_user_grade($userid); - $this->maxgrade = $att->get_user_max_grade($userid); + $this->grade = $att->att_get_user_grade($userid); + $this->maxgrade = $att->att_get_user_max_grade($userid); } @@ -360,7 +360,7 @@ public function __construct(attforblock $att, $userid) { $this->grade = array(); $this->maxgrade = array(); foreach ($this->coursesatts as $ca) { - $statuses = get_statuses($ca->attid); + $statuses = att_get_statuses($ca->attid); $user_taken_sessions_count = get_user_taken_sessions_count($ca->attid, $ca->coursestartdate, $userid); $user_statuses_stat = get_user_statuses_stat($ca->attid, $ca->coursestartdate, $userid); @@ -372,13 +372,13 @@ public function __construct(attforblock $att, $userid) { $this->gradable[$ca->attid] = $ca->attgrade > 0; if ($this->gradable[$ca->attid]) { - $this->grade[$ca->attid] = get_user_grade($user_statuses_stat, $statuses); + $this->grade[$ca->attid] = att_get_user_grade($user_statuses_stat, $statuses); // For getting sessions count implemented simplest method - taken sessions. // It can have error if users don't have attendance info for some sessions. // In the future we can implement another methods: // * all sessions between user start enrolment date and now; // * all sessions between user start and end enrolment date. - $this->maxgrade[$ca->attid] = get_user_max_grade($user_taken_sessions_count, $statuses); + $this->maxgrade[$ca->attid] = att_get_user_max_grade($user_taken_sessions_count, $statuses); } else { //for more comfortable and universal work with arrays @@ -441,8 +441,8 @@ public function __construct(attforblock $att) { $this->sessions = $att->get_filtered_sessions(); - $this->statuses = $att->get_statuses(); - $this->allstatuses = $att->get_statuses(false); + $this->statuses = $att->att_get_statuses(); + $this->allstatuses = $att->att_get_statuses(false); $this->gradable = $att->grade > 0; @@ -458,8 +458,8 @@ public function __construct(attforblock $att) { $this->usersstats[$user->id] = $att->get_user_statuses_stat($user->id); if ($this->gradable) { - $this->grades[$user->id] = $att->get_user_grade($user->id); - $this->maxgrades[$user->id] = $att->get_user_max_grade($user->id); + $this->grades[$user->id] = $att->att_get_user_grade($user->id); + $this->maxgrades[$user->id] = $att->att_get_user_max_grade($user->id); } } @@ -488,7 +488,7 @@ class attforblock_preferences_data implements renderable { private $att; public function __construct(attforblock $att) { - $this->statuses = $att->get_statuses(false); + $this->statuses = $att->att_get_statuses(false); foreach ($this->statuses as $st) $st->haslogs = has_logs_for_status ($st->id); diff --git a/renderer.php b/renderer.php index 60db004..5b81596 100644 --- a/renderer.php +++ b/renderer.php @@ -130,7 +130,7 @@ protected function render_view_controls(attforblock_filter_controls $fcontrols) $views[VIEW_ALLPAST] = get_string('allpast', 'attforblock'); $views[VIEW_MONTHS] = get_string('months', 'attforblock'); $views[VIEW_WEEKS] = get_string('weeks', 'attforblock'); - $views[VIEW_DAYS] = get_string('days', 'attforblock'); + $views[ATT_VIEW_DAYS] = get_string('days', 'attforblock'); $viewcontrols = ''; foreach ($views as $key => $sview) { if ($key != $fcontrols->pageparams->view) { diff --git a/renderhelpers.php b/renderhelpers.php index 7f8ec4c..1fd8010 100644 --- a/renderhelpers.php +++ b/renderhelpers.php @@ -213,13 +213,13 @@ function construct_full_user_stat_html_table($attforblock, $course, $user) { global $CFG; $gradeable = $attforblock->grade > 0; - $statuses = get_statuses($attforblock->id); + $statuses = att_get_statuses($attforblock->id); $userstatusesstat = get_user_statuses_stat($attforblock->id, $course->startdate, $user->id); $stat['completed'] = get_user_taken_sessions_count($attforblock->id, $course->startdate, $user->id); $stat['statuses'] = $userstatusesstat; if ($gradeable) { - $grade = get_user_grade($userstatusesstat, $statuses); - $maxgrade = get_user_max_grade(get_user_taken_sessions_count($attforblock->id, $course->startdate, $user->id), $statuses); + $grade = att_get_user_grade($userstatusesstat, $statuses); + $maxgrade = att_get_user_max_grade(get_user_taken_sessions_count($attforblock->id, $course->startdate, $user->id), $statuses); if (!$decimalpoints = grade_get_setting($course->id, 'decimalpoints')) { $decimalpoints = $CFG->grade_decimalpoints; }