Completed
Push — master ( 91fdab...75a7b9 )
by
unknown
13: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
16
/**
17
 * The AdminList configurator for the AbstractArticlePage
18
 */
19
abstract class AbstractArticlePageAdminListConfigurator extends AbstractDoctrineORMAdminListConfigurator
20
{
21
    /**
22
     * @var string
23
     */
24
    protected $locale;
25
26
    /**
27
     * @var string
28
     */
29
    protected $permission;
30
31
    /**
32
     * @param EntityManager $em         The entity manager
33
     * @param AclHelper     $aclHelper  The ACL helper
34
     * @param string        $locale     The current locale
35
     * @param string        $permission The permission
36
     */
37 View Code Duplication
    public function __construct(EntityManager $em, AclHelper $aclHelper, $locale, $permission)
38
    {
39
        parent::__construct($em, $aclHelper);
40
        $this->locale = $locale;
41
        $this->setPermissionDefinition(
42
            new PermissionDefinition(array($permission), 'Kunstmaan\NodeBundle\Entity\Node', 'n')
43
        );
44
    }
45
46
    /**
47
     * Return current bundle name.
48
     *
49
     * @return string
50
     */
51
    public function getBundleName()
52
    {
53
        return "KunstmaanArticleBundle";
54
    }
55
56
    /**
57
     * Return current entity name.
58
     *
59
     * @return string
60
     */
61
    public function getEntityName()
62
    {
63
        return "AbstractArticlePage";
64
    }
65
66
    /**
67
     * Configure filters
68
     */
69 View Code Duplication
    public function buildFilters()
70
    {
71
        $this->addFilter('title', new StringFilterType('title'), 'article.page.list.filter.title')
72
            ->addFilter('online', new BooleanFilterType('online'), 'article.page.list.filter.online')
73
            ->addFilter('created', new DateFilterType('created', 'nv'), 'article.page.list.filter.created_at')
74
            ->addFilter('updated', new DateFilterType('updated', 'nv'), 'article.page.list.filter.updated_at');
75
    }
76
77
    /**
78
     * Configure the visible columns
79
     */
80 View Code Duplication
    public function buildFields()
81
    {
82
        $this->addField('title', 'article.page.list.header.title', true, 'KunstmaanNodeBundle:Admin:title.html.twig')
83
            ->addField('created', 'article.page.list.header.created_at', true)
84
            ->addField('updated', 'article.page.list.header.updated_at', true)
85
            ->addField('online', 'article.page.list.header.online', true, 'KunstmaanNodeBundle:Admin:online.html.twig');
86
    }
87
88
    /**
89
     * @return QueryBuilder
90
     */
91
    protected function getQueryBuilder()
92
    {
93
        $queryBuilder = $this->em
94
            ->getRepository('KunstmaanNodeBundle:NodeTranslation')
95
            ->createQueryBuilder('b');
96
97
        return $queryBuilder;
98
    }
99
100
    /**
101
     * @param QueryBuilder $queryBuilder The query builder
102
     */
103
    public function adaptQueryBuilder(QueryBuilder $queryBuilder)
104
    {
105
        parent::adaptQueryBuilder($queryBuilder);
106
107
        $queryBuilder->innerJoin('b.node', 'n', 'WITH', 'b.node = n.id');
108
        $queryBuilder->innerJoin('b.nodeVersions', 'nv', 'WITH', 'b.publicNodeVersion = nv.id');
109
        $queryBuilder->andWhere('b.lang = :lang');
110
        $queryBuilder->andWhere('n.deleted = 0');
111
        $queryBuilder->andWhere('n.refEntityName = :class');
112
        $queryBuilder->addOrderBy("b.updated", "DESC");
113
        $queryBuilder->setParameter('lang', $this->locale);
114
    }
115
116
    /**
117
     * @param mixed $item
118
     *
119
     * @return array
120
     */
121 View Code Duplication
    public function getEditUrlFor($item)
122
    {
123
        /* @var Node $node */
124
        $node = $item->getNode();
125
126
        return array(
127
            'path'   => 'KunstmaanNodeBundle_nodes_edit',
128
            'params' => array('id' => $node->getId())
129
        );
130
    }
131
132
    /**
133
     * Get the delete url for the given $item
134
     *
135
     * @param object $item
136
     *
137
     * @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...
138
     */
139
    public function getDeleteUrlFor($item)
140
    {
141
        /* @var Node $node */
142
        $node = $item->getNode();
143
144
        return array(
145
            'path'   => 'KunstmaanNodeBundle_nodes_delete',
146
            'params' => array('id' => $node->getId())
147
        );
148
    }
149
150
    /**
151
     * Returns the OverviewPage of these articles
152
     *
153
     * @return AbstractArticleOverviewPage
154
     */
155
    public function getOverviewPage()
156
    {
157
        $repository = $this->getOverviewPageRepository();
158
        $pages = $repository->findActiveOverviewPages();
159
160
        if (isset($pages) && count($pages) > 0) {
161
            return $pages[0];
162
        }
163
164
        return null;
165
    }
166
167
    /**
168
     * Returns all overview pages
169
     * @return mixed
170
     */
171
    public function getOverviewPages()
172
    {
173
        return $this->getOverviewPageRepository()->findActiveOverviewPages();
174
    }
175
176
    /**
177
     * @return string
178
     */
179
    public function getListTemplate()
180
    {
181
        return 'KunstmaanArticleBundle:AbstractArticlePageAdminList:list.html.twig';
182
    }
183
184
    /**
185
     * Returns the full entity class name
186
     * @return string
187
     */
188
    public function getEntityClassName()
189
    {
190
        return $this->em->getRepository($this->getRepositoryName())->getClassName();
191
    }
192
193
    /**
194
     * @return \Doctrine\ORM\EntityRepository
195
     */
196
    abstract public function getOverviewPageRepository();
197
}
198