Exemple #1
0
 public function indexAction()
 {
     if (($response = parent::indexAction()) instanceof Response) {
         return $response;
     }
     $form = new Form(module_path('Brands', '/Resources/forms/admin/expired-filters.php'));
     $form->populate($this->view->filters);
     $this->view->assign('form', $form);
 }
Exemple #2
0
 public function indexAction()
 {
     if (($response = parent::indexAction()) instanceof Response) {
         return $response;
     }
     $form = new Form(package_path('Designs', 'Resources/forms/admin/index-filters.php'));
     $form->populate($this->view->filters);
     $this->view->assign('form', $form);
 }
Exemple #3
0
 /**
  * @param EntityInterface $entity
  * @return RedirectResponse|View
  */
 public function addAction(EntityInterface $entity = \null)
 {
     $module = $this->request->getParam('module');
     $controller = $this->request->getParam('controller');
     $model = $this->getModel();
     if ($entity === \null) {
         $entity = $model->createEntity();
     }
     $form = new Form(module_path(ucfirst(Utils::camelize($module)), '/Resources/forms/' . ($this->scope ? $this->scope . '/' : '') . $controller . '-add.php'));
     $form->populate($entity->toArray());
     // hook
     $this->prepareForm($form, $entity);
     if ($this->request->isPost()) {
         $post = $this->request->getPost();
         if (isset($post['btnBack'])) {
             return new RedirectResponse(route(\null, ['action' => 'index', 'id' => \null]));
         }
         $post = Utils::arrayMapRecursive('trim', $post);
         // hook
         $this->modifyPost($form, $entity, $post);
         // hook
         $this->preValidate($form, $entity, $post);
         $form->isValid($post);
         // hook
         $this->postValidate($form, $entity, $post);
         if (!$form->hasErrors()) {
             if (!isset($post['languageId']) && $this->container->has('language') && ($language = $this->container->get('language')) instanceof LanguageInterface) {
                 $post['languageId'] = $language->getId();
             }
             try {
                 $post = Utils::arrayMapRecursive('trim', $post, true);
                 // hook
                 $this->modifyData($post);
                 $entity->setFromArray($post);
                 // hook
                 $this->modifyEntity($entity);
                 $model->save($entity);
                 if (isset($post['btnApply'])) {
                     $redirectResponse = new RedirectResponse(route(\null, ['action' => 'edit', 'id' => $entity[$model->getIdentifier()]]));
                 } else {
                     $redirectResponse = new RedirectResponse(route(\null, ['action' => 'index', 'id' => \null]));
                 }
                 return $redirectResponse->withFlash('Информацията е записана');
             } catch (\Exception $e) {
                 if ($entity[$model->getIdentifier()]) {
                     $redirectResponse = new RedirectResponse(route(\null, ['action' => 'edit', 'id' => $entity[$model->getIdentifier()]]));
                 } else {
                     $redirectResponse = new RedirectResponse(route(\null, ['action' => 'add', 'id' => \null]));
                 }
                 return $redirectResponse->withFlash(env('development') ? $e->getMessage() : 'Възникна грешка. Опитайте по-късно', 'danger');
             }
         }
     }
     $this->view->setTemplate(($this->scope ? $this->scope . '/' : '') . $controller . '/add');
     return $this->view->assign(['form' => $form, 'item' => $entity]);
 }
Exemple #4
0
 public function loginAction()
 {
     $form = new Form(module_path('UserManagement', 'Resources/forms/admin/login.php'));
     if ($this->request->isPost()) {
         $data = $this->request->getPost();
         if ($form->isValid($data)) {
             $usersModel = new Users();
             if ($usersModel->login($data['username'], $data['password'])) {
                 if (($backTo = $this->request->getParam('backTo')) !== \null) {
                     return new RedirectResponse(urldecode($backTo));
                 } else {
                     return new RedirectResponse(route('admin', [], \true));
                 }
             } else {
                 $form->password->addError('Невалидни данни');
             }
         }
     }
     return ['form' => $form];
 }
