Example #1
0
 /**
  * @param Request $request
  * @return Response
  */
 public function call(Request $request)
 {
     // Create cURL
     $ch = curl_init();
     // Set-up URL
     curl_setopt($ch, CURLOPT_URL, $request->getUrl());
     // Set-up headers
     $headers = $request->getHeaders();
     array_walk($headers, function (&$item, $key) {
         $item = "{$key}: {$item}";
     });
     curl_setopt($ch, CURLOPT_HTTPHEADER, array_values($headers));
     // Set-up others
     curl_setopt_array($ch, $request->getOpts());
     // Receive result
     $result = curl_exec($ch);
     // Parse response
     $response = new Response();
     if ($result === FALSE) {
         $response->setError(curl_strerror(curl_errno($ch)));
         $response->setData(FALSE);
         $response->setCode(curl_errno($ch));
         $response->setHeaders(curl_getinfo($ch));
     } else {
         $response->setData(json_decode($result));
         $response->setCode(curl_getinfo($ch, CURLINFO_HTTP_CODE));
         $response->setHeaders(curl_getinfo($ch));
     }
     // Close cURL
     curl_close($ch);
     return $response;
 }
Example #2
0
 /**
  * Returns a list of users.
  * @return void
  */
 public function actionGet()
 {
     $response = new Response();
     $users = User::model()->findAll();
     $data = array();
     foreach ($users as $user) {
         $data[] = $user->getResponseData();
     }
     $response->setStatus(Response::STATUS_OK);
     $response->setData('list', $data);
     $response->setData('total', count($users));
     echo $response;
 }
 public static function draw(\Exception $oExp)
 {
     @header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
     $oResponse = new Response();
     $oResponse->setData(array('success' => false, 'error' => $oExp->getMessage(), 'errorDetail' => array('type' => get_class($oExp), 'code' => $oExp->getCode())));
     return $oResponse->flushJson();
 }
Example #4
0
 public static function jsonDeserialize($content)
 {
     $data = json_decode($content);
     $keys = array_keys(json_decode($content, true));
     $response = new Response();
     foreach ($keys as $key) {
         switch ($key) {
             case 'status':
                 $response->setStatus($data->status);
                 break;
             case 'data':
                 $response->setData($data->data);
                 break;
             case 'error':
                 $response->setErrorMessage($data->error);
                 break;
             case 'code':
                 $response->setErrorCode($data->code);
                 break;
             case 'metadata':
                 foreach ((array) $data->metadata as $key => $value) {
                     $response->setMetadata($key, $value);
                 }
                 break;
         }
     }
     return $response;
 }
Example #5
0
 function sendForBilling()
 {
     $response = new Response();
     try {
         $projectId = $this->input->post("project-id");
         $amount = $this->input->post("project-bill-amount");
         $billDoc = $this->input->post("bill-doc");
         $project = $this->findById("Project", $projectId);
         if ($project == null) {
             throw new RuntimeException("Invalid Project..!");
         }
         $project->setStatus(Project::PROJECT_BILL);
         $project->getWorkOrder()->setStatus(Workorder::STATUS_COMPLETED);
         $project->getWorkOrder()->setApprovedBy($this->getLoggedInUser());
         $bill = new Bill();
         $bill->setAmount($amount);
         $bill->setProject($project);
         $bill->setCreated(new DateTime());
         $bill->setStatus(Bill::STATUS_PENDING);
         if ($billDoc != null && $billDoc != "") {
             foreach ($billDoc as $file) {
                 $doc = new Document();
                 $doc->setName($file);
                 $doc->setCreated(new DateTime());
                 $bill->getBillDoc()->add($doc);
             }
         }
         $this->save($bill);
         $response->setData(Project::PROJECT_BILL);
     } catch (Exception $e) {
         $response->setStatus(false);
         $response->setErrorMessage($e->getMessage());
     }
     $this->output->set_content_type('application/json')->set_output(json_encode($response));
 }
