Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 6458 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 6458 Rev 6496
Línea 126... Línea 126...
126
                        'id' => $record->id,
126
                        'id' => $record->id,
127
                        'name' => $record->name,
127
                        'name' => $record->name,
128
                        'form' => $surveyForm->name,
128
                        'form' => $surveyForm->name,
129
                        'status' => $record->status,
129
                        'status' => $record->status,
130
                        'actions' => [
130
                        'actions' => [
131
                            'link_report_all' => $this->url()->fromRoute('survey/report/all', ['survey_id' => $record->uuid])
131
                            'link_report_all' => $this->url()->fromRoute('survey/report/all', ['survey_id' => $record->uuid]),
-
 
132
                            'link_overview' => $this->url()->fromRoute('survey/report/overview', ['survey_id' => $record->uuid])
132
                        ]
133
                        ]
133
                    ];
134
                    ];
Línea 134... Línea 135...
134
 
135
 
135
                    array_push($items, $item);
136
                    array_push($items, $item);
Línea 172... Línea 173...
172
            ]);
173
            ]);
173
        }
174
        }
Línea 174... Línea 175...
174
        
175
        
Línea -... Línea 176...
-
 
176
    }
-
 
177
 
-
 
178
    public function overviewAction(){
-
 
179
        $request = $this->getRequest();
-
 
180
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
181
        $currentCompany = $currentUserPlugin->getCompany();
-
 
182
        $currentUser = $currentUserPlugin->getUser();
-
 
183
 
-
 
184
        $request = $this->getRequest();
-
 
185
        $uuid = $this->params()->fromRoute('survey_id');
-
 
186
 
-
 
187
        if (!$uuid) {
-
 
188
            $data = [
-
 
189
                'success' => false,
-
 
190
                'data' => 'ERROR_INVALID_PARAMETER'
-
 
191
            ];
-
 
192
 
-
 
193
            return new JsonModel($data);
-
 
194
        }
-
 
195
 
-
 
196
        $surveyMapper = SurveyMapper::getInstance($this->adapter);
-
 
197
        $survey = $surveyMapper->fetchOneByUuid($uuid);
-
 
198
 
-
 
199
        $surveyMapper = SurveyMapper::getInstance($this->adapter);
-
 
200
        $survey = $surveyMapper->fetchOneByUuid($uuid);
-
 
201
       
-
 
202
        $surveyTestMapper = SurveyTestMapper::getInstance($this->adapter);
-
 
203
        $surveyTests = $surveyTestMapper->fetchAllBySurveyId($survey->id);
-
 
204
 
-
 
205
        $surveyFormMapper = SurveyFormMapper::getInstance($this->adapter);
-
 
206
        $surveyForm = $surveyFormMapper->fetchOne($survey->form_id);
-
 
207
 
-
 
208
        $sections = json_decode($surveyForm->content, true);
-
 
209
 
-
 
210
        $allTests = array_map(
-
 
211
            function($response) {
-
 
212
                return json_decode($response->content, true);
-
 
213
            },
-
 
214
            $surveyTests,
-
 
215
        );
-
 
216
 
-
 
217
        $averages = [];
-
 
218
 
-
 
219
        foreach($sections as $section) {
-
 
220
            foreach($section['questions'] as $question) {
-
 
221
                switch ($question['type']) {
-
 
222
                    case 'multiple':
-
 
223
                        $totals = [];
-
 
224
 
-
 
225
                        foreach($question['options'] as $option) {
-
 
226
                            $totals[$option['slug_option']] = 0;
-
 
227
                        }
-
 
228
 
-
 
229
                        foreach($question['options'] as $option) {
-
 
230
                            $totals[$option['slug_option']] = count(array_filter(
-
 
231
                                $allTests,
-
 
232
                                function ($test) use($option, $question) {
-
 
233
                                    return in_array($option['slug_option'], $test[$question['slug_question']]);
-
 
234
                                }
-
 
235
                            ));
-
 
236
                        }
-
 
237
 
-
 
238
                        $averages[$question['slug_question']] = $totals;
-
 
239
 
-
 
240
                        break;
-
 
241
                   
-
 
242
                    case 'simple':
-
 
243
                        $totals = [];
-
 
244
 
-
 
245
                        foreach($question['options'] as $option) {
-
 
246
                            $totals[$option['slug_option']] = 0;
-
 
247
                        }
-
 
248
 
-
 
249
                        foreach ($allTests as $test) {
-
 
250
                            $totals[$test[$question['slug_question']]]++;
-
 
251
                        }
-
 
252
 
-
 
253
                        foreach($totals as $slug => $amount) {
-
 
254
                            $totals[$slug] = ($amount / count($allTests)) * 100;
-
 
255
                        }
-
 
256
 
-
 
257
                        $averages[$question['slug_question']] = $totals;
-
 
258
                    break;
-
 
259
 
-
 
260
                }
-
 
261
            }
-
 
262
        }
-
 
263
 
-
 
264
        $this->layout()->setTemplate('layout/layout-backend.phtml');
-
 
265
        $viewModel = new ViewModel();
-
 
266
        $viewModel->setTemplate('leaders-linked/survey-report/overview.phtml');
-
 
267
        $viewModel->setVariables([  
-
 
268
        ]); 
-
 
269
        return $viewModel ;
-
 
270
 
175
    }
271
    }
176
 
272
 
177
    public function allAction() {
273
    public function allAction() {
178
        $request = $this->getRequest();
274
        $request = $this->getRequest();
179
        $currentUserPlugin = $this->plugin('currentUserPlugin');
275
        $currentUserPlugin = $this->plugin('currentUserPlugin');