/** * (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(); } } }
/** * (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(); } } }
/** * (non-PHPdoc) * @see \Micro\Application\Controller\Crud::postValidate() */ protected function postValidate(Form $form, EntityInterface $item, array $data) { if (isset($data['name']) && $data['name'] && isset($data['countryId']) && $data['countryId']) { $m = new \Brands\Model\Table\Brands(); $where = array('name = ?' => $data['name'], 'countryId = ?' => $data['countryId'], 'typeId = ?' => $data['typeId']); if ($item->getId()) { $where['id <> ?'] = $item->getId(); } if ($m->fetchRow($where)) { $form->countryId->addError('Тази марка и тип съществува за тази държава'); $form->markAsError(); } } if ($data['statusId'] && !$data['statusDate']) { $form->statusDate->addError('Дата на статуса е задължителна'); $form->markAsError(); } if (!$data['statusId'] && $data['statusDate']) { $form->statusId->addError('Статус на марката е задължителен'); $form->markAsError(); } }
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 (!move_uploaded_file($tmp_name, static::getImagePath($entity->getId(), $name))) { throw new \Exception('Файлът не може да се запише', 500); } $this->getTable()->update(array('image' => $name), array('id = ?' => $entity->getId())); } } }
/** * (non-PHPdoc) * @see \Light\Controller\Crud::prepareForm() */ protected function prepareForm(Form $form, EntityInterface $item) { $classes = $item->getClasses(); if ($classes) { $form->classes->setValue(explode(',', $classes)); } $form->statusId->setValue(""); $form->statusDate->setValue(""); $form->statusNote->setValue(""); $form->price->setValue(""); if ($item->getId() && $item->getCountryId()) { $countriesModel = new Countries(); $country = $countriesModel->find((int) $item->getCountryId()); if ($country) { $form->price->setValue($country['price']); } } }