public function indexAction()
 {
     //获取文章分类
     $mapCate = new Application_Model_CategoryMapper();
     $result = $mapCate->getCateAritcle(BLOGGER_ID);
     $this->view->data = $result;
 }
예제 #2
0
파일: Add.php 프로젝트: nlenepveu/testapp
 /**
  * Return multi options for category element
  *
  * @return array
  */
 protected function _getCategories()
 {
     if (!isset($this->_categories)) {
         $this->_categories = array();
         $mapper = new Application_Model_CategoryMapper();
         foreach ($mapper->fetchAll() as $category) {
             $this->_categories[$category->id_category] = $category->name;
         }
     }
     return $this->_categories;
 }
 public function indexAction()
 {
     $cache = Zend_Registry::get('cache');
     $id = md5("artcateControllerIndex");
     if (($result = $cache->load($id)) === false) {
         $mapCate = new Application_Model_CategoryMapper();
         $result = $mapCate->getCateAritcle(BLOGGER_ID);
         $cache->save($result, $id, array('artcatebox'));
     }
     //print_r($result);
     $this->view->data = $result;
 }
예제 #4
0
 public function getCategoryName()
 {
     if (!$this->category_id) {
         return null;
     }
     $categoryMapper = new Application_Model_CategoryMapper();
     $category = $categoryMapper->find($this->category_id);
     return $category->name;
 }
 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;
 }
 public function mycartAction()
 {
     $categoriesMapper = new Application_Model_CategoryMapper();
     $this->view->categories = $categoriesMapper->fetchAll();
     $this->view->headScript()->appendFile(JS_DIR . '/' . self::PROCESS_PAYMENT . '.js');
     $this->view->headScript()->appendFile(JS_DIR . '/' . self::DELETE_FROM_CART . '.js');
     $this->view->headScript()->appendFile(JS_DIR . '/' . self::COUNT_CART . '.js');
     $this->view->headScript()->appendFile(JS_DIR . '/' . self::ADD_TO_CART . '.js');
     $userMapper = new Application_Model_UserMapper();
     $auth = Zend_Auth::getInstance();
     $currentUser = null;
     if ($auth->hasIdentity()) {
         $currentUser = $auth->getIdentity();
     }
     //var_dump($userMapper->getShoppingCart($user_id));
     $auxItem = new Application_Model_CartItem();
     $auxItem->getCurrency()->setService(new My_Class_FakeService());
     $this->view->total = $auxItem->getCurrency();
     $this->view->shoppingcart = $userMapper->getShoppingCart($currentUser);
     $forms = array();
     foreach ($this->view->shoppingcart as $i => $product) {
         $upForm = new Application_Form_UpdateCart();
         $upForm->setAction($this->view->url(array('controller' => 'users', 'action' => 'updatecart'), null, true))->setName("upForm{$i}");
         $upForm->getElement('product_id')->setValue($product->id);
         $upForm->getElement('quantity')->setValue($product->quantity);
         $forms['upForm'][] = $upForm;
         $delForm = new Application_Form_DelFromCart();
         $delForm->setAction($this->view->url(array('controller' => 'users', 'action' => 'delfromcart'), null, true))->setName("delForm{$i}");
         $delForm->getElement('product_id')->setValue($product->id);
         $forms['delForm'][] = $delForm;
     }
     $this->view->forms = $forms;
     $this->view->delForm = new Application_Form_DelFromCart();
     $this->_helper->layout->setLayout('shop');
 }
예제 #7
0
 protected function _getCategories($categories = null)
 {
     $mapper = new Application_Model_CategoryMapper();
     $id = $this->_getParam('id_category');
     if (!empty($id) && $id != 'all') {
         // display only one category
         $category = $mapper->load($id);
         if ($category) {
             $categories = array($category);
             $this->view->id_category = $category->id_category;
         }
     } else {
         // or display all categories
         if (!isset($categories)) {
             $categories = $mapper->fetchAll();
         }
     }
     return $categories;
 }