load_search.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  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. $form->addHtml('</div></div></div>');
  331. $form->addHtml('<div class="panel panel-default">');
  332. $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>');
  333. $form->addHtml('<div id="collapseFive" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingFive">');
  334. $form->addHtml('<div class="panel-body"><p class="text-info">' . get_lang('NiveauLangueExplanation') . '</p>');
  335. $showOnlyThisFields = [
  336. 'ecouter',
  337. 'lire',
  338. 'participer_a_une_conversation',
  339. 's_exprimer_oralement_en_continu',
  340. 'ecrire'
  341. ];
  342. $extra = $extraField->addElements(
  343. $form,
  344. '',
  345. [],
  346. false, //filter
  347. true,
  348. $showOnlyThisFields,
  349. $showOnlyThisFields,
  350. $defaults,
  351. [],
  352. false, //$orderDependingDefaults
  353. true, // force
  354. [ 'domaine' => 3, $theme => 5], // $separateExtraMultipleSelect
  355. [
  356. 'domaine' => [
  357. get_lang('Domaine').' 1',
  358. get_lang('Domaine').' 2',
  359. get_lang('Domaine').' 3'
  360. ],
  361. $theme => [
  362. get_lang('Theme').' 1',
  363. get_lang('Theme').' 2',
  364. get_lang('Theme').' 3',
  365. get_lang('Theme').' 4',
  366. get_lang('Theme').' 5'
  367. ],
  368. ]
  369. );
  370. $form->addHtml('</div></div></div>');
  371. $form->addButtonSave(get_lang('SaveDiagnosticChanges'), 'save');
  372. $form->addButtonSearch(get_lang('SearchSessions'), 'search');
  373. $extraFieldsToFilter = $extraField->get_all(array('variable = ?' => 'temps_de_travail'));
  374. $extraFieldToSearch = array();
  375. if (!empty($extraFieldsToFilter)) {
  376. foreach ($extraFieldsToFilter as $filter) {
  377. $extraFieldToSearch[] = $filter['id'];
  378. }
  379. }
  380. $extraFieldListToString = implode(',', $extraFieldToSearch);
  381. $result = SessionManager::getGridColumns('simple', $extraFieldsToFilter);
  382. $columns = $result['columns'];
  383. $column_model = $result['column_model'];
  384. $form->setDefaults($defaults);
  385. /** @var HTML_QuickForm_select $element */
  386. $domaine1 = $form->getElementByName('extra_domaine[0]');
  387. $domaine2 = $form->getElementByName('extra_domaine[1]');
  388. $domaine3 = $form->getElementByName('extra_domaine[2]');
  389. $userForm->setDefaults($defaults);
  390. $domainList = array_merge(
  391. is_object($domaine1) ? $domaine1->getValue() : [],
  392. is_object($domaine3) ? $domaine3->getValue() : [],
  393. is_object($domaine2) ? $domaine2->getValue() : []
  394. );
  395. $themeList = [];
  396. $extraField = new ExtraField('session');
  397. $resultOptions = $extraField->searchOptionsFromTags('extra_domaine', 'extra_'.$theme, $domainList);
  398. if ($resultOptions) {
  399. $resultOptions = array_column($resultOptions, 'tag', 'id');
  400. $resultOptions = array_filter($resultOptions);
  401. for ($i = 0; $i < 5; $i++) {
  402. /** @var HTML_QuickForm_select $theme */
  403. $themeElement = $form->getElementByName('extra_'.$theme.'['.$i.']');
  404. foreach ($resultOptions as $key => $value) {
  405. $themeElement->addOption($value, $value);
  406. }
  407. }
  408. }
  409. $filterToSend = '';
  410. if ($formSearch->validate()) {
  411. $formSearchParams = $formSearch->getSubmitValues();
  412. }
  413. // Search filter
  414. $filters = [];
  415. foreach ($defaults as $key => $value) {
  416. if (substr($key, 0, 6) != 'extra_' && substr($key, 0, 7) != '_extra_') {
  417. continue;
  418. }
  419. if (!empty($value)) {
  420. $filters[$key] = $value;
  421. }
  422. }
  423. $filterToSend = [];
  424. if (!empty($filters)) {
  425. $filterToSend = ['groupOp' => 'AND'];
  426. if ($filters) {
  427. $count = 1;
  428. $countExtraField = 1;
  429. foreach ($result['column_model'] as $column) {
  430. if ($count > 5) {
  431. if (isset($filters[$column['name']])) {
  432. $defaultValues['jqg'.$countExtraField] = $filters[$column['name']];
  433. $filterToSend['rules'][] = ['field' => $column['name'], 'op' => 'cn', 'data' => $filters[$column['name']]];
  434. }
  435. $countExtraField++;
  436. }
  437. $count++;
  438. }
  439. }
  440. }
  441. $params = [];
  442. if ($form->validate()) {
  443. $params = $form->getSubmitValues();
  444. $save = false;
  445. $search = false;
  446. if (isset($params['search'])) {
  447. unset($params['search']);
  448. $search = true;
  449. }
  450. if (isset($params['save'])) {
  451. $save = true;
  452. unset($params['save']);
  453. }
  454. $form->setDefaults($params);
  455. $filters = [];
  456. // Search
  457. if ($search) {
  458. // Parse params.
  459. foreach ($params as $key => $value) {
  460. if (substr($key, 0, 6) != 'extra_' && substr($key, 0, 7) != '_extra_') {
  461. continue;
  462. }
  463. if (!empty($value)) {
  464. $filters[$key] = $value;
  465. }
  466. }
  467. $filterToSend = [];
  468. if (!empty($filters)) {
  469. $filterToSend = ['groupOp' => 'AND'];
  470. if ($filters) {
  471. $count = 1;
  472. $countExtraField = 1;
  473. foreach ($result['column_model'] as $column) {
  474. if ($count > 5) {
  475. if (isset($filters[$column['name']])) {
  476. $defaultValues['jqg'.$countExtraField] = $filters[$column['name']];
  477. $filterToSend['rules'][] = [
  478. 'field' => $column['name'],
  479. 'op' => 'cn',
  480. 'data' => $filters[$column['name']]
  481. ];
  482. }
  483. $countExtraField++;
  484. }
  485. $count++;
  486. }
  487. }
  488. }
  489. }
  490. if ($save) {
  491. $userData = $params;
  492. // Update extra_heures_disponibilite_par_semaine
  493. $extraFieldValue = new ExtraFieldValue('user');
  494. $userDataToSave = [
  495. 'item_id' => $userToLoad,
  496. 'extra_heures_disponibilite_par_semaine' => isset($userData['extra_heures_disponibilite_par_semaine']) ? $userData['extra_heures_disponibilite_par_semaine'] : ''
  497. ];
  498. $extraFieldValue->saveFieldValues($userDataToSave, true, false, ['heures_disponibilite_par_semaine']);
  499. // Save session search
  500. /** @var \Chamilo\UserBundle\Entity\User $user */
  501. $user = $em->getRepository('ChamiloUserBundle:User')->find($userToLoad);
  502. $extraFieldValueSession = new ExtraFieldValue('session');
  503. $sessionFields = [
  504. 'extra_access_start_date',
  505. 'extra_access_end_date',
  506. 'extra_filiere',
  507. 'extra_domaine',
  508. 'extra_domaine[0]',
  509. 'extra_domaine[1]',
  510. 'extra_domaine[3]',
  511. 'extra_temps_de_travail',
  512. //'extra_competenceniveau',
  513. 'extra_'.$theme,
  514. 'extra_ecouter',
  515. 'extra_lire',
  516. 'extra_participer_a_une_conversation',
  517. 'extra_s_exprimer_oralement_en_continu',
  518. 'extra_ecrire'
  519. ];
  520. foreach ($userData as $key => $value) {
  521. $found = strpos($key, '__persist__');
  522. if ($found === false) {
  523. continue;
  524. }
  525. }
  526. if (isset($userData['extra_filiere_want_stage']) &&
  527. isset($userData['extra_filiere_want_stage']['extra_filiere_want_stage'])
  528. ) {
  529. $wantStage = $userData['extra_filiere_want_stage']['extra_filiere_want_stage'];
  530. if ($wantStage === 'yes') {
  531. if (isset($userData['extra_filiere_user'])) {
  532. $userData['extra_filiere'] = [];
  533. $userData['extra_filiere']['extra_filiere'] = $userData['extra_filiere_user']['extra_filiere_user'];
  534. }
  535. }
  536. }
  537. // save in ExtraFieldSavedSearch.
  538. foreach ($userData as $key => $value) {
  539. if (substr($key, 0, 6) != 'extra_' && substr($key, 0, 7) != '_extra_') {
  540. continue;
  541. }
  542. if (!in_array($key, $sessionFields)) {
  543. continue;
  544. }
  545. $field_variable = substr($key, 6);
  546. $extraFieldInfo = $extraFieldValueSession
  547. ->getExtraField()
  548. ->get_handler_field_info_by_field_variable($field_variable);
  549. if (!$extraFieldInfo) {
  550. continue;
  551. }
  552. $extraFieldObj = $em->getRepository('ChamiloCoreBundle:ExtraField')->find($extraFieldInfo['id']);
  553. $search = [
  554. 'field' => $extraFieldObj,
  555. 'user' => $user
  556. ];
  557. /** @var ExtraFieldSavedSearch $saved */
  558. $saved = $em->getRepository('ChamiloCoreBundle:ExtraFieldSavedSearch')->findOneBy($search);
  559. if ($saved) {
  560. $saved
  561. ->setField($extraFieldObj)
  562. ->setUser($user)
  563. ->setValue($value)
  564. ;
  565. $em->merge($saved);
  566. } else {
  567. $saved = new ExtraFieldSavedSearch();
  568. $saved
  569. ->setField($extraFieldObj)
  570. ->setUser($user)
  571. ->setValue($value)
  572. ;
  573. $em->persist($saved);
  574. }
  575. $em->flush();
  576. }
  577. Display::addFlash(Display::return_message(get_lang('Saved'), 'success'));
  578. header('Location: '.api_get_self().'?user_id='.$userToLoad);
  579. exit;
  580. }
  581. }
  582. $view = $form->returnForm();
  583. $jsTag = '';
  584. if (!empty($tagsData)) {
  585. foreach ($tagsData as $extraField => $tags) {
  586. foreach ($tags as $tag) {
  587. $tag = api_htmlentities($tag);
  588. // $jsTag .= "$('#$extraField')[0].addItem('$tag', '$tag');";
  589. }
  590. }
  591. }
  592. $htmlHeadXtra[] ='<script>
  593. $(function() {
  594. '.$extra['jquery_ready_content'].'
  595. '.$jsTag.'
  596. });
  597. </script>';
  598. if (!empty($filterToSend)) {
  599. // Get start and end date from ExtraFieldSavedSearch
  600. $defaultExtraStartDate = isset($defaults['extra_access_start_date']) ? $defaults['extra_access_start_date'] : '';
  601. $defaultExtraEndDate = isset($defaults['extra_access_end_date']) ? $defaults['extra_access_end_date'] : '';
  602. $userStartDate = isset($params['extra_access_start_date']) ? $params['extra_access_start_date'] : $defaultExtraStartDate;
  603. $userEndDate = isset($params['extra_access_end_date']) ? $params['extra_access_end_date'] : $defaultExtraEndDate;
  604. // Minus 3 days
  605. $date = new DateTime($userStartDate);
  606. $date->sub(new DateInterval('P3D'));
  607. $userStartDateMinus = $date->format('Y-m-d h:i:s');
  608. // Plus 2 days
  609. $date = new DateTime($userEndDate);
  610. $date->add(new DateInterval('P2D'));
  611. $userEndDatePlus = $date->format('Y-m-d h:i:s');
  612. // Ofaj fix
  613. $userStartDateMinus = api_get_utc_datetime(substr($userStartDateMinus, 0, 11).'00:00:00');
  614. $userEndDatePlus = api_get_utc_datetime(substr($userEndDatePlus, 0, 11). '23:59:59');
  615. // Special OFAJ date logic
  616. $sql = " AND (
  617. (s.access_start_date >= '$userStartDateMinus' AND s.access_end_date < '$userEndDatePlus') OR
  618. (s.access_start_date >= '$userStartDateMinus' AND (s.access_end_date = '' OR s.access_end_date IS NULL)) OR
  619. ((s.access_start_date = '' OR s.access_start_date IS NULL) AND (s.access_end_date = '' OR s.access_end_date IS NULL))
  620. )";
  621. $deleteFiliere = false;
  622. $extraFieldOptions = new ExtraFieldOption('session');
  623. $extraFieldSession = new ExtraField('session');
  624. // Special filters
  625. // see https://task.beeznest.com/issues/10849#change-81902
  626. foreach ($filterToSend['rules'] as &$filterItem) {
  627. if (isset($filterItem['field']))
  628. switch ($filterItem['field']) {
  629. case 'extra_ecouter':
  630. case 'extra_lire':
  631. case 'extra_participer_a_une_conversation':
  632. case 'extra_s_exprimer_oralement_en_continu':
  633. case 'extra_ecrire':
  634. $selectedValue = '';
  635. $fieldExtra = str_replace('extra_', '', $filterItem['field']);
  636. $extraFieldSessionData = $extraFieldSession->get_handler_field_info_by_field_variable($fieldExtra);
  637. if (is_array($filterItem['data'])) {
  638. $myOrder = [];
  639. foreach ($filterItem['data'] as $option) {
  640. foreach ($extraFieldSessionData['options'] as $optionValue) {
  641. if ($option == $optionValue['option_value']) {
  642. $myOrder[$optionValue['option_order']] = $optionValue['option_value'];
  643. }
  644. }
  645. }
  646. if (!empty($myOrder)) {
  647. // Taking last from list
  648. $selectedValue = end($myOrder);
  649. }
  650. } else {
  651. $selectedValue = $filterItem['data'];
  652. }
  653. $newOptions = array_column(
  654. $extraFieldSessionData['options'],
  655. 'option_value',
  656. 'option_order'
  657. );
  658. $searchOptions = [];
  659. for ($i = 1; $i < count($newOptions); $i++) {
  660. if ($selectedValue == $newOptions[$i]) {
  661. if (isset($newOptions[$i-1])) {
  662. $searchOptions[] = $newOptions[$i-1];
  663. }
  664. if (isset($newOptions[$i])) {
  665. $searchOptions[] = $newOptions[$i];
  666. }
  667. if (isset($newOptions[$i+1])) {
  668. $searchOptions[] = $newOptions[$i+1];
  669. }
  670. break;
  671. }
  672. }
  673. $filterItem['data'] = $searchOptions;
  674. break;
  675. case 'extra_domaine':
  676. // Special condition see:
  677. // https://task.beeznest.com/issues/10849#note-218
  678. // Remove filiere
  679. $list = [
  680. 'vie-quotidienne',
  681. //'competente-dans-mon-domaine-de-specialite',
  682. 'arrivee-sur-mon-poste-de-travail'
  683. ];
  684. $deleteFiliere = false;
  685. if (is_array($filterItem['data'])) {
  686. $myOrder = [];
  687. foreach ($filterItem['data'] as $option) {
  688. if (in_array($option, $list)) {
  689. $deleteFiliere = true;
  690. break;
  691. }
  692. }
  693. } else {
  694. if (in_array($filterItem['data'], $list)) {
  695. $deleteFiliere = true;
  696. }
  697. }
  698. break;
  699. }
  700. if ($deleteFiliere) {
  701. foreach ($filterToSend['rules'] as &$filterItem) {
  702. if (isset($filterItem['field']) && $filterItem['field'] == 'extra_filiere') {
  703. $filterItem = [];
  704. }
  705. }
  706. }
  707. }
  708. if ($userStartDate && !empty($userStartDate)) {
  709. $filterToSend['custom_dates'] = $sql;
  710. }
  711. $filterToSend = json_encode($filterToSend);
  712. $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;
  713. } else {
  714. $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';
  715. }
  716. // Autowidth
  717. $extra_params['autowidth'] = 'true';
  718. // height auto
  719. $extra_params['height'] = 'auto';
  720. $extra_params['postData'] = array(
  721. 'filters' => array(
  722. "groupOp" => "AND",
  723. "rules" => $result['rules']
  724. )
  725. );
  726. $sessionByUserList = SessionManager::get_sessions_by_user($userToLoad, true, true);
  727. $sessionUserList = array();
  728. if (!empty($sessionByUserList)) {
  729. foreach ($sessionByUserList as $sessionByUser) {
  730. $sessionUserList[] = (string) $sessionByUser['session_id'];
  731. }
  732. }
  733. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  734. var sessionList = '.json_encode($sessionUserList).';
  735. var id = options.rowId.toString();
  736. if (sessionList.indexOf(id) == -1) {
  737. 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>'.'\';
  738. } else {
  739. 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>'.'\';
  740. }
  741. }';
  742. $htmlHeadXtra[] = api_get_jqgrid_js();
  743. $griJs = Display::grid_js(
  744. 'sessions',
  745. $url,
  746. $columns,
  747. $column_model,
  748. $extra_params,
  749. array(),
  750. $action_links,
  751. true
  752. );
  753. $grid = '<div id="session-table" class="table-responsive">';
  754. $grid .= Display::grid_html('sessions');
  755. $grid .= '</div>';
  756. $htmlHeadXtra[] ='<style>
  757. .control-label {
  758. width: 25% !important;
  759. }
  760. </style>';
  761. $htmlHeadXtra[] ='<script>
  762. $(document).ready(function() {
  763. var blocks = [
  764. "#collapseOne",
  765. "#collapseTwo",
  766. "#collapseThree",
  767. "#collapseFour",
  768. "#collapseFive",
  769. "#collapseSix",
  770. "#collapseSeven"
  771. ];
  772. $.each(blocks, function( index, value ) {
  773. $(value).collapse("hide");
  774. });
  775. });
  776. </script>';
  777. $tpl = new Template(get_lang('Diagnosis'));
  778. if (empty($items)) {
  779. $view = '';
  780. $grid = '';
  781. $griJs = '';
  782. }
  783. $tpl->assign('form', $view);
  784. $tpl->assign('form_search', $formSearch->returnForm().$userForm->returnForm());
  785. $table = new HTML_Table(array('class' => 'data_table'));
  786. $column = 0;
  787. $row = 0;
  788. $total = '0';
  789. $sumHours = '0';
  790. $numHours = '0';
  791. $field = 'heures_disponibilite_par_semaine';
  792. $extraField = new ExtraFieldValue('user');
  793. $data = $extraField->get_values_by_handler_and_field_variable($userToLoad, $field);
  794. $availableHoursPerWeek = 0;
  795. function dateDiffInWeeks($date1, $date2)
  796. {
  797. if ($date1 > $date2) {
  798. return dateDiffInWeeks($date2, $date1);
  799. }
  800. $first = new \DateTime($date1);
  801. $second = new \DateTime($date2);
  802. return floor($first->diff($second)->days / 7);
  803. }
  804. if ($data) {
  805. $availableHoursPerWeek = $data['value'];
  806. $numberWeeks = 0;
  807. if ($form->validate()) {
  808. $formData = $form->getSubmitValues();
  809. if (isset($formData['extra_access_start_date']) && isset($formData['extra_access_end_date'])) {
  810. $startDate = $formData['extra_access_start_date'];
  811. $endDate = $formData['extra_access_end_date'];
  812. $numberWeeks = dateDiffInWeeks($startDate, $endDate);
  813. }
  814. } else {
  815. if ($defaults) {
  816. if (isset($defaults['extra_access_start_date']) && isset($defaults['extra_access_end_date'])) {
  817. $startDate = $defaults['extra_access_start_date'];
  818. $endDate = $defaults['extra_access_end_date'];
  819. $numberWeeks = dateDiffInWeeks($startDate, $endDate);
  820. }
  821. }
  822. }
  823. $total = $numberWeeks * $availableHoursPerWeek;
  824. $sessions = SessionManager::getSessionsFollowedByUser($userToLoad);
  825. if ($sessions) {
  826. $sessionFieldValue = new ExtraFieldValue('session');
  827. foreach ($sessions as $session) {
  828. $sessionId = $session['id'];
  829. $data = $sessionFieldValue->get_values_by_handler_and_field_variable(
  830. $sessionId,
  831. 'temps_de_travail'
  832. );
  833. if ($data) {
  834. $sumHours += $data['value'];
  835. }
  836. }
  837. }
  838. }
  839. $numHours = $total - $sumHours;
  840. $headers = array(
  841. get_lang('TotalAvailableHours') => $total,
  842. get_lang('SumHoursSessionsSubscribed') => $sumHours,
  843. get_lang('CountHoursAvailable') => $numHours
  844. );
  845. foreach ($headers as $header => $value) {
  846. $table->setCellContents($row, 0, $header);
  847. $table->updateCellAttributes($row, 0, 'width="250px"');
  848. $table->setCellContents($row, 1, $value);
  849. $row++;
  850. }
  851. $button = '';
  852. if ($userToLoad) {
  853. $button = Display::url(
  854. get_lang('OfajEndOfLearnPath'),
  855. api_get_path(WEB_CODE_PATH).'messages/new_message.php?prefill=ofaj&send_to_user='.$userToLoad,
  856. ['class' => 'btn btn-default']
  857. );
  858. $button .= '<br /><br />';
  859. }
  860. $userReportButton = Display::url(
  861. get_lang('DiagnosticValidateLearningPath'),
  862. api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$userToLoad,
  863. ['class' => 'btn btn-primary']
  864. );
  865. $tpl->assign('grid', $grid.$button.$table->toHtml().$userReportButton);
  866. $tpl->assign('grid_js', $griJs);
  867. $content = $tpl->fetch('default/user_portal/search_extra_field.tpl');
  868. $tpl->assign('content', $content);
  869. $tpl->display_one_col_template();