exercise_result.class.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class ExerciseResult
  5. * which allows you to export exercises results in multiple presentation forms
  6. * @package chamilo.exercise
  7. * @author Yannick Warnier
  8. */
  9. class ExerciseResult
  10. {
  11. private $results = [];
  12. public $includeAllUsers = false;
  13. public $onlyBestAttempts = false;
  14. /**
  15. * @param bool $includeAllUsers
  16. */
  17. public function setIncludeAllUsers($includeAllUsers)
  18. {
  19. $this->includeAllUsers = $includeAllUsers;
  20. }
  21. /**
  22. * @param bool $value
  23. */
  24. public function setOnlyBestAttempts($value)
  25. {
  26. $this->onlyBestAttempts = $value;
  27. }
  28. /**
  29. * Gets the results of all students (or just one student if access is limited)
  30. *
  31. * @param string $document_path The document path (for HotPotatoes retrieval)
  32. * @param int $user_id User ID. Optional. If no user ID is provided, we take all the results. Defauts to null
  33. * @param int $filter
  34. * @param int $exercise_id
  35. *
  36. * @return bool
  37. */
  38. public function getExercisesReporting(
  39. $document_path,
  40. $user_id = null,
  41. $filter = 0,
  42. $exercise_id = 0
  43. ) {
  44. $return = array();
  45. $TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
  46. $TBL_TABLE_LP_MAIN = Database::get_course_table(TABLE_LP_MAIN);
  47. $TBL_USER = Database::get_main_table(TABLE_MAIN_USER);
  48. $TBL_TRACK_EXERCISES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  49. $TBL_TRACK_ATTEMPT_RECORDING = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
  50. $cid = api_get_course_id();
  51. $course_id = api_get_course_int_id();
  52. $user_id = intval($user_id);
  53. $sessionId = api_get_session_id();
  54. $session_id_and = ' AND te.session_id = ' . $sessionId . ' ';
  55. $exercise_id = intval($exercise_id);
  56. if (!empty($exercise_id)) {
  57. $session_id_and .= " AND exe_exo_id = $exercise_id ";
  58. }
  59. if (empty($user_id)) {
  60. $user_id_and = null;
  61. $sql = "SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").",
  62. official_code,
  63. ce.title as extitle,
  64. te.exe_result as exresult ,
  65. te.exe_weighting as exweight,
  66. te.exe_date as exdate,
  67. te.exe_id as exid,
  68. email as exemail,
  69. te.start_date as exstart,
  70. steps_counter as exstep,
  71. exe_user_id as excruid,
  72. te.exe_duration as duration,
  73. te.orig_lp_id as orig_lp_id,
  74. tlm.name as lp_name
  75. FROM $TBL_EXERCISES AS ce
  76. INNER JOIN $TBL_TRACK_EXERCISES AS te
  77. ON (te.exe_exo_id = ce.id)
  78. INNER JOIN $TBL_USER AS user
  79. ON (user.user_id = exe_user_id)
  80. LEFT JOIN $TBL_TABLE_LP_MAIN AS tlm
  81. ON (tlm.id = te.orig_lp_id AND tlm.c_id = ce.c_id)
  82. WHERE
  83. ce.c_id = $course_id AND
  84. te.status != 'incomplete' AND
  85. te.c_id = ce.c_id $user_id_and $session_id_and AND
  86. ce.active <>-1";
  87. } else {
  88. $user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' ';
  89. // get only this user's results
  90. $sql = "SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").",
  91. official_code,
  92. ce.title as extitle,
  93. te.exe_result as exresult,
  94. te.exe_weighting as exweight,
  95. te.exe_date as exdate,
  96. te.exe_id as exid,
  97. email as exemail,
  98. te.start_date as exstart,
  99. steps_counter as exstep,
  100. exe_user_id as excruid,
  101. te.exe_duration as duration,
  102. ce.results_disabled as exdisabled,
  103. te.orig_lp_id as orig_lp_id,
  104. tlm.name as lp_name
  105. FROM $TBL_EXERCISES AS ce
  106. INNER JOIN $TBL_TRACK_EXERCISES AS te
  107. ON (te.exe_exo_id = ce.id)
  108. INNER JOIN $TBL_USER AS user
  109. ON (user.user_id = exe_user_id)
  110. LEFT JOIN $TBL_TABLE_LP_MAIN AS tlm
  111. ON (tlm.id = te.orig_lp_id AND tlm.c_id = ce.c_id)
  112. WHERE
  113. ce.c_id = $course_id AND
  114. te.status != 'incomplete' AND
  115. te.c_id = ce.c_id $user_id_and $session_id_and AND
  116. ce.active <>-1 AND
  117. ORDER BY userpart2, te.c_id ASC, ce.title ASC, te.exe_date DESC";
  118. }
  119. $results = array();
  120. $resx = Database::query($sql);
  121. $bestAttemptPerUser = array();
  122. while ($rowx = Database::fetch_array($resx, 'ASSOC')) {
  123. if ($this->onlyBestAttempts) {
  124. if (!isset($bestAttemptPerUser[$rowx['excruid']])) {
  125. $bestAttemptPerUser[$rowx['excruid']] = $rowx;
  126. } else {
  127. if ($rowx['exresult'] > $bestAttemptPerUser[$rowx['excruid']]['exresult']) {
  128. $bestAttemptPerUser[$rowx['excruid']] = $rowx;
  129. }
  130. }
  131. } else {
  132. $results[] = $rowx;
  133. }
  134. }
  135. if ($this->onlyBestAttempts) {
  136. $results = $bestAttemptPerUser;
  137. }
  138. $filter_by_not_revised = false;
  139. $filter_by_revised = false;
  140. if ($filter) {
  141. switch ($filter) {
  142. case 1:
  143. $filter_by_not_revised = true;
  144. break;
  145. case 2:
  146. $filter_by_revised = true;
  147. break;
  148. default:
  149. null;
  150. }
  151. }
  152. if (empty($sessionId)) {
  153. $students = CourseManager::get_user_list_from_course_code($cid);
  154. } else {
  155. $students = CourseManager::get_user_list_from_course_code($cid, $sessionId);
  156. }
  157. $studentsUserIdList = array_keys($students);
  158. // Print the results of tests
  159. $userWithResults = array();
  160. if (is_array($results)) {
  161. $i = 0;
  162. foreach ($results as $result) {
  163. $revised = false;
  164. //revised or not
  165. $sql_exe = "SELECT exe_id
  166. FROM $TBL_TRACK_ATTEMPT_RECORDING
  167. WHERE
  168. author != '' AND
  169. exe_id = ".Database::escape_string($result['exid'])."
  170. LIMIT 1";
  171. $query = Database::query($sql_exe);
  172. if (Database:: num_rows($query) > 0) {
  173. $revised = true;
  174. }
  175. if ($filter_by_not_revised && $revised) {
  176. continue;
  177. }
  178. if ($filter_by_revised && !$revised) {
  179. continue;
  180. }
  181. $return[$i] = array();
  182. if (empty($user_id)) {
  183. $return[$i]['official_code'] = $result['official_code'];
  184. if (api_is_western_name_order()) {
  185. $return[$i]['first_name'] = $results[$i]['userpart1'];
  186. $return[$i]['last_name'] = $results[$i]['userpart2'];
  187. } else {
  188. $return[$i]['first_name'] = $results[$i]['userpart2'];
  189. $return[$i]['last_name'] = $results[$i]['userpart1'];
  190. }
  191. $return[$i]['user_id'] = $results[$i]['excruid'];
  192. $return[$i]['email'] = $results[$i]['exemail'];
  193. }
  194. $return[$i]['title'] = $result['extitle'];
  195. $return[$i]['start_date'] = api_get_local_time($result['exstart']);
  196. $return[$i]['end_date'] = api_get_local_time($result['exdate']);
  197. $return[$i]['duration'] = $result['duration'];
  198. $return[$i]['result'] = $result['exresult'];
  199. $return[$i]['max'] = $result['exweight'];
  200. $return[$i]['status'] = $revised ? get_lang('Validated') : get_lang('NotValidated');
  201. $return[$i]['lp_id'] = $result['orig_lp_id'];
  202. $return[$i]['lp_name'] = $result['lp_name'];
  203. if (in_array($result['excruid'], $studentsUserIdList)) {
  204. $return[$i]['is_user_subscribed'] = get_lang('Yes');
  205. } else {
  206. $return[$i]['is_user_subscribed'] = get_lang('No');
  207. }
  208. $userWithResults[$result['excruid']] = 1;
  209. $i++;
  210. }
  211. }
  212. if ($this->includeAllUsers) {
  213. $latestId = count($return);
  214. $userWithResults = array_keys($userWithResults);
  215. if (!empty($students)) {
  216. foreach ($students as $student) {
  217. if (!in_array($student['user_id'], $userWithResults)) {
  218. $i = $latestId;
  219. $isWestern = api_is_western_name_order();
  220. if (empty($user_id)) {
  221. $return[$i]['official_code'] = $student['official_code'];
  222. if ($isWestern) {
  223. $return[$i]['first_name'] = $student['firstname'];
  224. $return[$i]['last_name'] = $student['lastname'];
  225. } else {
  226. $return[$i]['first_name'] = $student['lastname'];
  227. $return[$i]['last_name'] = $student['firstname'];
  228. }
  229. $return[$i]['user_id'] = $student['user_id'];
  230. $return[$i]['email'] = $student['email'];
  231. }
  232. $return[$i]['title'] = null;
  233. $return[$i]['start_date'] = null;
  234. $return[$i]['end_date'] = null;
  235. $return[$i]['duration'] = null;
  236. $return[$i]['result'] = null;
  237. $return[$i]['max'] = null;
  238. $return[$i]['status'] = get_lang('NotAttempted');
  239. $return[$i]['lp_id'] = null;
  240. $return[$i]['lp_name'] = null;
  241. $return[$i]['is_user_subscribed'] = get_lang('Yes');
  242. $latestId++;
  243. }
  244. }
  245. }
  246. }
  247. $this->results = $return;
  248. return true;
  249. }
  250. /**
  251. * Exports the complete report as a CSV file
  252. * @param string $document_path Document path inside the document tool
  253. * @param integer $user_id Optional user ID
  254. * @param boolean $export_user_fields Whether to include user fields or not
  255. * @param int $export_filter
  256. * @param int $exercise_id
  257. *
  258. * @return boolean False on error
  259. */
  260. public function exportCompleteReportCSV(
  261. $document_path = '',
  262. $user_id = null,
  263. $export_user_fields = false,
  264. $export_filter = 0,
  265. $exercise_id = 0
  266. ) {
  267. global $charset;
  268. $this->getExercisesReporting(
  269. $document_path,
  270. $user_id,
  271. $export_filter,
  272. $exercise_id
  273. );
  274. $now = api_get_local_time();
  275. $filename = 'exercise_results_'.$now.'.csv';
  276. if (!empty($user_id)) {
  277. $filename = 'exercise_results_user_'.$user_id.'_'.$now.'.csv';
  278. }
  279. $filename = api_replace_dangerous_char($filename);
  280. $data = '';
  281. if (api_is_western_name_order()) {
  282. if (!empty($this->results[0]['first_name'])) {
  283. $data .= get_lang('FirstName').';';
  284. }
  285. if (!empty($this->results[0]['last_name'])) {
  286. $data .= get_lang('LastName').';';
  287. }
  288. } else {
  289. if (!empty($this->results[0]['last_name'])) {
  290. $data .= get_lang('LastName').';';
  291. }
  292. if (!empty($this->results[0]['first_name'])) {
  293. $data .= get_lang('FirstName').';';
  294. }
  295. }
  296. $officialCodeInList = api_get_setting('show_official_code_exercise_result_list');
  297. if ($officialCodeInList === 'true') {
  298. $data .= get_lang('OfficialCode').';';
  299. }
  300. $data .= get_lang('Email').';';
  301. $data .= get_lang('Groups').';';
  302. if ($export_user_fields) {
  303. //show user fields section with a big th colspan that spans over all fields
  304. $extra_user_fields = UserManager::get_extra_fields(
  305. 0,
  306. 1000,
  307. 5,
  308. 'ASC',
  309. false,
  310. 1
  311. );
  312. if (!empty($extra_user_fields)) {
  313. foreach ($extra_user_fields as $field) {
  314. $data .= '"'.str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES, $charset)).'";';
  315. }
  316. }
  317. }
  318. $data .= get_lang('Title').';';
  319. $data .= get_lang('StartDate').';';
  320. $data .= get_lang('EndDate').';';
  321. $data .= get_lang('Duration'). ' ('.get_lang('MinMinutes').') ;';
  322. $data .= get_lang('Score').';';
  323. $data .= get_lang('Total').';';
  324. $data .= get_lang('Status').';';
  325. $data .= get_lang('ToolLearnpath').';';
  326. $data .= get_lang('UserIsCurrentlySubscribed').';';
  327. $data .= "\n";
  328. //results
  329. foreach ($this->results as $row) {
  330. if (api_is_western_name_order()) {
  331. $data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';';
  332. $data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';';
  333. } else {
  334. $data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';';
  335. $data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';';
  336. }
  337. // Official code
  338. if ($officialCodeInList === 'true') {
  339. $data .= $row['official_code'].';';
  340. }
  341. // Email
  342. $data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset)).';';
  343. $data .= str_replace("\r\n",' ',implode(", ", GroupManager::get_user_group_name($row['user_id']))).';';
  344. if ($export_user_fields) {
  345. //show user fields data, if any, for this user
  346. $user_fields_values = UserManager::get_extra_user_data(
  347. $row['user_id'],
  348. false,
  349. false,
  350. false,
  351. true
  352. );
  353. if (!empty($user_fields_values)) {
  354. foreach($user_fields_values as $value) {
  355. $data .= '"'.str_replace('"','""',api_html_entity_decode(strip_tags($value), ENT_QUOTES, $charset)).'";';
  356. }
  357. }
  358. }
  359. $duration = !empty($row['duration']) ? round($row['duration'] / 60) : 0;
  360. $data .= str_replace("\r\n",' ', api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset)).';';
  361. $data .= str_replace("\r\n", ' ', $row['start_date']).';';
  362. $data .= str_replace("\r\n", ' ', $row['end_date']).';';
  363. $data .= str_replace("\r\n", ' ', $duration).';';
  364. $data .= str_replace("\r\n", ' ', $row['result']).';';
  365. $data .= str_replace("\r\n", ' ', $row['max']).';';
  366. $data .= str_replace("\r\n", ' ', $row['status']).';';
  367. $data .= str_replace("\r\n", ' ', $row['lp_name']).';';
  368. $data .= str_replace("\r\n", ' ', $row['is_user_subscribed']).';';
  369. $data .= "\n";
  370. }
  371. // output the results
  372. $len = strlen($data);
  373. header('Content-type: application/octet-stream');
  374. header('Content-Type: application/force-download');
  375. header('Content-length: '.$len);
  376. if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT'])) {
  377. header('Content-Disposition: filename= '.$filename);
  378. } else {
  379. header('Content-Disposition: attachment; filename= '.$filename);
  380. }
  381. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
  382. header('Pragma: ');
  383. header('Cache-Control: ');
  384. header('Cache-Control: public'); // IE cannot download from sessions without a cache
  385. }
  386. header('Content-Description: '.$filename);
  387. header('Content-transfer-encoding: binary');
  388. echo $data;
  389. return true;
  390. }
  391. /**
  392. * Exports the complete report as an XLS file
  393. *
  394. * @param string $document_path
  395. * @param null $user_id
  396. * @param bool $export_user_fields
  397. * @param int $export_filter
  398. * @param int $exercise_id
  399. * @param null $hotpotato_name
  400. * @return bool
  401. */
  402. public function exportCompleteReportXLS(
  403. $document_path = '',
  404. $user_id = null,
  405. $export_user_fields = false,
  406. $export_filter = 0,
  407. $exercise_id = 0,
  408. $hotpotato_name = null
  409. ) {
  410. global $charset;
  411. $this->getExercisesReporting(
  412. $document_path,
  413. $user_id,
  414. $export_filter,
  415. $exercise_id,
  416. $hotpotato_name
  417. );
  418. $now = api_get_local_time();
  419. $filename = 'exercise_results_'.$now.'.xlsx';
  420. if (!empty($user_id)) {
  421. $filename = 'exercise_results_user_'.$user_id.'_'.$now.'.xlsx';
  422. }
  423. $spreadsheet = new PHPExcel();
  424. $spreadsheet->setActiveSheetIndex(0);
  425. $worksheet = $spreadsheet->getActiveSheet();
  426. $line = 1; // Skip first line
  427. $column = 0; //skip the first column (row titles)
  428. // check if exists column 'user'
  429. $with_column_user = false;
  430. foreach ($this->results as $result) {
  431. if (!empty($result['last_name']) && !empty($result['first_name'])) {
  432. $with_column_user = true;
  433. break;
  434. }
  435. }
  436. $officialCodeInList = api_get_setting('show_official_code_exercise_result_list');
  437. if ($with_column_user) {
  438. if (api_is_western_name_order()) {
  439. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('FirstName'));
  440. $column++;
  441. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('LastName'));
  442. $column++;
  443. } else {
  444. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('LastName'));
  445. $column++;
  446. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('FirstName'));
  447. $column++;
  448. }
  449. if ($officialCodeInList === 'true') {
  450. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('OfficialCode'));
  451. $column++;
  452. }
  453. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Email'));
  454. $column++;
  455. }
  456. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Groups'));
  457. $column++;
  458. if ($export_user_fields) {
  459. //show user fields section with a big th colspan that spans over all fields
  460. $extra_user_fields = UserManager::get_extra_fields(
  461. 0,
  462. 1000,
  463. 5,
  464. 'ASC',
  465. false,
  466. 1
  467. );
  468. //show the fields names for user fields
  469. foreach ($extra_user_fields as $field) {
  470. $worksheet->setCellValueByColumnAndRow(
  471. $column,
  472. $line,
  473. api_html_entity_decode(
  474. strip_tags($field[3]),
  475. ENT_QUOTES,
  476. $charset
  477. )
  478. );
  479. $column++;
  480. }
  481. }
  482. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Title'));
  483. $column++;
  484. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('StartDate'));
  485. $column++;
  486. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('EndDate'));
  487. $column++;
  488. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Duration').' ('.get_lang('MinMinutes').')');
  489. $column++;
  490. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Score'));
  491. $column++;
  492. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Total'));
  493. $column++;
  494. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Status'));
  495. $column++;
  496. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('ToolLearnpath'));
  497. $column++;
  498. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('UserIsCurrentlySubscribed'));
  499. $line++;
  500. foreach ($this->results as $row) {
  501. $column = 0;
  502. if ($with_column_user) {
  503. if (api_is_western_name_order()) {
  504. $worksheet->setCellValueByColumnAndRow(
  505. $column,
  506. $line,
  507. api_html_entity_decode(
  508. strip_tags($row['first_name']),
  509. ENT_QUOTES,
  510. $charset
  511. )
  512. );
  513. $column++;
  514. $worksheet->setCellValueByColumnAndRow(
  515. $column,
  516. $line,
  517. api_html_entity_decode(
  518. strip_tags($row['last_name']),
  519. ENT_QUOTES,
  520. $charset
  521. )
  522. );
  523. $column++;
  524. } else {
  525. $worksheet->setCellValueByColumnAndRow(
  526. $column,
  527. $line,
  528. api_html_entity_decode(
  529. strip_tags($row['last_name']),
  530. ENT_QUOTES,
  531. $charset
  532. )
  533. );
  534. $column++;
  535. $worksheet->setCellValueByColumnAndRow(
  536. $column,
  537. $line,
  538. api_html_entity_decode(
  539. strip_tags($row['first_name']),
  540. ENT_QUOTES,
  541. $charset
  542. )
  543. );
  544. $column++;
  545. }
  546. if ($officialCodeInList === 'true') {
  547. $worksheet->setCellValueByColumnAndRow(
  548. $column,
  549. $line,
  550. api_html_entity_decode(
  551. strip_tags($row['official_code']),
  552. ENT_QUOTES,
  553. $charset
  554. )
  555. );
  556. $column++;
  557. }
  558. $worksheet->setCellValueByColumnAndRow(
  559. $column,
  560. $line,
  561. api_html_entity_decode(
  562. strip_tags($row['email']),
  563. ENT_QUOTES,
  564. $charset
  565. )
  566. );
  567. $column++;
  568. }
  569. $worksheet->setCellValueByColumnAndRow(
  570. $column,
  571. $line,
  572. api_html_entity_decode(
  573. strip_tags(
  574. implode(
  575. ", ",
  576. GroupManager:: get_user_group_name($row['user_id'])
  577. )
  578. ),
  579. ENT_QUOTES,
  580. $charset
  581. )
  582. );
  583. $column++;
  584. if ($export_user_fields) {
  585. //show user fields data, if any, for this user
  586. $user_fields_values = UserManager::get_extra_user_data(
  587. $row['user_id'],
  588. false,
  589. false,
  590. false,
  591. true
  592. );
  593. foreach ($user_fields_values as $value) {
  594. $worksheet->setCellValueByColumnAndRow(
  595. $column,
  596. $line,
  597. api_html_entity_decode(
  598. strip_tags($value),
  599. ENT_QUOTES,
  600. $charset
  601. )
  602. );
  603. $column++;
  604. }
  605. }
  606. $worksheet->setCellValueByColumnAndRow(
  607. $column,
  608. $line,
  609. api_html_entity_decode(
  610. strip_tags($row['title']),
  611. ENT_QUOTES,
  612. $charset
  613. )
  614. );
  615. $column++;
  616. $worksheet->setCellValueByColumnAndRow($column, $line, $row['start_date']);
  617. $column++;
  618. $worksheet->setCellValueByColumnAndRow($column, $line, $row['end_date']);
  619. $column++;
  620. $duration = !empty($row['duration']) ? round($row['duration'] / 60) : 0;
  621. $worksheet->setCellValueByColumnAndRow($column, $line, $duration);
  622. $column++;
  623. $worksheet->setCellValueByColumnAndRow($column, $line, $row['result']);
  624. $column++;
  625. $worksheet->setCellValueByColumnAndRow($column, $line, $row['max']);
  626. $column++;
  627. $worksheet->setCellValueByColumnAndRow($column, $line, $row['status']);
  628. $column++;
  629. $worksheet->setCellValueByColumnAndRow($column, $line, $row['lp_name']);
  630. $column++;
  631. $worksheet->setCellValueByColumnAndRow($column, $line, $row['is_user_subscribed']);
  632. $line++;
  633. }
  634. $file = api_get_path(SYS_ARCHIVE_PATH).api_replace_dangerous_char($filename);
  635. $writer = new PHPExcel_Writer_Excel2007($spreadsheet);
  636. $writer->save($file);
  637. DocumentManager::file_send_for_download($file, true, $filename);
  638. return true;
  639. }
  640. }