예제 #1
0
 public function indexAction()
 {
     try {
         $coupon_form = new Application_Form_CouponForm();
         $this->view->form = $coupon_form;
         $couponsMapper = new Application_Model_CouponsMapper();
         $coupons = new Application_Model_Coupons();
         $request = $this->getRequest();
         if ($request->isPost()) {
             $request_type = $request->getParam("request_type", false);
             if ($request_type) {
                 if ($request_type == "add") {
                     $params = $request->getParams();
                     if ($coupon_form->isValid($params)) {
                         foreach ($params as $param => $value) {
                             $coupons->__set($param, $value);
                         }
                         if ($couponsMapper->addNewCoupon($coupons)) {
                             $this->view->message = "Coupon added successfully";
                             $this->view->hasMessage = true;
                             $this->view->messageType = "success";
                         } else {
                             $this->view->message = "Error occured while adding. Please try again";
                             $this->view->hasMessage = true;
                             $this->view->messageType = "danger";
                         }
                     } else {
                         $this->view->message = "Error occured while Adding. Please fill form correctly";
                         $this->view->hasMessage = true;
                         $this->view->messageType = "danger";
                     }
                 } elseif ($request_type == "delete") {
                     $id = $request->getParam("id");
                     if ($couponsMapper->deleteCouponById($id)) {
                         $this->view->hasMessage = true;
                         $this->view->messageType = "success";
                         $this->view->message = "Coupon deleted successfully.";
                     } else {
                         $this->view->hasMessage = true;
                         $this->view->messageType = "danger";
                         $this->view->message = "Error occured while deleting. Please try again.";
                     }
                 }
             }
         }
         $coupon = $couponsMapper->getAllCoupons();
         $this->view->coupons = $coupon;
         $this->authorised = true;
     } catch (Exception $ex) {
         $this->authorised = false;
         $this->view->hasMessage = true;
         $this->view->messageType = "danger";
         $this->view->message = $ex->getMessage();
     }
 }
예제 #2
0
 public function updateCoupon(Application_Model_Coupons $coupon)
 {
     $data = array("coupon_code" => $coupon->__get("coupon_code"), "coupon_value" => $coupon->__get("coupon_value"), "coupon_type" => $coupon->__get("coupon_type"), "coupon_last_date" => date("Y-m-d", strtotime($coupon->__get("coupon_last_date"))), "coupon_occourence" => $coupon->__get("coupon_occourence"), "coupon_min_billing" => $coupon->__get("coupon_min_billing"), "coupon_max_discount" => $coupon->__get("coupon_max_discount"), "coupon_status" => $coupon->__get("coupon_status"));
     $where = array("coupon_id = ?" => $coupon->__get("coupon_id"));
     try {
         $updated_records = $this->_db_table->update($data, $where);
         return (object) array("success" => true, "error" => false, "message" => "Record Successfully Updated", "row_affected" => $updated_records);
     } catch (Zend_Exception $e) {
         /* Handle Exception Here  */
         return (object) array("success" => false, "error" => true, "message" => $e->getMessage(), "exception" => true, "exception_code" => $e->getCode());
     }
     return $result;
 }