Example #6
0
 function approve()
 {
     $response = new Response();
     try {
         $projectId = $this->input->post("project-id");
         $amount = floatval($this->input->post("project-bill-amount"));
         $project = $this->findById("Project", $projectId);
         if ($projectId == null) {
             throw new RuntimeException("Invalid Request");
         }
         $availableAmount = $this->getAvailableFundAmountByScheme($project->getScheme()->getId());
         if ($amount > floatval($availableAmount)) {
             throw new RuntimeException("Insufficient Funds !");
         }
         $utilisedAmt = 0;
         foreach ($this->getAvailableFunds($project->getScheme()) as $fund) {
             /*if($fund->getAmount() == $fund->getUsedAmount()){
                   continue;
               }*/
             $reqAmt = $amount - $utilisedAmt;
             $fundDetails = new FundDetails();
             $fundDetails->setCreated(new DateTime());
             $availableAmount = $fund->getAmount() - $fund->getUsedAmount();
             if ($availableAmount >= $reqAmt) {
                 $fundDetails->setAmount($reqAmt);
                 $fund->setUsedAmount($fund->getUsedAmount() + $reqAmt);
                 $utilisedAmt = $amount;
             } else {
                 if ($reqAmt <= $availableAmount) {
                     $fund->setUsedAmount($fund->getUsedAmount() + $reqAmt);
                     $fundDetails->setAmount($reqAmt);
                     $utilisedAmt = $utilisedAmt + $reqAmt;
                 } else {
                     $fund->setUsedAmount($fund->getUsedAmount() + $availableAmount);
                     $fundDetails->setAmount($availableAmount);
                     $utilisedAmt = $utilisedAmt + $availableAmount;
                 }
             }
             $fundDetails->setFund($fund);
             $fundDetails->setProject($project);
             $project->getFundDetails()->add($fundDetails);
             if ($utilisedAmt == $amount) {
                 break;
             }
         }
         $bill = $project->getBill();
         $bill->setApprovedBy($this->getLoggedInUser());
         $bill->setApprovedAmount($amount);
         $bill->setStatus(Bill::STATUS_APPROVED);
         $project->setStatus(Project::PROJECT_COMPLETED);
         $this->save($project);
         $response->setData(Bill::STATUS_APPROVED);
     } catch (Exception $e) {
         $response->setStatus(false);
         $response->setErrorMessage($e->getMessage());
     }
     $this->output->set_content_type('application/json')->set_output(json_encode($response));
 }
Example #7
0
 function getAvailableFundsAmount()
 {
     $response = new Response();
     try {
         $availableFunds = $this->getAvailableFundAmount(1);
         $response->setData($availableFunds);
     } catch (Exception $e) {
         $response->setStatus(false);
         $response->setErrorMessage($e->getMessage());
     }
     $this->output->set_content_type('application/json')->set_output(json_encode($response));
 }
 /**
  * Execute an SQL select query and generate Response object
  * @param  string $type   [description]
  * @param  string $sql SQL string to execute
  * @param  bool $isSingle Whether only one record should be returned
  * @return Response $response Generated Response object
  */
 public function doQueryResponse(Response $response, $sql, $type, $isSingle = false)
 {
     try {
         // Execute the query
         $result = $this->doQuery($sql, $isSingle);
         // Save the data to the response object
         $response->setData($type, $result);
     } catch (\Rapi\PDOException $e) {
         // Save the PDO error to the response
         $response->setError($e->getCode(), $e->getMessage());
     }
     return $response;
 }
 public static function select($type, $sql, $params = array(), $single = false)
 {
     $response = new Response();
     try {
         $db = PDO::getConnection();
         $stmt = $db->prepare($sql);
         foreach ($params as $param => $paramValue) {
             $stmt->bindParam($param, $paramValue[0], $paramValue[1]);
         }
         $stmt->execute();
         $result = $stmt->fetchAll(PDO::FETCH_OBJ);
         $db = null;
         if ($single && is_array($result) && isset($result[0])) {
             $result = $result[0];
         }
         $response->setData($type, $result);
     } catch (\Exception $e) {
         $response->setError($e->getCode(), $e->getMessage());
     }
     $response->output();
 }
