getCachedBySlug() public static method

public static getCachedBySlug ( $slug )
Exemplo n.º 1
0
 public function addAction()
 {
     $this->view->pick(['admin/edit']);
     $form = new PublicationForm();
     $model = new Publication();
     $type = $this->dispatcher->getParam('type');
     if ($type) {
         $typeEntity = Type::getCachedBySlug($type);
         $form->get('type_id')->setDefault($typeEntity->getId());
         $this->view->type = $type;
     }
     if ($this->request->isPost()) {
         $post = $this->request->getPost();
         $form->bind($post, $model);
         if ($form->isValid()) {
             if ($model->create()) {
                 $form->bind($post, $model);
                 $model->updateFields($post);
                 if ($model->update()) {
                     $this->flash->success($this->helper->at('Publication created'));
                     return $this->redirect($this->url->get() . 'publication/admin/edit/' . $model->getId() . '?lang=' . LANG);
                 } else {
                     $this->flashErrors($model);
                 }
             } else {
                 $this->flashErrors($model);
             }
         } else {
             $this->flashErrors($form);
         }
     }
     $this->view->model = $model;
     $this->view->form = $form;
     $this->helper->title($this->helper->at('Create a publication'), true);
 }
Exemplo n.º 2
0
 public function indexAction()
 {
     $type = $this->dispatcher->getParam('type', 'string');
     $typeModel = Type::getCachedBySlug($type);
     if (!$typeModel) {
         throw new Exception("Publication hasn't type = '{$type}''");
     }
     $typeLimit = $typeModel->getLimit() ? $typeModel->getLimit() : 10;
     $limit = $this->request->getQuery('limit', 'string', $typeLimit);
     if ($limit != 'all') {
         $paginatorLimit = (int) $limit;
     } else {
         $paginatorLimit = 9999;
     }
     $page = $this->request->getQuery('page', 'int', 1);
     /*$publications = Publication::find(array(
           "type_id = {$typeModel->getId()}",
           "order" => "date DESC",
       ));*/
     $publicationHelper = new PublicationHelper();
     $fields = $publicationHelper->translateFieldsSubQuery();
     $columns = ['p.*', 't_slug' => 't.slug'];
     $columns = array_merge($columns, $fields);
     $qb = $this->modelsManager->createBuilder()->columns($columns)->addFrom('Publication\\Model\\Publication', 'p')->leftJoin('Publication\\Model\\Type', null, 't')->andWhere('t.slug = :type:', ['type' => $type])->andWhere('p.date <= NOW()')->orderBy('p.date DESC');
     $paginator = new \Phalcon\Paginator\Adapter\QueryBuilder(["builder" => $qb, "limit" => $paginatorLimit, "page" => $page]);
     $this->view->paginate = $paginator->getPaginate();
     $this->helper->title()->append($typeModel->getHeadTitle());
     if ($page > 1) {
         $this->helper->title()->append($this->helper->translate('Страница №') . ' ' . $page);
     }
     $this->view->title = $typeModel->getTitle();
     $this->view->format = $typeModel->getFormat();
     $this->view->type = $type;
     $this->helper->menu->setActive($type);
 }
Exemplo n.º 3
0
 public function indexAction()
 {
     $type = $this->dispatcher->getParam('type', 'string');
     $typeModel = Type::getCachedBySlug($type);
     if (!$typeModel) {
         throw new Exception("Publication hasn't type = '{$type}''");
     }
     $typeLimit = $typeModel->getLimit() ? $typeModel->getLimit() : 10;
     $limit = $this->request->getQuery('limit', 'string', $typeLimit);
     if ($limit != 'all') {
         $paginatorLimit = (int) $limit;
     } else {
         $paginatorLimit = 9999;
     }
     $page = $this->request->getQuery('page', 'int', 1);
     $publications = Publication::find(array("type_id = {$typeModel->getId()}", "order" => "date DESC"));
     $paginator = new \Phalcon\Paginator\Adapter\Model(array("data" => $publications, "limit" => $paginatorLimit, "page" => $page));
     $this->view->paginate = $paginator->getPaginate();
     $this->helper->title()->append($typeModel->getHead_title());
     if ($page > 1) {
         $this->helper->title()->append($this->helper->translate('Страница №') . ' ' . $page);
     }
     $this->view->title = $typeModel->getTitle();
     $this->view->format = $typeModel->getFormat();
     $this->view->type = $type;
     $this->helper->menu->setActive($type);
 }