示例#1
0
 public function get_validate($apiKey = null)
 {
     $apiCheck = \Crm\Portal\Portal_Check::api_key($apiKey);
     if ($apiCheck === false) {
         $this->response(array('status' => 'FAIL', 'message' => 'Invalid API Key has been used, please contact your IT support!'));
     } else {
         $allFields = TRUE;
         $missingFields = array();
         $surveyChoice = $apiCheck->survey;
         $surveyQuestions = \Model_Survey_Question::query()->where('survey_id', $surveyChoice)->where('required', '1')->get();
         $allSurveyQuestions = \Model_Survey_Question::query()->where('survey_id', $surveyChoice)->get();
         foreach ($surveyQuestions as $surveyRequired) {
             $requiredFields[] = 'form-q' . $surveyRequired->id;
         }
         foreach ($allSurveyQuestions as $surveyQuestions) {
             $questionFields[] = 'form-q' . $surveyQuestions->id;
         }
         // Check and make a list of any missing fields
         foreach ($requiredFields as $field) {
             if (is_null(Input::get($field, null)) || strlen(Input::get($field, null)) < 1 && !is_integer(Input::get($field, null)) || Input::get($field, null) == "-- Select") {
                 $allFields = FALSE;
                 $missingFields[] = $field;
             }
         }
         // If we have everything we need then we do our logic
         if ($allFields) {
             // Get the client type from the given questions
             $questionPassOn = array();
             foreach ($questionFields as $singleQuestion) {
                 $questionPassOn[$singleQuestion] = Input::get($singleQuestion, null);
                 $questionPassOn[str_replace('form-q', 'form-e', $singleQuestion)] = Input::get(str_replace('form-q', 'form-e', $singleQuestion), null);
             }
             \log::write('PPI-DEBUG', \Format::forge($_GET)->to_json());
             $clientType = \Crm\Portal\Portal_Check::choice($questionPassOn, $_GET, $apiKey);
             // If we can decide on a client type
             if (!is_null($clientType)) {
                 $this->response(array('client_type' => $clientType));
             } else {
                 $this->response(array('status' => 'FAIL', 'message' => 'No client type could be decided. Please complete ALL the given questions.'));
             }
         } else {
             $this->response(array('status' => 'FAIL', 'code' => '101', 'message' => 'Not all required fields were submitted! Missing fields are ' . implode(", ", $missingFields), 'missing_fields' => $missingFields));
         }
     }
 }