Completed
Push — master ( 85ac50...d70b30 )
by Tim
14s
created

SqlStatements::__clone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Link\Utils\SqlStatements
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-product-link
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\Link\Utils;
22
23
use TechDivision\Import\Utils\AbstractSqlStatements;
24
25
/**
26
 * Utility class with the SQL statements to use.
27
 *
28
 * @author    Tim Wagner <[email protected]>
29
 * @copyright 2016 TechDivision GmbH <[email protected]>
30
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
 * @link      https://github.com/techdivision/import-product-link
32
 * @link      http://www.techdivision.com
33
 */
34
class SqlStatements extends AbstractSqlStatements
35
{
36
37
    /**
38
     * The SQL statement to load an existing product link by product/linked product/link type ID.
39
     *
40
     * @var string
41
     */
42
    const PRODUCT_LINK = 'product_link';
43
44
    /**
45
     * The SQL statement to load an existing product link attribute integer value by the passed product link attribute ID/link ID/value.
46
     *
47
     * @var string
48
     */
49
    const PRODUCT_LINK_ATTRIBUTE_INT = 'product_link_attribute_int';
50
51
    /**
52
     * The SQL statement to create a new product link.
53
     *
54
     * @var string
55
     */
56
    const CREATE_PRODUCT_LINK = 'insert.product_link';
57
58
    /**
59
     * The SQL statement to update an existing product link.
60
     *
61
     * @var string
62
     */
63
    const UPDATE_PRODUCT_LINK = 'update.product_link';
64
65
    /**
66
     * The SQL statement to create a new product link attribute integer value.
67
     *
68
     * @var string
69
     */
70
    const CREATE_PRODUCT_LINK_ATTRIBUTE_INT = 'insert:product_link_attribute_int';
71
72
    /**
73
     * The SQL statement to update an existing product link attribute integer value.
74
     *
75
     * @var string
76
     */
77
    const UPDATE_PRODUCT_LINK_ATTRIBUTE_INT = 'update.product_link_attribute_int';
78
79
    /**
80
     * The SQL statements.
81
     *
82
     * @var array
83
     */
84
    private $statements = array(
85
        SqlStatements::PRODUCT_LINK =>
86
            'SELECT *
87
               FROM catalog_product_link
88
              WHERE product_id = :product_id
89
                AND linked_product_id = :linked_product_id
90
                AND link_type_id = :link_type_id',
91
        SqlStatements::PRODUCT_LINK_ATTRIBUTE_INT =>
92
            'SELECT *
93
               FROM catalog_product_link_attribute_int
94
              WHERE product_link_attribute_id = :product_link_attribute_id
95
                AND link_id = :link_id',
96
        SqlStatements::CREATE_PRODUCT_LINK =>
97
            'INSERT
98
               INTO catalog_product_link
99
                    (product_id,
100
                     linked_product_id,
101
                     link_type_id)
102
             VALUES (:product_id,
103
                     :linked_product_id,
104
                     :link_type_id)',
105
        SqlStatements::UPDATE_PRODUCT_LINK =>
106
            'UPDATE catalog_product_link
107
                SET product_id = :product_id,
108
                    linked_product_id = :linked_product_id,
109
                    link_type_id = :link_type_id
110
              WHERE link_id = :link_id',
111
        SqlStatements::CREATE_PRODUCT_LINK_ATTRIBUTE_INT =>
112
            'INSERT
113
               INTO catalog_product_link_attribute_int
114
                    (product_link_attribute_id,
115
                     link_id,
116
                     value)
117
             VALUES (:product_link_attribute_id,
118
                     :link_id,
119
                     :value)',
120
        SqlStatements::UPDATE_PRODUCT_LINK_ATTRIBUTE_INT =>
121
            'UPDATE catalog_product_link_attribute_int
122
                SET product_link_attribute_id = :product_link_attribute_id,
123
                    link_id = :link_id,
124
                    value = :value
125
              WHERE value_id = :value_id'
126
    );
127
128
    /**
129
     * Initialize the the SQL statements.
130
     */
131
    public function __construct()
132
    {
133
134
        // merge the class statements
135
        foreach ($this->statements as $key => $statement) {
136
            $this->preparedStatements[$key] = $statement;
137
        }
138
    }
139
}
140