WIP: Admin: If a company field is defined into extra_field,

Lang variable: UserByEntityReport
 Suggested in spanish: Informe de usuario por entidad

 - Informes específicos por entidad y por autor BT#17648 - refs #3461
pull/3462/head
carlos alvarado 5 years ago
parent 8c51965bf8
commit 725f5775b7
  1. 29
      main/inc/lib/extra_field.lib.php
  2. 231
      main/inc/lib/myspace.lib.php
  3. 14
      main/mySpace/admin_view.php
  4. 268
      main/mySpace/company_view.php

@ -3537,4 +3537,33 @@ JAVASCRIPT;
}
);
}
/**
* Gets the display name of an extra field
*
* @param string $variableName
*/
public static function getDisplayNameByVariable($variableName = null)
{
if($variableName == null ) {
return null;
}
$variableName = Security::remove_XSS($variableName);
$variableName = Database::escape_string($variableName);
$tblExtraField = Database::get_main_table(TABLE_EXTRA_FIELD);
$query = "SELECT
display_text
FROM
$tblExtraField
WHERE
variable = '$variableName'";
$companyField = Database::fetch_assoc(Database::query($query));
if ($companyField == false or !isset($companyField['display_text'])) {
return null;
}
return $companyField['display_text'];
}
}

@ -65,6 +65,14 @@ class MySpace
],
];
$companyField = ExtraField::getDisplayNameByVariable('company');
if (!empty($companyField)) {
$actions [] =
[
'url' => api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php?display=company',
'content' => get_lang('UserByEntityReport'),
];
}
return Display::actions($actions, null);
}
@ -990,6 +998,229 @@ class MySpace
}
}
/**
* Gets a list of users who were enrolled in the lessons.
* It is necessary that in the extra field, a company is defined
*
* @param null $startDate
* @param null $endDate
* @return array
*/
protected static function getCompanyLearnpathSubscription($startDate = null, $endDate = null )
{
$tblItemProperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
$tblLp = Database::get_course_table(TABLE_LP_MAIN);
$tblExtraField = TABLE_EXTRA_FIELD;
$tblExtraFieldValue = TABLE_EXTRA_FIELD_VALUES;
$whereCondition = '';
//Validating dates
if (!empty($startDate)) {
$startDate = new DateTime($startDate);
}
if (!empty($endDate)) {
$endDate = new DateTime($endDate);
}
if (!empty($startDate) and !empty($endDate)) {
if ($startDate > $endDate) {
$dateTemp = $endDate;
$endDate = $startDate;
$startDate = $dateTemp;
unset($dateTemp);
}
}
// Settings condition and parametter GET to right date
if (!empty($startDate)) {
$startDate = $startDate->format('Y-m-d');
$_GET['startDate'] = $startDate;
$whereCondition .= " AND $tblItemProperty.lastedit_date >= '$startDate' ";
}
if (!empty($endDate)) {
$endDate = $endDate->format('Y-m-d');
$_GET['endDate'] = $endDate;
$whereCondition .= " AND $tblItemProperty.lastedit_date <= '$endDate' ";
}
$companys = [];
if (!empty($startDate) or !empty($endDate)) {
// get Compnay data
$selectToCompany = " (
SELECT
value
FROM
$tblExtraFieldValue
WHERE
field_id IN (
SELECT
id
FROM
$tblExtraField
WHERE
variable = 'company'
)
AND item_id = $tblItemProperty.to_user_id
) ";
$query = "
SELECT
* ,
$selectToCompany as company,
(
SELECT
name
FROM
$tblLp
WHERE
$tblLp.iid = c_item_property.ref
) as name_lp
FROM
$tblItemProperty
WHERE
c_id IN (
SELECT
c_id
FROM
".TABLE_MAIN_COURSE_USER."
WHERE
STATUS = 5
)
AND lastedit_type = 'LearnpathSubscription'
AND $selectToCompany IS NOT NULL ";
if (strlen($whereCondition) > 2) {
$query .= $whereCondition;
}
$queryResult = Database::query($query);
while ($row = Database::fetch_array($queryResult, 'ASSOC')) {
// $courseId = (int)$row['c_id'];
$studentId = (int)$row['to_user_id'];
$company = isset($row['company']) ? $row['company'] : '';
// $lpId = $row['ref'];
$companys[$company][] = $studentId;
$companys[$company] = array_unique($companys[$company]);
}
}
return $companys;
}
/**
* Export to cvs a list of users who were enrolled in the lessons.
* It is necessary that in the extra field, a company is defined
*
* @param null $startDate
* @param null $endDate
* @return array
*/
public static function export_company_resume_csv($startDate, $endDate)
{
$companys = self::getCompanyLearnpathSubscription($startDate, $endDate);
$csv_content = [];
// Printing table
$total = 0;
$displayText = ExtraField::getDisplayNameByVariable('company');
// the first line of the csv file with the column headers
$csv_row = [];
$csv_row[] = $displayText;
$csv_row[] = get_lang('CountOfSubscribedUsers');
$csv_content[] = $csv_row;
foreach($companys as $entity => $student) {
$csv_row = [];
// user official code
$csv_row[] = $entity;
$csv_row[] = count($student);
$total += count($student);
$csv_content[] = $csv_row;
}
$csv_row = [];
// user official code
$csv_row[] = get_lang('GeneralTotal');
$csv_row[] = $total;
$csv_content[] = $csv_row;
Export::arrayToCsv($csv_content, 'reporting_company_resume');
exit;
}
/**
* Displays a list as a table of users who were enrolled in the lessons.
* It is necessary that in the extra field, a company is defined
* @param null $startDate
* @param null $endDate
*/
public static function displayResumeCompany($startDate= null, $endDate=null ) {
$companys = self::getCompanyLearnpathSubscription($startDate, $endDate);
$tableHtml = '';
// Printing table
$total = 0;
$table = '<div class="table-responsive"><table class="table table-bordered">';
$displayText = ExtraField::getDisplayNameByVariable('company');
$table.="<thead><tr><td>$displayText</td><td> ".get_lang('CountOfSubscribedUsers')." </td></tr></thead><tbody>";
foreach($companys as $entity => $student) {
$table.="<tr><td>$entity</td><td>".count($student)."</td></tr>";
$total += count($student);
}
$table.="<tr><td>".get_lang('GeneralTotal')."</td><td>$total</td></tr>";
$table .= '</tbody></table></div>';
if(!empty($startDate) or !empty($endDate)){
$tableHtml = $table;
}
$form = new FormValidator('searchDate', 'get');
$form->addHidden('display', 'company');
$form->addDatePicker(
'startDate',
get_lang('DateStart'),
[]);
$form->addDatePicker(
'endDate',
get_lang('DateEnd'),
[]);
$form->addButtonSearch(get_lang('Search'));
if(count($companys)!=0) {
//$form->addButtonSave(get_lang('Ok'), 'export');
$form
->addButton(
'export_csv',
get_lang('ExportAsCSV'),
'check',
'primary',
null,
null,
[
]
);
}
$tableContent = $form->returnForm();
$tableContent .= $tableHtml;
// $tableContent .= $table->return_table();
$tpl = new Template('', false, false, false, false, false, false);
$tpl->assign('table', $tableContent);
$templateName = $tpl->get_template('my_space/course_summary.tpl');
$tpl->display($templateName);
}
/**
* Display a sortable table that contains an overview of all the reporting progress of all courses.
*/

