Ejemplo n.º 1
0
 /**
  * (non-PHPdoc)
  * @see \Micro\Model\DatabaseAbstract::save()
  */
 public function save(EntityInterface $entity)
 {
     try {
         $this->beginTransaction();
         $test = strip_tags($entity->getDescription());
         if (empty($test)) {
             $entity->setDescription(null);
         }
         if ($entity->getRegisterDate()) {
             $date = new \DateTime($entity->getRegisterDate());
             $entity->setRegisterDate($date->format('Y-m-d'));
             $entity->setReNewDate($date->modify('+10 years')->format('Y-m-d'));
         }
         if ($entity->getRequestDate()) {
             $date = new \DateTime($entity->getRequestDate());
             $entity->setRequestDate($date->format('Y-m-d'));
         }
         /*  if (!$entity->getStatusId() || !$entity->getStatusDate()) {
                 $entity->setStatusId(null);
                 $entity->setStatusDate(null);
                 $entity->setStatusNote(null);
             } */
         if ($entity->getStatusDate()) {
             $date = new \DateTime($entity->getStatusDate());
             $entity->setStatusDate($date->format('Y-m-d'));
         }
         /* if ($entity->getPrice() <= 0 || !$entity->getPriceDate()) {
                $entity->setPrice(null);
                $entity->setPriceDate(null);
                $entity->setPriceComment(null);
            } */
         if ($entity->getPriceDate()) {
             $date = new \DateTime($entity->getPriceDate());
             $entity->setPriceDate($date->format('Y-m-d'));
         }
         if ($entity->getReNewDate()) {
             $date = new \DateTime($entity->getReNewDate());
             $entity->setReNewDate($date->format('Y-m-d'));
         }
         $result = parent::save($entity);
         $this->saveStatus($entity);
         $this->savePrices($entity);
         $this->saveImage($entity);
         /**
          * @todo FIX me
          */
         $this->getTable()->getAdapter()->query('
             UPDATE NomCountries
             SET countBrands = (SELECT COUNT(1) FROM Brands WHERE Brands.countryId = NomCountries.id)
         ');
         $this->commit();
     } catch (\Exception $e) {
         $this->rollback();
         throw $e;
     }
     return $result;
 }