예제 #1
0
 public function api_entry_pickup()
 {
     $len = $this->Mdl_Dailywords->get_length();
     if ($len == 0) {
         parent::returnWithErr("No Daily words to pick at this time.");
     }
     $list = $this->Mdl_Dailywords->getAll();
     parent::returnWithoutErr("DWords has been created successfully.", $list[rand(0, $len - 1)]);
 }
예제 #2
0
 public function api_entry_remove()
 {
     parent::validateParams(array("noti"));
     if (!$this->Mdl_Notifications->get($_POST["noti"])) {
         parent::returnWithErr("Invalid notification.");
     }
     $this->Mdl_Notifications->remove($_POST["noti"]);
     return parent::returnWithoutErr("Notification is deleted successfully.");
 }
예제 #3
0
 public function api_entry_remove_user()
 {
     parent::validateParams(array("group", "user"));
     $this->load->model("Mdl_Users");
     $this->load->model("Mdl_Groups");
     if ($this->Mdl_Users->get($_POST["user"]) == null) {
         parent::returnWithErr("User id is not valid.");
     }
     if ($this->Mdl_Groups->get($_POST["group"]) == null) {
         parent::returnWithErr("Group id is not valid.");
     }
     if ($group = $this->Mdl_Groups->removeUser($_POST["group"], $_POST["user"]) == null) {
         parent::returnWithErr($this->Mdl_Groups->latestErr);
     }
     parent::returnWithoutErr("User has been removed successfully.", $group);
 }
예제 #4
0
 public function api_entry_list()
 {
     parent::validateParams(array("type", "user"));
     $this->load->model("Mdl_Requests");
     $this->load->model("Mdl_Users");
     if ($this->Mdl_Users->get($_POST["user"]) == null) {
         parent::returnWithErr("User id is not valid.");
     }
     $prays = $this->Mdl_Prays->getAll();
     $requests = array();
     foreach ($prays as $key => $val) {
         $request = $this->Mdl_Requests->get($val->request);
         $prayer = $this->Mdl_Users->get($val->prayer);
         unset($prayer->password);
         $request->host = $this->Mdl_Users->get($request->host);
         unset($request->host->password);
         $request->pray_time = $val->updated_time;
         $request->status = $val->status;
         $request->prayer = $prayer;
         if ($_POST["type"] == "ipray_praying_for_me") {
             if ($_POST["user"] == $request->host->id) {
                 array_push($requests, $request);
             }
         } else {
             if ($_POST["type"] == "ipray_i_am_praying_for") {
                 if ($_POST["user"] == $val->prayer) {
                     array_push($requests, $request);
                 }
             } else {
                 if ($_POST["type"] == "ipray_request_attended") {
                     if ($_POST["user"] == $request->host && $val->status == 1) {
                         array_push($requests, $request);
                     }
                 } else {
                     parent::returnWithErr("Unknown type.");
                 }
             }
         }
     }
     parent::returnWithoutErr("Successfully fetched.", $requests);
 }
예제 #5
0
 public function api_entry_pray()
 {
     parent::validateParams(array('prayer', 'subject', 'request'));
     $this->load->model('Mdl_Requests');
     $this->load->model('Mdl_Prays');
     if (!($prayer = $this->Mdl_Users->get($_POST['prayer']))) {
         parent::returnWithErr("Prayer is not valid");
     }
     if (!($request = $this->Mdl_Requests->get($_POST['request']))) {
         parent::returnWithErr("Request id is not valid");
     }
     if (!($host = $this->Mdl_Users->get($request->host))) {
         parent::returnWithErr("Unknown request host.");
     }
     if ($request->type != "REQ_COMMON") {
         parent::returnWithErr("Invalid request type. " . $request->type);
     }
     unset($prayer->password);
     unset($host->password);
     if ($host->id == $prayer->id) {
         parent::returnWithErr("You can't pray for yourself.");
     }
     if ($_POST['subject'] == 'ipray_sendprayrequest') {
         $msg = $prayer->username . " would like to pray for you.";
         $sender = $prayer;
         $receiver = $host;
         $status = 0;
     } else {
         if ($_POST['subject'] == 'ipray_answerprayrequest') {
             $msg = $host->username . " accepted your pray request.";
             $sender = $host;
             $receiver = $prayer;
             $status = 1;
         } else {
             parent::returnWithErr("Unknown subject is requested.");
         }
     }
     if ($receiver->devicetoken == "" || !isset($receiver->devicetoken)) {
         parent::returnWithErr("User didn't subscribe.");
     }
     $pray = $this->Mdl_Prays->create(array('request' => $request->id, 'prayer' => $prayer->id, 'status' => $status));
     $this->load->model('Mdl_Notifications');
     $noti = $this->Mdl_Notifications->create(array('subject' => $_POST['subject'], 'message' => $msg, 'sender' => $sender->id, 'receiver' => $receiver->id, 'meta' => json_encode(array('request' => $request))));
     $payload = array('sound' => "default", 'subject' => $_POST['subject'], 'alert' => $msg, 'sender' => $sender, 'receiver' => $receiver, 'request' => $request, 'pray_id' => $pray['id'], 'id' => $noti['id'], 'meta' => json_encode(array('request' => $request)));
     if (($failedCnt = $this->qbhelper->sendPN($receiver->devicetoken, json_encode($payload))) == 0) {
         parent::returnWithoutErr("Contact request has been sent successfully.");
     } else {
         parent::returnWithErr($failedCnt . " requests have not been sent.");
     }
 }
예제 #6
0
 public function api_entry_share()
 {
     parent::validateParams(array("request", "user"));
     $this->load->model("Mdl_Users");
     $this->load->model("Mdl_Requests");
     if (!$this->Mdl_Users->get($_POST['user'])) {
         parent::returnWithErr("User id is not valid.");
     }
     if (!$this->Mdl_Requests->get($_POST['request'])) {
         parent::returnWithErr("Request id is not valid.");
     }
     if (($request = $this->Mdl_Requests->share(array('request' => $_POST['request'], 'user' => $_POST['user']))) == null) {
         parent::returnWithErr($this->Mdl_Requests->latestErr);
     }
     parent::returnWithoutErr("User sharing is recorded successfully.", $request);
 }