load_search.php 32 KB

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