public function register()
 {
     $message = "";
     $status = false;
     $code = '';
     $data = array();
     if ($this->request->is('post')) {
         $this->User->create();
         $data = array('username' => $this->data['username'], 'password' => $this->data['password'], 'role_id' => $this->data['role_id'], 'school_id' => $this->data['school_id'], 'level_id' => $this->data['level_id'], 'first_name' => $this->data['first_name'], 'father_name' => $this->data['father_name'], 'grandfather_name' => $this->data['grandfather_name'], 'family_name' => $this->data['family_name'], 'address' => $this->data['address'], 'phone_number' => $this->data['phone_number'], 'mobile_number' => $this->data['mobile_number'], 'email' => $this->data['email'], 'nationality_id' => $this->data['nationality_id']);
         if ($this->User->save($data)) {
             $status = true;
             $code = '203';
         } else {
             $code = '406';
         }
     }
     $this->response->type('json');
     $json_body = json_encode(array("message" => AppController::getReturnedMessage($code), "status" => $status, "code" => $code));
     $this->response->body($json_body);
 }
 public function subjectDetails($id)
 {
     $message = "";
     $status = false;
     $code = '';
     $json_subject = array();
     $this->render(false);
     if (!$id) {
         $code = '404';
     } else {
         $subject = $this->Subject->findById($id);
         if (!$subject) {
             $code = '404';
         } else {
             $json_subject = $subject['Subject'];
             $code = "200";
             $status = true;
         }
     }
     $this->response->type('json');
     $json_body = json_encode(array("comments" => $json_subject, "message" => AppController::getReturnedMessage($code), "status" => $status, "code" => $code));
     $this->response->body($json_body);
 }
 public function editComment()
 {
     $message = "";
     $status = false;
     $code = '';
     $this->render(false);
     if ($this->request->is('get')) {
         throw new MethodNotAllowedException();
     }
     $id = $this->data['id'];
     $user_id = $this->data['user_id'];
     $data = array('id' => $this->data['id'], 'user_id' => $this->data['user_id'], 'subject_id' => $this->data['subject_id'], 'body' => $this->data['body']);
     if ($this->Comment->isOwendBy($id, $user_id)) {
         if ($this->Comment->save($data)) {
             $status = true;
             $code = '200';
         } else {
             $code = '409';
         }
     } else {
         $code = '408';
     }
     $this->response->type('json');
     $json_body = json_encode(array("message" => AppController::getReturnedMessage($code), "status" => $status, "code" => $code));
     $this->response->body($json_body);
 }