Minor - update code from preprodparkur

pull/3213/head
Julio Montoya 5 years ago
parent d7322af067
commit 2b92ced895
  1. 156
      main/admin/statistics/index.php
  2. 54
      main/inc/ajax/statistics.ajax.php
  3. 4
      main/inc/ajax/user_manager.ajax.php
  4. 4
      main/mySpace/student.php

@ -567,7 +567,7 @@ switch ($report) {
$courseId = $courses[0];
$courseInfo = api_get_course_info_by_id($courseId);
$language = $courseInfo['language'];
$language = str_replace('2', '', $language);
$language = get_lang(ucfirst(str_replace(2, '', $language)));
}
$table->setCellContents($row, 3, $language);
@ -735,16 +735,16 @@ switch ($report) {
$graph .= '<div class="row">';
$graph .= '<div class="col-md-6"><canvas id="canvas4" style="margin-bottom: 20px"></canvas></div>';
$graph .= '<div class="col-md-6"><canvas id="canvas5" style="margin-bottom: 20px"></canvas></div>';
$graph .= '<div class="col-md-6"><canvas id="canvas8" style="margin-bottom: 20px"></canvas></div>';
$graph .= '</div>';
$graph .= '<div class="row">';
$graph .= '<div class="col-md-6"><canvas id="canvas5" style="margin-bottom: 20px"></canvas></div>';
$graph .= '<div class="col-md-6"><canvas id="canvas6" style="margin-bottom: 20px"></canvas></div>';
$graph .= '<div class="col-md-6"><canvas id="canvas7" style="margin-bottom: 20px"></canvas></div>';
$graph .= '</div>';
$graph .= '<div class="row">';
$graph .= '<div class="col-md-4"><canvas id="canvas8" style="margin-bottom: 20px"></canvas></div>';
$graph .= '<div class="col-md-6"><canvas id="canvas7" style="margin-bottom: 20px"></canvas></div>';
$graph .= '</div>';
$conditions = [];
@ -832,7 +832,16 @@ switch ($report) {
$certificate = GradebookUtils::get_certificate_by_user_id(0, $userId);
$language = isset($extraFields['langue_cible']) ? $extraFields['langue_cible'] : '';
$contract = isset($extraFields['termactivated']) ? $extraFields['termactivated'] : '';
//$contract = isset($extraFields['termactivated']) ? $extraFields['termactivated'] : '';
$contract = false;
$legalAccept = $extraFieldValueUser->get_values_by_handler_and_field_variable($userId, 'legal_accept');
if ($legalAccept && isset($legalAccept['value'])) {
list($legalId, $legalLanguageId, $legalTime) = explode(':', $legalAccept['value']);
if ($legalId) {
$contract = true;
}
}
$residence = isset($extraFields['terms_paysresidence']) ? $extraFields['terms_paysresidence'] : '';
$career = isset($extraFields['filiere_user']) ? $extraFields['filiere_user'] : '';
$birthDate = isset($extraFields['terms_datedenaissance']) ? $extraFields['terms_datedenaissance'] : '';
@ -1096,6 +1105,74 @@ switch ($report) {
$extraTables .= $data['table'];
}
// Graph Age
$extraFieldValueUser = new ExtraField('user');
$extraField = $extraFieldValueUser->get_handler_field_info_by_field_variable('terms_datedenaissance');
if ($extraField) {
$users = UserManager::getUserListExtraConditions(
[],
[],
false,
false,
null,
$extraConditions,
false
);
$userIdList = array_column($users, 'user_id');
$userIdListToString = implode("', '", $userIdList);
$all = [];
$total = count($users);
$sql = "SELECT value
FROM $extraFieldValueUser->table_field_values
WHERE
item_id IN ('$userIdListToString') AND
field_id = ".$extraField['id'];
$query = Database::query($sql);
$usersFound = 0;
$now = new DateTime();
$all = [
//get_lang('N/A') => 0,
'16-17' => 0,
'18-25' => 0,
'26-30' => 0,
];
while ($row = Database::fetch_array($query)) {
++$usersFound;
if (!empty($row['value'])) {
$validDate = DateTime::createFromFormat('Y-m-d', $row['value']);
$validDate = $validDate && $validDate->format('Y-m-d') === $row['value'];
if ($validDate) {
$date1 = new DateTime($row['value']);
$interval = $now->diff($date1);
$years = (int) $interval->y;
if ($years >= 16 && $years <= 17) {
++$all['16-17'];
}
if ($years >= 18 && $years <= 25) {
++$all['18-25'];
}
if ($years >= 26 && $years <= 30) {
++$all['26-30'];
}
}
}
}
$data = Statistics::buildJsChartData($all, $reportName8);
$htmlHeadXtra[] = Statistics::getJSChartTemplateWithData(
$data['chart'],
'pie',
$reportOptions8,
'canvas8'
);
$extraTables .= $data['table'];
}
// graph 5
$extraFieldValueUser = new ExtraField('user');
$extraField = $extraFieldValueUser->get_handler_field_info_by_field_variable('filiere_user');
@ -1230,75 +1307,6 @@ switch ($report) {
$extraTables .= $data['table'];
}
// Graph 8
$extraFieldValueUser = new ExtraField('user');
$extraField = $extraFieldValueUser->get_handler_field_info_by_field_variable('terms_datedenaissance');
if ($extraField) {
$users = UserManager::getUserListExtraConditions(
[],
[],
false,
false,
null,
$extraConditions,
false
);
$userIdList = array_column($users, 'user_id');
$userIdListToString = implode("', '", $userIdList);
$all = [];
$total = count($users);
$sql = "SELECT value
FROM $extraFieldValueUser->table_field_values
WHERE
item_id IN ('$userIdListToString') AND
field_id = ".$extraField['id'];
$query = Database::query($sql);
$usersFound = 0;
$now = new DateTime();
$all = [
//get_lang('N/A') => 0,
'16-17' => 0,
'18-25' => 0,
'26-30' => 0,
];
while ($row = Database::fetch_array($query)) {
$usersFound++;
if (!empty($row['value'])) {
$validDate = DateTime::createFromFormat('Y-m-d', $row['value']);
$validDate = $validDate && $validDate->format('Y-m-d') === $row['value'];
if ($validDate) {
$date1 = new DateTime($row['value']);
$interval = $now->diff($date1);
$years = (int) $interval->y;
if ($years >= 16 && $years <= 17) {
$all['16-17']++;
}
if ($years >= 18 && $years <= 25) {
$all['18-25']++;
}
if ($years >= 26 && $years <= 30) {
$all['26-30']++;
}
}
}
}
$data = Statistics::buildJsChartData($all, $reportName8);
$htmlHeadXtra[] = Statistics::getJSChartTemplateWithData(
$data['chart'],
'pie',
$reportOptions8,
'canvas8'
);
$extraTables .= $data['table'];
}
$header = Display::page_subheader2(get_lang('TotalNumberOfStudents').': '.$studentCount);
$content = $header.$extraTables.$graph.$content;
}

@ -15,6 +15,7 @@ $sessionDuration = isset($_GET['session_duration']) ? (int) $_GET['session_durat
$exportFormat = isset($_REQUEST['export_format']) ? $_REQUEST['export_format'] : 'csv';
$operation = isset($_REQUEST['oper']) ? $_REQUEST['oper'] : false;
$order = isset($_REQUEST['sord']) && in_array($_REQUEST['sord'], ['asc', 'desc']) ? $_REQUEST['sord'] : 'asc';
$table = '';
switch ($action) {
case 'add_student_to_boss':
@ -22,7 +23,7 @@ switch ($action) {
$bossId = isset($_GET['boss_id']) ? (int) $_GET['boss_id'] : 0;
if ($studentId && $bossId) {
UserManager::subscribeBossToUsers($bossId, [$studentId], false);
UserManager::subscribeUserToBossList($studentId, [$bossId], true);
}
echo Statistics::getBossTable($bossId);
@ -166,10 +167,10 @@ switch ($action) {
// for global tools usage (number of clicks)
$list = [];
$palette = ChamiloApi::getColorPalette(true, true);
if ($action == 'tools_usage') {
if ($action === 'tools_usage') {
$statsName = 'Tools';
$all = Statistics::getToolsStats();
} elseif ($action == 'courses') {
} elseif ($action === 'courses') {
$statsName = 'CountCours';
$course_categories = Statistics::getCourseCategories();
// total amount of courses
@ -177,7 +178,7 @@ switch ($action) {
foreach ($course_categories as $code => $name) {
$all[$name] = Statistics::countCourses($code);
}
} elseif ($action == 'courses_by_language') {
} elseif ($action === 'courses_by_language') {
$statsName = 'CountCourseByLanguage';
$all = Statistics::printCourseByLanguageStats();
// use slightly different colors than previous chart
@ -185,20 +186,20 @@ switch ($action) {
$item = array_shift($palette);
array_push($palette, $item);
}
} elseif ($action == 'users') {
} elseif ($action === 'users') {
$statsName = 'NumberOfUsers';
$countInvisible = isset($_GET['count_invisible']) ? (int) $_GET['count_invisible'] : null;
$all = [
get_lang('Teachers') => Statistics::countUsers(COURSEMANAGER, null, $countInvisible),
get_lang('Students') => Statistics::countUsers(STUDENT, null, $countInvisible),
];
} elseif ($action == 'users_teachers') {
} elseif ($action === 'users_teachers') {
$statsName = 'Teachers';
$course_categories = Statistics::getCourseCategories();
$countInvisible = isset($_GET['count_invisible']) ? (int) $_GET['count_invisible'] : null;
$all = [];
foreach ($course_categories as $code => $name) {
$name = str_replace(get_lang('Department'), "", $name);
$name = str_replace(get_lang('Department'), '', $name);
$all[$name] = Statistics::countUsers(COURSEMANAGER, $code, $countInvisible);
}
// use slightly different colors than previous chart
@ -206,7 +207,7 @@ switch ($action) {
$item = array_shift($palette);
array_push($palette, $item);
}
} elseif ($action == 'users_students') {
} elseif ($action === 'users_students') {
$statsName = 'Students';
$course_categories = Statistics::getCourseCategories();
$countInvisible = isset($_GET['count_invisible']) ? (int) $_GET['count_invisible'] : null;
@ -303,6 +304,7 @@ switch ($action) {
$all = [];
$total = count($users);
$usersFound = 0;
$extraFieldOption = new ExtraFieldOption('user');
foreach ($extraField['options'] as $item) {
$value = Database::escape_string($item['option_value']);
$count = 0;
@ -314,8 +316,12 @@ switch ($action) {
field_id = ".$extraField['id'];
$query = Database::query($sql);
$result = Database::fetch_array($query);
$count = $result['count'];
$usersFound += $count;
$option = $extraFieldOption->get($item['id'], true);
$item['display_text'] = $option['display_text'];
$all[$item['display_text']] = $count;
}
$all[get_lang('N/A')] = $total - $usersFound;
@ -428,19 +434,14 @@ switch ($action) {
$years = (int) $interval->y;
if ($years >= 16 && $years <= 17) {
$all['16-17']++;
$all['16-17'] += 1;
}
if ($years >= 18 && $years <= 25) {
$all['18-25']++;
$all['18-25'] += 1;
}
if ($years >= 26 && $years <= 30) {
$all['26-30']++;
$all['26-30'] += 1;
}
/*if ($years >= 31) {
$all[get_lang('N/A')] += 1;
}*/
} else {
//$all[get_lang('N/A')] += 1;
}
}
@ -579,11 +580,6 @@ switch ($action) {
$startDate = Database::escape_string($_REQUEST['date_start']);
$endDate = Database::escape_string($_REQUEST['date_end']);
$statusId = (int) $_REQUEST['status'];
/*$extraConditions = '';
if (!empty($startDate) && !empty($endDate)) {
$extraConditions .= " AND registration_date BETWEEN '$startDate' AND '$endDate' ";
}*/
$table = Database::get_main_table(TABLE_MAIN_SESSION);
$statusCondition = '';
@ -611,6 +607,9 @@ switch ($action) {
}
$all[$label] = $row['count'];
}
$table = Statistics::buildJsChartData($all, '');
$table = $table['table'];
break;
case 'status':
$sessionStatusAllowed = api_get_configuration_value('allow_session_status');
@ -633,6 +632,8 @@ switch ($action) {
$row['status'] = SessionManager::getStatusLabel($row['status']);
$all[$row['status']] = $row['count'];
}
$table = Statistics::buildJsChartData($all, '');
$table = $table['table'];
break;
case 'language':
@ -652,14 +653,16 @@ switch ($action) {
$courseId = $courses[0];
$courseInfo = api_get_course_info_by_id($courseId);
$language = $courseInfo['language'];
$language = str_replace('2', '', $language);
$language = get_lang(ucfirst(str_replace(2, '', $language)));
}
if (!isset($all[$language])) {
$all[$language] = 0;
}
$all[$language]++;
$all[$language] += 1;
}
$table = Statistics::buildJsChartData($all, '');
$table = $table['table'];
break;
case 'course_in_session':
$sql = "SELECT id FROM $table
@ -692,6 +695,8 @@ switch ($action) {
$all[$courseInfo['name']] = $count;
}
}
$table = Statistics::buildJsChartData($all, '');
$table = $table['table'];
break;
}
@ -711,6 +716,9 @@ switch ($action) {
$i++;
}
$list['table'] = $table;
header('Content-type: application/json');
echo json_encode($list);
break;

@ -253,6 +253,7 @@ switch ($action) {
api_block_anonymous_users(false);
$status = isset($_REQUEST['status']) ? (int) $_REQUEST['status'] : DRH;
$active = isset($_REQUEST['active']) ? (int) $_REQUEST['active'] : null;
$criteria = new Criteria();
$criteria
@ -267,6 +268,9 @@ switch ($action) {
Criteria::expr()->eq('status', $status)
);
if (null !== $active) {
$criteria->andWhere(Criteria::expr()->eq('active', $active));
}
$users = UserManager::getRepository()->matching($criteria);
if (!$users->count()) {

@ -24,8 +24,8 @@ $nameTools = get_lang('Students');
$export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
$keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
$active = isset($_GET['active']) ? intval($_GET['active']) : 1;
$sleepingDays = isset($_GET['sleeping_days']) ? intval($_GET['sleeping_days']) : null;
$active = isset($_GET['active']) ? (int) $_GET['active'] : 1;
$sleepingDays = isset($_GET['sleeping_days']) ? (int) $_GET['sleeping_days'] : null;
$this_section = SECTION_TRACKING;
$webCodePath = api_get_path(WEB_CODE_PATH);

Loading…
Cancel
Save