diff --git a/main/admin/extra_field_options.php b/main/admin/extra_field_options.php
index d2d3622dfa..5041fed1c1 100755
--- a/main/admin/extra_field_options.php
+++ b/main/admin/extra_field_options.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();
diff --git a/main/inc/lib/extra_field.lib.php b/main/inc/lib/extra_field.lib.php
index 829b86f98c..aca53a33e1 100755
--- a/main/inc/lib/extra_field.lib.php
+++ b/main/inc/lib/extra_field.lib.php
@@ -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',
diff --git a/main/inc/lib/extra_field_option.lib.php b/main/inc/lib/extra_field_option.lib.php
index bf79afbd88..8660d3550a 100755
--- a/main/inc/lib/extra_field_option.lib.php
+++ b/main/inc/lib/extra_field_option.lib.php
@@ -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 '
';
echo Display::grid_html('extra_field_options');
}
diff --git a/main/inc/lib/myspace.lib.php b/main/inc/lib/myspace.lib.php
index 5a7d0ab245..721cae483d 100644
--- a/main/inc/lib/myspace.lib.php
+++ b/main/inc/lib/myspace.lib.php
@@ -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 = '';
+ $table .= "| ".get_lang('LearningPathList')." |
+".get_lang('CourseTeachers')." | ".get_lang('AllStudents')." |
";
+
+ 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']."
";
+ }
+ $table .= "
+ | $lpName |
+ $teachersName |
+ ".count($students)." |
+
";
+ }
+
+ $table .= '
';
+
+
+ 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']."
";
+ }
+ $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.
diff --git a/main/mySpace/admin_view.php b/main/mySpace/admin_view.php
index dcd1b1fc30..44288726e3 100644
--- a/main/mySpace/admin_view.php
+++ b/main/mySpace/admin_view.php
@@ -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;
diff --git a/main/mySpace/company_view.php b/main/mySpace/company_view.php
deleted file mode 100644
index 0abf613a45..0000000000
--- a/main/mySpace/company_view.php
+++ /dev/null
@@ -1,235 +0,0 @@
- $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 = '';
-$query = "SELECT
- display_text
- FROM
- extra_field
- WHERE
- variable = 'company'";
-$displayText = Database::fetch_assoc(Database::query($query));
-$displayText = $displayText['display_text'];
-$table.="| $displayText | numero de inscription en leccion |
";
-
-foreach($companys as $entity => $student) {
- $table.="| $entity | ".count($student)." |
";
- $total += count($student);
-}
-$table.="| Total nscritos | $total |
";
-$table .= '
';
-
-
-$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[] = '';
-
-Display::display_header($nameTools);
-echo '';
-echo MySpace::getTopMenu();
-echo '
';
-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 = '';
-echo $style;
-
-
-Display::display_footer();