예제 #1
0
 /**
  * Validate that an expert's text is a response to an enthusiast photo.
  *
  * @param IncomingTextObject $incomingText
  * @return array
  */
 private function validateText(IncomingTextObject $incomingText)
 {
     // break text into parts
     $text = explode(' ', $incomingText->getBody());
     // check if first string is an integer and an enthusiast user id
     if (!is_numeric($text[0])) {
         // not an integer
         return ['valid' => FALSE, 'message' => "Please respond in the format: \"12345 Yes\", where 12345 is the number you received with the photo."];
     } elseif (!($submission = $this->submissionModel->find($text[0]))) {
         // submission not found from integer provided
         return ['valid' => FALSE, 'message' => "We couldn't find that photo reference number!"];
     }
     // validate second part of text
     if (strtolower($text[1]) !== 'yes' and strtolower($text[1]) !== 'no') {
         return ['valid' => FALSE, 'message' => "Please respond in the format: \"12345 Yes\" or \"12345 No\", where 12345 is the number you received with the photo."];
     }
     return ['valid' => TRUE, 'submission' => $submission, 'answer' => strtolower($text[1])];
 }