예제 #1
0
 public function profileAction()
 {
     $form = new Form(module_path('UserManagement', 'Resources/forms/admin/profile.php'));
     $form->username->setValue(identity()->getUsername());
     if ($this->request->isPost()) {
         $data = $this->request->getPost();
         if (isset($data['btnBack'])) {
             return new RedirectResponse(route());
         }
         if ($form->isValid($data)) {
             $usersModel = new Users();
             $user = $usersModel->find(identity()->getId());
             if ($user && $data['password']) {
                 $user->password = Security::hash($data['password']);
                 $usersModel->save($user);
             }
             $redirect = new RedirectResponse(route());
             return $redirect->withFlash();
         }
     }
     return new View('admin/index/profile', ['form' => $form]);
 }
예제 #2
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);
 }
예제 #3
0
 /**
  * Delete selected status from history
  * @return RedirectResponse
  */
 public function deleteStatusAction()
 {
     $id = (int) $this->request->getParam('id');
     $brandId = (int) $this->request->getParam('brandId');
     $rel = new \Brands\Model\Table\BrandsStatusesRel();
     $row = $rel->find($id)->current();
     if ($row !== null) {
         $row->delete();
         $this->getModel()->fixLastStatus($brandId);
     }
     $redirect = new RedirectResponse(route(null, array('action' => 'edit', 'id' => $brandId, 'brandId' => null)));
     $redirect->withFlash(sprintf('Запис %s беше изтрит', $id));
     return $redirect;
 }
예제 #4
0
파일: Crud.php 프로젝트: control-corp/micro
 /**
  * Activate item Action
  * @param number $active
  */
 public function activateAction($active = 1)
 {
     $id = (int) $this->request->getParam('id');
     $ids = $this->request->getParam('ids', []);
     if ($id) {
         $ids = array($id);
     }
     $ids = array_filter($ids);
     $affected = 0;
     if (!empty($ids)) {
         $model = $this->getModel();
         $model->addWhere('id', $ids);
         $items = $model->getItems();
         foreach ($items as $item) {
             try {
                 $affected += $model->activate($item, $active);
             } catch (\Exception $e) {
             }
         }
     }
     $redirectResponse = new RedirectResponse(route(\null, ['action' => 'index', 'id' => \null, 'ids' => \null]));
     return $redirectResponse->withFlash(sprintf('Информацията е записана. Бяха %s %d запис(а)', $active ? 'активирани' : 'деактивирани', $affected));
 }