load_search.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\ExtraFieldSavedSearch;
  4. $cidReset = true;
  5. require_once 'main/inc/global.inc.php';
  6. $htmlHeadXtra[] = '<link href="'.api_get_path(WEB_PATH).'web/assets/cropper/dist/cropper.min.css" rel="stylesheet">';
  7. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_PATH).'web/assets/cropper/dist/cropper.min.js"></script>';
  8. $htmlHeadXtra[] = '<script>
  9. $(document).ready(function() {
  10. $("#filiere").on("click", function() {
  11. $("#filiere_panel").toggle();
  12. return false;
  13. });
  14. $("#dispo").on("click", function() {
  15. $("#dispo_panel").toggle();
  16. return false;
  17. });
  18. $("#dispo_pendant").on("click", function() {
  19. $("#dispo_pendant_panel").toggle();
  20. return false;
  21. });
  22. $("#niveau").on("click", function() {
  23. $("#niveau_panel").toggle();
  24. return false;
  25. });
  26. $("#methode").on("click", function() {
  27. $("#methode_panel").toggle();
  28. return false;
  29. });
  30. $("#themes").on("click", function() {
  31. $("#themes_panel").toggle();
  32. return false;
  33. });
  34. $("#objectifs").on("click", function() {
  35. $("#objectifs_panel").toggle();
  36. return false;
  37. });
  38. });
  39. </script>';
  40. api_block_anonymous_users();
  41. $allowToSee = api_is_drh() || api_is_student_boss() || api_is_platform_admin();
  42. if ($allowToSee === false) {
  43. api_not_allowed(true);
  44. }
  45. $userId = api_get_user_id();
  46. $userInfo = api_get_user_info();
  47. $userToLoad = isset($_GET['user_id']) ? $_GET['user_id'] : '';
  48. $userToLoadInfo = [];
  49. if ($userToLoad) {
  50. $userToLoadInfo = api_get_user_info($userToLoad);
  51. }
  52. $action = isset($_GET['action']) ? $_GET['action'] : '';
  53. switch ($action) {
  54. case 'subscribe_user':
  55. $sessionId = isset($_GET['session_id']) ? $_GET['session_id'] : '';
  56. SessionManager::subscribeUsersToSession(
  57. $sessionId,
  58. [$userToLoad],
  59. SESSION_VISIBLE_READ_ONLY,
  60. false
  61. );
  62. Display::addFlash(Display::return_message(get_lang('UserAdded')));
  63. header("Location: ".api_get_self().'?user_id='.$userToLoad.'#session-table');
  64. exit;
  65. break;
  66. case 'unsubscribe_user':
  67. $sessionId = isset($_GET['session_id']) ? $_GET['session_id'] : '';
  68. SessionManager::unsubscribe_user_from_session($sessionId, $userToLoad);
  69. Display::addFlash(Display::return_message(get_lang('Unsubscribed')));
  70. header("Location: ".api_get_self().'?user_id='.$userToLoad.'#session-table');
  71. break;
  72. }
  73. $em = Database::getManager();
  74. $formSearch = new FormValidator('load', 'get', api_get_self());
  75. $formSearch->addHeader(get_lang('LoadDiagnosis'));
  76. if (!empty($userInfo)) {
  77. $users = [];
  78. switch ($userInfo['status']) {
  79. case DRH:
  80. $users = UserManager::get_users_followed_by_drh($userId);
  81. break;
  82. case STUDENT_BOSS:
  83. $users = UserManager::getUsersFollowedByStudentBoss($userId);
  84. break;
  85. }
  86. if (!empty($users)) {
  87. $userList = [];
  88. foreach ($users as $user) {
  89. $userList[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
  90. }
  91. $formSearch->addSelect('user_id', get_lang('User'), $userList);
  92. }
  93. }
  94. if ($userToLoad) {
  95. $formSearch->setDefaults(['user_id' => $userToLoad]);
  96. }
  97. $formSearch->addButtonSearch(get_lang('ShowDiagnostic'), 'save');
  98. $form = new FormValidator('search', 'post', api_get_self().'?user_id='.$userToLoad.'#session-table');
  99. $form->addHeader(get_lang('Diagnosis'));
  100. $form->addHidden('user_id', $userToLoad);
  101. /** @var ExtraFieldSavedSearch $saved */
  102. $search = [
  103. 'user' => $userToLoad,
  104. ];
  105. $items = $em->getRepository('ChamiloCoreBundle:ExtraFieldSavedSearch')->findBy($search);
  106. if (empty($items)) {
  107. Display::addFlash(Display::return_message('NoData'));
  108. }
  109. $defaults = [];
  110. $tagsData = [];
  111. if (!empty($items)) {
  112. /** @var ExtraFieldSavedSearch $item */
  113. foreach ($items as $item) {
  114. $variable = 'extra_'.$item->getField()->getVariable();
  115. if ($item->getField()->getFieldType() == ExtraField::FIELD_TYPE_TAG) {
  116. $tagsData[$variable] = $item->getValue();
  117. }
  118. $defaults[$variable] = $item->getValue();
  119. }
  120. }
  121. $extraField = new ExtraField('session');
  122. $extraFieldValue = new ExtraFieldValue('session');
  123. $extraFieldValueUser = new ExtraFieldValue('user');
  124. $theme = 'theme_fr';
  125. $lang = $defaultLangCible = api_get_interface_language();
  126. if ($userToLoadInfo) {
  127. $lang = $userToLoadInfo['language'];
  128. $targetLanguageInfo = $extraFieldValueUser->get_values_by_handler_and_field_variable(
  129. $userToLoad,
  130. 'langue_cible'
  131. );
  132. if (!empty($targetLanguageInfo)) {
  133. $defaultLangCible = $targetLanguageInfo['value'];
  134. }
  135. switch ($lang) {
  136. case 'italian':
  137. $theme = 'theme_it';
  138. break;
  139. case 'polish':
  140. $theme = 'theme_pl';
  141. break;
  142. case 'spanish':
  143. $theme = 'theme_es';
  144. break;
  145. case 'french2':
  146. case 'french':
  147. $theme = 'theme_fr';
  148. break;
  149. case 'german2':
  150. case 'german':
  151. $theme = 'theme_de';
  152. break;
  153. }
  154. }
  155. $extraFieldUser = new ExtraField('user');
  156. $userForm = new FormValidator('user_form', 'post', api_get_self());
  157. $jqueryExtra = '';
  158. $userForm->addHtml('<div class="panel-group" id="search_extrafield" role="tablist" aria-multiselectable="true">');
  159. $userForm->addHtml('<div class="panel panel-default">');
  160. $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>');
  161. $userForm->addHtml('<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">');
  162. $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('FiliereExplanation').'</p>');
  163. $fieldsToShow = [
  164. 'statusocial',
  165. 'filiere_user',
  166. 'filiereprecision',
  167. 'filiere_want_stage',
  168. ];
  169. $forceShowFields = true;
  170. $filter = false;
  171. $extra = $extraFieldUser->addElements(
  172. $userForm,
  173. $userToLoad,
  174. [],
  175. $filter,
  176. true,
  177. $fieldsToShow,
  178. $fieldsToShow,
  179. [],
  180. false,
  181. $forceShowFields, //$forceShowFields = false
  182. [],
  183. []
  184. );
  185. $userForm->addHtml('</div></div></div>');
  186. $userForm->addHtml('<div class="panel panel-default">');
  187. $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>');
  188. $userForm->addHtml('<div id="collapseThree" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingThree">');
  189. $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('DisponibilitePendantMonStageExplanation').'</p>');
  190. $fieldsToShow = [
  191. 'datedebutstage',
  192. 'datefinstage',
  193. 'deja_sur_place',
  194. 'poursuiteapprentissagestage',
  195. 'heures_disponibilite_par_semaine_stage',
  196. ];
  197. $extra = $extraFieldUser->addElements(
  198. $userForm,
  199. $userToLoad,
  200. [],
  201. $filter,
  202. true,
  203. $fieldsToShow,
  204. $fieldsToShow,
  205. [],
  206. false,
  207. $forceShowFields, //$forceShowFields = false
  208. [],
  209. []
  210. );
  211. $userForm->addHtml('</div></div></div>');
  212. $userForm->addHtml('<div class="panel panel-default">');
  213. $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>');
  214. $userForm->addHtml('<div id="collapseSix" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingSix">');
  215. $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('ObjectifsApprentissageExplanation').'</p>');
  216. $fieldsToShow = [
  217. 'objectif_apprentissage',
  218. ];
  219. $extra = $extraFieldUser->addElements(
  220. $userForm,
  221. $userToLoad,
  222. [],
  223. $filter,
  224. false,
  225. $fieldsToShow,
  226. $fieldsToShow,
  227. $defaults,
  228. false,
  229. $forceShowFields,//$forceShowFields = false
  230. [],
  231. []
  232. );
  233. $userForm->addHtml('</div></div></div>');
  234. $userForm->addHtml('<div class="panel panel-default">');
  235. $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>');
  236. $userForm->addHtml('<div id="collapseSeven" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingSeven">');
  237. $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('MethodeTravailExplanation').'</p>');
  238. $fieldsToShow = [
  239. 'methode_de_travaille',
  240. 'accompagnement',
  241. ];
  242. $extra = $extraFieldUser->addElements(
  243. $userForm,
  244. $userToLoad,
  245. [],
  246. $filter,
  247. true,
  248. $fieldsToShow,
  249. $fieldsToShow,
  250. [],
  251. false,
  252. $forceShowFields, //$forceShowFields = false
  253. [],
  254. []
  255. );
  256. $userForm->addHtml('</div></div></div>');
  257. $form->addHtml('<div class="panel panel-default">');
  258. $form->addHtml('<div class="panel-heading"><a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseTwo" aria-expanded="true" aria-controls="collapseTwo">'.get_lang('DisponibiliteAvant').'</a></div>');
  259. $form->addHtml('<div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo">');
  260. $form->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('DisponibiliteAvantExplanation').'</p>');
  261. // Session fields
  262. $showOnlyThisFields = [
  263. 'access_start_date',
  264. 'access_end_date',
  265. ];
  266. $extra = $extraField->addElements(
  267. $form,
  268. '',
  269. [],
  270. false, //filter
  271. true,
  272. $showOnlyThisFields,
  273. $showOnlyThisFields,
  274. $defaults,
  275. false, //$orderDependingDefaults
  276. true, // force
  277. [], // $separateExtraMultipleSelect
  278. []
  279. );
  280. $fieldsToShow = [
  281. 'heures_disponibilite_par_semaine',
  282. 'moment_de_disponibilite',
  283. 'langue_cible',
  284. ];
  285. $extra = $extraFieldUser->addElements(
  286. $form,
  287. $userToLoad,
  288. [],
  289. $filter,
  290. true,
  291. $fieldsToShow,
  292. $fieldsToShow,
  293. [],
  294. false,
  295. $forceShowFields //$forceShowFields = false
  296. );
  297. $form->addHtml('</div></div></div>');
  298. $form->addHtml('<div class="panel panel-default">');
  299. $form->addHtml('<div class="panel-heading"><a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseFour" aria-expanded="true" aria-controls="collapseFour">'.get_lang('ThemesObjectifs').'</a></div>');
  300. $form->addHtml('<div id="collapseFour" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingFour">');
  301. $form->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('ThemesObjectifsExplanation').'</p>');
  302. $showOnlyThisFields = [
  303. 'domaine',
  304. 'filiere',
  305. $theme,
  306. ];
  307. $extra = $extraField->addElements(
  308. $form,
  309. '',
  310. [],
  311. false, //filter
  312. true,
  313. $showOnlyThisFields,
  314. $showOnlyThisFields,
  315. $defaults,
  316. false, //$orderDependingDefaults
  317. true, // force
  318. ['domaine' => 3, $theme => 5], // $separateExtraMultipleSelect
  319. [
  320. 'domaine' => [
  321. get_lang('Domaine').' 1',
  322. get_lang('Domaine').' 2',
  323. get_lang('Domaine').' 3',
  324. ],
  325. $theme => [
  326. get_lang('ThemeField').' 1',
  327. get_lang('ThemeField').' 2',
  328. get_lang('ThemeField').' 3',
  329. get_lang('ThemeField').' 4',
  330. get_lang('ThemeField').' 5',
  331. ],
  332. ],
  333. true
  334. );
  335. $fieldsToShow = [
  336. 'langue_cible',
  337. ];
  338. $extra = $extraFieldUser->addElements(
  339. $form,
  340. $userToLoad,
  341. [],
  342. $filter,
  343. true,
  344. $fieldsToShow,
  345. $fieldsToShow,
  346. [],
  347. false,
  348. $forceShowFields //$forceShowFields = false
  349. );
  350. $form->addHtml('</div></div></div>');
  351. $form->addHtml('<div class="panel panel-default">');
  352. $form->addHtml('<div class="panel-heading"><a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseFive" aria-expanded="true" aria-controls="collapseFive">'.get_lang('NiveauLangue').'</a></div>');
  353. $form->addHtml('<div id="collapseFive" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingFive">');
  354. $form->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('NiveauLangueExplanation').'</p>');
  355. $showOnlyThisFields = [
  356. 'ecouter',
  357. 'lire',
  358. 'participer_a_une_conversation',
  359. 's_exprimer_oralement_en_continu',
  360. 'ecrire',
  361. ];
  362. $extra = $extraField->addElements(
  363. $form,
  364. '',
  365. [],
  366. false, //filter
  367. true,
  368. $showOnlyThisFields,
  369. $showOnlyThisFields,
  370. $defaults,
  371. false, //$orderDependingDefaults
  372. true, // force
  373. ['domaine' => 3, $theme => 5], // $separateExtraMultipleSelect
  374. [
  375. 'domaine' => [
  376. get_lang('Domaine').' 1',
  377. get_lang('Domaine').' 2',
  378. get_lang('Domaine').' 3',
  379. ],
  380. $theme => [
  381. get_lang('Theme').' 1',
  382. get_lang('Theme').' 2',
  383. get_lang('Theme').' 3',
  384. get_lang('Theme').' 4',
  385. get_lang('Theme').' 5',
  386. ],
  387. ]
  388. );
  389. $form->addHtml('</div></div></div>');
  390. // Enviroment
  391. $userForm->addHtml('<div class="panel panel-default">');
  392. $userForm->addHtml(
  393. '<div class="panel-heading">
  394. <a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseEight" aria-expanded="true" aria-controls="collapseEight">'.
  395. get_lang('MonEnvironnementDeTravail').'</a></div>');
  396. $userForm->addHtml('<div id="collapseEight" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingEight">');
  397. $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('MonEnvironnementDeTravailExplanation').'</p>');
  398. $fieldsToShow = [
  399. 'outil_de_travail_ordinateur',
  400. 'outil_de_travail_ordinateur_so',
  401. 'outil_de_travail_tablette',
  402. 'outil_de_travail_tablette_so',
  403. 'outil_de_travail_smartphone',
  404. 'outil_de_travail_smartphone_so',
  405. ];
  406. $userForm->addLabel(null, get_lang('MonEnvironnementDeTravailExplanationIntro1'));
  407. $extra = $extraFieldUser->addElements(
  408. $userForm,
  409. $userToLoad,
  410. [],
  411. $filter,
  412. true,
  413. $fieldsToShow,
  414. $fieldsToShow,
  415. [],
  416. false,
  417. $forceShowFields
  418. );
  419. $userForm->addLabel(null, get_lang('MonEnvironnementDeTravailExplanationIntro2'));
  420. $jqueryExtra .= $extra['jquery_ready_content'];
  421. $fieldsToShow = [
  422. 'browser_platforme',
  423. 'browser_platforme_autre',
  424. 'browser_platforme_version',
  425. ];
  426. $extra = $extraFieldUser->addElements(
  427. $userForm,
  428. $userToLoad,
  429. [],
  430. $filter,
  431. true,
  432. $fieldsToShow,
  433. $fieldsToShow,
  434. [],
  435. false,
  436. $forceShowFields, //$forceShowFields = false
  437. [],
  438. []
  439. );
  440. $jqueryExtra .= $extra['jquery_ready_content'];
  441. $userForm->addHtml('<p class="text-info">'.get_lang('MonEnvironnementDeTravailRenvoiFAQ').'</p>');
  442. $userForm->addButtonSave(get_lang('Save'), 'submit_partial[collapseEight]');
  443. $userForm->addHtml('</div></div></div>');
  444. $form->addButtonSave(get_lang('SaveDiagnosticChanges'), 'save');
  445. $form->addButtonSearch(get_lang('SearchSessions'), 'search');
  446. $extraFieldsToFilter = $extraField->get_all(['variable = ?' => 'temps_de_travail']);
  447. $extraFieldToSearch = [];
  448. if (!empty($extraFieldsToFilter)) {
  449. foreach ($extraFieldsToFilter as $filter) {
  450. $extraFieldToSearch[] = $filter['id'];
  451. }
  452. }
  453. $extraFieldListToString = implode(',', $extraFieldToSearch);
  454. $result = SessionManager::getGridColumns('simple', $extraFieldsToFilter);
  455. $columns = $result['columns'];
  456. $column_model = $result['column_model'];
  457. $form->setDefaults($defaults);
  458. /** @var HTML_QuickForm_select $element */
  459. $domaine1 = $form->getElementByName('extra_domaine[0]');
  460. $domaine2 = $form->getElementByName('extra_domaine[1]');
  461. $domaine3 = $form->getElementByName('extra_domaine[2]');
  462. $userForm->setDefaults($defaults);
  463. $domainList = array_merge(
  464. is_object($domaine1) && !empty($domaine1->getValue()) ? $domaine1->getValue() : [],
  465. is_object($domaine3) && !empty($domaine3->getValue()) ? $domaine3->getValue() : [],
  466. is_object($domaine2) && !empty($domaine2->getValue()) ? $domaine2->getValue() : []
  467. );
  468. $themeList = [];
  469. $extraField = new ExtraField('session');
  470. $resultOptions = $extraField->searchOptionsFromTags('extra_domaine', 'extra_'.$theme, $domainList);
  471. if ($resultOptions) {
  472. $resultOptions = array_column($resultOptions, 'tag', 'id');
  473. $resultOptions = array_filter($resultOptions);
  474. for ($i = 0; $i < 5; $i++) {
  475. /** @var HTML_QuickForm_select $theme */
  476. $themeElement = $form->getElementByName('extra_'.$theme.'['.$i.']');
  477. foreach ($resultOptions as $key => $value) {
  478. $themeElement->addOption($value, $value);
  479. }
  480. }
  481. }
  482. $filterToSend = '';
  483. if ($formSearch->validate()) {
  484. $formSearchParams = $formSearch->getSubmitValues();
  485. }
  486. // Search filter
  487. $filters = [];
  488. foreach ($defaults as $key => $value) {
  489. if (substr($key, 0, 6) != 'extra_' && substr($key, 0, 7) != '_extra_') {
  490. continue;
  491. }
  492. if (!empty($value)) {
  493. $filters[$key] = $value;
  494. }
  495. }
  496. $filterToSend = [];
  497. if (!empty($filters)) {
  498. $filterToSend = ['groupOp' => 'AND'];
  499. if ($filters) {
  500. $count = 1;
  501. $countExtraField = 1;
  502. foreach ($result['column_model'] as $column) {
  503. if ($count > 5) {
  504. if (isset($filters[$column['name']])) {
  505. $defaultValues['jqg'.$countExtraField] = $filters[$column['name']];
  506. $filterToSend['rules'][] = ['field' => $column['name'], 'op' => 'cn', 'data' => $filters[$column['name']]];
  507. }
  508. $countExtraField++;
  509. }
  510. $count++;
  511. }
  512. }
  513. }
  514. $params = [];
  515. if ($form->validate()) {
  516. $params = $form->getSubmitValues();
  517. $save = false;
  518. $search = false;
  519. if (isset($params['search'])) {
  520. unset($params['search']);
  521. $search = true;
  522. }
  523. if (isset($params['save'])) {
  524. $save = true;
  525. unset($params['save']);
  526. }
  527. $form->setDefaults($params);
  528. $filters = [];
  529. // Search
  530. if ($search) {
  531. // Parse params.
  532. foreach ($params as $key => $value) {
  533. if (substr($key, 0, 6) != 'extra_' && substr($key, 0, 7) != '_extra_') {
  534. continue;
  535. }
  536. if (!empty($value)) {
  537. $filters[$key] = $value;
  538. }
  539. }
  540. $filterToSend = [];
  541. if (!empty($filters)) {
  542. $filterToSend = ['groupOp' => 'AND'];
  543. if ($filters) {
  544. $count = 1;
  545. $countExtraField = 1;
  546. foreach ($result['column_model'] as $column) {
  547. if ($count > 5) {
  548. if (isset($filters[$column['name']])) {
  549. $defaultValues['jqg'.$countExtraField] = $filters[$column['name']];
  550. $filterToSend['rules'][] = [
  551. 'field' => $column['name'],
  552. 'op' => 'cn',
  553. 'data' => $filters[$column['name']],
  554. ];
  555. }
  556. $countExtraField++;
  557. }
  558. $count++;
  559. }
  560. }
  561. }
  562. }
  563. if ($save) {
  564. $userData = $params;
  565. // Update extra_heures_disponibilite_par_semaine
  566. $extraFieldValue = new ExtraFieldValue('user');
  567. $userDataToSave = [
  568. 'item_id' => $userToLoad,
  569. 'extra_heures_disponibilite_par_semaine' => isset($userData['extra_heures_disponibilite_par_semaine']) ? $userData['extra_heures_disponibilite_par_semaine'] : '',
  570. 'extra_langue_cible' => isset($userData['extra_langue_cible']) ? $userData['extra_langue_cible'] : '',
  571. ];
  572. $extraFieldValue->saveFieldValues(
  573. $userDataToSave,
  574. true,
  575. false,
  576. ['heures_disponibilite_par_semaine', 'langue_cible']
  577. );
  578. // Save session search
  579. /** @var \Chamilo\UserBundle\Entity\User $user */
  580. $user = $em->getRepository('ChamiloUserBundle:User')->find($userToLoad);
  581. $extraFieldValueSession = new ExtraFieldValue('session');
  582. $sessionFields = [
  583. 'extra_access_start_date',
  584. 'extra_access_end_date',
  585. 'extra_filiere',
  586. 'extra_domaine',
  587. 'extra_domaine[0]',
  588. 'extra_domaine[1]',
  589. 'extra_domaine[3]',
  590. 'extra_temps_de_travail',
  591. //'extra_competenceniveau',
  592. 'extra_'.$theme,
  593. 'extra_ecouter',
  594. 'extra_lire',
  595. 'extra_participer_a_une_conversation',
  596. 'extra_s_exprimer_oralement_en_continu',
  597. 'extra_ecrire',
  598. ];
  599. foreach ($userData as $key => $value) {
  600. $found = strpos($key, '__persist__');
  601. if ($found === false) {
  602. continue;
  603. }
  604. }
  605. if (isset($userData['extra_filiere_want_stage']) &&
  606. isset($userData['extra_filiere_want_stage']['extra_filiere_want_stage'])
  607. ) {
  608. $wantStage = $userData['extra_filiere_want_stage']['extra_filiere_want_stage'];
  609. if ($wantStage === 'yes') {
  610. if (isset($userData['extra_filiere_user'])) {
  611. $userData['extra_filiere'] = [];
  612. $userData['extra_filiere']['extra_filiere'] = $userData['extra_filiere_user']['extra_filiere_user'];
  613. }
  614. }
  615. }
  616. // save in ExtraFieldSavedSearch.
  617. foreach ($userData as $key => $value) {
  618. if (substr($key, 0, 6) != 'extra_' && substr($key, 0, 7) != '_extra_') {
  619. continue;
  620. }
  621. if (!in_array($key, $sessionFields)) {
  622. continue;
  623. }
  624. $field_variable = substr($key, 6);
  625. $extraFieldInfo = $extraFieldValueSession
  626. ->getExtraField()
  627. ->get_handler_field_info_by_field_variable($field_variable);
  628. if (!$extraFieldInfo) {
  629. continue;
  630. }
  631. $extraFieldObj = $em->getRepository('ChamiloCoreBundle:ExtraField')->find($extraFieldInfo['id']);
  632. $search = [
  633. 'field' => $extraFieldObj,
  634. 'user' => $user,
  635. ];
  636. /** @var ExtraFieldSavedSearch $saved */
  637. $saved = $em->getRepository('ChamiloCoreBundle:ExtraFieldSavedSearch')->findOneBy($search);
  638. if ($saved) {
  639. $saved
  640. ->setField($extraFieldObj)
  641. ->setUser($user)
  642. ->setValue($value)
  643. ;
  644. $em->merge($saved);
  645. } else {
  646. $saved = new ExtraFieldSavedSearch();
  647. $saved
  648. ->setField($extraFieldObj)
  649. ->setUser($user)
  650. ->setValue($value)
  651. ;
  652. $em->persist($saved);
  653. }
  654. $em->flush();
  655. }
  656. Display::addFlash(Display::return_message(get_lang('Saved'), 'success'));
  657. header('Location: '.api_get_self().'?user_id='.$userToLoad);
  658. exit;
  659. }
  660. }
  661. $view = $form->returnForm();
  662. $jsTag = '';
  663. if (!empty($tagsData)) {
  664. foreach ($tagsData as $extraField => $tags) {
  665. foreach ($tags as $tag) {
  666. $tag = api_htmlentities($tag);
  667. }
  668. }
  669. }
  670. $htmlHeadXtra[] = '<script>
  671. $(function() {
  672. '.$jqueryExtra.'
  673. '.$jsTag.'
  674. });
  675. </script>';
  676. if (!empty($filterToSend)) {
  677. // Get start and end date from ExtraFieldSavedSearch
  678. $defaultExtraStartDate = isset($defaults['extra_access_start_date']) ? $defaults['extra_access_start_date'] : '';
  679. $defaultExtraEndDate = isset($defaults['extra_access_end_date']) ? $defaults['extra_access_end_date'] : '';
  680. $userStartDate = isset($params['extra_access_start_date']) ? $params['extra_access_start_date'] : $defaultExtraStartDate;
  681. $userEndDate = isset($params['extra_access_end_date']) ? $params['extra_access_end_date'] : $defaultExtraEndDate;
  682. // Minus 3 days
  683. $date = new DateTime($userStartDate);
  684. $date->sub(new DateInterval('P3D'));
  685. $userStartDateMinus = $date->format('Y-m-d h:i:s');
  686. // Plus 2 days
  687. $date = new DateTime($userEndDate);
  688. $date->add(new DateInterval('P2D'));
  689. $userEndDatePlus = $date->format('Y-m-d h:i:s');
  690. // Ofaj fix
  691. $userStartDateMinus = api_get_utc_datetime(substr($userStartDateMinus, 0, 11).'00:00:00');
  692. $userEndDatePlus = api_get_utc_datetime(substr($userEndDatePlus, 0, 11).'23:59:59');
  693. // Special OFAJ date logic
  694. if ($userEndDate == '') {
  695. $sql = " AND (
  696. (s.access_start_date >= '$userStartDateMinus') OR
  697. ((s.access_start_date = '' OR s.access_start_date IS NULL) AND (s.access_end_date = '' OR s.access_end_date IS NULL))
  698. )";
  699. } else {
  700. $sql = " AND (
  701. (s.access_start_date >= '$userStartDateMinus' AND s.access_end_date < '$userEndDatePlus') OR
  702. (s.access_start_date >= '$userStartDateMinus' AND (s.access_end_date = '' OR s.access_end_date IS NULL)) OR
  703. ((s.access_start_date = '' OR s.access_start_date IS NULL) AND (s.access_end_date = '' OR s.access_end_date IS NULL))
  704. )";
  705. }
  706. $deleteFiliere = false;
  707. $extraFieldOptions = new ExtraFieldOption('session');
  708. $extraFieldSession = new ExtraField('session');
  709. // Special filters
  710. // see https://task.beeznest.com/issues/10849#change-81902
  711. foreach ($filterToSend['rules'] as &$filterItem) {
  712. if (isset($filterItem['field'])) {
  713. switch ($filterItem['field']) {
  714. case 'extra_ecouter':
  715. case 'extra_lire':
  716. case 'extra_participer_a_une_conversation':
  717. case 'extra_s_exprimer_oralement_en_continu':
  718. case 'extra_ecrire':
  719. $selectedValue = '';
  720. $fieldExtra = str_replace('extra_', '', $filterItem['field']);
  721. $extraFieldSessionData = $extraFieldSession->get_handler_field_info_by_field_variable($fieldExtra);
  722. if (is_array($filterItem['data'])) {
  723. $myOrder = [];
  724. foreach ($filterItem['data'] as $option) {
  725. foreach ($extraFieldSessionData['options'] as $optionValue) {
  726. if ($option == $optionValue['option_value']) {
  727. $myOrder[$optionValue['option_order']] = $optionValue['option_value'];
  728. }
  729. }
  730. }
  731. if (!empty($myOrder)) {
  732. // Taking last from list
  733. $selectedValue = end($myOrder);
  734. }
  735. } else {
  736. $selectedValue = $filterItem['data'];
  737. }
  738. $newOptions = array_column(
  739. $extraFieldSessionData['options'],
  740. 'option_value',
  741. 'option_order'
  742. );
  743. $searchOptions = [];
  744. for ($i = 1; $i < count($newOptions); $i++) {
  745. if ($selectedValue == $newOptions[$i]) {
  746. if (isset($newOptions[$i - 1])) {
  747. $searchOptions[] = $newOptions[$i - 1];
  748. }
  749. if (isset($newOptions[$i])) {
  750. $searchOptions[] = $newOptions[$i];
  751. }
  752. if (isset($newOptions[$i + 1])) {
  753. $searchOptions[] = $newOptions[$i + 1];
  754. }
  755. break;
  756. }
  757. }
  758. $filterItem['data'] = $searchOptions;
  759. break;
  760. case 'extra_domaine':
  761. // Special condition see:
  762. // https://task.beeznest.com/issues/10849#note-218
  763. // Remove filiere
  764. $list = [
  765. 'vie-quotidienne',
  766. //'competente-dans-mon-domaine-de-specialite',
  767. 'arrivee-sur-mon-poste-de-travail',
  768. ];
  769. $deleteFiliere = false;
  770. if (is_array($filterItem['data'])) {
  771. $myOrder = [];
  772. foreach ($filterItem['data'] as $option) {
  773. if (in_array($option, $list)) {
  774. $deleteFiliere = true;
  775. break;
  776. }
  777. }
  778. } else {
  779. if (in_array($filterItem['data'], $list)) {
  780. $deleteFiliere = true;
  781. }
  782. }
  783. break;
  784. }
  785. }
  786. if ($deleteFiliere) {
  787. foreach ($filterToSend['rules'] as &$filterItem) {
  788. if (isset($filterItem['field']) && $filterItem['field'] == 'extra_filiere') {
  789. $filterItem = [];
  790. }
  791. }
  792. }
  793. }
  794. // Language
  795. $lang = isset($params['extra_langue_cible']) ? $params['extra_langue_cible'] : $defaultLangCible;
  796. $lang = strtolower($lang);
  797. if ($userStartDate && !empty($userStartDate)) {
  798. $filterToSend['custom_dates'] = $sql;
  799. }
  800. $filterToSend = json_encode($filterToSend);
  801. $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;
  802. $url .= '&lang='.$lang;
  803. } else {
  804. $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';
  805. }
  806. // Autowidth
  807. $extra_params['autowidth'] = 'true';
  808. // height auto
  809. $extra_params['height'] = 'auto';
  810. $extra_params['postData'] = [
  811. 'filters' => [
  812. "groupOp" => "AND",
  813. "rules" => $result['rules'],
  814. ],
  815. ];
  816. $sessionByUserList = SessionManager::get_sessions_by_user($userToLoad, true, true);
  817. $sessionUserList = [];
  818. if (!empty($sessionByUserList)) {
  819. foreach ($sessionByUserList as $sessionByUser) {
  820. $sessionUserList[] = (string) $sessionByUser['session_id'];
  821. }
  822. }
  823. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  824. var sessionList = '.json_encode($sessionUserList).';
  825. var id = options.rowId.toString();
  826. if (sessionList.indexOf(id) == -1) {
  827. 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>'.'\';
  828. } else {
  829. 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>'.'\';
  830. }
  831. }';
  832. $htmlHeadXtra[] = api_get_jqgrid_js();
  833. $griJs = Display::grid_js(
  834. 'sessions',
  835. $url,
  836. $columns,
  837. $column_model,
  838. $extra_params,
  839. [],
  840. $action_links,
  841. true
  842. );
  843. $grid = '<div id="session-table" class="table-responsive">';
  844. $grid .= Display::grid_html('sessions');
  845. $grid .= '</div>';
  846. $htmlHeadXtra[] = '<style>
  847. .control-label {
  848. width: 25% !important;
  849. }
  850. </style>';
  851. $htmlHeadXtra[] = '<script>
  852. $(document).ready(function() {
  853. var blocks = [
  854. "#collapseOne",
  855. "#collapseTwo",
  856. "#collapseThree",
  857. "#collapseFour",
  858. "#collapseFive",
  859. "#collapseSix",
  860. "#collapseSeven",
  861. "#collapseEight"
  862. ];
  863. $.each(blocks, function( index, value ) {
  864. $(value).collapse("hide");
  865. });
  866. });
  867. </script>';
  868. $tpl = new Template(get_lang('Diagnosis'));
  869. if (empty($items)) {
  870. $view = '';
  871. $grid = '';
  872. $griJs = '';
  873. }
  874. $tpl->assign('form', $view);
  875. $tpl->assign('form_search', $formSearch->returnForm().$userForm->returnForm());
  876. $table = new HTML_Table(['class' => 'data_table']);
  877. $column = 0;
  878. $row = 0;
  879. $total = '0';
  880. $sumHours = '0';
  881. $numHours = '0';
  882. $field = 'heures_disponibilite_par_semaine';
  883. $extraField = new ExtraFieldValue('user');
  884. $data = $extraField->get_values_by_handler_and_field_variable($userToLoad, $field);
  885. $availableHoursPerWeek = 0;
  886. function dateDiffInWeeks($date1, $date2)
  887. {
  888. if ($date1 > $date2) {
  889. return dateDiffInWeeks($date2, $date1);
  890. }
  891. $first = new \DateTime($date1);
  892. $second = new \DateTime($date2);
  893. return floor($first->diff($second)->days / 7);
  894. }
  895. if ($data) {
  896. $availableHoursPerWeek = $data['value'];
  897. $numberWeeks = 0;
  898. if ($form->validate()) {
  899. $formData = $form->getSubmitValues();
  900. if (isset($formData['extra_access_start_date']) && isset($formData['extra_access_end_date'])) {
  901. $startDate = $formData['extra_access_start_date'];
  902. $endDate = $formData['extra_access_end_date'];
  903. $numberWeeks = dateDiffInWeeks($startDate, $endDate);
  904. }
  905. } else {
  906. if ($defaults) {
  907. if (isset($defaults['extra_access_start_date']) && isset($defaults['extra_access_end_date'])) {
  908. $startDate = $defaults['extra_access_start_date'];
  909. $endDate = $defaults['extra_access_end_date'];
  910. $numberWeeks = dateDiffInWeeks($startDate, $endDate);
  911. }
  912. }
  913. }
  914. $total = $numberWeeks * $availableHoursPerWeek;
  915. $sessions = SessionManager::getSessionsFollowedByUser($userToLoad);
  916. if ($sessions) {
  917. $sessionFieldValue = new ExtraFieldValue('session');
  918. foreach ($sessions as $session) {
  919. $sessionId = $session['id'];
  920. $data = $sessionFieldValue->get_values_by_handler_and_field_variable(
  921. $sessionId,
  922. 'temps_de_travail'
  923. );
  924. if ($data) {
  925. $sumHours += $data['value'];
  926. }
  927. }
  928. }
  929. }
  930. $numHours = $total - $sumHours;
  931. $headers = [
  932. get_lang('TotalAvailableHours') => $total,
  933. get_lang('SumHoursSessionsSubscribed') => $sumHours,
  934. get_lang('CountHoursAvailable') => $numHours,
  935. ];
  936. foreach ($headers as $header => $value) {
  937. $table->setCellContents($row, 0, $header);
  938. $table->updateCellAttributes($row, 0, 'width="250px"');
  939. $table->setCellContents($row, 1, $value);
  940. $row++;
  941. }
  942. $button = '';
  943. if ($userToLoad) {
  944. $button = Display::url(
  945. get_lang('OfajEndOfLearnPath'),
  946. api_get_path(WEB_CODE_PATH).'messages/new_message.php?prefill=ofaj&send_to_user='.$userToLoad,
  947. ['class' => 'btn btn-default']
  948. );
  949. $button .= '<br /><br />';
  950. }
  951. $userReportButton = Display::url(
  952. get_lang('DiagnosticValidateLearningPath'),
  953. api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$userToLoad,
  954. ['class' => 'btn btn-primary']
  955. );
  956. $tpl->assign('grid', $grid.$button.$table->toHtml().$userReportButton);
  957. $tpl->assign('grid_js', $griJs);
  958. $content = $tpl->fetch('default/user_portal/search_extra_field.tpl');
  959. $tpl->assign('content', $content);
  960. $tpl->display_one_col_template();