exercise_result.class.php 26 KB

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