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

Commit

Permalink
To the user's report added taked sessions from previous groups
Browse files Browse the repository at this point in the history
  • Loading branch information
andreev-artem committed Mar 2, 2013
1 parent 6d4d20f commit 2b5bfc5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
39 changes: 31 additions & 8 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1051,20 +1051,18 @@ public function get_user_filtered_sessions_log($userid) {
public function get_user_filtered_sessions_log_extended($userid) {
global $DB;

$groups = array_keys(groups_get_all_groups($this->course->id, $userid));
$groups[] = 0;
list($gsql, $gparams) = $DB->get_in_or_equal($groups, SQL_PARAMS_NAMED, 'gid0');
// all taked sessions (including previous groups)

if ($this->pageparams->startdate && $this->pageparams->enddate) {
$where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate AND
ats.sessdate >= :sdate AND ats.sessdate < :edate AND ats.groupid $gsql";
ats.sessdate >= :sdate AND ats.sessdate < :edate";
} else {
$where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate AND ats.groupid $gsql";
$where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate";
}

$sql = "SELECT ats.id, ats.sessdate, ats.duration, ats.description, al.statusid, al.remarks
$sql = "SELECT ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, al.statusid, al.remarks
FROM {attendance_sessions} ats
LEFT JOIN {attendance_log} al
RIGHT JOIN {attendance_log} al
ON ats.id = al.sessionid AND al.studentid = :uid
WHERE $where
ORDER BY ats.sessdate ASC";
Expand All @@ -1075,8 +1073,33 @@ public function get_user_filtered_sessions_log_extended($userid) {
'csdate' => $this->course->startdate,
'sdate' => $this->pageparams->startdate,
'edate' => $this->pageparams->enddate);
$params = array_merge($params, $gparams);
$sessions = $DB->get_records_sql($sql, $params);


// all sessions for current groups

$groups = array_keys(groups_get_all_groups($this->course->id, $userid));
$groups[] = 0;
list($gsql, $gparams) = $DB->get_in_or_equal($groups, SQL_PARAMS_NAMED, 'gid0');

if ($this->pageparams->startdate && $this->pageparams->enddate) {
$where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate AND
ats.sessdate >= :sdate AND ats.sessdate < :edate AND ats.groupid $gsql";
} else {
$where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate AND ats.groupid $gsql";
}

$sql = "SELECT ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, al.statusid, al.remarks
FROM {attendance_sessions} ats
LEFT JOIN {attendance_log} al
ON ats.id = al.sessionid AND al.studentid = :uid
WHERE $where
ORDER BY ats.sessdate ASC";

$params = array_merge($params, $gparams);
$sessions = array_merge($sessions, $DB->get_records_sql($sql, $params));


foreach ($sessions as $sess) {
if (empty($sess->description)) {
$sess->description = get_string('nodescription', 'attforblock');
Expand Down
4 changes: 4 additions & 0 deletions renderables.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ class attforblock_user_data implements renderable {

public $sessionslog;

public $groups;

public $coursesatts;

private $urlpath;
Expand Down Expand Up @@ -364,6 +366,8 @@ public function __construct(attforblock $att, $userid) {
$this->filtercontrols = new attforblock_filter_controls($att);

$this->sessionslog = $att->get_user_filtered_sessions_log_extended($userid);

$this->groups = groups_get_all_groups($att->course->id);
}
else {
$this->coursesatts = att_get_user_courses_attendances($userid);
Expand Down
15 changes: 12 additions & 3 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,16 +594,25 @@ private function construct_user_data(attforblock_user_data $userdata) {
private function construct_user_sessions_log(attforblock_user_data $userdata) {
$table = new html_table();
$table->attributes['class'] = 'generaltable attwidth boxaligncenter';
$table->head = array('#', get_string('date'), get_string('time'), get_string('description','attforblock'), get_string('status','attforblock'), get_string('remarks','attforblock'));
$table->align = array('', '', 'left', 'left', 'center', 'left');
$table->size = array('1px', '1px', '1px', '*', '1px', '1px');
$table->head = array(
'#',
get_string('sessiontypeshort', 'attforblock'),
get_string('date'),
get_string('time'),
get_string('description','attforblock'),
get_string('status','attforblock'),
get_string('remarks','attforblock')
);
$table->align = array('', '', '', 'left', 'left', 'center', 'left');
$table->size = array('1px', '1px', '1px', '1px', '*', '1px', '1px');

$i = 0;
foreach ($userdata->sessionslog as $sess) {
$i++;

$row = new html_table_row();
$row->cells[] = $i;
$row->cells[] = html_writer::tag('nobr', $sess->groupid ? $userdata->groups[$sess->groupid]->name : get_string('commonsession', 'attforblock'));
$row->cells[] = userdate($sess->sessdate, get_string('strftimedmyw', 'attforblock'));
$row->cells[] = $this->construct_time($sess->sessdate, $sess->duration);
$row->cells[] = $sess->description;
Expand Down

0 comments on commit 2b5bfc5

Please sign in to comment.