Example #10
0
 function load($id)
 {
     $response = new Response();
     try {
         $workOrder = $this->findById("Workorder", $id);
         $comments = array();
         foreach ($workOrder->getComments() as $cmt) {
             $dto = new Commentdto();
             $dto->setId($cmt->getId());
             $dto->setComment($cmt->getComment());
             $dto->setCreated(date_format($cmt->getCreated(), "d-M-Y"));
             $dto->setCommentedBy($cmt->getCommentedBy()->getFirstName() . " " . $cmt->getCommentedBy()->getLastName());
             array_push($comments, $dto);
         }
         $response->setData($comments);
     } catch (Exception $e) {
         $response->setStatus(false);
         $response->setErrorMessage($e->getMessage());
     }
     $this->output->set_content_type('application/json')->set_output(json_encode($response));
 }
Example #11
0
 function getFundDetails($id = null)
 {
     $response = new Response();
     try {
         if ($id == null) {
             throw new RuntimeException("Invalid Request..!");
         }
         $funds = parent::getFundDetails($id);
         $fundArray = array();
         foreach ($funds as $fund) {
             $dto = new FundDetailsDto();
             $dto->setAmount($fund->getAmount());
             $dto->setProjectName($fund->getProject()->getName());
             $dto->setFundAmount($fund->getFund()->getAmount());
             array_push($fundArray, $dto);
         }
         $response->setData($fundArray);
     } catch (Exception $e) {
         $response->setStatus(false);
         $response->setErrorMessage($e->getMessage());
     }
     $this->output->set_content_type('application/json')->set_output(json_encode($response));
 }
Example #12
0
 public function sendCommand($command, $data = null)
 {
     $packet = $command;
     if ($data) {
         $packet .= ' ' . json_encode($data);
     }
     //echo "SENDING: [$packet]";
     fwrite($this->fp, $packet . chr(0x4));
     $res = $this->getResponse();
     $response = new Response();
     if ($res == 'ok') {
         $response->setType('ok');
     } else {
         $p = strpos($res, '{');
         if ($p > 0) {
             $type = substr($res, 0, $p - 1);
             $response->setType($type);
             $json = substr($res, $p);
             $data = json_decode($json, true);
             $response->setData($data);
         }
     }
     return $response;
 }
Example #13
0
 /**
  * Get Lists a Subscriber is Member of.
  * 
  * <p><strong>Parameters:</strong><br/>
  * [*subscriber_id] {integer} the Subscriber-ID.
  * <p><strong>Returns:</strong><br/>
  * Array of lists where the subscriber is assigned to.
  * </p>
  */
 public static function listsSubscriber($subscriber_id = 0)
 {
     $response = new Response();
     if ($subscriber_id == 0) {
         $subscriber_id = sprintf('%d', $_REQUEST['subscriber_id']);
     }
     $sql = 'SELECT * FROM ' . $GLOBALS['tables']['list'] . ' WHERE id IN 
       (SELECT listid FROM ' . $GLOBALS['tables']['listuser'] . ' WHERE userid=:subscriber_id) ORDER BY listorder;';
     if (!is_numeric($subscriber_id) || empty($subscriber_id)) {
         Response::outputErrorMessage('invalid call');
     }
     try {
         $db = PDO::getConnection();
         $stmt = $db->prepare($sql);
         $stmt->bindParam('subscriber_id', $subscriber_id, PDO::PARAM_INT);
         $stmt->execute();
         $result = $stmt->fetchAll(PDO::FETCH_OBJ);
         $db = null;
         $response->setData('Lists', $result);
         $response->output();
     } catch (\Exception $e) {
         Response::outputError($e);
     }
     die(0);
 }
 private function simpleSuccessResponse()
 {
     $response = new Response();
     $response->setData(['result' => ['success' => true]]);
     return $response;
 }
 public static function formtokenGet()
 {
     $key = md5(time() . mt_rand(0, 10000));
     Sql_Query(sprintf('insert into %s (adminid,value,entered,expires) values(%d,"%s",%d,date_add(now(),interval 1 hour))', $GLOBALS['tables']['admintoken'], $_SESSION['logindetails']['id'], $key, time()), 1);
     $response = new Response();
     $response->setData('formtoken', $key);
     $response->output();
 }
 /**
  * Generate and output a generic system message as a response
  * @param string $message System message
  */
 static function outputMessage($message)
 {
     $response = new Response();
     $response->setData('SystemMessage', $message);
     $response->output();
 }