public function createAction()
 {
     $time = time();
     if ($this->request->isPost()) {
         $question = new Question();
         $question->assign(array('pid' => 0, 'tstamp' => $time, 'crdate' => $time, 'cruser_id' => 0, 'deleted' => 0, 'hidden' => 0, 'session' => $this->request->hasPost('uniqueid') ? $this->request->getPost('uniqueid') : '', 'questionnumber' => $this->request->hasPost('question') ? $this->request->getPost('question') : 0, 'message' => $this->request->hasPost('message') ? $this->request->getPost('message') : ''));
         $question->save();
         if ($this->request->hasPost('item')) {
             if (is_array($this->request->getPost('item'))) {
                 foreach ($this->request->getPost('item') as $key => $itemData) {
                     $checkitem = new Questionitem();
                     $checkitem->assign(array('pid' => $question->uid, 'tstamp' => $time, 'crdate' => $time, 'cruser_id' => 0, 'deleted' => 0, 'hidden' => 0, 'session' => $question->session, 'questionnumber' => $question->questionnumber, 'itemnumber' => $itemData, 'checked' => 1, 'rating' => 0, 'message' => '', 'mode' => 0));
                     if (!$checkitem->save()) {
                         $this->flash->error($checkitem->getMessages());
                     }
                 }
             } else {
                 $radioitem = new Questionitem();
                 $radioitem->assign(array('pid' => $question->uid, 'tstamp' => $time, 'crdate' => $time, 'cruser_id' => 0, 'deleted' => 0, 'hidden' => 0, 'session' => $question->session, 'questionnumber' => $question->questionnumber, 'itemnumber' => $this->request->getPost('item'), 'checked' => 1, 'rating' => 0, 'message' => '', 'mode' => 1));
                 $radioitem->save();
             }
         }
         if ($this->request->hasPost('openitem')) {
             foreach ($this->request->getPost('openitem') as $key => $itemData) {
                 $openitem = new Questionitem();
                 $openitem->assign(array('pid' => $question->uid, 'tstamp' => $time, 'crdate' => $time, 'cruser_id' => 0, 'deleted' => 0, 'hidden' => 0, 'session' => $question->session, 'questionnumber' => $question->questionnumber, 'itemnumber' => $key, 'checked' => 1, 'rating' => 0, 'message' => $itemData, 'mode' => 3));
                 $openitem->save();
             }
         }
         if ($this->request->hasPost('rating')) {
             foreach ($this->request->getPost('rating') as $key => $itemData) {
                 $ratingName = 'rating_' . $itemData;
                 $ratingitem = new Questionitem();
                 $ratingitem->assign(array('pid' => $question->uid, 'tstamp' => $time, 'crdate' => $time, 'cruser_id' => 0, 'deleted' => 0, 'hidden' => 0, 'checked' => 0, 'session' => $question->session, 'questionnumber' => $question->questionnumber, 'itemnumber' => $itemData, 'rating' => $this->request->hasPost($ratingName) ? $this->request->getPost($ratingName) : 0, 'message' => '', 'mode' => 2));
                 $ratingitem->save();
             }
         }
         die;
     }
 }
 public function createAction()
 {
     $this->assets->addJs('js/vendor/reportInit.js');
     $this->view->setMainView('report');
     $mitarbeiterbefragung = false;
     if ($this->dispatcher->getParam("uid") > 0) {
         if ($this->dispatcher->getParam("uid") == 1) {
             $operator = '<';
             $qnumberArray = array(5 => 5);
         } else {
             $mitarbeiterbefragung = true;
             $operator = '>';
             $qnumberArray = array(1 => 101, 2 => 102, 4 => 104, 5 => 105, 6 => 106, 9 => 109, 10 => 110, 11 => 111);
         }
         $sessions = array();
         $questions = Questions::find(array('conditions' => 'questionnumber ' . $operator . ' 100', 'order' => 'session,questionnumber', 'group' => 'session'));
         $total = $questions->count();
         foreach ($questions as $question) {
             $sessionArray[] = '"' . $question->session . '"';
             $sessions[$question->session] = $question->tstamp;
         }
         $surveyQuestions = Questions::find(array('conditions' => 'session IN (' . implode(',', $sessionArray) . ')', 'order' => 'session,questionnumber'));
         $surveyQuestionsArr = array();
         foreach ($surveyQuestions as $surveyQuestion) {
             $surveyQuestionsArr[$surveyQuestion->session][$surveyQuestion->questionnumber]['message'] = $surveyQuestion->message;
             $surveyQuestionsArr[$surveyQuestion->session][$surveyQuestion->questionnumber]['uid'] = $surveyQuestion->uid;
         }
         foreach ($surveyQuestionsArr as $sessionId => $questions) {
             foreach ($qnumberArray as $key => $qnumber) {
                 $messages[$sessionId][$key] = isset($questions[$qnumber]) ? $questions[$qnumber]['message'] : '';
             }
             foreach ($questions as $qnumber => $qData) {
                 $qAnswers = Items::find(array('conditions' => 'pid = ?1', 'bind' => array(1 => $qData['uid'])));
                 $answerItemsArray = array();
                 foreach ($qAnswers as $answerItem) {
                     if ($answerItem->mode < 3) {
                         $answerItemsArray[$answerItem->itemnumber] = $answerItem;
                     } else {
                         $answerItemsArray['other'][] = $answerItem;
                     }
                 }
                 $qAnswersArr[$sessionId][$qnumber] = $answerItemsArray;
             }
         }
     }
     $this->view->setVar('total', $total);
     $this->view->setVar('sessions', $sessions);
     $this->view->setVar('messages', $messages);
     $this->view->setVar('qanswers', $qAnswersArr);
     $this->view->setVar('mitarbeiterbefragung', $mitarbeiterbefragung);
 }