From 4e29ffd64ddd4d3a754f72beb9bafaad1abff766 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 8 Jul 2020 09:14:35 +0200 Subject: [PATCH] Add TC and TI report BT#16341 --- main/inc/lib/myspace.lib.php | 10 +- main/mySpace/tc_report.php | 184 ++++++++++++++++++++++++++++++ main/mySpace/ti_report.php | 211 +++++++++++++++++++++++++++++++++++ 3 files changed, 404 insertions(+), 1 deletion(-) create mode 100644 main/mySpace/tc_report.php create mode 100644 main/mySpace/ti_report.php diff --git a/main/inc/lib/myspace.lib.php b/main/inc/lib/myspace.lib.php index c1e906dbe3..0693d0ea39 100644 --- a/main/inc/lib/myspace.lib.php +++ b/main/inc/lib/myspace.lib.php @@ -55,6 +55,14 @@ class MySpace 'url' => api_get_path(WEB_CODE_PATH).'mySpace/survey_report.php', 'content' => get_lang('SurveysReport'), ], + [ + 'url' => api_get_path(WEB_CODE_PATH).'mySpace/tc_report.php', + 'content' => get_lang('TCReport'), + ], + [ + 'url' => api_get_path(WEB_CODE_PATH).'mySpace/ti_report.php', + 'content' => get_lang('TIReport'), + ], ]; return Display::actions($actions, null); @@ -490,7 +498,7 @@ class MySpace if (api_is_multiple_url_enabled()) { $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); $access_url_id = api_get_current_access_url_id(); - if (-1 != $access_url_id) { + if ($access_url_id != -1) { $sqlCoachs = "SELECT DISTINCT scu.user_id as id_coach, u.id as user_id, diff --git a/main/mySpace/tc_report.php b/main/mySpace/tc_report.php new file mode 100644 index 0000000000..5f241c3f93 --- /dev/null +++ b/main/mySpace/tc_report.php @@ -0,0 +1,184 @@ +addHeader(get_lang('AddUser').' '.$bossInfo['complete_name']); + $form->addHidden('a', 'add_user'); + $form->addHidden('boss_id', $bossId); + $form->addSelectAjax( + 'user_id', + get_lang('User'), + [], + [ + 'url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=user_by_role&active=1&status='.STUDENT, + ] + ); + $form->addButtonSave(get_lang('Add')); + if ($form->validate()) { + $values = $form->getSubmitValues(); + $studentInfo = api_get_user_info($values['user_id']); + UserManager::subscribeUserToBossList($values['user_id'], [$values['boss_id']], true); + Display::addFlash(Display::return_message(get_lang('Saved').' '.$studentInfo['complete_name'])); + header('Location: '.api_get_self()); + exit; + } + $content = $form->returnForm(); + + break; +} + +$url = api_get_path(WEB_AJAX_PATH).'statistics.ajax.php?a=add_student_to_boss'; + +$htmlHeadXtra[] = ''; + + +Display::display_header($nameTools); +echo '
'; +echo MySpace::getTopMenu(); +echo '
'; +echo MySpace::getAdminActions(); + +if ($action !== 'add_user') { + $form = new FormValidator('language_filter'); + $form->addHidden('a', 'language_filter'); + $form->addSelectLanguage( + 'language', + get_lang('Language'), + ['placeholder' => get_lang('SelectAnOption')] + ); + $form->addButtonSearch(get_lang('Search')); + + echo $form->returnForm(); +} + +echo $content; +$style = ''; +echo $style; + +$tableContent = ''; + +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 .= '
'; + foreach ($bossList as $boss) { + $bossId = $boss['id']; + $tableContent .= '
'; + $tableContent .= '
'; + $tableContent .= '
'.api_get_person_name($boss['firstname'], $boss['lastname']).'
'; + $tableContent .= Statistics::getBossTable($bossId); + + $url = api_get_self().'?a=add_user&boss_id='.$bossId; + + $tableContent .= '
'; + $tableContent .= ''.get_lang('AddStudent').''; + $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 .= '
'; + + $tableContent .= '
'; + $tableContent .= '
'; + } + $tableContent .= '
'; +} + +echo $tableContent; + +Display::display_footer(); diff --git a/main/mySpace/ti_report.php b/main/mySpace/ti_report.php new file mode 100644 index 0000000000..17a4ea91c3 --- /dev/null +++ b/main/mySpace/ti_report.php @@ -0,0 +1,211 @@ +'; +echo MySpace::getTopMenu(); +echo ''; +echo MySpace::getAdminActions(); + +echo ''; + +$form = new FormValidator('users', 'get', api_get_self().'?a=users_active'); +$form->addDateRangePicker( + 'daterange', + get_lang('DateRange'), + true, + ['format' => 'YYYY-MM-DD', 'timePicker' => 'false', 'validate_format' => 'Y-m-d'] +); +$form->addHidden('a', 'users_active'); +$form->addButtonFilter(get_lang('Search')); + +$weekFormat = 'oW'; + +if ($form->validate()) { + $values = $form->getSubmitValues(); + $startDate = Database::escape_string($values['daterange_start']); + $endDate = Database::escape_string($values['daterange_end']); + //$startDate = Database::escape_string($_REQUEST['daterange_start']); + //$endDate = Database::escape_string($_REQUEST['daterange_end']); + + $date = new DateTime($startDate); + $weekStart = $date->format($weekFormat); + + $date = new DateTime($endDate); + $weekEnd = $date->format($weekFormat); + $first = DateTime::createFromFormat('Y-m-d', $startDate); + $second = DateTime::createFromFormat('Y-m-d', $endDate); + $numberOfWeeks = floor($first->diff($second)->days / 7); + + $sql = " SELECT id_coach, name, id as session_id, display_start_date, display_end_date + FROM session + WHERE display_start_date BETWEEN '$startDate' AND '$endDate' + ORDER BY id_coach"; + $result = Database::query($sql); + + $coachList = []; + while ($row = Database::fetch_array($result, 'ASSOC')) { + $coachId = $row['id_coach']; + if (!isset($coachList[$coachId])) { + $userInfo = api_get_user_info($coachId); + $coachList[$coachId]['complete_name'] = $userInfo['complete_name']; + $coachList[$coachId]['session_count'] = 0; + } + + // Start + $date = new DateTime($row['display_start_date']); + $week = $date->format($weekFormat); + $coachList[$coachId]['week'][$week]['sessions'][] = $row; + + // End + $endDate = new DateTime($row['display_end_date']); + $endWeek = $endDate->format($weekFormat); + + $numberOfWeeksBetween = floor($date->diff($endDate)->days / 7); + + for ($i = 0; $i < $numberOfWeeksBetween; $i++) { + $date->add(new DateInterval('P1W')); + $week = $date->format($weekFormat); + $coachList[$coachId]['week'][$week]['sessions'][] = $row; + } + + $coachList[$coachId]['session_count'] += 1; + $coachList[$coachId]['data'] = $row; + } + + $table = new HTML_Table(['class' => 'table table-responsive']); + $headers = [ + get_lang('Coach'), + get_lang('Sessions'), + ]; + + $date = new DateTime($startDate); + for ($i = 0; $i <= $numberOfWeeks; $i++) { + $headers[] = $date->format('o-W'); + $date->add(new DateInterval('P1W')); + } + + $width = ' width:300px;'; + $row = 0; + $column = 0; + foreach ($headers as $header) { + $table->setHeaderContents($row, $column, $header); + $table->updateCellAttributes( + $row, + $column, + 'style="'.$width.'"' + ); + $column++; + } + $row++; + $url = api_get_path(WEB_CODE_PATH).'session/resume_session.php?'; + foreach ($coachList as $coachData) { + $column = 0; + $table->updateCellAttributes( + $row, + $column, + 'style="'.$width.'"' + ); + $table->setCellContents($row, $column++, $coachData['complete_name']); + + $table->updateCellAttributes( + $row, + $column, + 'style="'.$width.'"' + ); + $table->setCellContents($row, $column++, $coachData['session_count']); + + $date = new DateTime($startDate); + $sessionAdded = []; + for ($i = 2; $i <= $numberOfWeeks; $i++) { + $dateWeekToCheck = $date->format($weekFormat); + if (isset($coachData['week'][$dateWeekToCheck])) { + $sessionArray = []; + foreach ($coachData['week'][$dateWeekToCheck]['sessions'] as $session) { + $date2 = new DateTime($session['display_start_date']); + $name = $session['name']; + + $showName = true; + if (in_array($session['session_id'], $sessionAdded)) { + $showName = false; + } else { + $sessionAdded[] = $session['session_id']; + } + + if ($showName === false) { + $name = ''; + } + $sessionArray[] = Display::url( + $name, + $url.'id_session='.$session['session_id'], + ['class' => 'label label-success', 'target' => '_blank', 'title' => addslashes($session['name'])] + ); + } + $value = implode('

', $sessionArray); + $value = "
$value
"; + $table->setCellContents($row, $i, $value); + $table->updateCellAttributes( + $row, + $i, + 'style="background:green; '.$width.'"' + ); + } else { + $table->setCellContents($row, $i, '
'); + $table->updateCellAttributes( + $row, + $i, + 'style="'.$width.'"' + ); + } + $date->add(new DateInterval('P1W')); + } + $row++; + } + + $content = $table->toHtml(); +} + +echo $form->returnForm(); +echo $content; + +Display::display_footer();