@ -9,6 +9,8 @@ require_once __DIR__.'/../inc/global.inc.php';
api_block_anonymous_users();
$exportCSV = isset($_GET['export']) && $_GET['export'] === 'csv' ? true : false;
// Catch param export_csv from buttom
$exportCSV = isset($_GET['export_csv']) && $exportCSV == false ? true : false;
$display = isset($_GET['display']) ? Security::remove_XSS($_GET['display']) : null;
$htmlHeadXtra[] = api_get_jqgrid_js();
@ -37,6 +39,12 @@ if ($exportCSV) {
} elseif ('course' === $display) {
MySpace::export_tracking_course_overview();
exit;
} elseif ('company' === $display) {
// Getting dates
$startDate = isset($_GET['startDate']) ? $_GET['startDate'] : null;
$endDate = isset($_GET['endDate']) ? $_GET['endDate'] : null;
MySpace::export_company_resume_csv($startDate, $endDate);
exit;
}
}
@ -59,6 +67,12 @@ switch ($display) {
case 'course':
MySpace::display_tracking_course_overview();
break;
case 'company':
// Getting dates
$startDate = isset($_GET['startDate']) ? $_GET['startDate'] : null;
$endDate = isset($_GET['endDate']) ? $_GET['endDate'] : null;
MySpace::displayResumeCompany($startDate, $endDate);
break;
case 'accessoverview':
$courseId = isset($_GET['course_id']) ? (int) $_GET['course_id'] : 0;
$sessionId = isset($_GET['session_id']) ? (int) $_GET['session_id'] : 0;

@ -26,47 +26,76 @@ $languageFilter = isset($_REQUEST['language']) ? $_REQUEST['language'] : '';
$content = '';
// fechas
$startDate = isset($_GET['startDate']) ? $_GET['startDate'] : null;
$endDate = isset($_GET['endDate']) ? $_GET['endDate'] : null;
$tblItemProperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
$tblLp = Database::get_course_table(TABLE_LP_MAIN);
$whereCondition = '';
// Getting dates
$startDate = isset($_GET['startDate']) ? $_GET['startDate'] : null;
$endDate = isset($_GET['endDate']) ? $_GET['endDate'] : null;
//Validating dates
if (!empty($startDate)) {
$startDate = new DateTime($startDate);
}
if (!empty($endDate)) {
$endDate = new DateTime($endDate);
}
if (!empty($startDate) and !empty($endDate)) {
if ($startDate > $endDate) {
$dateTemp = $endDate;
$endDate = $startDate;
$startDate = $dateTemp;
unset($dateTemp);
}
}
// Settings condition and parametter GET to right date
if (!empty($startDate)) {
$startDate = $startDate->format('Y-m-d');
$_GET['startDate'] = $startDate;
$whereCondition .= " AND $tblItemProperty.lastedit_date >= '$startDate' ";
}
if (!empty($endDate)) {
$endDate = $endDate->format('Y-m-d');
$_GET['endDate'] = $endDate;
$whereCondition .= " AND $tblItemProperty.lastedit_date <= '$endDate' ";
}
// get id of company
$selectToNameLp = "(select name from $tblLp where $tblLp.iid =c_item_property.ref) as name_lp";
$selectToCompany = "(
// Get lp name
$selectToNameLp = "(
SELECT
name
FROM
$tblLp
WHERE
$tblLp.iid = c_item_property.ref
) as name_lp";
// get Compnay data
$selectToCompany = " (
SELECT
value
FROM
extra_field_values
WHERE
field_id IN (
SELECT
item_id
id
FROM
extra_field_values
extra_field
WHERE
field_id IN (
SELECT
id
FROM
extra_field
WHERE
variable = 'company'
)
AND item_id = $tblItemProperty.to_user_id
LIMIT 1
) AS company";
variable = 'company'
)
AND item_id = $tblItemProperty.to_user_id
) ";
$query = "
SELECT
* ,
$selectToCompany ,
$selectToCompany as company,
$selectToNameLp
FROM
$tblItemProperty
@ -80,93 +109,68 @@ WHERE
STATUS = 5
)
AND
lastedit_type = 'LearnpathSubscription'";
lastedit_type = 'LearnpathSubscription'
and $selectToCompany is not null ";
if (strlen($whereCondition) > 2) {
$query .= $whereCondition;
}
$queryResult = Database::query($query);
$cursos = [];
$estudiantes = [];
$estudiantesCompany = [];
$estudiantesPorCurso = [];
// $estudiantesCompanyPorCurso = [];
$NumeroEstudiantesCompany = 0;
// $detalleCurso = [];
//$studentInfo = [];
//$print = [];
$elementos = [];
$companys =[];
if (!empty($startDate) and !empty($endDate)) {
while ($row = Database::fetch_array($queryResult, 'ASSOC')) {
$courseId = (int)$row['c_id'];
$studentId = (int)$row['to_user_id'];
$studentCompanyId = (int)$row['company'];
$company = isset($row['company']) ? $row['company'] : '';
$lpId = $row['ref'];
$studiantein = api_get_user_info($studentId);
$courseInfo = api_get_course_info_by_id($courseId);
$lpName = $row['name_lp'];
$tempPrint['courseName'] = $courseInfo['name'];
$tempPrint['insert_date'] = $row['insert_date'];
$tempPrint['lastedit_date'] = $row['lastedit_date'];
$tempPrint['lpId'] = $lpId;
$tempPrint['lpName'] = $lpName;
$tempPrint['studentName'] = $studiantein['complete_name'];
$tempPrint['studentCompany'] = ($studentCompanyId != 0) ? true : false;
// $studentInfo[$studentId] = $studiantein;
//$cursos[] = $courseId;
$cursos[$courseId][$lpId][] = $tempPrint;
$estudiantes[] = $studentId;
if ($studentCompanyId != 0) {
$estudiantesCompany[] = $studentCompanyId;
//$estudiantesCompanyPorCurso[$courseId][] = $studentCompanyId;
//$estudiantesCompanyPorCurso[$courseId] = array_unique($estudiantesCompanyPorCurso[$courseId]);
}
/* else {
$estudiantesPorCurso[$courseId][] = $studentId;
$estudiantesPorCurso[$courseId] = array_unique($estudiantesPorCurso[$courseId]);
}
$print[] = $tempPrint;
*/
$companys[$company][] = $studentId;
$companys[$company] = array_unique($companys[$company]);
}
}
$estudiantes = array_unique($estudiantes);
$estudiantesCompany = array_unique($estudiantesCompany);
$NumeroEstudiantes = count($estudiantes);
$NumeroEstudiantesCompany = count($estudiantesCompany);
$cursoText = "Cantidad de alumnos inscritos $NumeroEstudiantes <br> <br> Cantidad de estudiantes con company $NumeroEstudiantesCompany";
$cursoText .= '<br>Listado de cursos<br><br>';
// Printing table
$total = 0;
$table = '<div class="table-responsive"><table class="table table-bordered">';
$query = "SELECT
display_text
FROM
extra_field
WHERE
variable = 'company'";
$displayText = Database::fetch_assoc(Database::query($query));
$displayText = $displayText['display_text'];
$table.="<thead><tr><td>$displayText</td><td> numero de inscription en leccion </td></tr></thead><tbody>";
foreach($companys as $entity => $student) {
$table.="<tr><td>$entity</td><td>".count($student)."</td></tr>";
$total += count($student);
}
$table.="<tr><td>Total nscritos</td><td>$total</td></tr>";
$table .= '</tbody></table></div>';
$cursoText = $table;
//bloque exportar
$fileName = 'works_in_session_'.api_get_local_time();
switch ($_GET['export']) {
case 'xls':
Export::export_table_xls_html($cursos, $fileName);
break;
$exportTo = strtolower(isset($_GET['export'])?$_GET['export']:null);
switch (!empty($exportTo)) {
case 'csv':
Export::arrayToCsv($cursos, $fileName);
Export::arrayToCsv($companys, $fileName);
break;
case 'xls':
Export::export_table_xls_html($companys, $fileName);
break;
default:
//do nothing
continue;
}
//bloque exportar
foreach ($cursos as $courseId => $Course) {
$cursoText .= "Curso id = $courseId<br>";
foreach ($Course as $lpIndex => $lpData) {
$cursoText .= "\t Lp id = $lpIndex<br>";
foreach($lpData as $row) {
$cursoText .= "<br> <strong>".var_export($row, true)."</strong><br>";
}
}
}
$htmlHeadXtra[] = '<script>
$(function() {
@ -179,22 +183,23 @@ echo '<div class="actions">';
echo MySpace::getTopMenu();
echo '</div>';
echo MySpace::getAdminActions();
echo $cursoText;
// if (!empty($startDate)) {
$form = new FormValidator('searchExtra', 'get');
$form->addHidden('a', 'searchExtra');
$form->addDatePicker(
'startDate',
'startDate',
[]);
$form->addDatePicker(
'endDate',
'endDate',
[]);
$form->addButtonSearch(get_lang('Search'));
echo $form->returnForm();
// }
if (!empty($startDate)) {
$form = new FormValidator('searchDate', 'get');
$form->addHidden('a', 'searchDate');
$form->addDatePicker(
'startDate',
'startDate',
[]);
$form->addDatePicker(
'endDate',
'endDate',
[]);
$form->addButtonSearch(get_lang('Search'));
echo $form->returnForm();
echo $cursoText;
}
echo $content;
$style = '<style>
@ -226,60 +231,5 @@ $style = '<style>
</style>';
echo $style;
$tableContent = '';
if (!empty($startDate)) {
$tableContent .= "<br><pre>".var_export($startDate, true)."</pre>";
}
if (!empty($endDate)) {
$tableContent .= "<br><pre>".var_export($endDate, true)."</pre>";
}
if ($action !== 'add_user') {
$conditions = ['status' => STUDENT_BOSS, 'active' => 1];
if (!empty($languageFilter) && $languageFilter !== 'placeholder') {
$conditions['language'] = $languageFilter;
}
$bossList = UserManager::get_user_list($conditions, ['firstname']);
$tableContent .= '<div class="container-fluid"><div class="row flex-row flex-nowrap">';
foreach ($bossList as $boss) {
$bossId = $boss['id'];
$tableContent .= '<div class="col-md-1">';
$tableContent .= '<div class="boss_column">';
$tableContent .= '<h5><strong>'.api_get_person_name($boss['firstname'], $boss['lastname']).'</strong></h5>';
$tableContent .= Statistics::getBossTable($bossId);
$url = api_get_self().'?a=add_user&boss_id='.$bossId;
$tableContent .= '<div class="add_user">';
$tableContent .= '<strong>'.get_lang('AddStudent').'</strong>';
$addUserForm = new FormValidator(
'add_user_to_'.$bossId,
'post',
'',
'',
[],
FormValidator::LAYOUT_BOX_NO_LABEL
);
$addUserForm->addSelectAjax(
'user_id',
'',
[],
[
'width' => '200px',
'url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=user_by_role&active=1&status='.STUDENT,
]
);
$addUserForm->addButtonSave(get_lang('Add'));
$tableContent .= $addUserForm->returnForm();
$tableContent .= '</div>';
$tableContent .= '</div>';
$tableContent .= '</div>';
}
$tableContent .= '</div></div>';
}
echo $tableContent;
Display::display_footer();

Loading…
Cancel
Save