Skip to content
This repository has been archived by the owner on Jun 15, 2020. It is now read-only.

Commit

Permalink
Appending prefixes to non prefixed functions and defines
Browse files Browse the repository at this point in the history
  • Loading branch information
sirhcsenots committed Nov 17, 2011
1 parent a97c6d2 commit e91283a
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 69 deletions.
6 changes: 3 additions & 3 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
94 changes: 47 additions & 47 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand All @@ -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.
Expand All @@ -974,16 +974,16 @@ 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) {
$grades = array();

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',
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion preferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit e91283a

Please sign in to comment.