Completed
Push — master ( 9b5821...aba493 )
by Ruud
307:53 queued 297:17
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 6 View Code Duplication
    public function __construct(EntityManager $em, AclHelper $aclHelper, $locale, $permission)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

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