public function store()
 {
     $content = file_get_contents('php://input');
     $check_input = $this->validateInput($content);
     if (!$check_input[0]) {
         return $check_input[1];
     }
     $users = GCMUser::where('activated', '=', 1)->get();
     if ($users->count() < 1) {
         return $this->getOutput(200);
     }
     $this->init($this->data);
     $ret_add = $this->notification->addMessageToDB($this->message);
     if (!$ret_add[0]) {
         return $this->getOutput($ret_add[1]);
     }
     $this->message_id = $ret_add[1];
     $message_arr = array("message" => $this->message);
     $ret = $this->notification->sendNotification($this->message_id, $message_arr, $users);
     if ($ret != 101) {
         $del = $this->notification->deleteMessage($this->message_id);
         if (!$del) {
             return $this->getOutput(-100);
         }
     }
     return $this->getOutput($ret);
 }
 public function checkExistsByEmail($email, $id = 0)
 {
     if ($id != 0) {
         //update
         $count = GCMUser::where('email', '=', $email)->where('id', '<>', $id)->count();
     } else {
         //add
         $count = GCMUser::where('email', '=', $email)->count();
     }
     if ($count > 0) {
         return true;
     }
     return false;
 }
 public function destroy()
 {
     $content = file_get_contents('php://input');
     $this->validate_array = array('gcm_regid');
     $check_input = $this->validateInput($content);
     if (!$check_input[0]) {
         return $check_input[1];
     }
     $this->init2($this->data);
     $check_exist = $this->user_obj->checkUserExistByRegID($this->gcm_regid);
     if (!$check_exist) {
         return $this->getOutput(-201);
         //no user exists with this reg_id
     }
     try {
         GCMUser::where('gcm_regid', '=', $this->gcm_regid)->delete();
         return $this->getOutput(102);
     } catch (Exception $e) {
         return $this->getOutput(-106);
     }
 }
 public function postDelete()
 {
     $id = Input::get('id');
     $validator = Validator::make(array('id' => $id), $this->validate_id_arr);
     if ($validator->fails()) {
         //            return Redirect::to('gcm-users')
         //                            ->with('msg', 'Invalid ID')
         //                            ->with('state', '-1');
         return json_encode(array(false, "Invalid ID"));
     }
     $user = GCMUser::find($id);
     if (!$user) {
         return json_encode(array(false, "User isn't found"));
     }
     try {
         $user->delete();
         //            return Redirect::to('gcm-users')
         //                            ->with('msg', 'User deleted successfully');
         return json_encode(array(true, "User deleted successfully"));
     } catch (Exception $e) {
         //            return Redirect::to('gcm-users')
         //                            ->with('msg', 'Can\'t delete User')
         //                            ->with('state', '-1');
         return json_encode(array(false, "Can\\'t delete User"));
     }
 }
 public function init()
 {
     $this->send_option = Input::get('sendOption');
     if ($this->send_option == 1) {
         //all
         $this->users = GCMUser::where('activated', '=', 1)->get();
         $this->not_active_users_count = GCMUser::where('activated', '=', 0)->count();
         if ($this->users) {
             $this->count = $this->users->count();
         } else {
             $this->count = 0;
         }
     } elseif ($this->send_option == 2) {
         //user
         $id = Input::get('users');
         $this->users = array(GCMUser::find($id));
         if (GCMUser::find($id)) {
             $this->count = 1;
         } else {
             $this->count = 0;
         }
     }
 }