Exemplo n.º 1
0
 function user_post()
 {
     $user_id = $this->uri->segment(3);
     $this->load->model("Model_internal_users");
     // $users = array(
     //   1 => array("first_name" => "constant_ilyas", "last_name" => "constant_abdighni"),
     //   2 => array("first_name" => "constant_gvlmerem", "last_name" => "constant_mutellip"),
     // );
     $user = $this->Model_internal_users->get_by(array("idInternalUser" => $user_id));
     if (isset($user["idInternalUser"])) {
         $this->load->library("form_validation");
         $data = remove_unknown_fields($this->post(), $this->form_validation->get_field_names("user_post"));
         $this->form_validation->set_data($data);
         //$this->form_validation->set_message("is_unique[internaluser.InternalUserEmail]", "This email is already exist!");
         if ($this->form_validation->run("user_post") != false) {
             $this->load->model("Model_internal_users");
             // validate email address if it exists
             // $safe_email_address = !isset($data["InternalUserEmail"]) || $data["InternalUserEmail"] == $user["InternalUserEmail"] || !$this->Model_internal_users->get_by(array("InternalUserEmail" => $data["InternalUserEmail"]));
             // if (!$safe_email_address) {
             //   $this->response( array("status" => "failed", "message" => "This email address is already in use."), REST_Controller::HTTP_INTERNAL_SERVER_ERROR );
             // }
             // insert the post data to the database
             $updated = $this->Model_internal_users->update($user_id, $data);
             if (!$updated) {
                 $this->response(array("status" => "failed", "message" => "An ucexpected error uccred when updating to the database."), REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
             } else {
                 $this->response(array("status" => "success", "message" => "successfully updated to the database"), REST_Controller::HTTP_OK);
             }
         } else {
             $this->response(array("status" => "failed", "message" => $this->form_validation->get_errors_as_array()), REST_Controller::HTTP_BAD_REQUEST);
         }
     } else {
         $this->response(array("status" => "failed", "message" => "The specified user could not be found."), REST_Controller::HTTP_NOT_FOUND);
     }
 }
Exemplo n.º 2
0
 function student_post()
 {
     $student_id = $this->uri->segment(3);
     $this->load->model('Model_students');
     $student = $this->Model_students->get_by(array('student_id' => $student_id, 'status' => 'active'));
     if (isset($student['student_id'])) {
         $this->load->library('form_validation');
         $data = remove_unknown_fields($this->post(), $this->form_validation->get_field_names('student_post'));
         $this->form_validation->set_data($data);
         if ($this->form_validation->run('student_post') != false) {
             $this->load->model('Model_students');
             $safe_email = !isset($data['email_address']) || $data['email_address'] == $student['email_address'] || $this->Model_students->get_by(array('email_address' => $data['email_address']));
             if (!$safe_email) {
                 $this->response(array('status' => 'failure', 'message' => 'The specified email address is already in use !'), REST_Controller::HTTP_NOT_FOUND);
             }
             $updated = $this->Model_students->update($student_id, $data);
             if (!$updated) {
                 $this->response(array('status' => 'failure', 'message' => 'An unexpected error occurred on db !'), REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
             } else {
                 $this->response(array('status' => 'success', 'message' => 'Updated'));
             }
         } else {
             $this->response(array('status' => 'failure', 'message' => $this->form_validation->get_errors_as_array()), REST_Controller::HTTP_NOT_FOUND);
         }
     } else {
         $this->response(array('status' => 'failure', 'message' => 'The specified student could not be found !'), REST_Controller::HTTP_CONFLICT);
     }
 }
Exemplo n.º 3
0
 function patient_post()
 {
     $id = $this->uri->segment(3);
     //refers to the third segment ie, third one after the servername on the url: http://localhost/API1/api/student/1
     $this->load->model('model_demographics');
     $patient = $this->model_demographics->get_by(array('id' => $id));
     if (isset($patient['id'])) {
         $this->load->library('form_validation');
         $data = remove_unknown_fields($this->post(), $this->form_validation->get_field_names('patient_post'));
         $this->form_validation->set_data($data);
         if ($this->form_validation->run('patient_post') != false) {
             $this->load->model('model_demographics');
             $safe_name = !isset($data['first_name']) || $data['first_name'] == $patient['first_name'] || !$this->model_demographics->get_by(array('first_name' => $data['first_name']));
             if (!$safe_name) {
                 $this->response(array('Status' => 'Failure', 'message' => 'name already in use'), REST_Controller::HTTP_CONFLICT);
             }
             $updated = $this->model_demographics->update($id, $data);
             if (!$updated) {
                 $this->response(array('Status' => 'Failure', 'message' => 'Patient not updated'), REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
             } else {
                 $this->response(array('Status' => 'Success', 'message' => 'Patient updated'));
             }
         } else {
             $this->response(array('Status' => 'Failure', 'message' => $this->form_validation->get_errors_as_array()), REST_Controller::HTTP_BAD_REQUEST);
         }
     } else {
         $this->response(array('Status' => 'Failure', 'message' => 'Patient not found'), 404);
     }
 }
Exemplo n.º 4
0
 function product_post()
 {
     $PRODUCT_ID = $this->uri->segment(3);
     $this->load->model('model_products');
     $product = $this->model_products->get_by(array('PRODUCT_ID' => $PRODUCT_ID, 'status' => 'active'));
     if (isset($product['PRODUCT_ID'])) {
         $this->load->library('form_validation');
         $data = remove_unknown_fields($this->post(), $this->form_validation->get_field_names('product_post'));
         $this->form_validation->set_data($data);
         if ($this->form_validation->run('product_post') != false) {
             $this->load->model('model_Products');
             //$product = $this->put();
             $updated = $this->model_Products->update($PRODUCT_ID, $data);
             if (!$updated) {
                 $this->response(array('status' => 'failure', 'message' => 'An unexcepted erroRS occured while trying to update the product'), REST_CONTROLLER::HTTP_INTERNAL_SERVER_ERROR);
             } else {
                 $this->response(array('status' => 'success', 'message' => 'updated'));
             }
         }
     } else {
         $this->response(array('status' => 'failure', 'message' => 'product not found'));
     }
 }