示例#1
0
 public function afterInitialization()
 {
     parent::afterInitialization();
     $this->container->dispatcher->addListener('publiccontroller.render.before', function ($event) {
         $page = $event->getParams()->pageData['pageData'];
         if ($page instanceof \App\Models\Sections) {
             $path = $page->path;
             $url = $event->getContainer()->router->pathFor('page.s' . $page->id);
         }
         if ($page instanceof \App\Models\Pages && $page->category_id > 0) {
             $path = ModelsFactory::getModel('sections')->find($page->category_id)['path'];
             $path .= $page->category_id;
             $url = $event->getContainer()->router->pathFor('page.sp' . $page->category_id, ['pageCode' => $page->code]);
         }
         if ($page instanceof \App\Models\Pages && $page->category_id <= 0) {
             $path = '0' . \App\Models\Sections::PATH_DELIMITER;
             //$url = $event->getContainer()->router->pathFor('page.'.$page->id);
         }
         $bc = new BreadcrumbsBuilder($path);
         if (true) {
             $bc->parsePath()->addLastItem($url, $page->name);
         }
         $event->getParams()->pageData['breadcrumbs'] = $bc;
     });
 }
示例#2
0
 public function makeUrls()
 {
     if ($this->path) {
         $this->parsePath();
     }
     if ($this->arItems) {
         $items = ModelsFactory::getModel('sections')->find($this->arItems)->keyBy('id');
         $this->breadcrumbs = '<ol class="breadcrumb">';
         $cnt = count($this->arItems);
         for ($i = 1; $i <= $cnt; $i++) {
             $item = $this->arItems[$i];
             if ($item === "") {
                 continue;
             }
             $url = '/';
             $name = 'Главная';
             if ($item > 0) {
                 $url = $GLOBALS['app']->getContainer()->router->pathFor('page.s' . $item);
                 $name = $items[$item]->name;
             }
             $this->breadcrumbs .= '<li><a href="' . $url . '">' . $name . '</a></li>';
         }
         if (!$this->activeLastItem && $this->addCurrentItem) {
             $this->breadcrumbs .= '<li class="active">' . $this->arLastItem['name'] . '</li>';
         }
         if ($this->activeLastItem && $this->addCurrentItem) {
             $this->breadcrumbs .= '<li><a href="' . $this->arLastItem['url'] . '">' . $this->arLastItem['name'] . '</a></li>';
         }
         $this->breadcrumbs .= '</ol>';
     }
     $this->isBuild = true;
 }
示例#3
0
 public static function getPageWithRequest(Request $req)
 {
     $pageId = self::getPageId($req->getAttribute('route')->getName());
     if ($pageId > 0) {
         return ModelsFactory::getModel('pages')->find($pageId);
     }
     return new \stdClass();
 }
示例#4
0
 public function doDelete(request $req, $res, $args)
 {
     $this->initRoute($req, $res);
     $model = ModelsFactory::getModelWithRequest($req);
     $model = $model->find($args['id']);
     $model->delete();
     $this->flash->addMessage('success', $this->controllerName . ' success deleted!');
     return $res->withStatus(301)->withHeader('Location', $this->router->pathFor('list.' . $this->controllerName));
 }
 protected function storeParams($value)
 {
     $u_id = Session::get('user')['id'];
     $model = ModelsFactory::getModel('UserViewsSettings');
     $result = $model->where('user_id', $u_id)->where('group', $this->groupName)->where('code', $this->variableName)->first();
     if (!$result) {
         $result = ModelsFactory::getModel('UserViewsSettings', ['user_id' => $u_id, 'group' => $this->groupName, 'code' => $this->variableName]);
         $result->user_id = $u_id;
     }
     $result->value = $value;
     $result->save();
     return $result;
 }
示例#6
0
 public function index($req, $res)
 {
     $this->controllerName = $req->getAttribute('route')->getName();
     $this->resourse = false;
     $this->initRoute($req, $res);
     $this->data['h1'] = 'Dashboard';
     $this->data['cnt'] = new \stdClass();
     $this->data['cnt']->pages = ModelsFactory::getModel('pages')->count();
     $this->data['cnt']->users = ModelsFactory::getModel('users')->count();
     $this->data['cnt']->options = ModelsFactory::getModel('options')->count();
     if ($this->containerSlim->get('db')->schema()->hasTable('sections')) {
         $this->data['cnt']->sections = ModelsFactory::getModel('sections')->count();
     }
     $this->view->render($res, 'admin\\dashboard.twig', $this->data);
 }
