16817 |
efrain |
1 |
<?php
|
|
|
2 |
declare(strict_types=1);
|
|
|
3 |
|
|
|
4 |
namespace LeadersLinked\Controller;
|
|
|
5 |
|
|
|
6 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
7 |
|
|
|
8 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
9 |
use Laminas\Log\LoggerInterface;
|
|
|
10 |
use Laminas\View\Model\JsonModel;
|
|
|
11 |
use Laminas\View\Model\ViewModel;
|
|
|
12 |
use LeadersLinked\Library\Functions;
|
|
|
13 |
use LeadersLinked\Mapper\QueryMapper;
|
|
|
14 |
use LeadersLinked\Mapper\UserMapper;
|
|
|
15 |
use Laminas\Hydrator\ArraySerializableHydrator;
|
|
|
16 |
use Laminas\Db\ResultSet\HydratingResultSet;
|
|
|
17 |
use Laminas\Paginator\Adapter\DbSelect;
|
|
|
18 |
use Laminas\Paginator\Paginator;
|
|
|
19 |
use Laminas\Mvc\I18n\Translator;
|
|
|
20 |
use LeadersLinked\Cache\CacheInterface;
|
|
|
21 |
use LeadersLinked\Cache\CacheImpl;
|
|
|
22 |
use LeadersLinked\Mapper\SurveyTestMapper;
|
|
|
23 |
use LeadersLinked\Form\Survey\SurveyTakeAnTestForm;
|
|
|
24 |
use LeadersLinked\Model\SurveyTest;
|
|
|
25 |
use LeadersLinked\Library\UniqueSurveyReport;
|
|
|
26 |
use Laminas\Http\Response;
|
|
|
27 |
use LeadersLinked\Mapper\SurveyCampaignMapper;
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
class ActivityCenterSurveyController extends AbstractActionController
|
|
|
31 |
{
|
|
|
32 |
/**
|
|
|
33 |
*
|
|
|
34 |
* @var \Laminas\Db\Adapter\AdapterInterface
|
|
|
35 |
*/
|
|
|
36 |
private $adapter;
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
*
|
|
|
40 |
* @var \LeadersLinked\Cache\CacheInterface
|
|
|
41 |
*/
|
|
|
42 |
private $cache;
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
/**
|
|
|
46 |
*
|
|
|
47 |
* @var \Laminas\Log\LoggerInterface
|
|
|
48 |
*/
|
|
|
49 |
private $logger;
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
*
|
|
|
53 |
* @var array
|
|
|
54 |
*/
|
|
|
55 |
private $config;
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
/**
|
|
|
59 |
*
|
|
|
60 |
* @var \Laminas\Mvc\I18n\Translator
|
|
|
61 |
*/
|
|
|
62 |
private $translator;
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
/**
|
|
|
66 |
*
|
|
|
67 |
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
|
|
|
68 |
* @param \LeadersLinked\Cache\CacheInterface $cache
|
|
|
69 |
* @param \Laminas\Log\LoggerInterface LoggerInterface $logger
|
|
|
70 |
* @param array $config
|
|
|
71 |
* @param \Laminas\Mvc\I18n\Translator $translator
|
|
|
72 |
*/
|
|
|
73 |
public function __construct($adapter, $cache, $logger, $config, $translator)
|
|
|
74 |
{
|
|
|
75 |
$this->adapter = $adapter;
|
|
|
76 |
$this->cache = $cache;
|
|
|
77 |
$this->logger = $logger;
|
|
|
78 |
$this->config = $config;
|
|
|
79 |
$this->translator = $translator;
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
public function indexAction()
|
|
|
83 |
{
|
|
|
84 |
$request = $this->getRequest();
|
|
|
85 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
86 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
87 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
$request = $this->getRequest();
|
|
|
91 |
if ($request->isGet()) {
|
|
|
92 |
|
|
|
93 |
$headers = $request->getHeaders();
|
|
|
94 |
|
|
|
95 |
$isJson = false;
|
|
|
96 |
if ($headers->has('Accept')) {
|
|
|
97 |
$accept = $headers->get('Accept');
|
|
|
98 |
|
|
|
99 |
$prioritized = $accept->getPrioritized();
|
|
|
100 |
|
|
|
101 |
foreach ($prioritized as $key => $value) {
|
|
|
102 |
$raw = trim($value->getRaw());
|
|
|
103 |
|
|
|
104 |
if (!$isJson) {
|
|
|
105 |
$isJson = strpos($raw, 'json');
|
|
|
106 |
}
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
//$isJson = true;
|
|
|
111 |
if ($isJson) {
|
|
|
112 |
|
|
|
113 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
|
|
114 |
$allowTakeATest = $acl->isAllowed($currentUser->usertype_id, 'activities-center/survey/take-a-test');
|
|
|
115 |
$allowReport = $acl->isAllowed($currentUser->usertype_id, 'activities-center/survey/report');
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
|
119 |
$search = $this->params()->fromQuery('search', []);
|
|
|
120 |
$search = empty($search['value']) ? '' : Functions::sanitizeFilterString($search['value']);
|
|
|
121 |
|
|
|
122 |
$start = intval($this->params()->fromQuery('start', 0), 10);
|
|
|
123 |
$records_x_page = intval($this->params()->fromQuery('length', 10), 10);
|
|
|
124 |
$page = intval($start / $records_x_page);
|
|
|
125 |
$page++;
|
|
|
126 |
|
|
|
127 |
$order = $this->params()->fromQuery('order', []);
|
|
|
128 |
$order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
|
|
|
129 |
$order_direction = empty($order[0]['dir']) ? 'ASC' : Functions::sanitizeFilterString(filter_var($order[0]['dir']));
|
|
|
130 |
|
|
|
131 |
$fields = ['name', 'start_date', 'end_date', 'status'];
|
|
|
132 |
$order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'name';
|
|
|
133 |
|
|
|
134 |
if (!in_array($order_direction, ['ASC', 'DESC'])) {
|
|
|
135 |
$order_direction = 'ASC';
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
$surveyTestMapper = SurveyTestMapper::getInstance($this->adapter);
|
|
|
139 |
$paginator = $surveyTestMapper->fetchAllNormalDataTableByUserId($currentUser->id, $search, $page, $records_x_page, $order_field, $order_direction);
|
|
|
140 |
|
|
|
141 |
$items = [];
|
|
|
142 |
$records = $paginator->getCurrentItems();
|
|
|
143 |
|
|
|
144 |
foreach ($records as $record)
|
|
|
145 |
{
|
|
|
146 |
$link_pdf = '';
|
|
|
147 |
$link_take_a_test = '';
|
|
|
148 |
|
|
|
149 |
if($allowReport && $record['status'] == SurveyTest::STATUS_COMPLETED) {
|
|
|
150 |
$link_pdf = $this->url()->fromRoute('activities-center/survey/report', ['id' => $record['uuid']]);
|
|
|
151 |
$link_take_a_test = '';
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
}
|
|
|
155 |
if($allowTakeATest && $record['status'] == SurveyTest::STATUS_PENDING) {
|
|
|
156 |
$link_pdf = '';
|
|
|
157 |
$link_take_a_test = $this->url()->fromRoute('activities-center/survey/take-a-test', ['id' => $record['uuid']]);
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
|
|
|
161 |
|
|
|
162 |
|
|
|
163 |
switch($record['status'])
|
|
|
164 |
{
|
|
|
165 |
case SurveyTest::STATUS_PENDING :
|
|
|
166 |
$status = 'LABEL_PENDING';
|
|
|
167 |
break;
|
|
|
168 |
|
|
|
169 |
case SurveyTest::STATUS_COMPLETED :
|
|
|
170 |
$status = 'LABEL_COMPLETED';
|
|
|
171 |
break;
|
|
|
172 |
|
|
|
173 |
default :
|
|
|
174 |
$status = 'LABEL_UNKNOWD';
|
|
|
175 |
break;
|
|
|
176 |
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
$dtStart = \DateTime::createFromFormat('Y-m-d', $record['start_date']);
|
|
|
180 |
$dtEnd = \DateTime::createFromFormat('Y-m-d', $record['end_date']);
|
|
|
181 |
|
|
|
182 |
$item = [
|
|
|
183 |
'name' => $record['name'],
|
|
|
184 |
'start_date' => $dtStart->format('d/m/Y'),
|
|
|
185 |
'end_date' => $dtEnd->format('d/m/Y'),
|
|
|
186 |
'status' => $status,
|
|
|
187 |
'actions' => [
|
|
|
188 |
'link_pdf' => $link_pdf,
|
|
|
189 |
'link_take_a_test' => $link_take_a_test,
|
|
|
190 |
|
|
|
191 |
]
|
|
|
192 |
];
|
|
|
193 |
|
|
|
194 |
array_push($items, $item);
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
return new JsonModel([
|
|
|
198 |
'success' => true,
|
|
|
199 |
'data' => [
|
|
|
200 |
'items' => $items,
|
|
|
201 |
'total' => $paginator->getTotalItemCount(),
|
|
|
202 |
]
|
|
|
203 |
]);
|
|
|
204 |
} else {
|
16820 |
efrain |
205 |
if($this->cache->hasItem('ACTIVITY_CENTER_RELATIONAL')) {
|
|
|
206 |
$search = $this->cache->getItem('ACTIVITY_CENTER_RELATIONAL');
|
|
|
207 |
$this->cache->removeItem('ACTIVITY_CENTER_RELATIONAL');
|
16817 |
efrain |
208 |
} else {
|
|
|
209 |
$search = '';
|
|
|
210 |
}
|
|
|
211 |
|
16820 |
efrain |
212 |
|
16817 |
efrain |
213 |
$form = new SurveyTakeAnTestForm();
|
|
|
214 |
|
|
|
215 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
216 |
$viewModel = new ViewModel();
|
|
|
217 |
$viewModel->setTemplate('leaders-linked/activity-center-survey/index.phtml');
|
|
|
218 |
$viewModel->setVariables([
|
|
|
219 |
'form' => $form,
|
|
|
220 |
'search' => $search
|
|
|
221 |
]);
|
|
|
222 |
return $viewModel;
|
|
|
223 |
}
|
|
|
224 |
} else {
|
|
|
225 |
return new JsonModel([
|
|
|
226 |
'success' => false,
|
|
|
227 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
228 |
]);
|
|
|
229 |
|
|
|
230 |
}
|
|
|
231 |
}
|
|
|
232 |
|
|
|
233 |
public function takeaTestAction()
|
|
|
234 |
{
|
|
|
235 |
$request = $this->getRequest();
|
|
|
236 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
237 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
238 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
239 |
|
|
|
240 |
$request = $this->getRequest();
|
|
|
241 |
$uuid = $this->params()->fromRoute('id');
|
|
|
242 |
|
|
|
243 |
if (!$uuid) {
|
|
|
244 |
$data = [
|
|
|
245 |
'success' => false,
|
|
|
246 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
247 |
];
|
|
|
248 |
|
|
|
249 |
return new JsonModel($data);
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
$surveyTestMapper = SurveyTestMapper::getInstance($this->adapter);
|
|
|
253 |
$surveyTest = $surveyTestMapper->fetchOneByUuid($uuid);
|
|
|
254 |
if (! $surveyTest) {
|
|
|
255 |
$data = [
|
|
|
256 |
'success' => false,
|
|
|
257 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
258 |
];
|
|
|
259 |
|
|
|
260 |
return new JsonModel($data);
|
|
|
261 |
}
|
|
|
262 |
|
|
|
263 |
|
|
|
264 |
if ( $surveyTest->company_id != $currentCompany->id) {
|
|
|
265 |
return new JsonModel([
|
|
|
266 |
'success' => false,
|
|
|
267 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
268 |
]);
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
if ($surveyTest->user_id != $currentUser->id ) {
|
|
|
272 |
return new JsonModel([
|
|
|
273 |
'success' => false,
|
|
|
274 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
275 |
]);
|
|
|
276 |
}
|
|
|
277 |
|
|
|
278 |
if($surveyTest->status == SurveyTest::STATUS_COMPLETED) {
|
|
|
279 |
return new JsonModel([
|
|
|
280 |
'success' => false,
|
|
|
281 |
'data' => 'ERROR_SURVEY_ALREADY_COMPLETED'
|
|
|
282 |
]);
|
|
|
283 |
|
|
|
284 |
}
|
|
|
285 |
|
|
|
286 |
|
|
|
287 |
|
|
|
288 |
$request = $this->getRequest();
|
|
|
289 |
if ($request->isGet()) {
|
|
|
290 |
|
|
|
291 |
$content = json_decode($surveyTest->content);
|
|
|
292 |
|
|
|
293 |
return new JsonModel([
|
|
|
294 |
'success' => true,
|
|
|
295 |
'data' => [
|
|
|
296 |
'name' => $content->name,
|
|
|
297 |
'text' => $content->text,
|
|
|
298 |
'content' => $content->content
|
|
|
299 |
]
|
|
|
300 |
]);
|
|
|
301 |
|
|
|
302 |
|
|
|
303 |
|
|
|
304 |
return ;
|
|
|
305 |
}
|
|
|
306 |
else if ( $request->isPost()) {
|
|
|
307 |
|
|
|
308 |
$surveyTestContent = json_decode($surveyTest->content, true);
|
|
|
309 |
|
|
|
310 |
$max_sections = count($surveyTestContent['content']);
|
|
|
311 |
for($i = 0; $i < $max_sections; $i++)
|
|
|
312 |
{
|
|
|
313 |
$max_questions = count($surveyTestContent['content'][$i]['questions']);
|
|
|
314 |
for($j = 0; $j < $max_questions; $j++)
|
|
|
315 |
{
|
|
|
316 |
|
|
|
317 |
if($surveyTestContent['content'][$i]['questions'][$j]['type'] == 'open') {
|
|
|
318 |
$surveyTestContent['content'][$i]['questions'][$j]['answer'] = Functions::sanitizeFilterString( $this->params()->fromPost($surveyTestContent['content'][$i]['questions'][$j]['slug_question'], ''));
|
|
|
319 |
}
|
|
|
320 |
else if($surveyTestContent['content'][$i]['questions'][$j]['type'] == 'simple') {
|
|
|
321 |
$val = Functions::sanitizeFilterString( $this->params()->fromPost($surveyTestContent['content'][$i]['questions'][$j]['slug_question'], ''));
|
|
|
322 |
|
|
|
323 |
$max_options = count($surveyTestContent['content'][$i]['questions'][$j]['options']);
|
|
|
324 |
for($x = 0; $x < $max_options; $x++)
|
|
|
325 |
{
|
|
|
326 |
$surveyTestContent['content'][$i]['questions'][$j]['options'][$x]['checked'] = $surveyTestContent['content'][$i]['questions'][$j]['options'][$x]['slug_option'] == $val ? 1 : 0;
|
|
|
327 |
}
|
|
|
328 |
|
|
|
329 |
} else if($surveyTestContent['content'][$i]['questions'][$j]['type'] == 'multiple') {
|
|
|
330 |
$val = $this->params()->fromPost($surveyTestContent['content'][$i]['questions'][$j]['slug_question']);
|
|
|
331 |
$val = is_array($val) ? $val : [];
|
|
|
332 |
|
|
|
333 |
$max_options = count($surveyTestContent['content'][$i]['questions'][$j]['options']);
|
|
|
334 |
for($x = 0; $x < $max_options; $x++)
|
|
|
335 |
{
|
|
|
336 |
$surveyTestContent['content'][$i]['questions'][$j]['options'][$x]['checked'] = in_array($surveyTestContent['content'][$i]['questions'][$j]['options'][$x]['slug_option'], $val) ? 1 : 0;
|
|
|
337 |
}
|
|
|
338 |
|
|
|
339 |
} else if($surveyTestContent['content'][$i]['questions'][$j]['type'] == 'range1to5') {
|
|
|
340 |
$surveyTestContent['content'][$i]['questions'][$j]['answer'] = intval($this->params()->fromPost($surveyTestContent['content'][$i]['questions'][$j]['slug_question'], '0'), 10);
|
|
|
341 |
}
|
|
|
342 |
}
|
|
|
343 |
}
|
|
|
344 |
|
|
|
345 |
|
|
|
346 |
$surveyTest->content = json_encode($surveyTestContent);
|
|
|
347 |
$surveyTest->status = SurveyTest::STATUS_COMPLETED;
|
|
|
348 |
|
|
|
349 |
if($surveyTestMapper->update($surveyTest)) {
|
|
|
350 |
|
|
|
351 |
|
|
|
352 |
return new JsonModel([
|
|
|
353 |
'success' => true,
|
|
|
354 |
'data' => 'LABEL_SURVEY_TEST_COMPLETED'
|
|
|
355 |
]);
|
|
|
356 |
} else {
|
|
|
357 |
return new JsonModel([
|
|
|
358 |
'success' => false,
|
|
|
359 |
'data' => $surveyTestMapper->getError()
|
|
|
360 |
]);
|
|
|
361 |
|
|
|
362 |
}
|
|
|
363 |
|
|
|
364 |
} else {
|
|
|
365 |
|
|
|
366 |
|
|
|
367 |
return new JsonModel([
|
|
|
368 |
'success' => false,
|
|
|
369 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
370 |
]);
|
|
|
371 |
}
|
|
|
372 |
}
|
|
|
373 |
|
|
|
374 |
public function reportAction()
|
|
|
375 |
{
|
|
|
376 |
$request = $this->getRequest();
|
|
|
377 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
378 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
379 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
380 |
|
|
|
381 |
$request = $this->getRequest();
|
|
|
382 |
$uuid = $this->params()->fromRoute('id');
|
|
|
383 |
|
|
|
384 |
if (!$uuid) {
|
|
|
385 |
$data = [
|
|
|
386 |
'success' => false,
|
|
|
387 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
388 |
];
|
|
|
389 |
|
|
|
390 |
return new JsonModel($data);
|
|
|
391 |
}
|
|
|
392 |
|
|
|
393 |
$surveyTestMapper = SurveyTestMapper::getInstance($this->adapter);
|
|
|
394 |
$surveyTest = $surveyTestMapper->fetchOneByUuid($uuid);
|
|
|
395 |
if (! $surveyTest) {
|
|
|
396 |
$data = [
|
|
|
397 |
'success' => false,
|
|
|
398 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
399 |
];
|
|
|
400 |
|
|
|
401 |
return new JsonModel($data);
|
|
|
402 |
}
|
|
|
403 |
|
|
|
404 |
|
|
|
405 |
if ( $surveyTest->company_id != $currentCompany->id) {
|
|
|
406 |
return new JsonModel([
|
|
|
407 |
'success' => false,
|
|
|
408 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
409 |
]);
|
|
|
410 |
}
|
|
|
411 |
|
|
|
412 |
if ($surveyTest->user_id != $currentUser->id ) {
|
|
|
413 |
return new JsonModel([
|
|
|
414 |
'success' => false,
|
|
|
415 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
416 |
]);
|
|
|
417 |
}
|
|
|
418 |
|
|
|
419 |
if($surveyTest->status != SurveyTest::STATUS_COMPLETED) {
|
|
|
420 |
return new JsonModel([
|
|
|
421 |
'success' => false,
|
|
|
422 |
'data' => 'ERROR_SURVEY_IS_NOT_COMPLETED'
|
|
|
423 |
]);
|
|
|
424 |
|
|
|
425 |
}
|
|
|
426 |
|
|
|
427 |
$request = $this->getRequest();
|
|
|
428 |
if ($request->isGet()) {
|
|
|
429 |
|
|
|
430 |
//Generate New PDF
|
|
|
431 |
$pdf = new UniqueSurveyReport();
|
|
|
432 |
$pdf->translator = $this->translator;
|
|
|
433 |
|
|
|
434 |
$target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $currentCompany->uuid;
|
|
|
435 |
$header = $currentCompany->header ? $target_path . DIRECTORY_SEPARATOR . $currentCompany->header : '';
|
|
|
436 |
if (empty($header) || !file_exists($header)) {
|
|
|
437 |
$header = $this->config['leaderslinked.images_default.company_pdf_header'];
|
|
|
438 |
}
|
|
|
439 |
|
|
|
440 |
$footer = $currentCompany->footer ? $target_path . DIRECTORY_SEPARATOR . $currentCompany->footer : '';
|
|
|
441 |
if (empty($footer) || !file_exists($footer)) {
|
|
|
442 |
$footer = $this->config['leaderslinked.images_default.company_pdf_footer'];
|
|
|
443 |
}
|
|
|
444 |
|
|
|
445 |
$pdf->header = $header;
|
|
|
446 |
$pdf->footer = $footer;
|
|
|
447 |
|
|
|
448 |
|
|
|
449 |
|
|
|
450 |
|
|
|
451 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
452 |
$user = $userMapper->fetchOne($surveyTest->user_id);
|
|
|
453 |
|
|
|
454 |
$content = json_decode($surveyTest->content, true);
|
|
|
455 |
|
|
|
456 |
$dt = \DateTime::createFromFormat('Y-m-d H:i:s', $surveyTest->update_on);
|
|
|
457 |
|
|
|
458 |
$pdf->SetTitle(Functions::utf8_decode($content['name']));
|
|
|
459 |
$pdf->formName = Functions::utf8_decode($content['name']);
|
|
|
460 |
$pdf->formText = Functions::utf8_decode($content['text']);
|
|
|
461 |
$pdf->formDate = $dt->format('d/m/Y H:i a');
|
|
|
462 |
$pdf->userName = Functions::utf8_decode($user->first_name . ' ' . $user->last_name) . ' (' . $user->email . ') ';
|
|
|
463 |
|
|
|
464 |
|
|
|
465 |
|
|
|
466 |
$pdf->SetMargins(10, 0, 10);
|
|
|
467 |
|
|
|
468 |
$pdf->AliasNbPages();
|
|
|
469 |
$pdf->AddPage();
|
|
|
470 |
|
17002 |
efrain |
471 |
|
16817 |
efrain |
472 |
foreach($content['content'] as $section)
|
|
|
473 |
{
|
|
|
474 |
if($pdf->GetY() > 250) {
|
|
|
475 |
$pdf->AddPage();
|
|
|
476 |
}
|
|
|
477 |
|
|
|
478 |
$pdf->addSection($section['name'], $section['text']);
|
|
|
479 |
|
|
|
480 |
|
|
|
481 |
|
|
|
482 |
foreach($section['questions'] as $question)
|
|
|
483 |
{
|
|
|
484 |
switch($question['type']) {
|
|
|
485 |
case 'range1to5' :
|
|
|
486 |
$pdf->questionAndAnswer($question['text'], $question['answer']);
|
|
|
487 |
break;
|
|
|
488 |
|
|
|
489 |
case 'multiple' :
|
|
|
490 |
case 'simple' :
|
|
|
491 |
$values = [];
|
|
|
492 |
|
|
|
493 |
foreach($question['options'] as $option)
|
|
|
494 |
{
|
|
|
495 |
if($option['checked']) {
|
|
|
496 |
array_push($values, $option['text']);
|
|
|
497 |
}
|
|
|
498 |
}
|
|
|
499 |
|
|
|
500 |
$pdf->questionAndAnswers($question['text'], $values);
|
|
|
501 |
break;
|
|
|
502 |
|
|
|
503 |
}
|
|
|
504 |
}
|
|
|
505 |
|
|
|
506 |
}
|
|
|
507 |
|
|
|
508 |
|
|
|
509 |
$content = $pdf->Output('S');
|
|
|
510 |
|
|
|
511 |
$response = new Response();
|
|
|
512 |
$response->setStatusCode(200);
|
|
|
513 |
$response->setContent($content);
|
|
|
514 |
|
|
|
515 |
|
|
|
516 |
|
|
|
517 |
$headers = $response->getHeaders();
|
|
|
518 |
$headers->clearHeaders();
|
|
|
519 |
|
|
|
520 |
$headers->addHeaderLine('Content-Description: File Transfer');
|
|
|
521 |
$headers->addHeaderLine('Content-Type: application/pdf');
|
|
|
522 |
//$headers->addHeaderLine('Content-Disposition: attachment; filename=' . $filename);
|
|
|
523 |
$headers->addHeaderLine('Content-Transfer-Encoding: binary');
|
|
|
524 |
$headers->addHeaderLine('Expires: 0');
|
|
|
525 |
$headers->addHeaderLine('Cache-Control: must-revalidate');
|
|
|
526 |
$headers->addHeaderLine('Pragma: public');
|
|
|
527 |
return $response;
|
|
|
528 |
|
|
|
529 |
} else {
|
|
|
530 |
|
|
|
531 |
|
|
|
532 |
return new JsonModel([
|
|
|
533 |
'success' => false,
|
|
|
534 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
535 |
]);
|
|
|
536 |
}
|
|
|
537 |
}
|
|
|
538 |
|
|
|
539 |
|
|
|
540 |
|
|
|
541 |
|
|
|
542 |
|
|
|
543 |
}
|