Beispiel #1
0
 /**
  * This endpoint update an interview. It return the new interview if success. If some parameters is missing it will return a BadRequest.
  * @param $id string the ID of the interview to update
  * @param $param string[]
  * @throws InvalidRequestError
  * @return Interview
  */
 public static function update($id, $param)
 {
     if (!isset($param["name"]) || !isset($param["questions"]) || !isset($param["video"]) || !isset($param["text"])) {
         $missing = array();
         !isset($param["name"]) ? $missing[] = "name" : null;
         !isset($param["questions"]) ? $missing[] = "questions" : null;
         !isset($param["video"]) ? $missing[] = "video" : null;
         !isset($param["text"]) ? $missing[] = "text" : null;
         throw new InvalidRequestError("missing param: " . implode($missing, ", "));
     } else {
         if (!is_array($param["questions"]) || count($param["questions"]) == 0) {
             throw new InvalidRequestError("wrong param questions");
         }
     }
     foreach ($param["questions"] as $questions) {
         if (!isset($questions["content"]) || !isset($questions["readingTime"]) || !isset($questions["answerTime"]) || !isset($questions["number"])) {
             $missing = array();
             !isset($param["content"]) ? $missing[] = "content" : null;
             !isset($param["readingTime"]) ? $missing[] = "readingTime" : null;
             !isset($param["answerTime"]) ? $missing[] = "answerTime" : null;
             !isset($param["number"]) ? $missing[] = "number" : null;
             throw new InvalidRequestError("missing param: " . implode($missing, ", "));
         } else {
             if (!in_array($questions["readingTime"], Interview::$acceptedValue) || !in_array($questions["answerTime"], Interview::$acceptedValue)) {
                 throw new InvalidRequestError("invalid duration of readingTime or answerTime");
             }
         }
     }
     $itw = ApiRequest::put("/api/v1/interview/" . $id, $param);
     $questions = array();
     foreach ($itw["questions"] as $q) {
         $questions[] = new Question($q["content"], $q["readingTime"], $q["answerTime"], $q["number"]);
     }
     return new Interview($itw["_id"], $itw["name"], $questions, $itw["video"], $itw["text"], $itw["callback"], $itw["sent"], $itw["answers"], $itw["new"]);
 }
Beispiel #2
0
 public function testPutRequest()
 {
     $this->assertNotNull(ApiRequestTest::$interviewId);
     $array = ["name" => "interview 1", "questions" => [["content" => "question 1 - Updated", "readingTime" => 60, "answerTime" => 60, "number" => 1]], "video" => "", "text" => ""];
     $res = ApiRequest::put("/api/v1/interview/" . ApiRequestTest::$interviewId, $array);
     $this->assertTrue(is_array($res));
 }