예제 #1
0
 public function indexAction()
 {
     $params = array();
     $name = $this->getRequest()->getParam('name');
     $shop = new Default_Model_Shops();
     $select = $shop->getMapper()->getDbTable()->select()->where('NOT deleted');
     if (!empty($name)) {
         $params['name'] = $name;
         $select->where('name LIKE ?', '%' . $name . '%');
     }
     $select->order(array('name ASC'));
     $result = $shop->fetchAll($select);
     if (NULL != $result) {
         $paginator = Zend_Paginator::factory($result);
         $paginator->setItemCountPerPage(10);
         $paginator->setCurrentPageNumber($this->_getParam('page'));
         $paginator->setPageRange(5);
         $this->view->result = $paginator;
         $this->view->itemCountPerPage = $paginator->getItemCountPerPage();
         $this->view->totalItemCount = $paginator->getTotalItemCount();
         Zend_Paginator::setDefaultScrollingStyle('Sliding');
         Zend_View_Helper_PaginationControl::setDefaultViewPartial('_pagination.phtml');
     }
     $form = new Default_Form_ShopsSearch();
     $form->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/shops/shops-search.phtml'))));
     $this->view->form = $form;
     $this->view->search = $params;
     $formAdd = new Default_Form_Shops();
     $formAdd->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/shops/add-shops.phtml'))));
     $this->view->formAdd = $formAdd;
     if ($this->getRequest()->isPost()) {
         $post = $this->getRequest()->getPost();
         if (!empty($post['action']) && $post['action'] == 'add') {
             if ($formAdd->isValid($post)) {
                 $model = new Default_Model_Shops();
                 $model->setOptions($formAdd->getValues());
                 if ($model->save()) {
                     //mesaj de succes
                     $this->_flashMessenger->addMessage("<div class='success  canhide'><p>Shop successfully added<p></div>");
                 } else {
                     //mesaj de eroare
                     $this->_flashMessenger->addMessage("<div class='failure canhide'><p>The shop was not successfully saved<p></div>");
                 }
                 //redirect
                 $this->_redirect(WEBROOT . 'shops/index');
             }
         }
     }
 }
예제 #2
0
파일: Shops.php 프로젝트: valizr/MMA
 public function fetchRow($select, Default_Model_Shops $model)
 {
     $result = $this->getDbTable()->fetchRow($select);
     if (0 == count($result)) {
         return;
     }
     $model->setOptions($result->toArray());
     return $model;
 }