示例#7
0
 /**
  * @param request $req
  * @param $res
  * @param $args
  * @return mixed
  */
 public function edit(request $req, $res, $args)
 {
     $this->initRoute($req, $res);
     $model = ModelsFactory::getModelWithRequest($req);
     $this->data['fields'] = $this->getFields($model->getColumnsNames(), ['id']);
     $this->data['fieldsValues'] = $model->find($args['id']);
     $this->data['type_link'] = $this->data['save_link'];
     if ($this->data['fieldsValues']['frozen'] && (!$this->containerSlim->systemOptions->isDevMode() && $this->data['fieldsValues']['code'] != 'develop_mode')) {
         $this->flash->addMessage('errors', $this->controllerName . ' this value not editable, set developers mode.');
         return $res->withStatus(302)->withHeader('Location', $this->router->pathFor('list.' . $this->controllerName));
     }
     $builder = new BuildFields();
     $builder->setFields($model->getColumnsNames())->addJsonShema($model->getAnnotations());
     $builder->build();
     $builder->setType('id', 'hidden');
     $builder->setType('options_group_id', 'select');
     $builder->setType('value', $this->data['fieldsValues']->type);
     if (in_array($this->data['fieldsValues']->type, ['select', 'multiselect', 'checkbox', 'radio']) && $this->data['fieldsValues']->values) {
         $builder->getField('value')->values = json_decode($this->data['fieldsValues']->values);
     }
     $model = ModelsFactory::getModel('GroupOptions');
     foreach ($model->where('active', 1)->get() as $item) {
         $builder->getField('options_group_id')->values[$item->id] = $item->name;
     }
     foreach ($this->data['fields'] as $name) {
         $builder->getField($name)->setValue($this->data['fieldsValues']->{$name});
     }
     if ($this->containerSlim->systemOptions->isHideFunctionality()) {
         $builder->getField('values')->noVisible();
         $builder->getField('type')->noVisible();
         $builder->getField('frozen')->noVisible();
         $builder->getField('code')->noVisible();
     }
     if ($this->containerSlim->systemOptions->isDevMode() && !$this->data['fieldsValues']->frozen) {
         $builder->getField('values')->noVisible(false);
         $builder->getField('type')->noVisible(false);
     }
     $this->data['ttt'] = $builder->getAll();
     $this->render('admin\\addTables.twig');
 }
示例#8
0
 protected function initRoute($req, $res)
 {
     $this->request = $req;
     $this->response = $res;
     $s = $req->getAttribute('route')->getName();
     $this->data['current_route_name'] = $s;
     $this->containerSlim->get('logger')->addInfo("Run admin page: ", [Session::get('user')['login']]);
     $this->containerSlim->get('logger')->addInfo("Get route: ", [$s]);
     $model = ModelsFactory::getModel('UserViewsSettings');
     $result = $model->where('user_id', Session::get('user')['id'])->where('group', 'last.page.' . basename($req->getUri()->getPath()))->where('code', 'page')->first();
     if ($result) {
         $current_page = $result->value;
     }
     Paginator::currentPageResolver(function () use($current_page) {
         return $current_page;
     });
     $result = $model->where('user_id', Session::get('user')['id'])->where('group', 'items.perpage.' . basename($req->getUri()->getPath()))->where('code', 'count_page')->first();
     if ($result) {
         $this->pagecount = $result->value;
         $this->data['page_count'] = $this->pagecount;
     }
     $result = $model->where('user_id', Session::get('user')['id'])->where('group', 'order.type.' . basename($req->getUri()->getPath()))->where('code', 'order_by')->first();
     $this->pageOrderBy = "id";
     if ($result) {
         $this->pageOrderBy = $result->value;
     }
     $this->data['page_order_by'] = $this->pageOrderBy;
     $result = $model->where('user_id', Session::get('user')['id'])->where('group', 'order.type.' . basename($req->getUri()->getPath()))->where('code', 'order_type')->first();
     $this->pageOrderType = "asc";
     if ($result) {
         $this->pageOrderType = $result->value;
     }
     $this->data['page_order_type'] = $this->pageOrderType;
     if (!$this->controllerName) {
         $this->controllerName = substr($s, strpos($s, '.') + 1);
     }
     $this->init();
     $this->csrf($req);
 }
示例#9
0
 public function afterInitialization()
 {
     parent::afterInitialization();
     $this->adminPanelRouteRegister();
     $this->menuCreator();
     $this->container->dispatcher->addListener('basecontroller.render.before', function ($event) {
         $arItems = $this->findFieldValues($event);
         if (!$arItems) {
             return true;
         }
         $model = ModelsFactory::getModel('sections');
         $arRes = $model->where('active', 1)->get();
         $data = [];
         foreach ($arRes as $item) {
             if (($arItems['parent_id'] || null === $arItems['parent_id']) && $item->id != $event->getParams()['fieldsValues']->id) {
                 $data[$item->id] = $item->name;
             }
         }
         foreach ($arItems as $name => $values) {
             $event->getParams()['ttt'][$name]->values = $values + $data;
         }
     });
 }