exercise_result.class.php 24 KB

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