diff --git a/classes/report_page_params.php b/classes/report_page_params.php index 1187ef3..e5b77f9 100644 --- a/classes/report_page_params.php +++ b/classes/report_page_params.php @@ -43,17 +43,17 @@ class mod_attendance_report_page_params extends mod_attendance_page_with_filter_ $this->group = $this->get_current_sesstype() > 0 ? $this->get_current_sesstype() : 0; } if (!isset($this->sort)) { - $this->sort = ATT_SORT_LASTNAME; + $this->sort = ATT_SORT_DEFAULT; } } public function get_significant_params() { $params = array(); - if ($this->sort != ATT_SORT_LASTNAME) { + if ($this->sort != ATT_SORT_DEFAULT) { $params['sort'] = $this->sort; } return $params; } -} \ No newline at end of file +} diff --git a/classes/structure.php b/classes/structure.php index 4acc3a7..2a3b309 100644 --- a/classes/structure.php +++ b/classes/structure.php @@ -549,10 +549,15 @@ class mod_attendance_structure { // Fields we need from the user table. $userfields = user_picture::fields('u', array('username' , 'idnumber' , 'institution' , 'department')); - if (isset($this->pageparams->sort) and ($this->pageparams->sort == ATT_SORT_FIRSTNAME)) { - $orderby = "u.firstname ASC, u.lastname ASC, u.idnumber ASC, u.institution ASC, u.department ASC"; + if (empty($this->pageparams->sort)) { + $this->pageparams->sort = ATT_SORT_DEFAULT; + } + if ($this->pageparams->sort == ATT_SORT_FIRSTNAME) { + $orderby = $DB->sql_fullname('u.firstname', 'u.lastname') . ', u.id'; + } else if ($this->pageparams->sort == ATT_SORT_LASTNAME) { + $orderby = 'u.lastname, u.firstname, u.id'; } else { - $orderby = "u.lastname ASC, u.firstname ASC, u.idnumber ASC, u.institution ASC, u.department ASC"; + list($orderby, $sortparams) = users_order_by_sql('u'); } if ($page) { diff --git a/classes/take_page_params.php b/classes/take_page_params.php index 98c052e..563aaa3 100644 --- a/classes/take_page_params.php +++ b/classes/take_page_params.php @@ -50,7 +50,7 @@ class mod_attendance_take_page_params { $this->group = 0; } if (!isset($this->sort)) { - $this->sort = ATT_SORT_LASTNAME; + $this->sort = ATT_SORT_DEFAULT; } $this->init_view_mode(); $this->init_gridcols(); @@ -80,7 +80,7 @@ class mod_attendance_take_page_params { if ($this->group) { $params['group'] = $this->group; } - if ($this->sort != ATT_SORT_LASTNAME) { + if ($this->sort != ATT_SORT_DEFAULT) { $params['sort'] = $this->sort; } if (isset($this->copyfrom)) { @@ -89,4 +89,4 @@ class mod_attendance_take_page_params { return $params; } -} \ No newline at end of file +} diff --git a/locallib.php b/locallib.php index 22a5c1e..57467b9 100644 --- a/locallib.php +++ b/locallib.php @@ -35,6 +35,7 @@ define('ATT_VIEW_ALL', 5); define('ATT_VIEW_NOTPRESENT', 6); define('ATT_VIEW_SUMMARY', 7); +define('ATT_SORT_DEFAULT', 0); define('ATT_SORT_LASTNAME', 1); define('ATT_SORT_FIRSTNAME', 2); diff --git a/renderer.php b/renderer.php index e8c7b36..1cb5ae4 100644 --- a/renderer.php +++ b/renderer.php @@ -624,14 +624,13 @@ class mod_attendance_renderer extends plugin_renderer_base { if ($data->pageparams->sort == ATT_SORT_LASTNAME) { $firstname = html_writer::link($data->url(array('sort' => ATT_SORT_FIRSTNAME)), get_string('firstname')); - } else { + $lastname = get_string('lastname'); + } else if ($data->pageparams->sort == ATT_SORT_FIRSTNAME) { $firstname = get_string('firstname'); - } - - if ($data->pageparams->sort == ATT_SORT_FIRSTNAME) { $lastname = html_writer::link($data->url(array('sort' => ATT_SORT_LASTNAME)), get_string('lastname')); } else { - $lastname = get_string('lastname'); + $firstname = html_writer::link($data->url(array('sort' => ATT_SORT_FIRSTNAME)), get_string('firstname')); + $lastname = html_writer::link($data->url(array('sort' => ATT_SORT_LASTNAME)), get_string('lastname')); } if ($CFG->fullnamedisplay == 'lastname firstname') { diff --git a/report.php b/report.php index 42eaa82..a785ba5 100644 --- a/report.php +++ b/report.php @@ -32,7 +32,7 @@ $from = optional_param('from', null, PARAM_ACTION); $pageparams->view = optional_param('view', null, PARAM_INT); $pageparams->curdate = optional_param('curdate', null, PARAM_INT); $pageparams->group = optional_param('group', null, PARAM_INT); -$pageparams->sort = optional_param('sort', null, PARAM_INT); +$pageparams->sort = optional_param('sort', ATT_SORT_DEFAULT, PARAM_INT); $pageparams->page = optional_param('page', 1, PARAM_INT); $pageparams->perpage = get_config('attendance', 'resultsperpage'); diff --git a/take.php b/take.php index f616a44..2e0843f 100644 --- a/take.php +++ b/take.php @@ -30,7 +30,7 @@ $pageparams = new mod_attendance_take_page_params(); $id = required_param('id', PARAM_INT); $pageparams->sessionid = required_param('sessionid', PARAM_INT); $pageparams->grouptype = required_param('grouptype', PARAM_INT); -$pageparams->sort = optional_param('sort', null, PARAM_INT); +$pageparams->sort = optional_param('sort', ATT_SORT_DEFAULT, PARAM_INT); $pageparams->copyfrom = optional_param('copyfrom', null, PARAM_INT); $pageparams->viewmode = optional_param('viewmode', null, PARAM_INT); $pageparams->gridcols = optional_param('gridcols', null, PARAM_INT);