Example #1
0
 /**
  * (non-PHPdoc)
  * @see \Micro\Application\Controller\Crud::postValidate()
  */
 protected function postValidate(Form $form, EntityInterface $item, array $data)
 {
     if (isset($data['alias']) && $data['alias']) {
         $m = new Model\Table\Menu();
         $where = array('alias = ?' => $data['alias']);
         if ($item->getId()) {
             $where['id <> ?'] = $item->getId();
         }
         if ($m->fetchRow($where)) {
             $form->alias->addError('Псевдонимът се използва');
             $form->markAsError();
         }
     }
 }
Example #2
0
 /**
  * (non-PHPdoc)
  * @see \Micro\Application\Controller\Crud::postValidate()
  */
 protected function postValidate(Form $form, EntityInterface $item, array $data)
 {
     if (isset($data['description']) && $data['description']) {
         $test = strip_tags($data['description']);
         if (empty($test)) {
             $form->description->addError('Полето е задължително');
             $form->markAsError();
         }
     }
     if (isset($data['alias']) && $data['alias']) {
         $m = new Model\Table\Templates();
         $where = array('alias = ?' => $data['alias']);
         if ($item->getId()) {
             $where['id <> ?'] = $item->getId();
         }
         if ($m->fetchRow($where)) {
             $form->alias->addError('Псевдонимът се използва');
             $form->markAsError();
         }
     }
 }
Example #3
0
 protected function saveImage(EntityInterface $entity)
 {
     if (isset($_FILES['image'])) {
         if ($_FILES['image']['error'] === 0) {
             $name = $_FILES['image']['name'];
             $tmp_name = $_FILES['image']['tmp_name'];
             @unlink(static::getImagePath($entity->getId(), $name, true));
             if (!copy($tmp_name, static::getImagePath($entity->getId(), $name))) {
                 throw new \Exception('Файлът не може да се запише', 500);
             }
             $this->getTable()->update(array('image' => $name), array('id = ?' => $entity->getId()));
         }
     }
 }
Example #4
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->getDateStart()) {
             $date = new \DateTime($entity->getDateStart());
             $entity->setDateStart($date->format('Y-m-d'));
         }
         if ($entity->getDateEnd()) {
             $date = new \DateTime($entity->getDateEnd());
             $entity->setDateEnd($date->format('Y-m-d'));
         }
         $result = parent::save($entity);
         $this->commit();
     } catch (\Exception $e) {
         $this->rollback();
         throw $e;
     }
     return $result;
 }
Example #5
0
 /**
  * (non-PHPdoc)
  * @see \Light\Controller\Crud::modifyEntity()
  */
 protected function modifyEntity(EntityInterface $entity)
 {
     $entity->setClasses(implode(',', $entity->getClasses()));
 }
Example #6
0
 public function save(EntityInterface $entity)
 {
     $this->trigger('beforesave', compact('entity'));
     $data = $originalData = $entity->toArray();
     try {
         $this->beginTransaction();
         $data = array_merge($data, $this->saveToTable($this->table, $data));
         foreach ($this->table->getDependentTables() as $dependentTable) {
             $dependentTableInstance = $this->table->getDependentTableInstance($dependentTable);
             $reference = $dependentTableInstance->getReference(get_class($this->table));
             foreach ($data as $k => $v) {
                 $refColumnKey = array_search($k, $reference['refColumns']);
                 if ($refColumnKey !== \false) {
                     $data[$reference['columns'][$refColumnKey]] = $v;
                 }
             }
             $data = array_merge($data, $this->saveToTable($dependentTableInstance, $data));
         }
         $entity->setFromArray($data);
         $this->trigger('aftersave', compact('entity'));
         $this->commit();
     } catch (\Exception $e) {
         $this->rollBack();
         $entity->setFromArray($originalData);
         throw $e;
     }
     $this->removeCache();
     return $entity;
 }