Ejemplo n.º 1
0
 /**
  * @param Book $address
  * @return \Zend\Db\Adapter\Driver\StatementInterface|\Zend\Db\ResultSet\ResultSet
  */
 public function saveAddress(Book $address)
 {
     $data = array('name' => $address->getName() ?: null, 'mobile' => $address->getMobile() ?: null, 'email' => $address->getEmail() ?: null, 'cityId' => $address->getCityId() ?: null, 'districtId' => (int) $address->getDistrictId() ?: null, 'address' => $address->getAddress() ?: null, 'createdById' => (int) $address->getCreatedById() ?: null);
     /* @var $dbAdapter \Zend\Db\Adapter\Adapter */
     $dbAdapter = $this->getServiceLocator()->get('dbAdapter');
     /* @var $dbSql \Zend\Db\Sql\Sql */
     $dbSql = $this->getServiceLocator()->get('dbSql');
     if (null === ($id = $address->getId())) {
         $insert = $dbSql->insert(self::TABLE_NAME);
         $insert->values($data);
         $query = $dbSql->buildSqlString($insert);
         $results = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE);
     } else {
         $update = $dbSql->update(self::TABLE_NAME);
         $update->set($data);
         $update->where("id = " . $address->getId());
         $query = $dbSql->buildSqlString($update);
         $results = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE);
     }
     return $results;
 }
Ejemplo n.º 2
0
 public function indexAction()
 {
     $add = new \Address\Model\Book();
     $addMapper = $this->getServiceLocator()->get('Address\\Model\\BookMapper');
     /* @var $cityMapper \Address\Model\CityMapper */
     $cityMapper = $this->getServiceLocator()->get('Address\\Model\\CityMapper');
     $city = new \Address\Model\City();
     /* @var $districtMapper \Address\Model\DistrictMapper */
     $districtMapper = $this->getServiceLocator()->get('Address\\Model\\DistrictMapper');
     $district = new \Address\Model\District();
     $districts = array();
     if (!!($cityId = $this->getRequest()->getPost()->get('cityId'))) {
         $district->setCityId($cityId);
         $districts = $districtMapper->fetchAll($district);
     }
     /* @var $form \User\Form\Signup */
     $form = $this->getServiceLocator()->get('Address\\Form\\Book');
     $form->setInputFilter($this->getServiceLocator()->get('Address\\Form\\BookFilter'));
     $form->setCities($city->toSelectBoxArray($cityMapper->fetchAll()));
     $form->setDistricts($district->toSelectBoxArray($districts));
     $form->bind($add);
     $viewModel = new ViewModel();
     if ($this->params()->fromQuery('layout') == 'false') {
         $viewModel->setTerminal(true);
     }
     if ($this->getRequest()->isPost()) {
         $form->setData($this->getRequest()->getPost());
         $address = new Book();
         if ($form->isValid()) {
             $address->exchangeArray((array) $this->getRequest()->getPost());
             $address->setCreatedById($this->user()->getUser()->getId());
             $addMapper->saveAddress($address);
             $this->redirect()->toUrl('/profile');
         }
     }
     $viewModel->setVariable('form', $form);
     return $viewModel;
 }