public function applycouponAction() { $cartSession = new Zend_Session_Namespace('laundryCart'); $this->_helper->viewRenderer->setNoRender(true); $this->_helper->layout->disableLayout(); $response = array("success" => false, "message" => "Coupon code not valid"); $couponCode = $this->_getParam("coupon_code"); if (!empty($couponCode)) { $CouponsMapperModel = new Application_Model_CouponsMapper(); $couponData = $CouponsMapperModel->getCouponByCouponCode($couponCode); $namespace = new Zend_Session_Namespace('userInfo'); if (!empty($couponData)) { $isAllowedResult = $this->isCouponAllowedToUse($namespace->user_id, $couponData->__get("coupon_id")); if ($isAllowedResult->allowed === true) { $response['success'] = true; $response['message'] = "coupon is active"; $response['coupondata'] = array("amount" => $couponData->__get("coupon_value"), "type" => $couponData->__get("coupon_type"), "minbill" => $couponData->__get("coupon_min_billing"), "maxdis" => $couponData->__get("coupon_max_discount")); } else { $response['message'] = $isAllowedResult->message; } } } echo Zend_Json::Encode($response); die; }
/** * Visual reports * * @return void */ public function visualAction() { if ($this->_checkIdent()) { $data = array('data' => array(), 'legend' => array()); // Obtain parameters in request for instruction of what data to return $request = $this->getRequest(); $refdata = $request->getParam('refdata'); $landdata = $request->getParam('landdata'); $tendata = $request->getParam('tendata'); $commdata = $request->getParam('commdata'); $yearnum_1 = $request->getParam('yearnum_1'); $yearnum_2 = $request->getParam('yearnum_2'); $yearnum_3 = $request->getParam('yearnum_3'); // Obtain start/end years for 3 year history or data $endyear = date("Y"); $startyear = $endyear - 2; if ($refdata != null) { // Ref data requested $mireport = new Datasource_Connect_Mi_RefSales(); $year = $startyear; $seriesdata = array(); if ($yearnum_1) { $reportdata = $mireport->refSalesCountByMonthForYear($this->_agentSchemeNumber, $year); $seriesdata = array_merge($seriesdata, $reportdata); } $year++; if ($yearnum_2) { $reportdata = $mireport->refSalesCountByMonthForYear($this->_agentSchemeNumber, $year); $seriesdata = array_merge($seriesdata, $reportdata); } $year++; if ($yearnum_3) { $reportdata = $mireport->refSalesCountByMonthForYear($this->_agentSchemeNumber, $year); $seriesdata = array_merge($seriesdata, $reportdata); } array_push($data['data'], $seriesdata); array_push($data['legend'], 'Referencing'); } if ($landdata != null) { // Ref data requested $mireport = new Datasource_Connect_Mi_InsuranceSales(); $year = $startyear; $seriesdata = array(); if ($yearnum_1) { $reportdata = $mireport->landlordsSalesCountByMonthForYear($this->_agentSchemeNumber, $year); $seriesdata = array_merge($seriesdata, $reportdata); } $year++; if ($yearnum_2) { $reportdata = $mireport->landlordsSalesCountByMonthForYear($this->_agentSchemeNumber, $year); $seriesdata = array_merge($seriesdata, $reportdata); } $year++; if ($yearnum_3) { $reportdata = $mireport->landlordsSalesCountByMonthForYear($this->_agentSchemeNumber, $year); $seriesdata = array_merge($seriesdata, $reportdata); } array_push($data['data'], $seriesdata); array_push($data['legend'], 'Landlords'); } if ($tendata != null) { // Ref data requested $mireport = new Datasource_Connect_Mi_InsuranceSales(); $year = $startyear; $seriesdata = array(); if ($yearnum_1) { $reportdata = $mireport->tenantSalesCountByMonthForYear($this->_agentSchemeNumber, $year); $seriesdata = array_merge($seriesdata, $reportdata); } $year++; if ($yearnum_2) { $reportdata = $mireport->tenantSalesCountByMonthForYear($this->_agentSchemeNumber, $year); $seriesdata = array_merge($seriesdata, $reportdata); } $year++; if ($yearnum_3) { $reportdata = $mireport->tenantSalesCountByMonthForYear($this->_agentSchemeNumber, $year); $seriesdata = array_merge($seriesdata, $reportdata); } array_push($data['data'], $seriesdata); array_push($data['legend'], 'Tenants'); } if ($commdata != null) { // Ref data requested // Ref data requested $mireport = new Datasource_Connect_Mi_InsuranceSales(); $year = $startyear; $seriesdata = array(); if ($yearnum_1) { $reportdata = $mireport->commmissionByMonthForYear($this->_agentSchemeNumber, $year); $seriesdata = array_merge($seriesdata, $reportdata); } $year++; if ($yearnum_2) { $reportdata = $mireport->commmissionByMonthForYear($this->_agentSchemeNumber, $year); $seriesdata = array_merge($seriesdata, $reportdata); } $year++; if ($yearnum_3) { $reportdata = $mireport->commmissionByMonthForYear($this->_agentSchemeNumber, $year); $seriesdata = array_merge($seriesdata, $reportdata); } array_push($data['data'], $seriesdata); array_push($data['legend'], 'Commission'); } echo Zend_Json::Encode($data); } }
/** * Implement Zend_Server_Interface::handle() * * @param array $request * @throws Zend_Rest_Server_Exception * @return string|void */ public function handle($request = false) { // Si aucun header de préciser, on annonce qu'on va envoyer du Json // (Rétrocompatibilité) if (!$this->_headers || empty($this->_headers)) { $this->_headers = array('Content-Type: application/json'); } // On paramètre le detecteur de mise en défaut $failed = false; // Copié collé de Zend_Rest_Server::handle() ... (mais un peu custom quand même !) if (!$request) { $request = $_REQUEST; } if (isset($request['method'])) { $this->_method = $request['method']; if (isset($this->_functions[$this->_method])) { if ($this->_functions[$this->_method] instanceof Zend_Server_Reflection_Function || $this->_functions[$this->_method] instanceof Zend_Server_Reflection_Method && $this->_functions[$this->_method]->isPublic()) { $request_keys = array_keys($request); array_walk($request_keys, array(__CLASS__, "lowerCase")); $request = array_combine($request_keys, $request); $func_args = $this->_functions[$this->_method]->getParameters(); $calling_args = array(); $missing_args = array(); foreach ($func_args as $arg) { if (isset($request[strtolower($arg->getName())])) { $calling_args[] = $request[strtolower($arg->getName())]; } elseif ($arg->isOptional()) { $calling_args[] = $arg->getDefaultValue(); } else { $missing_args[] = $arg->getName(); } } foreach ($request as $key => $value) { if (substr($key, 0, 3) == 'arg') { $key = str_replace('arg', '', $key); $calling_args[$key] = $value; if (($index = array_search($key, $missing_args)) !== false) { unset($missing_args[$index]); } } } // Sort arguments by key -- @see ZF-2279 ksort($calling_args); $result = false; if (count($calling_args) < count($func_args)) { require_once 'Zend/Rest/Server/Exception.php'; $result = $this->fault(new Zend_Rest_Server_Exception('Invalid Method Call to ' . $this->_method . '. Missing argument(s): ' . implode(', ', $missing_args) . '.'), 400); $failed = true; } if (!$result && $this->_functions[$this->_method] instanceof Zend_Server_Reflection_Method) { // Get class $class = $this->_functions[$this->_method]->getDeclaringClass()->getName(); if ($this->_functions[$this->_method]->isStatic()) { // for some reason, invokeArgs() does not work the same as // invoke(), and expects the first argument to be an object. // So, using a callback if the method is static. $result = $this->_callStaticMethod($class, $calling_args); } else { // Object method $result = $this->_callObjectMethod($class, $calling_args); } } elseif (!$result) { try { $result = call_user_func_array($this->_functions[$this->_method]->getName(), $calling_args); //$this->_functions[$this->_method]->invokeArgs($calling_args); } catch (Exception $e) { $result = $this->fault($e); $failed = true; } } } else { require_once "Zend/Rest/Server/Exception.php"; $result = $this->fault(new Zend_Rest_Server_Exception("Unknown Method '{$this->_method}'."), 404); $failed = true; } } else { require_once "Zend/Rest/Server/Exception.php"; $result = $this->fault(new Zend_Rest_Server_Exception("Unknown Method '{$this->_method}'."), 404); $failed = true; } } else { require_once "Zend/Rest/Server/Exception.php"; $result = $this->fault(new Zend_Rest_Server_Exception("No Method Specified."), 404); $failed = true; } // Si la réponse attendu est en JSON, ou le résultat à failed, // on parse la réponse en json if ($failed || $this->_jsonResponse) { $response = Zend_Json::Encode(array('response' => $result, 'status' => $failed ? 'failed' : 'success')); } else { $response = ''; } // On gère la fonction returnResponse() if (!$this->returnResponse()) { if (!headers_sent()) { foreach ($this->_headers as $header) { header($header); } } echo $response; return; } // On envoie le json return $response; }