Sort the report data - refs BT#9087

1.10.x
Angel Fernando Quiroz Campos 11 years ago
parent b0352afae7
commit e6c12c0951
  1. 57
      main/admin/teacher_time_report.php
  2. 101
      main/inc/lib/TeacherTimeReport.class.php
  3. 21
      main/inc/lib/usermanager.lib.php
  4. 2
      main/template/default/admin/teacher_time_report.tpl

@ -2,11 +2,9 @@
/* For licensing terms, see /license.txt */
/**
* With this tool you can easily adjust non critical configuration settings.
* Non critical means that changing them will not result in a broken campus.
* Generate a teacher time report in platform or sessions/courses
*
* @author Patrick Cool
* @author Julio Montoya - Multiple URL site
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.admin
*/
/* INIT SECTION */
@ -26,6 +24,7 @@ $cidReset = true;
// Including some necessary library files.
require_once '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH) . 'TeacherTimeReport.class.php';
// Setting the section (for the tabs).
$this_section = SECTION_PLATFORM_ADMIN;
@ -51,7 +50,7 @@ $selectedUntil = isset($_REQUEST['from']) && !empty($_REQUEST['until']) ? $_REQU
$courseList = CourseManager::get_courses_list(0, 0, 'title');
$sessionsList = SessionManager::get_sessions_list(array(), array('name'));
$teacherList = SessionManager::getAllCourseCoaches();
$teacherList = UserManager::getTeachersList();
$htmlHeadXtra[] = '
<script src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/daterange/moment.min.js"></script>
@ -63,7 +62,7 @@ $withFilter = false;
$reportTitle = 'TimeReportIncludingAllCoursesAndSessionsByTeacher';
$reportSubTitle = sprintf(get_lang('TimeSpentBetweenXAndY'), $selectedFrom, $selectedUntil);
$rows = array();
$timeReport = new TeacherTimeReport();
if (!empty($selectedCourse)) {
$withFilter = true;
@ -86,7 +85,7 @@ if (!empty($selectedCourse)) {
$selectedUntil
);
$rows[] = array(
$timeReport->data[] = array(
'session' => array(
'id' => $session['id'],
'name' => $session['name']
@ -129,13 +128,13 @@ if (!empty($selectedSession)) {
$selectedUntil
);
$rows[] = array(
$timeReport->data[] = array(
'session' => array(
'id' => $session['id'],
'name' => $session['name']
),
'course' => array(
'id' => $course['real_id'],
'id' => $course['id'],
'name' => $course['title']
),
'coach' => array(
@ -173,7 +172,7 @@ if (!empty($selectedTeacher)) {
$selectedUntil
);
$rows[] = array(
$timeReport->data[] = array(
'session' => array(
'id' => $session['id'],
'name' => $session['name']
@ -196,48 +195,22 @@ if (!empty($selectedTeacher)) {
if (empty($selectedCourse) && empty($selectedSession) && empty($selectedTeacher)) {
foreach ($teacherList as &$teacher) {
$rows[] = array(
$timeReport->data[] = array(
'coach' => array(
'username' => $teacher['username'],
'completeName' => $teacher['completeName'],
),
'totalTime' => SessionManager::getTotalUserTimeInPlatform($teacher['id'], $selectedFrom, $selectedUntil)
'totalTime' => SessionManager::getTotalUserTimeInPlatform($teacher['user_id'], $selectedFrom, $selectedUntil)
);
}
}
$timeReport->sortData($withFilter);
if (isset($_GET['export'])) {
require_once api_get_path(LIBRARY_PATH) . 'export.lib.inc.php';
$dataToExport = array();
if ($withFilter) {
$dataToExport[] = array(
get_lang('Session'),
get_lang('Course'),
get_lang('Coach'),
get_lang('TotalTime')
);
} else {
$dataToExport[] = array(
get_lang('Coach'),
get_lang('TotalTime')
);
}
foreach ($rows as $row) {
$data = array();
if ($withFilter) {
$data[] = $row['session']['name'];
$data[] = $row['course']['name'];
}
$data[] = $row['coach']['completeName'];
$data[] = $row['totalTime'];
$dataToExport[] = $data;
}
$dataToExport = $timeReport->prepareDataToExport($withFilter);
$fileName = get_lang('TeacherTimeReport') . ' ' . api_get_local_time();
@ -296,7 +269,7 @@ $tpl->assign('courses', $courseList);
$tpl->assign('sessions', $sessionsList);
$tpl->assign('courseCoaches', $teacherList);
$tpl->assign('rows', $rows);
$tpl->assign('rows', $timeReport->data);
$contentTemplate = $tpl->get_template('admin/teacher_time_report.tpl');

@ -0,0 +1,101 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Library for generate a teacher time report
*
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.admin
*/
class TeacherTimeReport
{
/**
* The report data
* @var array
*/
public $data = array();
/**
* Callback for compare sessions names
* @param array $dataA The datab A
* @param array $dataB The data B
* @return int returns -1 if dataA is less than dataB, 1 if dataA is greater than dataB, and 0 if they are equal
*/
public function compareSessions($dataA, $dataB)
{
return strnatcmp($dataA['session']['name'], $dataB['session']['name']);
}
/**
* Callback for compare courses names
* @param array $dataA The datab A
* @param array $dataB The data B
* @return int returns -1 if dataA is less than dataB, 1 if dataA is greater than dataB, and 0 if they are equal
*/
public function compareCourses($dataA, $dataB)
{
return strnatcmp($dataA['course']['name'], $dataB['course']['name']);
}
/**
* Callback for compare coaches names
* @param array $dataA The datab A
* @param array $dataB The data B
* @return int returns -1 if dataA is less than dataB, 1 if dataA is greater than dataB, and 0 if they are equal
*/
public function compareCoaches($dataA, $dataB)
{
return strnatcmp($dataA['coach']['completeName'], $dataB['coach']['completeName']);
}
/**
* Sort the report data
* @param boolean $withFilter Whether sort by sessions and courses
*/
public function sortData($withFilter = false)
{
if ($withFilter) {
uasort($this->data, array($this, 'compareSessions'));
uasort($this->data, array($this, 'compareCourses'));
}
uasort($this->data, array($this, 'compareCoaches'));
}
public function prepareDataToExport($withFilter = false)
{
$dataToExport = array();
if ($withFilter) {
$dataToExport[] = array(
get_lang('Session'),
get_lang('Course'),
get_lang('Coach'),
get_lang('TotalTime')
);
} else {
$dataToExport[] = array(
get_lang('Coach'),
get_lang('TotalTime')
);
}
foreach ($this->data as $row) {
$data = array();
if ($withFilter) {
$data[] = $row['session']['name'];
$data[] = $row['course']['name'];
}
$data[] = $row['coach']['completeName'];
$data[] = $row['totalTime'];
$dataToExport[] = $data;
}
return $dataToExport;
}
}

@ -4857,4 +4857,25 @@ EOF;
Database::query($sql);
}
}
/**
* Get the teacher (users with COURSEMANGER status) list
* @return array The list
*/
public static function getTeachersList()
{
$userTable = Database::get_main_table(TABLE_MAIN_USER);
$resultData = Database::select('user_id, lastname, firstname, username', $userTable, array(
'where' => array(
'status = ?' => COURSEMANAGER
)
));
foreach ($resultData as &$teacherData) {
$teacherData['completeName'] = api_get_person_name($teacherData['firstname'], $teacherData['lastname']);
}
return $resultData;
}
}

@ -81,7 +81,7 @@
<select name="teacher" id="teacher">
<option value="0">{{ 'None' | get_lang }}</option>
{% for teacher in courseCoaches %}
<option value="{{ teacher.id }}" {{ (teacher.id == selectedTeacher) ? 'selected' : '' }}>{{ teacher.completeName }}</option>
<option value="{{ teacher.user_id }}" {{ (teacher.user_id == selectedTeacher) ? 'selected' : '' }}>{{ teacher.completeName }}</option>
{% endfor %}
</select>
</div>

Loading…
Cancel
Save