ContentLoop::buildModelCriteria()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
/*************************************************************************************/
3
/*      This file is part of the Thelia package.                                     */
4
/*                                                                                   */
5
/*      Copyright (c) OpenStudio                                                     */
6
/*      email : [email protected]                                                       */
7
/*      web : http://www.thelia.net                                                  */
8
/*                                                                                   */
9
/*      For the full copyright and license information, please view the LICENSE.txt  */
10
/*      file that was distributed with this source code.                             */
11
/*************************************************************************************/
12
/*************************************************************************************/
13
14
namespace Dealer\Loop;
15
16
use Dealer\Model\Map\DealerContentTableMap;
17
use Propel\Runtime\ActiveQuery\Criteria;
18
use Propel\Runtime\ActiveQuery\Join;
19
use Thelia\Core\Template\Loop\Argument\Argument;
20
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
21
use Thelia\Core\Template\Loop\Content;
22
use Thelia\Model\Map\ContentTableMap;
23
24
/**
25
 * Class ContentLoop
26
 * @package Dealer\Loop
27
 */
28
class ContentLoop extends Content
29
{
30
    /**
31
     * @inheritDoc
32
     */
33
    protected function getArgDefinitions()
34
    {
35
        /** @var ArgumentCollection $arguments */
36
        $arguments = parent::getArgDefinitions();
37
38
        $arguments->addArgument(
39
            Argument::createIntListTypeArgument("dealer_id")
40
        );
41
42
        return $arguments;
43
    }
44
45
    public function buildModelCriteria()
46
    {
47
        $query = parent::buildModelCriteria();
48
49
        if (null != $id = $this->getDealerId()) {
50
            if (is_array($id)) {
51
                $id = implode(",", $id);
52
            }
53
54
            $dealerJoin = new Join(ContentTableMap::ID, DealerContentTableMap::CONTENT_ID, Criteria::LEFT_JOIN);
55
            $query
56
                ->addJoinObject($dealerJoin, "dealerJoin")
57
                ->where(DealerContentTableMap::DEALER_ID . " " . Criteria::IN . " (" . $id . ")");
58
        }
59
60
        return $query;
61
    }
62
}
63