コード例 #1
0
ファイル: IndexController.php プロジェクト: rmancheker/zf
 public function addAction()
 {
     if ($this->getRequest()->isPost()) {
         $formdata = $this->getRequest()->getPost();
         $model = new Application_Model_Product($formdata);
         $objMapper = new Application_Model_ProductMapper($model);
         $pro_id = $objMapper->save($model);
         if (is_numeric($pro_id)) {
             $err = "record saved";
         }
     }
     $this->view;
 }
コード例 #2
0
ファイル: Category.php プロジェクト: nlenepveu/testapp
 public function addProduct(Application_Model_Product $product)
 {
     $mapper = new Application_Model_ProductMapper();
     $mapper->addProductToCategory($product, $this);
     $this->_products = null;
 }
コード例 #3
0
 public function getSaveProductForm($id)
 {
     $form = new Zend_Form();
     //get product whitch want update
     $productMapper = new Application_Model_ProductMapper();
     $product = new Application_Model_Product();
     if ($id) {
         $product = $productMapper->getProductById($id);
     }
     // Set the method for the display form to POST
     $form->setMethod('post');
     $form->setAttribs(array('class' => 'form-horizontal', 'enctype' => 'multipart/form-data'));
     $decoratorField = new My_Decorator_Field();
     $elements = array();
     //Add id hidden field
     $input = new Zend_Form_Element_Hidden('id', array('value' => $id));
     $elements[] = $input;
     // Add name field
     $input = new Zend_Form_Element_Text('name', array('required' => true, 'label' => 'Name:', 'id' => 'name', 'placeholder' => 'Type something..', 'value' => $product->getName(), 'class' => 'form-control'));
     $input->addValidators(array(new Zend_Validate_Alnum(), new Zend_Validate_NotEmpty()));
     $input->addDecorator($decoratorField);
     $elements[] = $input;
     // Add category field
     $select = new Zend_Form_Element_Select('category_id', array('required' => true, 'label' => 'Category:', 'id' => 'category', 'class' => 'form-control'));
     $categoryMapper = new Application_Model_CategoryMapper();
     $categories = $categoryMapper->fetchAll();
     foreach ($categories as $category) {
         $select->addMultiOption($category->getId(), $category->getName());
     }
     // set selected option
     $select->setValue($product->getCategoryId());
     $select->addDecorator($decoratorField);
     $elements[] = $select;
     $currencyMapper = new Application_Model_CurrencyMapper();
     $currency = $currencyMapper->getDefaultCurrency();
     // Add Price field
     $input = new Zend_Form_Element_Text('price', array('required' => true, 'label' => 'Price in ' . $currency->getCode() . ':', 'id' => 'price', 'placeholder' => 'Type something..', 'value' => number_format((double) $product->price, 2), 'class' => 'form-control', 'min' => self::MIN, 'max' => self::MAX, 'step' => 'any', 'type' => 'number'));
     $min = new Zend_Validate_LessThan(self::MAX);
     $max = new Zend_Validate_GreaterThan(self::MIN);
     $input->addValidators(array(new Zend_Validate_Float(), $min, $max, new Zend_Validate_NotEmpty()));
     $input->addDecorator($decoratorField);
     $elements[] = $input;
     if ($id) {
         //Add File field
         if ($product->file) {
             $input = new Zend_Form_Element('file', array('label' => 'File:', 'id' => 'file', 'class' => 'form-control', 'value' => $product->file));
             $input->addDecorator(new My_Decorator_AnchoraFileForm());
             $elements[] = $input;
         } else {
             $input = new Zend_Form_Element_File('file', array('label' => 'File:', 'id' => 'file', 'class' => 'form-control'));
             $input->addDecorator($decoratorField);
             $elements[] = $input;
         }
         //Add Image field
         if ($product->image) {
             $input = new Zend_Form_Element('image', array('label' => 'Image:', 'id' => 'image', 'class' => 'form-control', 'value' => $product->image));
             $input->addDecorator(new My_Decorator_ImageForm());
             $elements[] = $input;
         } else {
             $input = new Zend_Form_Element_File('image', array('label' => 'Image:', 'id' => 'image', 'class' => 'form-control'));
             $input->addDecorator($decoratorField);
             $elements[] = $input;
         }
     } else {
         //Add File field
         $input = new Zend_Form_Element_File('file', array('label' => 'File:', 'id' => 'file', 'class' => 'form-control'));
         $input->addDecorator($decoratorField);
         $elements[] = $input;
         //Add Image field
         $input = new Zend_Form_Element_File('image', array('label' => 'Image:', 'id' => 'image', 'class' => 'form-control'));
         $input->addDecorator($decoratorField);
         $elements[] = $input;
     }
     //Add Description field
     $input = new Zend_Form_Element_Textarea('description', array('label' => 'Description:', 'id' => 'description', 'class' => 'form-control', 'value' => $product->description));
     $input->addDecorator($decoratorField);
     $elements[] = $input;
     //Add Submit button
     if (!$id) {
         $input = new Zend_Form_Element_Submit('submit', array('Label' => ' ', 'class' => 'btn btn-success', 'value' => 'Add New Product'));
     } else {
         $input = new Zend_Form_Element_Submit('submit', array('Label' => ' ', 'class' => 'btn btn-info', 'value' => 'Update Product'));
     }
     $input->addDecorator($decoratorField);
     $elements[] = $input;
     $form->addElements($elements);
     $form->addDisplayGroup(array('name', 'category_id', 'price', 'currency_id', 'file', 'image', 'description', 'submit'), 'displgrp', array('legend' => 'Add Products', 'decorators' => array('FormElements', 'Fieldset')));
     return $form;
 }
