12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169 |
- <?php
- /* For licensing terms, see /license.txt */
- use Chamilo\CoreBundle\Entity\ExtraFieldSavedSearch;
- use ChamiloSession as Session;
- $cidReset = true;
- require_once 'main/inc/global.inc.php';
- $htmlHeadXtra[] = '<link href="'.api_get_path(WEB_PATH).'web/assets/cropper/dist/cropper.min.css" rel="stylesheet">';
- $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_PATH).'web/assets/cropper/dist/cropper.min.js"></script>';
- $htmlHeadXtra[] = '<script>
- $(document).ready(function() {
- $("#filiere").on("click", function() {
- $("#filiere_panel").toggle();
- return false;
- });
-
- $("#dispo").on("click", function() {
- $("#dispo_panel").toggle();
- return false;
- });
-
- $("#dispo_pendant").on("click", function() {
- $("#dispo_pendant_panel").toggle();
- return false;
- });
-
- $("#niveau").on("click", function() {
- $("#niveau_panel").toggle();
- return false;
- });
-
- $("#methode").on("click", function() {
- $("#methode_panel").toggle();
- return false;
- });
-
- $("#themes").on("click", function() {
- $("#themes_panel").toggle();
- return false;
- });
-
- $("#objectifs").on("click", function() {
- $("#objectifs_panel").toggle();
- return false;
- });
- });
- </script>';
- api_block_anonymous_users();
- $allowToSee = api_is_drh() || api_is_student_boss() || api_is_platform_admin();
- if ($allowToSee === false) {
- api_not_allowed(true);
- }
- $userId = api_get_user_id();
- $userInfo = api_get_user_info();
- $userToLoad = isset($_GET['user_id']) ? $_GET['user_id'] : '';
- $userToLoadInfo = [];
- if ($userToLoad) {
- $userToLoadInfo = api_get_user_info($userToLoad);
- }
- $action = isset($_GET['action']) ? $_GET['action'] : '';
- switch ($action) {
- case 'subscribe_user':
- $sessionId = isset($_GET['session_id']) ? $_GET['session_id'] : '';
- SessionManager::subscribeUsersToSession(
- $sessionId,
- [$userToLoad],
- SESSION_VISIBLE_READ_ONLY,
- false
- );
- Display::addFlash(Display::return_message(get_lang('UserAdded')));
- header("Location: ".api_get_self().'?user_id='.$userToLoad.'#session-table');
- exit;
- break;
- case 'unsubscribe_user':
- $sessionId = isset($_GET['session_id']) ? $_GET['session_id'] : '';
- SessionManager::unsubscribe_user_from_session($sessionId, $userToLoad);
- Display::addFlash(Display::return_message(get_lang('Unsubscribed')));
- header("Location: ".api_get_self().'?user_id='.$userToLoad.'#session-table');
- break;
- }
- $em = Database::getManager();
- $formSearch = new FormValidator('load', 'get', api_get_self());
- $formSearch->addHeader(get_lang('LoadDiagnosis'));
- if (!empty($userInfo)) {
- $users = [];
- switch ($userInfo['status']) {
- case DRH:
- $users = UserManager::get_users_followed_by_drh($userId);
- break;
- case STUDENT_BOSS:
- $users = UserManager::getUsersFollowedByStudentBoss($userId);
- break;
- }
- if (!empty($users)) {
- $userList = [];
- foreach ($users as $user) {
- $userList[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
- }
- $formSearch->addSelect('user_id', get_lang('User'), $userList);
- }
- }
- if ($userToLoad) {
- $formSearch->setDefaults(['user_id' => $userToLoad]);
- }
- $formSearch->addButtonSearch(get_lang('ShowDiagnostic'), 'save');
- $form = new FormValidator('search', 'post', api_get_self().'?user_id='.$userToLoad.'#session-table');
- $form->addHeader(get_lang('Diagnosis'));
- $form->addHidden('user_id', $userToLoad);
- /** @var ExtraFieldSavedSearch $saved */
- $search = [
- 'user' => $userToLoad,
- ];
- $items = $em->getRepository('ChamiloCoreBundle:ExtraFieldSavedSearch')->findBy($search);
- if (empty($items)) {
- Display::addFlash(Display::return_message('NoData'));
- }
- $defaults = [];
- $tagsData = [];
- if (!empty($items)) {
- /** @var ExtraFieldSavedSearch $item */
- foreach ($items as $item) {
- $variable = 'extra_'.$item->getField()->getVariable();
- if ($item->getField()->getFieldType() == ExtraField::FIELD_TYPE_TAG) {
- $tagsData[$variable] = $item->getValue();
- }
- $defaults[$variable] = $item->getValue();
- }
- }
- $extraField = new ExtraField('session');
- $extraFieldValue = new ExtraFieldValue('session');
- $extraFieldValueUser = new ExtraFieldValue('user');
- $theme = 'theme_fr';
- $lang = $defaultLangCible = api_get_interface_language();
- if ($userToLoadInfo) {
- $lang = $userToLoadInfo['language'];
- $targetLanguageInfo = $extraFieldValueUser->get_values_by_handler_and_field_variable(
- $userToLoad,
- 'langue_cible'
- );
- if (!empty($targetLanguageInfo)) {
- $defaultLangCible = $targetLanguageInfo['value'];
- }
- switch ($lang) {
- case 'italian':
- $theme = 'theme_it';
- break;
- case 'polish':
- $theme = 'theme_pl';
- break;
- case 'spanish':
- $theme = 'theme_es';
- break;
- case 'french2':
- case 'french':
- $theme = 'theme_fr';
- break;
- case 'german2':
- case 'german':
- $theme = 'theme_de';
- break;
- }
- }
- $extraFieldUser = new ExtraField('user');
- $userForm = new FormValidator('user_form', 'post', api_get_self());
- $jqueryExtra = '';
- $userForm->addHtml('<div class="panel-group" id="search_extrafield" role="tablist" aria-multiselectable="true">');
- $userForm->addHtml('<div class="panel panel-default">');
- $userForm->addHtml('<div class="panel-heading"><a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">'.get_lang('Filiere').'</a></div>');
- $userForm->addHtml('<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">');
- $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('FiliereExplanation').'</p>');
- $fieldsToShow = [
- 'statusocial',
- 'filiere_user',
- 'filiereprecision',
- 'filiere_want_stage',
- ];
- $forceShowFields = true;
- $filter = false;
- $extra = $extraFieldUser->addElements(
- $userForm,
- $userToLoad,
- [],
- $filter,
- true,
- $fieldsToShow,
- $fieldsToShow,
- [],
- false,
- $forceShowFields, //$forceShowFields = false
- [],
- []
- );
- $userForm->addHtml('</div></div></div>');
- $userForm->addHtml('<div class="panel panel-default">');
- $userForm->addHtml('<div class="panel-heading"><a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseThree" aria-expanded="true" aria-controls="collapseThree">'.get_lang('DisponibilitePendantMonStage').'</a></div>');
- $userForm->addHtml('<div id="collapseThree" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingThree">');
- $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('DisponibilitePendantMonStageExplanation').'</p>');
- $fieldsToShow = [
- 'datedebutstage',
- 'datefinstage',
- 'deja_sur_place',
- 'poursuiteapprentissagestage',
- 'heures_disponibilite_par_semaine_stage',
- ];
- $extra = $extraFieldUser->addElements(
- $userForm,
- $userToLoad,
- [],
- $filter,
- true,
- $fieldsToShow,
- $fieldsToShow,
- [],
- false,
- $forceShowFields, //$forceShowFields = false
- [],
- []
- );
- $userForm->addHtml('</div></div></div>');
- $userForm->addHtml('<div class="panel panel-default">');
- $userForm->addHtml('<div class="panel-heading"><a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseSix" aria-expanded="true" aria-controls="collapseSix">'.get_lang('ObjectifsApprentissage').'</a></div>');
- $userForm->addHtml('<div id="collapseSix" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingSix">');
- $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('ObjectifsApprentissageExplanation').'</p>');
- $fieldsToShow = [
- 'objectif_apprentissage',
- ];
- $extra = $extraFieldUser->addElements(
- $userForm,
- $userToLoad,
- [],
- $filter,
- false,
- $fieldsToShow,
- $fieldsToShow,
- $defaults,
- false,
- $forceShowFields,//$forceShowFields = false
- [],
- []
- );
- $userForm->addHtml('</div></div></div>');
- $userForm->addHtml('<div class="panel panel-default">');
- $userForm->addHtml('<div class="panel-heading"><a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseSeven" aria-expanded="true" aria-controls="collapseSeven">'.get_lang('MethodeTravail').'</a></div>');
- $userForm->addHtml('<div id="collapseSeven" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingSeven">');
- $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('MethodeTravailExplanation').'</p>');
- $fieldsToShow = [
- 'methode_de_travaille',
- 'accompagnement',
- ];
- $extra = $extraFieldUser->addElements(
- $userForm,
- $userToLoad,
- [],
- $filter,
- true,
- $fieldsToShow,
- $fieldsToShow,
- [],
- false,
- $forceShowFields, //$forceShowFields = false
- [],
- []
- );
- $userForm->addHtml('</div></div></div>');
- if (isset($_POST) && !empty($_POST)) {
- $searchChecked1 = isset($_POST['search_using_1']) ? 'checked' : '';
- $searchChecked2 = isset($_POST['search_using_2']) ? 'checked' : '';
- $searchChecked3 = isset($_POST['search_using_3']) ? 'checked' : '';
- Session::write('search_using_1', $searchChecked1);
- Session::write('search_using_2', $searchChecked2);
- Session::write('search_using_3', $searchChecked3);
- } else {
- $searchChecked1 = Session::read('search_using_1');
- $searchChecked1 = $searchChecked1 === null ? 'checked' : $searchChecked1;
- $searchChecked2 = Session::read('search_using_2');
- $searchChecked2 = $searchChecked2 === null ? 'checked' : $searchChecked2;
- $searchChecked3 = Session::read('search_using_3');
- $searchChecked3 = $searchChecked3 === null ? 'checked' : $searchChecked3;
- }
- $form->addHtml('<div class="panel panel-default">');
- $form->addHtml('<div class="panel-heading"><input type="checkbox" name="search_using_1" '.$searchChecked1.' /> <a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseTwo" aria-expanded="true" aria-controls="collapseTwo">'.get_lang('DisponibiliteAvant').'</a></div>');
- $form->addHtml('<div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo">');
- $form->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('DisponibiliteAvantExplanation').'</p>');
- // Session fields
- $showOnlyThisFields = [
- 'access_start_date',
- 'access_end_date',
- ];
- $extra = $extraField->addElements(
- $form,
- '',
- [],
- false, //filter
- true,
- $showOnlyThisFields,
- $showOnlyThisFields,
- $defaults,
- false, //$orderDependingDefaults
- true, // force
- [], // $separateExtraMultipleSelect
- []
- );
- $fieldsToShow = [
- 'heures_disponibilite_par_semaine',
- 'moment_de_disponibilite',
- //'langue_cible',
- ];
- $extra = $extraFieldUser->addElements(
- $form,
- $userToLoad,
- [],
- $filter,
- true,
- $fieldsToShow,
- $fieldsToShow,
- [],
- false,
- $forceShowFields //$forceShowFields = false
- );
- $form->addHtml('</div></div></div>');
- $form->addHtml('<div class="panel panel-default">');
- $form->addHtml('<div class="panel-heading"><input type="checkbox" name="search_using_2" '.$searchChecked2.' /> <a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseFour" aria-expanded="true" aria-controls="collapseFour">'.get_lang('ThemesObjectifs').'</a></div>');
- $form->addHtml('<div id="collapseFour" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingFour">');
- $form->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('ThemesObjectifsExplanation').'</p>');
- $showOnlyThisFields = [
- 'domaine',
- 'filiere',
- $theme,
- ];
- $extra = $extraField->addElements(
- $form,
- '',
- [],
- false, //filter
- true,
- $showOnlyThisFields,
- $showOnlyThisFields,
- $defaults,
- false, //$orderDependingDefaults
- true, // force
- ['domaine' => 3, $theme => 5], // $separateExtraMultipleSelect
- [
- 'domaine' => [
- get_lang('Domaine').' 1',
- get_lang('Domaine').' 2',
- get_lang('Domaine').' 3',
- ],
- $theme => [
- get_lang('ThemeField').' 1',
- get_lang('ThemeField').' 2',
- get_lang('ThemeField').' 3',
- get_lang('ThemeField').' 4',
- get_lang('ThemeField').' 5',
- ],
- ],
- true
- );
- // Commented because BT#15776
- $fieldsToShow = [
- 'langue_cible',
- ];
- $extra = $extraFieldUser->addElements(
- $form,
- $userToLoad,
- [],
- $filter,
- true,
- $fieldsToShow,
- $fieldsToShow,
- [],
- false,
- $forceShowFields //$forceShowFields = false
- );
- $form->addHtml('</div></div></div>');
- $form->addHtml('<div class="panel panel-default">');
- $form->addHtml('<div class="panel-heading"><input type="checkbox" name="search_using_3" '.$searchChecked3.' /> <a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseFive" aria-expanded="true" aria-controls="collapseFive">'.get_lang('NiveauLangue').'</a></div>');
- $form->addHtml('<div id="collapseFive" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingFive">');
- $form->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('NiveauLangueExplanation').'</p>');
- $showOnlyThisFields = [
- 'ecouter',
- 'lire',
- 'participer_a_une_conversation',
- 's_exprimer_oralement_en_continu',
- 'ecrire',
- ];
- $extra = $extraField->addElements(
- $form,
- '',
- [],
- false, //filter
- true,
- $showOnlyThisFields,
- $showOnlyThisFields,
- $defaults,
- false, //$orderDependingDefaults
- true, // force
- ['domaine' => 3, $theme => 5], // $separateExtraMultipleSelect
- [
- 'domaine' => [
- get_lang('Domaine').' 1',
- get_lang('Domaine').' 2',
- get_lang('Domaine').' 3',
- ],
- $theme => [
- get_lang('Theme').' 1',
- get_lang('Theme').' 2',
- get_lang('Theme').' 3',
- get_lang('Theme').' 4',
- get_lang('Theme').' 5',
- ],
- ]
- );
- $form->addHtml('</div></div></div>');
- // Enviroment
- $userForm->addHtml('<div class="panel panel-default">');
- $userForm->addHtml(
- '<div class="panel-heading">
- <a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseEight" aria-expanded="true" aria-controls="collapseEight">'.
- get_lang('MonEnvironnementDeTravail').'</a></div>');
- $userForm->addHtml('<div id="collapseEight" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingEight">');
- $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('MonEnvironnementDeTravailExplanation').'</p>');
- $fieldsToShow = [
- 'outil_de_travail_ordinateur',
- 'outil_de_travail_ordinateur_so',
- 'outil_de_travail_tablette',
- 'outil_de_travail_tablette_so',
- 'outil_de_travail_smartphone',
- 'outil_de_travail_smartphone_so',
- ];
- $userForm->addLabel(null, get_lang('MonEnvironnementDeTravailExplanationIntro1'));
- $extra = $extraFieldUser->addElements(
- $userForm,
- $userToLoad,
- [],
- $filter,
- true,
- $fieldsToShow,
- $fieldsToShow,
- [],
- false,
- $forceShowFields
- );
- $userForm->addLabel(null, get_lang('MonEnvironnementDeTravailExplanationIntro2'));
- $jqueryExtra .= $extra['jquery_ready_content'];
- $fieldsToShow = [
- 'browser_platforme',
- 'browser_platforme_autre',
- 'browser_platforme_version',
- ];
- $extra = $extraFieldUser->addElements(
- $userForm,
- $userToLoad,
- [],
- $filter,
- true,
- $fieldsToShow,
- $fieldsToShow,
- [],
- false,
- $forceShowFields, //$forceShowFields = false
- [],
- []
- );
- $jqueryExtra .= $extra['jquery_ready_content'];
- $userForm->addHtml('<p class="text-info">'.get_lang('MonEnvironnementDeTravailRenvoiFAQ').'</p>');
- $userForm->addButtonSave(get_lang('Save'), 'submit_partial[collapseEight]');
- $userForm->addHtml('</div></div></div>');
- $form->addButtonSave(get_lang('SaveDiagnosticChanges'), 'save');
- $form->addButtonSearch(get_lang('SearchSessions'), 'search');
- $extraFieldsToFilter = $extraField->get_all(['variable = ?' => 'temps_de_travail']);
- $extraFieldToSearch = [];
- if (!empty($extraFieldsToFilter)) {
- foreach ($extraFieldsToFilter as $filter) {
- $extraFieldToSearch[] = $filter['id'];
- }
- }
- $extraFieldListToString = implode(',', $extraFieldToSearch);
- $result = SessionManager::getGridColumns('simple', $extraFieldsToFilter);
- $columns = $result['columns'];
- $column_model = $result['column_model'];
- $form->setDefaults($defaults);
- /** @var HTML_QuickForm_select $element */
- $domaine1 = $form->getElementByName('extra_domaine[0]');
- $domaine2 = $form->getElementByName('extra_domaine[1]');
- $domaine3 = $form->getElementByName('extra_domaine[2]');
- $userForm->setDefaults($defaults);
- $domainList = array_merge(
- is_object($domaine1) && !empty($domaine1->getValue()) ? $domaine1->getValue() : [],
- is_object($domaine3) && !empty($domaine3->getValue()) ? $domaine3->getValue() : [],
- is_object($domaine2) && !empty($domaine2->getValue()) ? $domaine2->getValue() : []
- );
- $themeList = [];
- $extraField = new ExtraField('session');
- $resultOptions = $extraField->searchOptionsFromTags('extra_domaine', 'extra_'.$theme, $domainList);
- if ($resultOptions) {
- $resultOptions = array_column($resultOptions, 'tag', 'id');
- $resultOptions = array_filter($resultOptions);
- for ($i = 0; $i < 5; $i++) {
- /** @var HTML_QuickForm_select $theme */
- $themeElement = $form->getElementByName('extra_'.$theme.'['.$i.']');
- foreach ($resultOptions as $key => $value) {
- $themeElement->addOption($value, $value);
- }
- }
- }
- $filterToSend = '';
- if ($formSearch->validate()) {
- $formSearchParams = $formSearch->getSubmitValues();
- }
- // Search filter
- $filters = [];
- foreach ($defaults as $key => $value) {
- if (substr($key, 0, 6) != 'extra_' && substr($key, 0, 7) != '_extra_') {
- continue;
- }
- if (!empty($value)) {
- $filters[$key] = $value;
- }
- }
- $filterToSend = [];
- if (!empty($filters)) {
- $filterToSend = ['groupOp' => 'AND'];
- if ($filters) {
- $count = 1;
- $countExtraField = 1;
- foreach ($result['column_model'] as $column) {
- if ($count > 5) {
- if (isset($filters[$column['name']])) {
- $defaultValues['jqg'.$countExtraField] = $filters[$column['name']];
- /*switch ($column['name']) {
- case 'extra_theme_it':
- case 'extra_theme_de':
- case 'extra_theme_es':
- case 'extra_theme_fr':
- break;
- case 'extra_domaine':
- break;
- case '':
- break;
- }*/
- $filterToSend['rules'][] = ['field' => $column['name'], 'op' => 'cn', 'data' => $filters[$column['name']]];
- }
- $countExtraField++;
- }
- $count++;
- }
- }
- }
- $params = [];
- if ($form->validate()) {
- $params = $form->getSubmitValues();
- $save = false;
- $search = false;
- if (isset($params['search'])) {
- unset($params['search']);
- $search = true;
- }
- if (isset($params['save'])) {
- $save = true;
- unset($params['save']);
- }
- $form->setDefaults($params);
- $filters = [];
- // Search
- if ($search) {
- // Parse params.
- foreach ($params as $key => $value) {
- if (substr($key, 0, 6) != 'extra_' && substr($key, 0, 7) != '_extra_') {
- continue;
- }
- if (!empty($value)) {
- $filters[$key] = $value;
- }
- }
- $filterToSend = [];
- if (!empty($filters)) {
- $filterToSend = ['groupOp' => 'AND'];
- if ($filters) {
- $count = 1;
- $countExtraField = 1;
- foreach ($result['column_model'] as $column) {
- if ($count > 5) {
- if (isset($filters[$column['name']])) {
- $defaultValues['jqg'.$countExtraField] = $filters[$column['name']];
- $filterToSend['rules'][] = [
- 'field' => $column['name'],
- 'op' => 'cn',
- 'data' => $filters[$column['name']],
- ];
- }
- $countExtraField++;
- }
- $count++;
- }
- }
- }
- }
- if ($save) {
- $userData = $params;
- // Update extra_heures_disponibilite_par_semaine
- $extraFieldValue = new ExtraFieldValue('user');
- $userDataToSave = [
- 'item_id' => $userToLoad,
- 'extra_heures_disponibilite_par_semaine' => isset($userData['extra_heures_disponibilite_par_semaine']) ? $userData['extra_heures_disponibilite_par_semaine'] : '',
- 'extra_langue_cible' => isset($userData['extra_langue_cible']) ? $userData['extra_langue_cible'] : '',
- ];
- $extraFieldValue->saveFieldValues(
- $userDataToSave,
- true,
- false,
- ['heures_disponibilite_par_semaine' , 'langue_cible']
- );
- // Save session search
- /** @var \Chamilo\UserBundle\Entity\User $user */
- $user = $em->getRepository('ChamiloUserBundle:User')->find($userToLoad);
- $extraFieldValueSession = new ExtraFieldValue('session');
- $sessionFields = [
- 'extra_access_start_date',
- 'extra_access_end_date',
- 'extra_filiere',
- 'extra_domaine',
- 'extra_domaine[0]',
- 'extra_domaine[1]',
- 'extra_domaine[3]',
- 'extra_temps_de_travail',
- //'extra_competenceniveau',
- 'extra_'.$theme,
- 'extra_ecouter',
- 'extra_lire',
- 'extra_participer_a_une_conversation',
- 'extra_s_exprimer_oralement_en_continu',
- 'extra_ecrire',
- ];
- foreach ($userData as $key => $value) {
- $found = strpos($key, '__persist__');
- if ($found === false) {
- continue;
- }
- }
- if (isset($userData['extra_filiere_want_stage']) &&
- isset($userData['extra_filiere_want_stage']['extra_filiere_want_stage'])
- ) {
- $wantStage = $userData['extra_filiere_want_stage']['extra_filiere_want_stage'];
- if ($wantStage === 'yes') {
- if (isset($userData['extra_filiere_user'])) {
- $userData['extra_filiere'] = [];
- $userData['extra_filiere']['extra_filiere'] = $userData['extra_filiere_user']['extra_filiere_user'];
- }
- }
- }
- // save in ExtraFieldSavedSearch.
- foreach ($userData as $key => $value) {
- if (substr($key, 0, 6) != 'extra_' && substr($key, 0, 7) != '_extra_') {
- continue;
- }
- if (!in_array($key, $sessionFields)) {
- continue;
- }
- $field_variable = substr($key, 6);
- $extraFieldInfo = $extraFieldValueSession
- ->getExtraField()
- ->get_handler_field_info_by_field_variable($field_variable);
- if (!$extraFieldInfo) {
- continue;
- }
- $extraFieldObj = $em->getRepository('ChamiloCoreBundle:ExtraField')->find($extraFieldInfo['id']);
- $search = [
- 'field' => $extraFieldObj,
- 'user' => $user,
- ];
- /** @var ExtraFieldSavedSearch $saved */
- $saved = $em->getRepository('ChamiloCoreBundle:ExtraFieldSavedSearch')->findOneBy($search);
- if ($saved) {
- $saved
- ->setField($extraFieldObj)
- ->setUser($user)
- ->setValue($value)
- ;
- $em->merge($saved);
- } else {
- $saved = new ExtraFieldSavedSearch();
- $saved
- ->setField($extraFieldObj)
- ->setUser($user)
- ->setValue($value)
- ;
- $em->persist($saved);
- }
- $em->flush();
- }
- Display::addFlash(Display::return_message(get_lang('Saved'), 'success'));
- header('Location: '.api_get_self().'?user_id='.$userToLoad);
- exit;
- }
- }
- $view = $form->returnForm();
- $jsTag = '';
- if (!empty($tagsData)) {
- foreach ($tagsData as $extraField => $tags) {
- foreach ($tags as $tag) {
- $tag = api_htmlentities($tag);
- }
- }
- }
- $htmlHeadXtra[] = '<script>
- $(function() {
- '.$jqueryExtra.'
- '.$jsTag.'
- });
- </script>';
- if (!empty($filterToSend)) {
- if (isset($params['search_using_1'])) {
- // Get start and end date from ExtraFieldSavedSearch
- $defaultExtraStartDate = isset($defaults['extra_access_start_date']) ? $defaults['extra_access_start_date'] : '';
- $defaultExtraEndDate = isset($defaults['extra_access_end_date']) ? $defaults['extra_access_end_date'] : '';
- $userStartDate = isset($params['extra_access_start_date']) ? $params['extra_access_start_date'] : $defaultExtraStartDate;
- $userEndDate = isset($params['extra_access_end_date']) ? $params['extra_access_end_date'] : $defaultExtraEndDate;
- // Minus 3 days
- $date = new DateTime($userStartDate);
- $date->sub(new DateInterval('P3D'));
- $userStartDateMinus = $date->format('Y-m-d h:i:s');
- // Plus 2 days
- $date = new DateTime($userEndDate);
- $date->add(new DateInterval('P2D'));
- $userEndDatePlus = $date->format('Y-m-d h:i:s');
- // Ofaj fix
- $userStartDateMinus = api_get_utc_datetime(substr($userStartDateMinus, 0, 11).'00:00:00');
- $userEndDatePlus = api_get_utc_datetime(substr($userEndDatePlus, 0, 11).'23:59:59');
- // Special OFAJ date logic
- if ($userEndDate == '') {
- $sql = " AND (
- (s.access_start_date >= '$userStartDateMinus') OR
- ((s.access_start_date = '' OR s.access_start_date IS NULL) AND (s.access_end_date = '' OR s.access_end_date IS NULL))
- )";
- } else {
- $sql = " AND (
- (s.access_start_date >= '$userStartDateMinus' AND s.access_end_date < '$userEndDatePlus') OR
- (s.access_start_date >= '$userStartDateMinus' AND (s.access_end_date = '' OR s.access_end_date IS NULL)) OR
- ((s.access_start_date = '' OR s.access_start_date IS NULL) AND (s.access_end_date = '' OR s.access_end_date IS NULL))
- )";
- }
- }
- $deleteFiliere = false;
- $extraFieldOptions = new ExtraFieldOption('session');
- $extraFieldSession = new ExtraField('session');
- // Special filters
- // see https://task.beeznest.com/issues/10849#change-81902
- foreach ($filterToSend['rules'] as &$filterItem) {
- if (isset($filterItem['field'])) {
- switch ($filterItem['field']) {
- case 'extra_filiere':
- case 'extra_domaine':
- case 'extra_theme_it':
- case 'extra_theme_fr':
- case 'extra_theme_de':
- case 'extra_theme_pl':
- if (!isset($params['search_using_2'])) {
- $filterItem = null;
- }
- break;
- }
- switch ($filterItem['field']) {
- case 'extra_ecouter':
- case 'extra_lire':
- case 'extra_participer_a_une_conversation':
- case 'extra_s_exprimer_oralement_en_continu':
- case 'extra_ecrire':
- if (!isset($params['search_using_3'])) {
- $filterItem = null;
- break;
- }
- $selectedValue = '';
- $fieldExtra = str_replace('extra_', '', $filterItem['field']);
- $extraFieldSessionData = $extraFieldSession->get_handler_field_info_by_field_variable($fieldExtra);
- if (is_array($filterItem['data'])) {
- $myOrder = [];
- foreach ($filterItem['data'] as $option) {
- foreach ($extraFieldSessionData['options'] as $optionValue) {
- if ($option == $optionValue['option_value']) {
- $myOrder[$optionValue['option_order']] = $optionValue['option_value'];
- }
- }
- }
- if (!empty($myOrder)) {
- // Taking last from list
- $selectedValue = end($myOrder);
- }
- } else {
- $selectedValue = $filterItem['data'];
- }
- $newOptions = array_column(
- $extraFieldSessionData['options'],
- 'option_value',
- 'option_order'
- );
- $searchOptions = [];
- for ($i = 1; $i < count($newOptions); $i++) {
- if ($selectedValue == $newOptions[$i]) {
- if (isset($newOptions[$i - 1])) {
- $searchOptions[] = $newOptions[$i - 1];
- }
- if (isset($newOptions[$i])) {
- $searchOptions[] = $newOptions[$i];
- }
- if (isset($newOptions[$i + 1])) {
- $searchOptions[] = $newOptions[$i + 1];
- }
- break;
- }
- }
- $filterItem['data'] = $searchOptions;
- break;
- case 'extra_domaine':
- if (!isset($params['search_using_2'])) {
- break;
- }
- // Special condition see:
- // https://task.beeznest.com/issues/10849#note-218
- // Remove filiere
- $list = [
- 'vie-quotidienne',
- //'competente-dans-mon-domaine-de-specialite',
- 'arrivee-sur-mon-poste-de-travail',
- ];
- $deleteFiliere = false;
- if (is_array($filterItem['data'])) {
- $myOrder = [];
- foreach ($filterItem['data'] as $option) {
- if (in_array($option, $list)) {
- $deleteFiliere = true;
- break;
- }
- }
- } else {
- if (in_array($filterItem['data'], $list)) {
- $deleteFiliere = true;
- }
- }
- break;
- }
- }
- if ($deleteFiliere) {
- foreach ($filterToSend['rules'] as &$filterItem) {
- if (isset($filterItem['field']) && $filterItem['field'] == 'extra_filiere') {
- $filterItem = [];
- }
- }
- }
- }
- // Language
- $lang = isset($params['extra_langue_cible']) ? $params['extra_langue_cible'] : $defaultLangCible;
- $lang = strtolower($lang);
- if (isset($params['search_using_1'])) {
- if ($userStartDate && !empty($userStartDate)) {
- $filterToSend['custom_dates'] = $sql;
- }
- }
- $filterToSend = json_encode($filterToSend);
- $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&_search=true&load_extra_field='.
- $extraFieldListToString.'&_force_search=true&rows=20&page=1&sidx=&sord=asc&filters2='.$filterToSend;
- if (isset($params['search_using_2'])) {
- $url .= '&lang='.$lang;
- }
- } else {
- $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&_search=true&load_extra_field='.
- $extraFieldListToString.'&_force_search=true&rows=20&page=1&sidx=&sord=asc';
- }
- // Autowidth
- $extra_params['autowidth'] = 'true';
- // height auto
- $extra_params['height'] = 'auto';
- $extra_params['postData'] = [
- 'filters' => [
- 'groupOp' => 'AND',
- 'rules' => $result['rules'],
- ],
- ];
- $sessionByUserList = SessionManager::get_sessions_by_user($userToLoad, true, true);
- $sessionUserList = [];
- if (!empty($sessionByUserList)) {
- foreach ($sessionByUserList as $sessionByUser) {
- $sessionUserList[] = (string) $sessionByUser['session_id'];
- }
- }
- $action_links = 'function action_formatter(cellvalue, options, rowObject) {
- var sessionList = '.json_encode($sessionUserList).';
- var id = options.rowId.toString();
- if (sessionList.indexOf(id) == -1) {
- return \'<a href="'.api_get_self().'?action=subscribe_user&user_id='.$userToLoad.'&session_id=\'+id+\'">'.Display::return_icon('add.png', addslashes(get_lang('Subscribe')), '', ICON_SIZE_SMALL).'</a>'.'\';
- } else {
- return \'<a href="'.api_get_self().'?action=unsubscribe_user&user_id='.$userToLoad.'&session_id=\'+id+\'">'.Display::return_icon('delete.png', addslashes(get_lang('Delete')), '', ICON_SIZE_SMALL).'</a>'.'\';
- }
- }';
- $htmlHeadXtra[] = api_get_jqgrid_js();
- $griJs = Display::grid_js(
- 'sessions',
- $url,
- $columns,
- $column_model,
- $extra_params,
- [],
- $action_links,
- true
- );
- $grid = '<div id="session-table" class="table-responsive">';
- $grid .= Display::grid_html('sessions');
- $grid .= '</div>';
- $htmlHeadXtra[] = '<style>
- .control-label {
- width: 25% !important;
- }
- </style>';
- $htmlHeadXtra[] = '<script>
- $(document).ready(function() {
- var blocks = [
- "#collapseOne",
- "#collapseTwo",
- "#collapseThree",
- "#collapseFour",
- "#collapseFive",
- "#collapseSix",
- "#collapseSeven",
- "#collapseEight"
- ];
-
- $.each(blocks, function( index, value ) {
- $(value).collapse("hide");
- });
- });
- </script>';
- $tpl = new Template(get_lang('Diagnosis'));
- if (empty($items)) {
- $view = '';
- $grid = '';
- $griJs = '';
- }
- $tpl->assign('form', $view);
- $tpl->assign('form_search', $formSearch->returnForm().$userForm->returnForm());
- $table = new HTML_Table(['class' => 'data_table']);
- $column = 0;
- $row = 0;
- $total = '0';
- $sumHours = '0';
- $numHours = '0';
- $field = 'heures_disponibilite_par_semaine';
- $extraField = new ExtraFieldValue('user');
- $data = $extraField->get_values_by_handler_and_field_variable($userToLoad, $field);
- $availableHoursPerWeek = 0;
- function dateDiffInWeeks($date1, $date2)
- {
- if ($date1 > $date2) {
- return dateDiffInWeeks($date2, $date1);
- }
- $first = new \DateTime($date1);
- $second = new \DateTime($date2);
- return floor($first->diff($second)->days / 7);
- }
- if ($data) {
- $availableHoursPerWeek = $data['value'];
- $numberWeeks = 0;
- if ($form->validate()) {
- $formData = $form->getSubmitValues();
- if (isset($formData['extra_access_start_date']) && isset($formData['extra_access_end_date'])) {
- $startDate = $formData['extra_access_start_date'];
- $endDate = $formData['extra_access_end_date'];
- $numberWeeks = dateDiffInWeeks($startDate, $endDate);
- }
- } else {
- if ($defaults) {
- if (isset($defaults['extra_access_start_date']) && isset($defaults['extra_access_end_date'])) {
- $startDate = $defaults['extra_access_start_date'];
- $endDate = $defaults['extra_access_end_date'];
- $numberWeeks = dateDiffInWeeks($startDate, $endDate);
- }
- }
- }
- $total = $numberWeeks * $availableHoursPerWeek;
- $sessions = SessionManager::getSessionsFollowedByUser($userToLoad);
- if ($sessions) {
- $sessionFieldValue = new ExtraFieldValue('session');
- foreach ($sessions as $session) {
- $sessionId = $session['id'];
- $data = $sessionFieldValue->get_values_by_handler_and_field_variable(
- $sessionId,
- 'temps_de_travail'
- );
- if ($data) {
- $sumHours += $data['value'];
- }
- }
- }
- }
- $numHours = $total - $sumHours;
- $headers = [
- get_lang('TotalAvailableHours') => $total,
- get_lang('SumHoursSessionsSubscribed') => $sumHours,
- get_lang('CountHoursAvailable') => $numHours,
- ];
- foreach ($headers as $header => $value) {
- $table->setCellContents($row, 0, $header);
- $table->updateCellAttributes($row, 0, 'width="250px"');
- $table->setCellContents($row, 1, $value);
- $row++;
- }
- $button = '';
- if ($userToLoad) {
- $button = Display::url(
- get_lang('OfajEndOfLearnPath'),
- api_get_path(WEB_CODE_PATH).'messages/new_message.php?prefill=ofaj&send_to_user='.$userToLoad,
- ['class' => 'btn btn-default']
- );
- $button .= '<br /><br />';
- }
- $userReportButton = Display::url(
- get_lang('DiagnosticValidateLearningPath'),
- api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$userToLoad,
- ['class' => 'btn btn-primary']
- );
- $tpl->assign('grid', $grid.$button.$table->toHtml().$userReportButton);
- $tpl->assign('grid_js', $griJs);
- $content = $tpl->fetch('default/user_portal/search_extra_field.tpl');
- $tpl->assign('content', $content);
- $tpl->display_one_col_template();
|