Inheritance: extends Application\Mvc\Model\Model
Esempio n. 1
0
 public function initialize()
 {
     $type = new Select('type_id', Type::cachedListArray(['key' => 'id']));
     $type->setLabel('Type of Publication');
     $this->add($type);
     $title = new Text('title', ['required' => true]);
     $title->addValidator(new PresenceOf(['message' => 'Title can not be empty']));
     $title->setLabel('Title');
     $this->add($title);
     $slug = new Text('slug');
     $slug->setLabel('Slug');
     $this->add($slug);
     $date = new Text('date');
     $date->setLabel('Publication Date');
     $this->add($date);
     $text = new TextArea('text');
     $text->setLabel('Text');
     $this->add($text);
     $meta_title = new Text('meta_title', ['required' => true]);
     $meta_title->setLabel('meta-title');
     $this->add($meta_title);
     $meta_description = new TextArea('meta_description', ['style' => 'height:4em; min-height: inherit']);
     $meta_description->setLabel('meta-description');
     $this->add($meta_description);
     $meta_keywords = new TextArea('meta_keywords', ['style' => 'height:4em; min-height: inherit']);
     $meta_keywords->setLabel('meta-keywords');
     $this->add($meta_keywords);
     $preview_inner = new Check('preview_inner');
     $preview_inner->setLabel('Show preview image inside publication');
     $this->add($preview_inner);
     $image = new Image('preview_src');
     $image->setLabel('Thumbnail Image');
     $this->add($image);
 }
Esempio n. 2
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);
 }
 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);
 }
Esempio n. 4
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);
 }
Esempio n. 5
0
 public function init($router)
 {
     $types_keys = array_keys(Type::types());
     $types_regex = '(' . implode('|', $types_keys) . ')';
     $router->add('/publication/admin/{type:' . $types_regex . '}', array('module' => 'publication', 'controller' => 'admin', 'action' => 'index'))->setName('publications_admin');
     $router->add('/publication/admin/{type:' . $types_regex . '}/([a-zA-Z0-9_]+)', array('module' => 'publication', 'controller' => 'admin', 'action' => 2))->setName('publications_admin_action');
     $router->addML('/{type:' . $types_regex . '}', array('module' => 'publication', 'controller' => 'index', 'action' => 'index'), 'publications');
     $router->addML('/{type:' . $types_regex . '}/{slug:[a-zA-Z0-9_-]+}.html', array('module' => 'publication', 'controller' => 'index', 'action' => 'publication'), 'publication');
     return $router;
 }
Esempio n. 6
0
 public function deleteAction($id)
 {
     $model = Type::findFirst($id);
     $count = Type::count();
     if ($count == 1) {
         $this->flash->error($this->helper->at('Can not Delete the last Publication Type'));
         return;
     }
     if ($this->request->isPost()) {
         $model->delete();
         $this->redirect($this->url->get() . 'publication/type');
     }
     $this->view->model = $model;
     $this->helper->title($this->helper->at('Delete Type'));
 }
Esempio n. 7
0
 public function getTypeSlug()
 {
     if ($this->type_id) {
         $types = Type::cachedListArray(['key' => 'id', 'value' => 'slug']);
         if (array_key_exists($this->type_id, $types)) {
             return $types[$this->type_id];
         }
     }
 }
Esempio n. 8
0
 public function getTypeDisplayDate()
 {
     if ($this->type_id) {
         $types = Type::cachedListArray(['key' => 'id', 'value' => 'display_date']);
         if (array_key_exists($this->type_id, $types)) {
             return $types[$this->type_id];
         }
     }
 }