exercise_result.class.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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. // Remove userId indexes to avoid issues in output
  137. foreach ($bestAttemptPerUser as $attempt) {
  138. $results[] = $attempt;
  139. }
  140. }
  141. $filter_by_not_revised = false;
  142. $filter_by_revised = false;
  143. if ($filter) {
  144. switch ($filter) {
  145. case 1:
  146. $filter_by_not_revised = true;
  147. break;
  148. case 2:
  149. $filter_by_revised = true;
  150. break;
  151. default:
  152. null;
  153. }
  154. }
  155. if (empty($sessionId)) {
  156. $students = CourseManager::get_user_list_from_course_code($cid);
  157. } else {
  158. $students = CourseManager::get_user_list_from_course_code($cid, $sessionId);
  159. }
  160. $studentsUserIdList = array_keys($students);
  161. // Print the results of tests
  162. $userWithResults = array();
  163. if (is_array($results)) {
  164. $i = 0;
  165. foreach ($results as $result) {
  166. $revised = false;
  167. //revised or not
  168. $sql_exe = "SELECT exe_id
  169. FROM $TBL_TRACK_ATTEMPT_RECORDING
  170. WHERE
  171. author != '' AND
  172. exe_id = ".Database::escape_string($result['exid'])."
  173. LIMIT 1";
  174. $query = Database::query($sql_exe);
  175. if (Database:: num_rows($query) > 0) {
  176. $revised = true;
  177. }
  178. if ($filter_by_not_revised && $revised) {
  179. continue;
  180. }
  181. if ($filter_by_revised && !$revised) {
  182. continue;
  183. }
  184. $return[$i] = array();
  185. if (empty($user_id)) {
  186. $return[$i]['official_code'] = $result['official_code'];
  187. if (api_is_western_name_order()) {
  188. $return[$i]['first_name'] = $results[$i]['userpart1'];
  189. $return[$i]['last_name'] = $results[$i]['userpart2'];
  190. } else {
  191. $return[$i]['first_name'] = $results[$i]['userpart2'];
  192. $return[$i]['last_name'] = $results[$i]['userpart1'];
  193. }
  194. $return[$i]['user_id'] = $results[$i]['excruid'];
  195. $return[$i]['email'] = $results[$i]['exemail'];
  196. }
  197. $return[$i]['title'] = $result['extitle'];
  198. $return[$i]['start_date'] = api_get_local_time($result['exstart']);
  199. $return[$i]['end_date'] = api_get_local_time($result['exdate']);
  200. $return[$i]['duration'] = $result['duration'];
  201. $return[$i]['result'] = $result['exresult'];
  202. $return[$i]['max'] = $result['exweight'];
  203. $return[$i]['status'] = $revised ? get_lang('Validated') : get_lang('NotValidated');
  204. $return[$i]['lp_id'] = $result['orig_lp_id'];
  205. $return[$i]['lp_name'] = $result['lp_name'];
  206. if (in_array($result['excruid'], $studentsUserIdList)) {
  207. $return[$i]['is_user_subscribed'] = get_lang('Yes');
  208. } else {
  209. $return[$i]['is_user_subscribed'] = get_lang('No');
  210. }
  211. $userWithResults[$result['excruid']] = 1;
  212. $i++;
  213. }
  214. }
  215. if ($this->includeAllUsers) {
  216. $latestId = count($return);
  217. $userWithResults = array_keys($userWithResults);
  218. if (!empty($students)) {
  219. foreach ($students as $student) {
  220. if (!in_array($student['user_id'], $userWithResults)) {
  221. $i = $latestId;
  222. $isWestern = api_is_western_name_order();
  223. if (empty($user_id)) {
  224. $return[$i]['official_code'] = $student['official_code'];
  225. if ($isWestern) {
  226. $return[$i]['first_name'] = $student['firstname'];
  227. $return[$i]['last_name'] = $student['lastname'];
  228. } else {
  229. $return[$i]['first_name'] = $student['lastname'];
  230. $return[$i]['last_name'] = $student['firstname'];
  231. }
  232. $return[$i]['user_id'] = $student['user_id'];
  233. $return[$i]['email'] = $student['email'];
  234. }
  235. $return[$i]['title'] = null;
  236. $return[$i]['start_date'] = null;
  237. $return[$i]['end_date'] = null;
  238. $return[$i]['duration'] = null;
  239. $return[$i]['result'] = null;
  240. $return[$i]['max'] = null;
  241. $return[$i]['status'] = get_lang('NotAttempted');
  242. $return[$i]['lp_id'] = null;
  243. $return[$i]['lp_name'] = null;
  244. $return[$i]['is_user_subscribed'] = get_lang('Yes');
  245. $latestId++;
  246. }
  247. }
  248. }
  249. }
  250. $this->results = $return;
  251. return true;
  252. }
  253. /**
  254. * Exports the complete report as a CSV file
  255. * @param string $document_path Document path inside the document tool
  256. * @param integer $user_id Optional user ID
  257. * @param boolean $export_user_fields Whether to include user fields or not
  258. * @param int $export_filter
  259. * @param int $exercise_id
  260. *
  261. * @return boolean False on error
  262. */
  263. public function exportCompleteReportCSV(
  264. $document_path = '',
  265. $user_id = null,
  266. $export_user_fields = false,
  267. $export_filter = 0,
  268. $exercise_id = 0
  269. ) {
  270. global $charset;
  271. $this->getExercisesReporting(
  272. $document_path,
  273. $user_id,
  274. $export_filter,
  275. $exercise_id
  276. );
  277. $now = api_get_local_time();
  278. $filename = 'exercise_results_'.$now.'.csv';
  279. if (!empty($user_id)) {
  280. $filename = 'exercise_results_user_'.$user_id.'_'.$now.'.csv';
  281. }
  282. $filename = api_replace_dangerous_char($filename);
  283. $data = '';
  284. if (api_is_western_name_order()) {
  285. if (!empty($this->results[0]['first_name'])) {
  286. $data .= get_lang('FirstName').';';
  287. }
  288. if (!empty($this->results[0]['last_name'])) {
  289. $data .= get_lang('LastName').';';
  290. }
  291. } else {
  292. if (!empty($this->results[0]['last_name'])) {
  293. $data .= get_lang('LastName').';';
  294. }
  295. if (!empty($this->results[0]['first_name'])) {
  296. $data .= get_lang('FirstName').';';
  297. }
  298. }
  299. $officialCodeInList = api_get_setting('show_official_code_exercise_result_list');
  300. if ($officialCodeInList === 'true') {
  301. $data .= get_lang('OfficialCode').';';
  302. }
  303. $data .= get_lang('Email').';';
  304. $data .= get_lang('Groups').';';
  305. if ($export_user_fields) {
  306. //show user fields section with a big th colspan that spans over all fields
  307. $extra_user_fields = UserManager::get_extra_fields(
  308. 0,
  309. 1000,
  310. 5,
  311. 'ASC',
  312. false,
  313. 1
  314. );
  315. if (!empty($extra_user_fields)) {
  316. foreach ($extra_user_fields as $field) {
  317. $data .= '"'.str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES, $charset)).'";';
  318. }
  319. }
  320. }
  321. $data .= get_lang('Title').';';
  322. $data .= get_lang('StartDate').';';
  323. $data .= get_lang('EndDate').';';
  324. $data .= get_lang('Duration').' ('.get_lang('MinMinutes').') ;';
  325. $data .= get_lang('Score').';';
  326. $data .= get_lang('Total').';';
  327. $data .= get_lang('Status').';';
  328. $data .= get_lang('ToolLearnpath').';';
  329. $data .= get_lang('UserIsCurrentlySubscribed').';';
  330. $data .= "\n";
  331. //results
  332. foreach ($this->results as $row) {
  333. if (api_is_western_name_order()) {
  334. $data .= str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';';
  335. $data .= str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';';
  336. } else {
  337. $data .= str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';';
  338. $data .= str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';';
  339. }
  340. // Official code
  341. if ($officialCodeInList === 'true') {
  342. $data .= $row['official_code'].';';
  343. }
  344. // Email
  345. $data .= str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset)).';';
  346. $data .= str_replace("\r\n", ' ', implode(", ", GroupManager::get_user_group_name($row['user_id']))).';';
  347. if ($export_user_fields) {
  348. //show user fields data, if any, for this user
  349. $user_fields_values = UserManager::get_extra_user_data(
  350. $row['user_id'],
  351. false,
  352. false,
  353. false,
  354. true
  355. );
  356. if (!empty($user_fields_values)) {
  357. foreach ($user_fields_values as $value) {
  358. $data .= '"'.str_replace('"', '""', api_html_entity_decode(strip_tags($value), ENT_QUOTES, $charset)).'";';
  359. }
  360. }
  361. }
  362. $duration = !empty($row['duration']) ? round($row['duration'] / 60) : 0;
  363. $data .= str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset)).';';
  364. $data .= str_replace("\r\n", ' ', $row['start_date']).';';
  365. $data .= str_replace("\r\n", ' ', $row['end_date']).';';
  366. $data .= str_replace("\r\n", ' ', $duration).';';
  367. $data .= str_replace("\r\n", ' ', $row['result']).';';
  368. $data .= str_replace("\r\n", ' ', $row['max']).';';
  369. $data .= str_replace("\r\n", ' ', $row['status']).';';
  370. $data .= str_replace("\r\n", ' ', $row['lp_name']).';';
  371. $data .= str_replace("\r\n", ' ', $row['is_user_subscribed']).';';
  372. $data .= "\n";
  373. }
  374. // output the results
  375. $len = strlen($data);
  376. header('Content-type: application/octet-stream');
  377. header('Content-Type: application/force-download');
  378. header('Content-length: '.$len);
  379. if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT'])) {
  380. header('Content-Disposition: filename= '.$filename);
  381. } else {
  382. header('Content-Disposition: attachment; filename= '.$filename);
  383. }
  384. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
  385. header('Pragma: ');
  386. header('Cache-Control: ');
  387. header('Cache-Control: public'); // IE cannot download from sessions without a cache
  388. }
  389. header('Content-Description: '.$filename);
  390. header('Content-transfer-encoding: binary');
  391. echo $data;
  392. return true;
  393. }
  394. /**
  395. * Exports the complete report as an XLS file
  396. *
  397. * @param string $document_path
  398. * @param null $user_id
  399. * @param bool $export_user_fields
  400. * @param int $export_filter
  401. * @param int $exercise_id
  402. * @param null $hotpotato_name
  403. * @return bool
  404. */
  405. public function exportCompleteReportXLS(
  406. $document_path = '',
  407. $user_id = null,
  408. $export_user_fields = false,
  409. $export_filter = 0,
  410. $exercise_id = 0,
  411. $hotpotato_name = null
  412. ) {
  413. global $charset;
  414. $this->getExercisesReporting(
  415. $document_path,
  416. $user_id,
  417. $export_filter,
  418. $exercise_id,
  419. $hotpotato_name
  420. );
  421. $now = api_get_local_time();
  422. $filename = 'exercise_results_'.$now.'.xlsx';
  423. if (!empty($user_id)) {
  424. $filename = 'exercise_results_user_'.$user_id.'_'.$now.'.xlsx';
  425. }
  426. $spreadsheet = new PHPExcel();
  427. $spreadsheet->setActiveSheetIndex(0);
  428. $worksheet = $spreadsheet->getActiveSheet();
  429. $line = 1; // Skip first line
  430. $column = 0; //skip the first column (row titles)
  431. // check if exists column 'user'
  432. $with_column_user = false;
  433. foreach ($this->results as $result) {
  434. if (!empty($result['last_name']) && !empty($result['first_name'])) {
  435. $with_column_user = true;
  436. break;
  437. }
  438. }
  439. $officialCodeInList = api_get_setting('show_official_code_exercise_result_list');
  440. if ($with_column_user) {
  441. if (api_is_western_name_order()) {
  442. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('FirstName'));
  443. $column++;
  444. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('LastName'));
  445. $column++;
  446. } else {
  447. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('LastName'));
  448. $column++;
  449. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('FirstName'));
  450. $column++;
  451. }
  452. if ($officialCodeInList === 'true') {
  453. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('OfficialCode'));
  454. $column++;
  455. }
  456. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Email'));
  457. $column++;
  458. }
  459. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Groups'));
  460. $column++;
  461. if ($export_user_fields) {
  462. //show user fields section with a big th colspan that spans over all fields
  463. $extra_user_fields = UserManager::get_extra_fields(
  464. 0,
  465. 1000,
  466. 5,
  467. 'ASC',
  468. false,
  469. 1
  470. );
  471. //show the fields names for user fields
  472. foreach ($extra_user_fields as $field) {
  473. $worksheet->setCellValueByColumnAndRow(
  474. $column,
  475. $line,
  476. api_html_entity_decode(
  477. strip_tags($field[3]),
  478. ENT_QUOTES,
  479. $charset
  480. )
  481. );
  482. $column++;
  483. }
  484. }
  485. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Title'));
  486. $column++;
  487. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('StartDate'));
  488. $column++;
  489. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('EndDate'));
  490. $column++;
  491. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Duration').' ('.get_lang('MinMinutes').')');
  492. $column++;
  493. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Score'));
  494. $column++;
  495. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Total'));
  496. $column++;
  497. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Status'));
  498. $column++;
  499. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('ToolLearnpath'));
  500. $column++;
  501. $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('UserIsCurrentlySubscribed'));
  502. $line++;
  503. foreach ($this->results as $row) {
  504. $column = 0;
  505. if ($with_column_user) {
  506. if (api_is_western_name_order()) {
  507. $worksheet->setCellValueByColumnAndRow(
  508. $column,
  509. $line,
  510. api_html_entity_decode(
  511. strip_tags($row['first_name']),
  512. ENT_QUOTES,
  513. $charset
  514. )
  515. );
  516. $column++;
  517. $worksheet->setCellValueByColumnAndRow(
  518. $column,
  519. $line,
  520. api_html_entity_decode(
  521. strip_tags($row['last_name']),
  522. ENT_QUOTES,
  523. $charset
  524. )
  525. );
  526. $column++;
  527. } else {
  528. $worksheet->setCellValueByColumnAndRow(
  529. $column,
  530. $line,
  531. api_html_entity_decode(
  532. strip_tags($row['last_name']),
  533. ENT_QUOTES,
  534. $charset
  535. )
  536. );
  537. $column++;
  538. $worksheet->setCellValueByColumnAndRow(
  539. $column,
  540. $line,
  541. api_html_entity_decode(
  542. strip_tags($row['first_name']),
  543. ENT_QUOTES,
  544. $charset
  545. )
  546. );
  547. $column++;
  548. }
  549. if ($officialCodeInList === 'true') {
  550. $worksheet->setCellValueByColumnAndRow(
  551. $column,
  552. $line,
  553. api_html_entity_decode(
  554. strip_tags($row['official_code']),
  555. ENT_QUOTES,
  556. $charset
  557. )
  558. );
  559. $column++;
  560. }
  561. $worksheet->setCellValueByColumnAndRow(
  562. $column,
  563. $line,
  564. api_html_entity_decode(
  565. strip_tags($row['email']),
  566. ENT_QUOTES,
  567. $charset
  568. )
  569. );
  570. $column++;
  571. }
  572. $worksheet->setCellValueByColumnAndRow(
  573. $column,
  574. $line,
  575. api_html_entity_decode(
  576. strip_tags(
  577. implode(
  578. ", ",
  579. GroupManager:: get_user_group_name($row['user_id'])
  580. )
  581. ),
  582. ENT_QUOTES,
  583. $charset
  584. )
  585. );
  586. $column++;
  587. if ($export_user_fields) {
  588. //show user fields data, if any, for this user
  589. $user_fields_values = UserManager::get_extra_user_data(
  590. $row['user_id'],
  591. false,
  592. false,
  593. false,
  594. true
  595. );
  596. foreach ($user_fields_values as $value) {
  597. $worksheet->setCellValueByColumnAndRow(
  598. $column,
  599. $line,
  600. api_html_entity_decode(
  601. strip_tags($value),
  602. ENT_QUOTES,
  603. $charset
  604. )
  605. );
  606. $column++;
  607. }
  608. }
  609. $worksheet->setCellValueByColumnAndRow(
  610. $column,
  611. $line,
  612. api_html_entity_decode(
  613. strip_tags($row['title']),
  614. ENT_QUOTES,
  615. $charset
  616. )
  617. );
  618. $column++;
  619. $worksheet->setCellValueByColumnAndRow($column, $line, $row['start_date']);
  620. $column++;
  621. $worksheet->setCellValueByColumnAndRow($column, $line, $row['end_date']);
  622. $column++;
  623. $duration = !empty($row['duration']) ? round($row['duration'] / 60) : 0;
  624. $worksheet->setCellValueByColumnAndRow($column, $line, $duration);
  625. $column++;
  626. $worksheet->setCellValueByColumnAndRow($column, $line, $row['result']);
  627. $column++;
  628. $worksheet->setCellValueByColumnAndRow($column, $line, $row['max']);
  629. $column++;
  630. $worksheet->setCellValueByColumnAndRow($column, $line, $row['status']);
  631. $column++;
  632. $worksheet->setCellValueByColumnAndRow($column, $line, $row['lp_name']);
  633. $column++;
  634. $worksheet->setCellValueByColumnAndRow($column, $line, $row['is_user_subscribed']);
  635. $line++;
  636. }
  637. $file = api_get_path(SYS_ARCHIVE_PATH).api_replace_dangerous_char($filename);
  638. $writer = new PHPExcel_Writer_Excel2007($spreadsheet);
  639. $writer->save($file);
  640. DocumentManager::file_send_for_download($file, true, $filename);
  641. return true;
  642. }
  643. }