Skip to content

Commit

Permalink
v0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-torosh committed Nov 13, 2016
1 parent 2735018 commit dc5aa9c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
36 changes: 25 additions & 11 deletions app/modules/Publication/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,55 @@ class IndexController extends Controller

public function indexAction()
{
$type = $this->dispatcher->getParam('type', 'string');
$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);
$limit = $this->request->getQuery('limit', 'string', $typeLimit);
if ($limit != 'all') {
$paginatorLimit = (int) $limit;
$paginatorLimit = (int)$limit;
} else {
$paginatorLimit = 9999;
}
$page = $this->request->getQuery('page', 'int', 1);

$publications = Publication::find(array(
/*$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' => 'news'])
->andWhere('p.date <= NOW()')
->orderBy('p.date DESC');

$paginator = new \Phalcon\Paginator\Adapter\Model(array(
"data" => $publications,
$paginator = new \Phalcon\Paginator\Adapter\QueryBuilder([
"builder" => $qb,
"limit" => $paginatorLimit,
"page" => $page
));
"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->title = $typeModel->getTitle();
$this->view->format = $typeModel->getFormat();
$this->view->type = $type;
$this->view->type = $type;

$this->helper->menu->setActive($type);
}
Expand Down
10 changes: 5 additions & 5 deletions app/modules/Publication/views/index/format/grid.volt
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{% set image = helper.image([
'id': item.getId(),
'id': item.p.getId(),
'type': 'publication',
'width': 300,
'height': 240,
'strategy': 'a'
]) %}
{% set link = helper.langUrl(['for':'publication', 'type':item.getTypeSlug(), 'slug':item.getSlug()]) %}
{% set link = helper.langUrl(['for':'publication', 'type':item.t_slug, 'slug':item.p.getSlug()]) %}
{% if image.isExists() %}{% set imageExists = true %}{% else %}{% set imageExists = false %}{% endif %}
<div class="item">
{% if imageExists %}
<a class="image" href="{{ link }}">{{ image.imageHTML() }}</a>
{% endif %}
<div class="text">
<section class="date">{{ item.getDate('d.m.Y') }}</section>
<a href="{{ link }}" class="title">{{ item.getTitle() }}</a>
<section class="announce">{{ helper.announce(item.getText(), 300) }}</section>
<section class="date">{{ item.p.getDate('d.m.Y') }}</section>
<a href="{{ link }}" class="title">{{ item.title }}</a>
<section class="announce">{{ helper.announce(item.text, 300) }}</section>

<a href="{{ link }}" class="details">{{ helper.translate('Подробнее') }} &rarr;</a>
</div>
Expand Down
10 changes: 5 additions & 5 deletions app/modules/Publication/views/index/format/list.volt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{% set image = helper.image([
'id': item.getId(),
'id': item.p.getId(),
'type': 'publication',
'width': 300,
'strategy': 'w'
]) %}
{% set link = helper.langUrl(['for':'publication', 'type':item.getTypeSlug(), 'slug':item.getSlug()]) %}
{% set link = helper.langUrl(['for':'publication', 'type':item.t_slug, 'slug':item.p.getSlug()]) %}
{% if image.isExists() %}{% set imageExists = true %}{% else %}{% set imageExists = false %}{% endif %}
<div class="item{% if imageExists %} with-image{% endif %}">
{% if imageExists %}
<a class="image" href="{{ link }}">{{ image.imageHTML() }}</a>
{% endif %}
<div class="text">
<section class="date">{{ item.getDate('d.m.Y') }}</section>
<a href="{{ link }}" class="title">{{ item.getTitle() }}</a>
<section class="announce">{{ helper.announce(item.getText(), 300) }}</section>
<section class="date">{{ item.p.getDate('d.m.Y') }}</section>
<a href="{{ link }}" class="title">{{ item.title }}</a>
<section class="announce">{{ helper.announce(item.text, 300) }}</section>

<a href="{{ link }}" class="details">{{ helper.translate('Подробнее') }} &rarr;</a>
</div>
Expand Down

2 comments on commit dc5aa9c

@pletsky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app/modules/Publication/Controller/IndexController.php, line 46:
->andWhere('t.slug = :type:', ['type' => 'news'])

  • seems to return news even for articles or another custom p.type
    Possible fix:
    ->andWhere('t.slug = :type:', ['type' => $type])

@sergeyklay
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just send PR

Please sign in to comment.