Completed
Push — master ( ae5e03...0447ee )
by Jeroen
10:35 queued 04:37
created

AbstractArticlePageAdminListConfigurator.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\ArticleBundle\AdminList;
4
5
use Doctrine\ORM\EntityManager;
6
use Doctrine\ORM\QueryBuilder;
7
use Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper;
8
use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\PermissionDefinition;
9
use Kunstmaan\AdminListBundle\AdminList\Configurator\AbstractDoctrineORMAdminListConfigurator;
10
use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM\BooleanFilterType;
11
use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM\DateFilterType;
12
use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM\StringFilterType;
13
use Kunstmaan\ArticleBundle\Entity\AbstractArticleOverviewPage;
14
use Kunstmaan\NodeBundle\Entity\Node;
15
use Kunstmaan\NodeBundle\Entity\NodeTranslation;
16
17
/**
18
 * The AdminList configurator for the AbstractArticlePage
19
 */
20
abstract class AbstractArticlePageAdminListConfigurator extends AbstractDoctrineORMAdminListConfigurator
21
{
22
    /**
23
     * @var string
24
     */
25
    protected $locale;
26
27
    /**
28
     * @var string
29
     */
30
    protected $permission;
31
32
    /**
33
     * @param EntityManager $em         The entity manager
34
     * @param AclHelper     $aclHelper  The ACL helper
35
     * @param string        $locale     The current locale
36
     * @param string        $permission The permission
37
     */
38 6 View Code Duplication
    public function __construct(EntityManager $em, AclHelper $aclHelper, $locale, $permission)
39
    {
40 6
        parent::__construct($em, $aclHelper);
41 6
        $this->locale = $locale;
42 6
        $this->setPermissionDefinition(
43 6
            new PermissionDefinition(array($permission), 'Kunstmaan\NodeBundle\Entity\Node', 'n')
44
        );
45 6
    }
46
47
    /**
48
     * Return current bundle name.
49
     *
50
     * @return string
51
     */
52 2
    public function getBundleName()
53
    {
54 2
        return 'KunstmaanArticleBundle';
55
    }
56
57
    /**
58
     * Return current entity name.
59
     *
60
     * @return string
61
     */
62 2
    public function getEntityName()
63
    {
64 2
        return 'AbstractArticlePage';
65
    }
66
67
    /**
68
     * Configure filters
69
     */
70 1 View Code Duplication
    public function buildFilters()
71
    {
72 1
        $this->addFilter('title', new StringFilterType('title'), 'article.page.list.filter.title')
73 1
            ->addFilter('online', new BooleanFilterType('online'), 'article.page.list.filter.online')
74 1
            ->addFilter('created', new DateFilterType('created', 'nv'), 'article.page.list.filter.created_at')
75 1
            ->addFilter('updated', new DateFilterType('updated', 'nv'), 'article.page.list.filter.updated_at');
76 1
    }
77
78
    /**
79
     * Configure the visible columns
80
     */
81 1
    public function buildFields()
82
    {
83 1
        $this->addField('title', 'article.page.list.header.title', true, '@KunstmaanNode/Admin/title.html.twig')
84 1
            ->addField('created', 'article.page.list.header.created_at', true)
85 1
            ->addField('updated', 'article.page.list.header.updated_at', true)
86 1
            ->addField('online', 'article.page.list.header.online', true, '@KunstmaanNode/Admin/online.html.twig');
87 1
    }
88
89
    /**
90
     * @return QueryBuilder
91
     */
92 1
    protected function getQueryBuilder()
93
    {
94 1
        $queryBuilder = $this->em
95 1
            ->getRepository(NodeTranslation::class)
96 1
            ->createQueryBuilder('b');
97
98 1
        return $queryBuilder;
99
    }
100
101
    /**
102
     * @param QueryBuilder $queryBuilder The query builder
103
     */
104 1
    public function adaptQueryBuilder(QueryBuilder $queryBuilder)
105
    {
106 1
        parent::adaptQueryBuilder($queryBuilder);
107
108 1
        $queryBuilder->innerJoin('b.node', 'n', 'WITH', 'b.node = n.id');
109 1
        $queryBuilder->innerJoin('b.nodeVersions', 'nv', 'WITH', 'b.publicNodeVersion = nv.id');
110 1
        $queryBuilder->andWhere('b.lang = :lang');
111 1
        $queryBuilder->andWhere('n.deleted = 0');
112 1
        $queryBuilder->andWhere('n.refEntityName = :class');
113 1
        $queryBuilder->addOrderBy('b.updated', 'DESC');
114 1
        $queryBuilder->setParameter('lang', $this->locale);
115 1
    }
116
117
    /**
118
     * @param mixed $item
119
     *
120
     * @return array
121
     */
122 1 View Code Duplication
    public function getEditUrlFor($item)
123
    {
124
        /* @var Node $node */
125 1
        $node = $item->getNode();
126
127
        return array(
128 1
            'path' => 'KunstmaanNodeBundle_nodes_edit',
129 1
            'params' => array('id' => $node->getId()),
130
        );
131
    }
132
133
    /**
134
     * Get the delete url for the given $item
135
     *
136
     * @param object $item
137
     *
138
     * @return array
0 ignored issues
show
Consider making the return type a bit more specific; maybe use array<string,string|array<string,integer>>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
139
     */
140 1
    public function getDeleteUrlFor($item)
141
    {
142
        /* @var Node $node */
143 1
        $node = $item->getNode();
144
145
        return array(
146 1
            'path' => 'KunstmaanNodeBundle_nodes_delete',
147 1
            'params' => array('id' => $node->getId()),
148
        );
149
    }
150
151
    /**
152
     * Returns the OverviewPage of these articles
153
     *
154
     * @return AbstractArticleOverviewPage
155
     */
156 1
    public function getOverviewPage()
157
    {
158 1
        $repository = $this->getOverviewPageRepository();
159 1
        $pages = $repository->findActiveOverviewPages();
160
161 1
        if (isset($pages) && \count($pages) > 0) {
162 1
            return $pages[0];
163
        }
164
165 1
        return null;
166
    }
167
168
    /**
169
     * Returns all overview pages
170
     *
171
     * @return mixed
172
     */
173 1
    public function getOverviewPages()
174
    {
175 1
        return $this->getOverviewPageRepository()->findActiveOverviewPages();
176
    }
177
178
    /**
179
     * @return string
180
     */
181 1
    public function getListTemplate()
182
    {
183 1
        return '@KunstmaanArticle/AbstractArticlePageAdminList/list.html.twig';
184
    }
185
186
    /**
187
     * Returns the full entity class name
188
     *
189
     * @return string
190
     */
191 1
    public function getEntityClassName()
192
    {
193 1
        return $this->em->getRepository($this->getRepositoryName())->getClassName();
194
    }
195
196
    /**
197
     * @return \Doctrine\ORM\EntityRepository
198
     */
199
    abstract public function getOverviewPageRepository();
200
}
201