Exemple #5
0
 /**
  * (non-PHPdoc)
  * @see \Light\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\Pages();
         $where = array('alias = ?' => $data['alias']);
         if ($item['id']) {
             $where['id <> ?'] = $item['id'];
         }
         if ($m->fetchRow($where)) {
             $form->alias->addError('Псевдонимът се използва');
             $form->markAsError();
         }
     }
 }
Exemple #6
0
 /**
  * (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();
     }
 }
Exemple #7
0
 public function wizzardAction()
 {
     $form = new Form(package_path('Brands', 'Resources/forms/admin/wizzard.php'));
     if ($this->request->isPost()) {
         $post = $this->request->getPost();
         $post = Utils::arrayMapRecursive('trim', $post);
         if (isset($post['btnBack'])) {
             return new RedirectResponse(route(\null, ['action' => 'index', 'id' => \null]));
         }
         $form->isValid($post);
         if (isset($post['name']) && $post['name'] && isset($post['countryId']) && $post['countryId']) {
             $m = new \Brands\Model\Table\Brands();
             foreach ($post['countryId'] as $countryId) {
                 $where = array('name = ?' => $post['name'], 'countryId = ?' => $countryId, 'typeId = ?' => $post['typeId']);
                 if ($m->fetchRow($where)) {
                     $form->countryId->addError('Тази марка и тип съществува за някои от избраните държави');
                     $form->markAsError();
                     break;
                 }
             }
         }
         if (!$form->hasErrors()) {
             $redirectResponse = new RedirectResponse(route(\null, ['action' => 'index', 'id' => \null]));
             try {
                 $post = Utils::arrayMapRecursive('trim', $post, true);
                 $this->getModel()->multipleInsert($post);
                 return $redirectResponse->withFlash('Информацията е записана');
             } catch (\Exception $e) {
                 return $redirectResponse->withFlash($e->getMessage(), 'danger');
             }
         }
     }
     $this->view->assign('form', $form);
 }
Exemple #8
0
 public function addItemAction()
 {
     $menuId = $this->request->getParam('menuId');
     $id = $this->request->getParam('id');
     $menu = $this->getModel()->find((int) $menuId);
     if ($menu === null) {
         return new RedirectResponse(route(\null, array('action' => 'index', 'menuId' => \null)));
     }
     $model = new Model\Items();
     if ($id) {
         $item = $model->find((int) $id);
         if ($item === null) {
             return new RedirectResponse(route(\null, array('action' => 'items', 'id' => \null)));
         }
     } else {
         $item = $model->createEntity();
     }
     if ($item instanceof Model\Entity\Item) {
     }
     $form = new Form(package_path('Navigation', 'Resources/forms/admin/index-add-item.php'));
     $tree = new Helper\Tree($menu->getAlias());
     $form->parentId->setMultiOptions($tree->flat($tree->getTree(null), '---', array((int) $id)));
     $form->populate($item->toArray());
     if ($this->request->isPost()) {
         $post = $this->request->getPost();
         if (isset($post['btnBack'])) {
             return new RedirectResponse(route(\null, array('action' => 'items', 'id' => \null)));
         }
         $form->isValid($post);
         if (isset($post['alias']) && $post['alias']) {
             $m = new Model\Table\Items();
             $where = array('alias = ?' => $post['alias']);
             if ($item->getId()) {
                 $where['id <> ?'] = $item->getId();
             }
             if ($m->fetchRow($where)) {
                 $form->alias->addError('Псевдонимът се използва');
                 $form->markAsError();
             }
         }
         if (!$form->hasErrors()) {
             if (isset($post['routeData'])) {
                 $routeData = $post['routeData'];
             } else {
                 $routeData = array();
             }
             foreach ($routeData as $k => $v) {
                 if (empty($v)) {
                     unset($routeData[$k]);
                 }
             }
             $post = Utils::arrayMapRecursive('trim', $post, true);
             $item->setFromArray($post);
             $item->setMenuId($menuId);
             if ($item->getRoute() === \null) {
                 if ($item->getUrl() === \null) {
                     $item->setUrl('#');
                 }
             } else {
                 $item->setUrl(\null);
             }
             if ($item->getRoute()) {
                 if (($navigationHelper = $this->getNavigationHelper($item->getRoute())) !== \null) {
                     if (method_exists($navigationHelper, 'decode')) {
                         $navigationHelper->decode($routeData, $item);
                     }
                 }
             }
             $item->setRouteData(empty($routeData) ? \null : json_encode($routeData));
             if ($item->getOrder() === \null) {
                 if ($item->getParentId()) {
                     $and = ' AND parentId = ' . (int) $item->getParentId();
                 } else {
                     $and = ' AND parentId IS NULL';
                 }
                 $item->setOrder($model->getTable()->getAdapter()->fetchOne('SELECT IFNULL(MAX(`order`), 0) + 1 FROM MenuItems WHERE menuId = ' . (int) $menuId . $and));
             }
             try {
                 $model->save($item);
                 if (isset($post['btnApply'])) {
                     $redirectResponse = new RedirectResponse(route(\null, ['action' => 'add-item', 'id' => $item->getId()]));
                 } else {
                     $redirectResponse = new RedirectResponse(route(\null, ['action' => 'items', 'id' => \null]));
                 }
                 return $redirectResponse->withFlash('Информацията е записана');
             } catch (\Exception $e) {
                 if ($item->getId()) {
                     $redirectResponse = new RedirectResponse(route(\null, ['action' => 'add-item', 'id' => $item->getId()]));
                 } else {
                     $redirectResponse = new RedirectResponse(route(\null, ['action' => 'items', 'id' => \null]));
                 }
                 return $redirectResponse->withFlash(env('development') ? $e->getMessage() : 'Възникна грешка. Опитайте по-късно', 'danger');
             }
         }
     }
     $this->view->assign('menu', $menu);
     $this->view->assign('item', $item);
     $this->view->assign('form', $form);
 }
Exemple #9
0
 public function brandsAction()
 {
     $filters = parent::handleFilters();
     if ($filters instanceof Response) {
         return $filters;
     }
     $form = new Form(package_path('Brands', 'Resources/forms/admin/reports-brands-filters.php'));
     $form->populate($filters);
     $brands = array();
     $brandImages = array();
     if (isset($filters['brandId'])) {
         $brandsModel = new Brands();
         $brandsModel->addWhere('name', $filters['brandId']);
         if (isset($filters['date']) && $filters['date']) {
             try {
                 $date = new \DateTime($filters['date']);
                 $statusDate = $date->format('Y-m-d');
                 //$brandsModel->addWhere(new Expr('statusDate <= "' . $brandsModel->getAdapter()->quote($statusDate) . '"'));
             } catch (\Exception $e) {
             }
         }
         $brandsRows = $brandsModel->getItems();
         foreach ($brandsRows as $brandRow) {
             if (!isset($brands[$brandRow['countryId']])) {
                 $brands[$brandRow['countryId']] = array();
             }
             $brands[$brandRow['countryId']][$brandRow['typeId']] = $brandRow;
             if (!isset($brandImages[$brandRow['typeId']])) {
                 if ($brandRow->getThumb()) {
                     $brandImages[$brandRow['typeId']] = array('path' => $brandRow->getThumb(), 'image' => 'uploads/brands/thumbs/' . $brandRow->getId() . '.' . pathinfo($brandRow->getImage(), PATHINFO_EXTENSION), 'real' => 'uploads/brands/' . $brandRow->getId() . '.' . pathinfo($brandRow->getImage(), PATHINFO_EXTENSION));
                 }
             }
         }
     }
     if (empty($brands)) {
         return ['form' => $form, 'brands' => $brands];
     }
     $currentCurrency = null;
     if (isset($filters['currency'])) {
         $currencyModel = new Currencies();
         $currentCurrency = $currencyModel->find((int) $filters['currency']);
     }
     $nomContinents = new Continents();
     $continents = $nomContinents->fetchCachedPairs(array('active' => 1), null, array('id' => 'ASC'));
     $nomTypes = new Types();
     $types = $nomTypes->fetchCachedPairs(['active' => 1], null, ['id' => 'ASC']);
     $nomCountries = new Countries();
     $nomCountries->addWhere('active', '1');
     $nomCountries->addOrder('name', 'ASC');
     $countriesRows = $nomCountries->getItems();
     $countries = array();
     $populations = array();
     foreach ($countriesRows as $countryRow) {
         if (empty($countryRow['continentId'])) {
             continue;
         }
         /**
          * Създаване на списъци от държави за континент
          */
         if (!isset($countries[$countryRow['continentId']])) {
             $countries[$countryRow['continentId']] = array();
         }
         $countries[$countryRow['continentId']][$countryRow['id']] = $countryRow;
         /**
          * Изчисляване на популацията за континент
          */
         if (!isset($populations[$countryRow['continentId']])) {
             $populations[$countryRow['continentId']] = 0;
         }
         $populations[$countryRow['continentId']] += $countryRow['population'];
     }
     $nomStatus = new Statuses();
     $statuses = $nomStatus->fetchCachedPairs();
     $nomStatus->resetSelect(true);
     $statusesColors = $nomStatus->fetchCachedPairs(null, array('id', 'color'));
     return ['form' => $form, 'continents' => $continents, 'populations' => $populations, 'types' => $types, 'countries' => $countries, 'brands' => $brands, 'brandImages' => $brandImages, 'statuses' => $statuses, 'statusesColors' => $statusesColors, 'filters' => $filters, 'currentCurrency' => $currentCurrency];
 }