Completed
Push — master ( f60ac0...8504d1 )
by Tim
06:02 queued 03:28
created

UrlRewriteRepository::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 0
cts 6
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Repositories\UrlRewriteRepository
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Repositories;
22
23
use TechDivision\Import\Repositories\AbstractRepository;
24
use TechDivision\Import\Utils\MemberNames;
25
26
/**
27
 * Repository implementation to load URL rewrite data.
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @copyright 2016 TechDivision GmbH <[email protected]>
31
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
 * @link      https://github.com/techdivision/import
33
 * @link      http://www.techdivision.com
34
 */
35
class UrlRewriteRepository extends AbstractRepository
36
{
37
38
    /**
39
     * The prepared statement to load the existing URL rewrites.
40
     *
41
     * @var \PDOStatement
42
     */
43
    protected $urlRewritesStmt;
44
45
    /**
46
     * Initializes the repository's prepared statements.
47
     *
48
     * @return void
49
     */
50
    public function init()
51
    {
52
53
        // load the utility class name
54
        $utilityClassName = $this->getUtilityClassName();
55
56
        // initialize the prepared statements
57
        $this->urlRewritesStmt = $this->getConnection()
58
                                      ->prepare($utilityClassName::URL_REWRITES_BY_ENTITY_TYPE_AND_ENTITY_ID);
59
    }
60
61
    /**
62
     * Return's an array with the URL rewrites for the passed entity type and ID.
63
     *
64
     * @param string  $entityType The entity type to load the URL rewrites for
65
     * @param integer $entityId   The entity ID to load the URL rewrites for
66
     *
67
     * @return array The URL rewrites
68
     */
69
    public function findAllByEntityTypeAndEntityId($entityType, $entityId)
70
    {
71
72
        // initialize the params
73
        $params = array(
74
            MemberNames::ENTITY_TYPE => $entityType,
75
            MemberNames::ENTITY_ID   => $entityId
76
        );
77
78
        // load and return the URL rewrites
79
        $this->urlRewritesStmt->execute($params);
80
        return $this->urlRewritesStmt->fetchAll(\PDO::FETCH_ASSOC);
81
    }
82
}
83