コード例 #1
0
ファイル: FormsController.php プロジェクト: 3AD/Survey
 protected function _checkCondition($condition)
 {
     // check if condition is fulfilled
     $returnArray = array();
     if (!isset($this->_formResponse['data'][$condition["field"]]) || empty($this->_formResponse['data'][$condition["field"]])) {
         $returnArray[] = false;
     } else {
         // check type of required value for condition and check if condition is fulfilled
         if (is_array($condition["value"])) {
             if (is_array($condition["value"]["value"])) {
                 foreach ($condition["value"]["value"] as $value) {
                     if (is_array($this->_formResponse['data'][$condition["field"]])) {
                         foreach ($this->_formResponse['data'][$condition["field"]] as $response) {
                             $returnArray[] = in_array($response, $condition["value"]["value"]);
                         }
                     } elseif (is_string($this->_formResponse['data'][$condition["field"]])) {
                         $returnArray[] = in_array($value, $this->_formResponse['data'][$condition["field"]]);
                     }
                 }
             } elseif (is_string($condition["value"]["value"])) {
                 if (is_array($this->_formResponse['data'][$condition["field"]])) {
                     $returnArray[] = in_array($condition["value"]["value"], $this->_formResponse['data'][$condition["field"]]);
                 } elseif (is_string($this->_formResponse['data'][$condition["field"]])) {
                     $returnArray[] = $condition["value"]["value"] == $this->_formResponse['data'][$condition["field"]] ? true : false;
                 }
             }
             // check type of required value for condition and check if condition is fulfilled
         } elseif (is_string($condition["value"])) {
             if (is_array($this->_formResponse['data'][$condition["field"]])) {
                 $returnArray[] = in_array($condition["value"], $this->_formResponse['data'][$condition["field"]]);
             } elseif (is_string($this->_formResponse['data'][$condition["field"]])) {
                 $returnArray[] = in_array($value, $this->_formResponse['data'][$condition["field"]]);
                 $type = $this->_getFieldType($condition["field"]);
                 switch ($type) {
                     case "textfield":
                     case "textareafield":
                         $returnArray[] = strtolower($condition["value"]) == strtolower($this->_formResponse['data'][$condition["field"]]) ? true : false;
                         break;
                     case "datefield":
                         $returnArray[] = $condition["value"] == Manager::getService('Date')->convertToTimeStamp($this->_formResponse['data'][$condition["field"]]) ? true : false;
                         break;
                     case "timefield":
                         $returnArray[] = Manager::getService('Date')->convertToTimeStamp($condition["value"]) == Manager::getService('Date')->convertToTimeStamp($this->_formResponse['data'][$condition["field"]]) ? true : false;
                         break;
                     case "numberfield":
                         $returnArray[] = intval($condition["value"]) == intval($this->_formResponse['data'][$condition["field"]]) ? true : false;
                         break;
                 }
             }
         }
     }
     return $returnArray;
 }