コード例 #4
0
 public function dashboardAction()
 {
     $this->view->headScript()->appendFile(JS_DIR . '/' . self::VALIDATE_FORM . '.js');
     $this->view->headScript()->appendFile(JS_DIR . '/' . self::STATE_UPDATE . '.js');
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $currentUser = $auth->getIdentity();
     }
     $productMapper = new Application_Model_ProductMapper();
     $this->view->products = $productMapper->fetchAll();
     $userMapper = new Application_Model_UserMapper();
     $this->view->users = $userMapper->fetchAll();
     $mailMapper = new Application_Model_MailsettingMapper();
     $this->view->mailSettings = $mailMapper->fetchAll();
     $orderMapper = new Application_Model_OrderMapper();
     $this->view->orders = $orderMapper->fetchAll();
     $currencyMapper = new Application_Model_CurrencyMapper();
     $this->view->currencies = $currencyMapper->fetchAll();
     $forms = array();
     foreach ($this->view->mailSettings as $setting) {
         $form = new Application_Form_SubmitButton();
         $form->setAction($this->view->url(array('controller' => 'mailsettings', 'action' => 'delete'), null, true));
         $form->addAttribs(array('id' => 'delSettingForm' . $setting->id, 'onsubmit' => self::VALIDATE_FORM . "('delSettingForm" . $setting->id . "')"));
         $form->getElement('id')->setValue($setting->id);
         $form->getElement('submit')->setAttribs(array('class' => 'btn btn-danger'));
         $form->getElement('submit')->setLabel('Delete');
         $forms['delSettingForm'][] = $form;
         $form = new Application_Form_SubmitButton();
         if ($setting->getDefaultConfig()) {
             $form->getElement('submit')->setAttribs(array('class' => 'btn btn-primary disabled'));
             $form->getElement('submit')->setLabel('Default');
         } else {
             $form->addAttribs(array('id' => 'defSettingForm' . $setting->id, 'onsubmit' => self::VALIDATE_FORM . "('defSettingForm" . $setting->id . "')"));
             $form->setAction($this->view->url(array('controller' => 'mailsettings', 'action' => 'mkdefault'), null, true));
             $form->getElement('submit')->setAttribs(array('class' => 'btn btn-primary'));
             $form->getElement('submit')->setLabel('Make Default');
             $form->getElement('id')->setValue($setting->id);
         }
         $forms['defSettingForm'][] = $form;
     }
     //initialize forms
     foreach ($this->view->users as $user) {
         $form = new Application_Form_SubmitButton();
         if ($user->id == $currentUser->id || $user->getAdminId() == 1) {
             // is current user or is superuser
             $form->getElement('submit')->setAttribs(array('class' => 'btn btn-danger disabled'));
             $form->getElement('submit')->setLabel('Delete');
         } else {
             $form->setAction($this->view->url(array('controller' => 'users', 'action' => 'delete'), null, true));
             $form->addAttribs(array('id' => 'delUserForm' . $user->id, 'onsubmit' => self::VALIDATE_FORM . "('delUserForm" . $user->id . "')"));
             $form->getElement('id')->setValue($user->id);
             $form->getElement('submit')->setAttribs(array('class' => 'btn btn-danger'));
             $form->getElement('submit')->setLabel('Delete');
         }
         $forms['delUserForm'][] = $form;
         $form = new Application_Form_SubmitButton();
         if ($user->id == $currentUser->id || $user->getAdminId() == 1 || !$user->verified) {
             $form->getElement('submit')->setAttribs(array('class' => 'btn btn-primary disabled'));
             $form->getElement('submit')->setLabel('Make Admin');
         } else {
             if ($user->getAdminId()) {
                 $form->addAttribs(array('id' => 'umkUserForm' . $user->id, 'onsubmit' => self::VALIDATE_FORM . "('umkUserForm" . $user->id . "')"));
                 $form->setAction($this->view->url(array('controller' => 'users', 'action' => 'umkadmin'), null, true));
                 $form->getElement('submit')->setAttribs(array('class' => 'btn btn-primary'));
                 $form->getElement('submit')->setLabel('Unmake Admin');
             } else {
                 $form->addAttribs(array('id' => 'mkUserForm' . $user->id, 'onsubmit' => self::VALIDATE_FORM . "('mkUserForm" . $user->id . "')"));
                 $form->setAction($this->view->url(array('controller' => 'users', 'action' => 'mkadmin'), null, true));
                 $form->getElement('submit')->setAttribs(array('class' => 'btn btn-primary'));
                 $form->getElement('submit')->setLabel('Make Admin');
             }
             $form->getElement('id')->setValue($user->id);
         }
         $forms['mkUserForm'][] = $form;
     }
     // initialize forms
     foreach ($this->view->products as $i => $product) {
         $delForm = new Application_Form_DeleteProduct();
         $delForm->setAction($this->view->url(array('controller' => 'products', 'action' => 'delete'), null, true));
         $delForm->addAttribs(array('id' => 'delForm' . $product->id, 'onsubmit' => self::VALIDATE_FORM . "('delForm" . $product->id . "')"));
         $delForm->getElement('product_id')->setValue($product->id);
         $forms['delProductForm'][] = $delForm;
     }
     $this->view->forms = $forms;
 }
コード例 #5
0
ファイル: IndexController.php プロジェクト: nlenepveu/testapp
 public function deleteSelectionAction()
 {
     $this->_helper->getHelper('viewRenderer')->setNoRender();
     if ($this->getRequest()->isPost()) {
         $selection = $this->_getParam('selection');
         if (!empty($selection)) {
             $mapper = new Application_Model_ProductMapper();
             foreach ($selection as $id) {
                 try {
                     $mapper->delete($id);
                 } catch (Exception $e) {
                     continue;
                 }
             }
             $this->view->result = 'success';
             $this->view->alert = 'Products removed from the list';
         } else {
             $this->view->result = 'warning';
             $this->view->alert = 'No products selected';
         }
     }
 }