Exemplo n.º 1
0
 public function end_post()
 {
     //checkIsLoggedIn($this);
     $status = 200;
     $return["result"] = "OK";
     $datestring = "%Y/%m/%d %H:%i:%s";
     $currentDate = mdate($datestring, now());
     $arrOptions['userFromId'] = $this->post('userFromId');
     $arrOptions['userToId'] = $this->post('userToId');
     $arrOptions['publicationId'] = $this->post('publicationId');
     $arrOptions['publicationType'] = $this->post('publicationType');
     $arrOptions['objectId'] = $this->post('objectId');
     $arrOptions['comments'] = $this->post('comments');
     $arrOptions['quantity'] = $this->post('quantity');
     $processState = $arrOptions['publicationType'] == "money" ? "F" : "W";
     try {
         $donation = new CI_Donation();
         $donation->setUserId($arrOptions['userFromId']);
         $donation->setPublicationId($arrOptions['publicationId']);
         $donation->setDonationDate($currentDate);
         $donation->setProcessState($processState);
         $donationId = $donation->save();
         if ($donationId) {
             $donatedObject = new CI_DonatedObject();
             $donatedObject->setDonationId($donationId);
             $donatedObject->setObjectId($arrOptions['objectId']);
             $donatedObject->setQuantity($arrOptions['quantity']);
             $donatedObjectId = $donatedObject->save();
             $message = new CI_Message();
             $message->setUserFrom($arrOptions['userFromId']);
             $message->setUserTo($arrOptions['userToId']);
             $message->setPublication($arrOptions['publicationId']);
             $message->setText($arrOptions['comments']);
             $message->save();
         }
     } catch (Exception $ex) {
         $status = 500;
         $return["result"] = "NOOK";
     }
     if ($status == 200) {
         if ($arrOptions['publicationType'] == "money") {
             $request = CI_Request::getById($arrOptions['publicationId'])[0];
             $amountCollected = $request->amountCollected[0]->quan;
             $quantityGoal = $request->quantity;
             if ($amountCollected >= $quantityGoal) {
                 CI_Publication::pause($arrOptions['publicationId']);
             }
             $return["data"]['amountCollected'] = $amountCollected;
             $return["data"]['quantityGoal'] = $quantityGoal;
         } else {
             CI_Publication::pause($arrOptions['publicationId']);
         }
     }
     $this->response($return, $status);
 }
Exemplo n.º 2
0
 public function quantity_get()
 {
     $status = 404;
     $return["data"] = "";
     $return["result"] = "NOOK";
     $userId = $this->get("userId");
     $quantity = CI_Message::getQuantityUnreadMessages($userId);
     if (isset($quantity)) {
         $status = 200;
         $return["data"] = $quantity;
         $return["result"] = "OK";
     }
     $this->response($return, $status);
 }
Exemplo n.º 3
0
 public function notify_post()
 {
     $status = 404;
     $return['result'] = 'NOOK';
     $return['data'] = '';
     $id = $this->input->post('id');
     $donations = CI_Donation::getById($id);
     if (empty($donations)) {
         $this->response($return, $status);
     }
     $donation = $donations[0];
     $publication = CI_Request::getById($donation->getPublicationId())[0];
     $publicationId = $donation->getPublicationId();
     $userIdTo = $donation->getUserId();
     $userIdFrom = $publication->userId;
     $ownerPublication = CI_User::getById($userIdFrom)[0];
     $ownerDonation = CI_User::getById($userIdTo)[0];
     $options['donatedObjects'] = $donation->getDonatedObjects();
     $options['nameOwnerPublication'] = $ownerPublication->getName();
     $options['nameOwnerDonation'] = $ownerDonation->getName();
     $options['publicationTitle'] = $publication->title;
     $options['personalDataOwnerDonation'] = $ownerDonation->getPersonalData();
     $notifyMessage = new CI_Message();
     $notifyMessage->setUserIdTo($userIdTo);
     $notifyMessage->setUserIdFrom($userIdFrom);
     $notifyMessage->setPublicationId($publicationId);
     $notifyMessage->setCommonState('N');
     $notifyMessage->setNotifyText($options);
     if ($notifyMessage->save()) {
         $status = 200;
         $return['result'] = 'OK';
         $return['data'] = $donation;
     }
     $this->response($return, $status);
 }