コード例 #2
0
ファイル: FormsController.php プロジェクト: 3AD/Survey
 /**
  * @todo convert to ZF2
  * @throws \Rubedo\Exceptions\User
  */
 public function getCsvAction()
 {
     $formId = $this->params()->fromQuery('form-id');
     if (!$formId) {
         throw new \Rubedo\Exceptions\User('This action needs a form id as argument.', "Exception11");
     }
     $form = Manager::getService('Forms')->findById($formId);
     $displayQnb = $this->params()->fromPost('display-qnb', false);
     $fileTitle = "export";
     $fileName = $fileTitle . '_' . $formId . '_' . date('Ymd') . '.csv';
     $filePath = sys_get_temp_dir() . '/' . $fileName;
     $csvResource = fopen($filePath, 'w+');
     $fieldsArray = array();
     $headerArray = array('Date', 'Terminé');
     $definiedAnswersArray = array();
     foreach ($form['formPages'] as $page) {
         foreach ($page['elements'] as $element) {
             switch ($element['itemConfig']['fType']) {
                 case 'multiChoiceQuestion':
                     if ($element['itemConfig']['fieldType'] == 'checkboxgroup') {
                         $tempSubField = array();
                         foreach ($element['itemConfig']['fieldConfig']['items'] as $item) {
                             $headerArray[] = $element['itemConfig']["qNb"] . ' - ' . $item['boxLabel'];
                             $tempSubField[] = $item['inputValue'];
                             $definiedAnswersArray[$item['inputValue']] = $item['boxLabel'];
                         }
                         $fieldsArray[] = array('type' => 'qcm', 'value' => array('id' => $element['id'], 'items' => $tempSubField));
                         break;
                     } else {
                         $headerArray[] = $element['itemConfig']["qNb"];
                         $fieldsArray[] = array('type' => 'simple', 'value' => $element['id']);
                         foreach ($element['itemConfig']['fieldConfig']['items'] as $item) {
                             $definiedAnswersArray[$item['inputValue']] = $item['boxLabel'];
                         }
                         break;
                     }
                 case 'openQuestion':
                     $headerArray[] = $element['itemConfig']["qNb"];
                     $fieldsArray[] = array('type' => 'open', 'value' => $element['id']);
                     break;
                 case 'predefinedPrefsQuestion':
                     for ($i = 1; $i <= $element['itemConfig']['numberOfQuestions']; $i++) {
                         $headerArray[] = $element['itemConfig']["qNb"] . " - question " . $i . " - ligne du plan d'expérience";
                         $fieldsArray[] = array('type' => 'add1', 'value' => $element['id'] . "question" . $i . "expPlanRow");
                         for ($j = 1; $j <= $element['itemConfig']['numberOfChoices']; $j++) {
                             $headerArray[] = $element['itemConfig']["qNb"] . " - question " . $i . " - choix " . $j;
                             $fieldsArray[] = array('type' => 'open', 'value' => $element['id'] . "question" . $i . "choice" . $j);
                         }
                     }
                     break;
                 default:
                     break;
             }
         }
     }
     $list = Manager::getService('FormsResponses')->getResponsesByFormId($formId);
     fputcsv($csvResource, $headerArray, ';');
     foreach ($list['data'] as $response) {
         $csvLine = array(Manager::getService('Date')->getDefaultDatetime($response['lastUpdateTime']), $response['status'] == 'finished' ? 'oui' : 'non');
         foreach ($fieldsArray as $element) {
             switch ($element['type']) {
                 case 'open':
                     $csvLine[] = isset($response['data'][$element['value']]) ? $response['data'][$element['value']] : null;
                     break;
                 case 'add1':
                     $csvLine[] = isset($response['data'][$element['value']]) ? $response['data'][$element['value']] + 1 : null;
                     break;
                 case 'simple':
                     if (isset($response['data'][$element['value']]) && is_array($response['data'][$element['value']])) {
                         $result = array_pop($response['data'][$element['value']]);
                         $csvLine[] = $definiedAnswersArray[$result];
                     } else {
                         $csvLine[] = null;
                     }
                     break;
                 case 'qcm':
                     foreach ($element['value']['items'] as $item) {
                         if (isset($response['data'][$element['value']['id']])) {
                             $csvLine[] = in_array($item, $response['data'][$element['value']['id']]);
                         } else {
                             $csvLine[] = null;
                         }
                     }
                     break;
                 default:
                     break;
             }
         }
         fputcsv($csvResource, $csvLine, ';');
     }
     $content = file_get_contents($filePath);
     $response = $this->getResponse();
     $headers = $response->getHeaders();
     $headers->addHeaderLine('Content-Type', 'text/csv');
     $headers->addHeaderLine('Content-Disposition', "attachment; filename=\"{$fileName}\"");
     $headers->addHeaderLine('Accept-Ranges', 'bytes');
     $headers->addHeaderLine('Content-Length', strlen($content));
     $response->setContent(utf8_decode($content));
     return $response;
 }