WIP: Extra Fields: Reverting extra_field_options.php and

extra_field_option.lib.php.

Removing company_view.php.

If authors exist, this will be select a actual list of teacher's active
and show it on add/edit lp.

*Before try $form->setDefault() *
BT#17648
-
refs
#3461
pull/3462/head
carlos alvarado 5 years ago
parent 77b2e8259c
commit b3f14d4f5e
  1. 72
      main/admin/extra_field_options.php
  2. 19
      main/inc/lib/extra_field.lib.php
  3. 11
      main/inc/lib/extra_field_option.lib.php
  4. 201
      main/inc/lib/myspace.lib.php
  5. 12
      main/mySpace/admin_view.php
  6. 235
      main/mySpace/company_view.php

@ -29,12 +29,7 @@ if (!in_array($type, ExtraField::getValidExtraFieldTypes())) {
$extra_field = new ExtraField($type);
$extra_field_info = $extra_field->get($field_id);
// Get info about extra field
$extraFieldType = (int)$extra_field_info['field_type'];
if($extra_field_info['variable'] != 'authors'){
//Only aviable to field variable autors BT##17648
$extraFieldType = 0;
}
$check = Security::check_token('request');
$token = Security::get_token();
@ -165,7 +160,7 @@ switch ($action) {
echo Display::return_message(get_lang('ItemAdded'), 'confirmation');
}
}
$obj->display($extraFieldType);
$obj->display();
} else {
$form->addElement('hidden', 'sec_token');
$form->setConstants(['sec_token' => $token]);
@ -188,7 +183,7 @@ switch ($action) {
false
);
}
$obj->display($extraFieldType);
$obj->display();
} else {
$form->addElement('hidden', 'sec_token');
$form->setConstants(['sec_token' => $token]);
@ -203,67 +198,10 @@ switch ($action) {
echo Display::return_message(get_lang('ItemDeleted'), 'confirmation');
}
}
$obj->display($extraFieldType);
break;
case 'addTeachers':
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
api_not_allowed();
}
$id = isset($_GET['id']) ? (int) $_GET['id'] : '';
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&'.$params;
$form_name = $type.'_field';
$checkAllTeachers = (int)isset($_POST['choiseAllTeachers'] )?$_POST['choiseAllTeachers']:0;
$form = new FormValidator($form_name, 'post', $url);
if ($form->validate()) {
if ($check) {
if ($checkAllTeachers == 1) {
$conditions = [
'enabled' => 1,
'status' => COURSEMANAGER,
];
$res = false;
$teachers = UserManager::get_user_list($conditions);
foreach ($teachers as $teacher) {
$value = [
'type' => $type,
'field_id' =>$field_id,
'display_text' => $teacher['complete_name'],
'option_value' => $teacher['id'],
];
$res = $obj->save_one_item($value);
}
if ($res) {
echo Display::return_message(get_lang('ItemDeleted'), 'confirmation');
}
}
}
$obj->display($extraFieldType);
} else {
$form = new FormValidator($form_name, 'post', $url);
// Setting the form elements
$header = get_lang('SubscribeUserToCourseAsTeacher');
//$form->addElement('header', $header);
$form->addElement('hidden', 'id', $id);
$form->addElement('hidden', 'type', $type);
$form->addElement('hidden', 'field_id', $field_id);
$form->addElement('select', 'choiseAllTeachers', $header,
[
0 => get_lang('SelectAnOption'),
1 => get_lang('Yes'),
2 => get_lang('No'),
]);
$form->addButtonCreate(get_lang('Add'));
$form->addElement('hidden', 'sec_token');
$form->setConstants(['sec_token' => $token]);
$form->display();
}
$obj->display();
break;
default:
$obj->display($extraFieldType);
$obj->display();
break;
}
Display::display_footer();

