load_search.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  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();