Ejemplo n.º 1
0
 public function init()
 {
     /* Form Elements & Other Definitions Here ... */
     $this->setMethod('post');
     $this->setElementDecorators($this->elementDecorators);
     $itemMapper = new Application_Model_ItemsMapper();
     $items = $itemMapper->getAllItems();
     $item_options = array('Select Item');
     $categoriesMapper = new Application_Model_CategoriesMapper();
     $servicesMapper = new Application_Model_ServiceMasterMapper();
     if ($items) {
         foreach ($items as $item) {
             $category = $categoriesMapper->getCategoryById($item->__get("category_id"));
             $service = $servicesMapper->getServiceMasterById($item->__get("service_id"));
             $item_options[$item->__get("item_id")] = $category->__get("category_name") . " > " . $item->__get("item_name") . " (" . $service->__get("service_name") . ")";
         }
     }
     $this->addElement('select', 'item_id', array('label' => 'Item', 'required' => true, 'placeholder' => "Select Item", 'filters' => array('StringTrim'), 'class' => 'mws-textinput', 'multiOptions' => $item_options));
     $serviceMapper = new Application_Model_ServiceMasterMapper();
     $services = $serviceMapper->getAllServiceMasters();
     $service_options = array('Select Service');
     if ($services) {
         foreach ($services as $service) {
             $service_options[$service->__get("service_id")] = $service->__get("service_name");
         }
     }
     $this->addElement('select', 'service_id', array('label' => 'Service', 'required' => true, 'filters' => array('StringTrim'), 'placeholder' => "Enter Item Price", 'class' => 'mws-textinput', 'multiOptions' => $service_options));
     $deliveryMapper = new Application_Model_DeliveryTypeMasterMapper();
     $deliveries = $deliveryMapper->getAllDeliveryTypeMaster();
     $delivery_options = array('Select Delivery Type');
     if ($deliveries) {
         foreach ($deliveries as $delivery) {
             $delivery_options[$delivery->__get("delivery_type_name")] = $delivery->__get("delivery_type_name");
         }
     }
     $this->addElement('select', 'delivery_type_name', array('label' => 'Delivery Type', 'required' => true, 'filters' => array('StringTrim'), 'placeholder' => "Enter Item Price", 'class' => 'mws-textinput', 'multiOptions' => $delivery_options));
     $this->addElement('text', 'price', array('label' => 'Price', 'required' => true, 'filters' => array('StringTrim'), 'placeholder' => "Enter Price", 'class' => 'mws-textinput'));
 }
Ejemplo n.º 2
0
 public function indexAction()
 {
     try {
         $item_form = new Application_Form_ItemForm();
         $this->view->form = $item_form;
         $itemsMapper = new Application_Model_ItemsMapper();
         $items = new Application_Model_Items();
         $request = $this->getRequest();
         if ($request->isPost()) {
             $request_type = $request->getParam("request_type", false);
             if ($request_type) {
                 if ($request_type == "add") {
                     $params = $request->getParams();
                     $input_name = "item_image";
                     $file_prefix = "file";
                     $fileName = $this->_imageUpload($input_name, $file_prefix);
                     if ($item_form->isValid($params)) {
                         foreach ($params as $param => $value) {
                             $items->__set($param, $value);
                         }
                         $items->__set("item_image", $fileName);
                         if ($itemsMapper->addNewItem($items)) {
                             $this->view->message = "Item 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 ($itemsMapper->deleteItemById($id)) {
                         $this->view->hasMessage = true;
                         $this->view->messageType = "success";
                         $this->view->message = "Item deleted successfully.";
                     } else {
                         $this->view->hasMessage = true;
                         $this->view->messageType = "danger";
                         $this->view->message = "Error occured while deleting. Please try again.";
                     }
                 }
             }
         }
         $item = $itemsMapper->getAllItems();
         $this->view->items = $item;
         $this->authorised = true;
     } catch (Exception $ex) {
         $this->authorised = false;
         $this->view->hasMessage = true;
         $this->view->messageType = "danger";
         $this->view->message = $ex->getMessage();
     }
 }