@ -1174,8 +1174,23 @@ class ExtraField extends Model
if (empty($defaultValueId)) {
$options[''] = get_lang('SelectAnOption');
}
foreach ($field_details['options'] as $optionDetails) {
$options[$optionDetails['option_value']] = $optionDetails['display_text'];
// for task BT#17648
//When a varible is 'authors', this will be a select of teachers
$variable = $field_details['variable'];
if($variable != 'authors'){
foreach ($field_details['options'] as $optionDetails) {
$options[$optionDetails['option_value']] = $optionDetails['display_text'];
}
}else{
$conditions = [
'enabled' => 1,
'status' => COURSEMANAGER,
];
$teachers = UserManager::get_user_list($conditions);
foreach ($teachers as $teacher) {
$options[$teacher['id']] = $teacher['complete_name'];
}
}
$form->addElement(
'select',

@ -679,23 +679,14 @@ class ExtraFieldOption extends Model
/**
* Display a form with the options for the field_id given in REQUEST.
*
* @param int $extraFieldType
*
*/
public function display( $extraFieldType = 0)
public function display()
{
// action links
echo '<div class="actions">';
$field_id = isset($_REQUEST['field_id']) ? intval($_REQUEST['field_id']) : null;
echo '<a href="'.api_get_self().'?action=add&type='.$this->type.'&field_id='.$field_id.'">'.
Display::return_icon('add_user_fields.png', get_lang('Add'), '', ICON_SIZE_MEDIUM).'</a>';
//add teachers list when extra field type is 5, equal to "Drop down with multiple choice"
if($this->type == 'lp' && $extraFieldType == 5 && !empty($field_id)) {
echo '<a href="'.api_get_self().'?action=addTeachers&type='.$this->type.'&field_id='.$field_id.'">'.
Display::return_icon('add-class.png', get_lang('SubscribeUserToCourseAsTeacher'), '', ICON_SIZE_MEDIUM).
'</a>';
}
echo '</div>';
echo Display::grid_html('extra_field_options');
}

@ -73,6 +73,14 @@ class MySpace
'content' => get_lang('UserByEntityReport'),
];
}
$authorsField = ExtraField::getDisplayNameByVariable('authors');
if (!empty($authorsField)) {
$actions [] =
[
'url' => api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php?display=learningPath',
'content' => get_lang('LpByAuthor'),
];
}
return Display::actions($actions, null);
}
@ -1003,11 +1011,13 @@ 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
*
* if lpId is different to 0, this search by lp id too
* @param null $startDate
* @param null $endDate
* @param int $lpId
* @return array
*/
protected static function getCompanyLearnpathSubscription($startDate = null, $endDate = null )
protected static function getCompanyLearnpathSubscription($startDate = null, $endDate = null , $lpId = 0)
{
$tblItemProperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
@ -1037,14 +1047,20 @@ class MySpace
if (!empty($startDate)) {
$startDate = $startDate->format('Y-m-d');
$_GET['startDate'] = $startDate;
$whereCondition .= " AND $tblItemProperty.lastedit_date >= '$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' ";
$whereCondition .= "
AND $tblItemProperty.lastedit_date <= '$endDate' ";
}
if( $lpId != 0){
$whereCondition .= "
AND c_item_property.ref = $lpId ";
}
$companys = [];
if (!empty($startDate) or !empty($endDate)) {
@ -1100,10 +1116,15 @@ class MySpace
$studentId = (int)$row['to_user_id'];
$company = isset($row['company']) ? $row['company'] : '';
// $lpId = $row['ref'];
$companys[$company][] = $studentId;
$companys[$company] = array_unique($companys[$company]);
if( $lpId != 0) {
$companys[] = $studentId;
}else{
$companys[$company][] = $studentId;
$companys[$company] = array_unique($companys[$company]);
}
}
}
}
return $companys;
}
@ -1220,6 +1241,174 @@ class MySpace
$tpl->display($templateName);
}
/**
* @TODO make a definition
* @param null $startDate
* @param null $endDate
*/
public static function displayResumeLP($startDate= null, $endDate=null, $csv = false) {
$tableHtml = '';
$query = "
SELECT
item_id AS lp_id,
REPLACE (s.value, ';', ',') AS users_id
FROM
extra_field_values s
INNER JOIN extra_field sf ON (s.field_id = sf.id)
WHERE
field_id IN (
SELECT
id
FROM
extra_field
WHERE
variable = 'authors'
)
AND sf.extra_field_type = 6
AND (s.value != '' OR s.value IS NOT NULL)
";
$queryResult = Database::query($query);
$tblCourse = TABLE_MAIN_COURSE;
$data = [];
while ($row = Database::fetch_array($queryResult, 'ASSOC')) {
$lp_id = (int)$row['lp_id'];
// get data when lastedit_type is LearnpathSubscription
$registeredUsers = self::getCompanyLearnpathSubscription($startDate, $endDate ,$lp_id);
if(!empty($registeredUsers)) {
$lp_info = [];
$teacherList = [];
$teachersId = trim($row['users_id'], ",");
$lp_table = Database::get_course_table(TABLE_LP_MAIN);
$query = "
SELECT *,
(select title from $tblCourse where course.id = c_lp.c_id) as courseTitle
FROM
$lp_table
WHERE
id = $lp_id
";
$res = Database::query($query);
if (Database::num_rows($res)) {
$lp_info = Database::fetch_array($res);
}
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$query1 = "SELECT * FROM $user_table WHERE id in ($teachersId)";
$res = Database::query($query1);
if (Database::num_rows($res)) {
while ($rowTeacher = Database::fetch_array($res, 'ASSOC')) {
$teacherList[] = $rowTeacher;
}
}
$data[] = [
'lp' => $lp_info,
'teachers' => $teacherList,
'students' => $registeredUsers
];
}
}
if($csv == false) {
$table = '<div class="table-responsive"><table class="table table-bordered">';
$table .= "<thead><tr><td>".get_lang('LearningPathList')."</td>
<td>".get_lang('CourseTeachers')."</td><td>".get_lang('AllStudents')."</td></tr></thead><tbody>";
foreach ($data as $listLp) {
$lpName = $listLp['lp']['name'];
$teachers = $listLp['teachers'];
$students = $listLp['students'];
$teachersName = '';
for ($i = 0; $i < count($teachers); $i++) {
$teachersName .= $teachers[$i]['firstname']."<br>";
}
$table .= "<tr>
<td>$lpName</td>
<td>$teachersName</td>
<td>".count($students)."</td>
</tr>";
}
$table .= '</tbody></table></div>';
if (!empty($startDate) or !empty($endDate)) {
$tableHtml = $table;
}
$form = new FormValidator('searchDate', 'get');
$form->addHidden('display', 'learningPath');
$form->addDatePicker(
'startDate',
get_lang('DateStart'),
[]);
$form->addDatePicker(
'endDate',
get_lang('DateEnd'),
[]);
$form->addButtonSearch(get_lang('Search'));
if (count($data) != 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);
}else{
$csv_row = [];
$csv_content = [];
$csv_row[] = get_lang('LearningPathList');
$csv_row[] = get_lang('CourseTeachers');
$csv_row[] = get_lang('AllStudents');
$csv_content[] = $csv_row;
$csv_row = [];
foreach ($data as $listLp) {
$lpName = $listLp['lp']['name'];
$teachers = $listLp['teachers'];
$students = $listLp['students'];
$teachersName = '';
for ($i = 0; $i < count($teachers); $i++) {
$teachersName .= $teachers[$i]['firstname']."<br>";
}
$csv_row[] = $lpName;
$csv_row[] = $teachersName;
$csv_row[] = count($students);
$csv_content[] = $csv_row;
$csv_row = [];
Export::arrayToCsv($csv_content, 'reporting_lp_by_authors');
}
}
}
/**
* Display a sortable table that contains an overview of all the reporting progress of all courses.

@ -45,6 +45,12 @@ if ($exportCSV) {
$endDate = isset($_GET['endDate']) ? $_GET['endDate'] : null;
MySpace::export_company_resume_csv($startDate, $endDate);
exit;
}elseif ('learningPath' === $display) {
// Getting dates
$startDate = isset($_GET['startDate']) ? $_GET['startDate'] : null;
$endDate = isset($_GET['endDate']) ? $_GET['endDate'] : null;
MySpace::displayResumeLP($startDate, $endDate,true);
exit;
}
}
@ -73,6 +79,12 @@ switch ($display) {
$endDate = isset($_GET['endDate']) ? $_GET['endDate'] : null;
MySpace::displayResumeCompany($startDate, $endDate);
break;
case 'learningPath':
// Getting dates
$startDate = isset($_GET['startDate']) ? $_GET['startDate'] : null;
$endDate = isset($_GET['endDate']) ? $_GET['endDate'] : null;
MySpace::displayResumeLP($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;

@ -1,235 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/*
No es 'usersubscribe' pero 'LearnpathSubscription' y en la columna to_user_id tienes el user_id del usuario que ha sido
inscrito y en la columna ref tienes el lp_id al cual ha sido inscrito.
*/
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_TRACKING;
$csv_content = [];
$nameTools = get_lang('MySpace');
$allowToTrack = api_is_platform_admin(true, true);
if (!$allowToTrack) {
api_not_allowed(true);
}
$userInfo = [];
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
$languageFilter = isset($_REQUEST['language']) ? $_REQUEST['language'] : '';
$content = '';
$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 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
id
FROM
extra_field
WHERE
variable = 'company'
)
AND item_id = $tblItemProperty.to_user_id
) ";
$query = "
SELECT
* ,
$selectToCompany as company,
$selectToNameLp
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);
$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'];
$company = isset($row['company']) ? $row['company'] : '';
$lpId = $row['ref'];
$companys[$company][] = $studentId;
$companys[$company] = array_unique($companys[$company]);
}
}
// 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();
$exportTo = strtolower(isset($_GET['export'])?$_GET['export']:null);
switch (!empty($exportTo)) {
case 'csv':
Export::arrayToCsv($companys, $fileName);
break;
case 'xls':
Export::export_table_xls_html($companys, $fileName);
break;
default:
//do nothing
continue;
}
//bloque exportar
$htmlHeadXtra[] = '<script>
$(function() {
});
</script>';
Display::display_header($nameTools);
echo '<div class="actions">';
echo MySpace::getTopMenu();
echo '</div>';
echo MySpace::getAdminActions();
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>
.boss_column {
display: block;
}
.row .col-md-1 {
display:flex;
flex: 0 0 20%;
}
.flex-nowrap {
-webkit-flex-wrap: nowrap!important;
-ms-flex-wrap: nowrap!important;
flex-wrap: nowrap!important;
}
.flex-row {
display:flex;
-webkit-box-orient: horizontal!important;
-webkit-box-direction: normal!important;
-webkit-flex-direction: row!important;
-ms-flex-direction: row!important;
flex-direction: row!important;
}
.add_user {
//display:none;
}
</style>';
echo $style;
Display::display_footer();
Loading…
Cancel
Save