/**
  * Connects to DB and inserts the user response.
  * @param $response (array) data we'll be saving to the response table
  * @return builds and returns a response message
  */
 protected function increase_mc_option_responses($mc_option_id)
 {
     // connect to PDO
     $pdo = new enp_quiz_Db();
     // Get our Parameters ready
     $params = array(':mc_option_id' => $mc_option_id);
     // write our SQL statement
     // write our SQL statement
     $sql = "UPDATE " . $pdo->question_mc_option_table . "\n                   SET  mc_option_responses = mc_option_responses + 1\n                 WHERE  mc_option_id = :mc_option_id";
     // update the question view the database
     $stmt = $pdo->query($sql, $params);
     // success!
     if ($stmt !== false) {
         // set-up our response array
         $return = array('mc_option_id' => $mc_option_id, 'status' => 'success', 'action' => 'increase_mc_option_responses');
         // merge the response arrays
         self::$return = array_merge($return, self::$return);
         // see what type of question we're working on and save that response
     } else {
         // handle errors
         self::$return['error'][] = 'Increase MC Option Responses failed.';
     }
     // return response
     return self::$return;
 }
 public function update_response_question($response)
 {
     /*
             * It's already been validated by Enp_quiz_Save_quiz_take()
             $valid = $this->validate_response_data($response);
             if($valid !== true) {
                 //response is invalid
                 $return['error'] = 'Invalid response.';
                 return $return;
             }*/
     $response = $this->setup_response_save_data($response);
     // we have a valid response, so let's see if it's correct or not
     $response['response_correct'] = $this->is_response_correct($response);
     // Select the response we need to update
     $response_question_id = $this->get_response_question_id($response);
     // Get our Parameters ready
     $params = array(':response_question_id' => $response_question_id, ':question_responded' => '1', ':response_correct' => $response['response_correct'], ':response_question_updated_at' => $response['response_quiz_updated_at']);
     // connect to PDO
     $pdo = new enp_quiz_Db();
     // write our SQL statement
     $sql = "UPDATE " . $pdo->response_question_table . "\n                   SET  question_responded = :question_responded,\n                        response_correct = :response_correct,\n                        response_question_updated_at = :response_question_updated_at\n                 WHERE  response_question_id = :response_question_id";
     // insert the mc_option into the database
     $stmt = $pdo->query($sql, $params);
     // success!
     if ($stmt !== false) {
         // set-up our response array
         $return = array('response_question_id' => $response_question_id, 'status' => 'success', 'action' => 'update');
         // merge the response arrays
         $return = array_merge($response, $return);
         // see what type of question we're working on and save that response
         if ($response['question_type'] === 'mc') {
             // save the mc option response
             $response_mc = new Enp_quiz_Save_quiz_take_Response_MC();
             $return_mc_response = $response_mc->insert_response_mc($return);
             // increase the count on the mc option responses
             $response_mc->increase_mc_option_responses($response['question_response']);
             // merge the response arrays
             $return = array_merge($return, $return_mc_response);
         } elseif ($response['question_type'] === 'slider') {
             // TODO: Build slider save response
             $response_slider = new Enp_quiz_Save_quiz_take_Response_Slider();
             $return_slider_response = $response_slider->insert_response_slider($return);
             // merge the response arrays
             $return = array_merge($return, $return_slider_response);
         }
         // update question response data
         $this->update_question_response_data($response);
     } else {
         // handle errors
         $return['error'] = 'Save response failed.';
     }
     // return response
     return $return;
 }