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 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;
         }
     }
 }