Completed
Push — master ( b26934...7f62ea )
by Jonas
15s
created

RemoteCategory::addLocalCategory()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 3
eloc 9
nc 3
nop 1
dl 0
loc 13
rs 9.4285
c 1
b 1
f 0
1
<?php
2
/**
3
 * (c) shopware AG <[email protected]>
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace Shopware\CustomModels\Connect;
9
10
use Doctrine\ORM\Mapping as ORM;
11
use Shopware\Components\Model\ModelEntity;
12
use Shopware\Models\Category\Category;
13
use Shopware\Models\Attribute\Category as CategoryAttribute;
14
15
/**
16
 * Describes Shopware Connect categories
17
 *
18
 * @ORM\Table(name="s_plugin_connect_categories")
19
 * @ORM\Entity(repositoryClass="RemoteCategoryRepository")
20
 */
21
class RemoteCategory extends ModelEntity
22
{
23
    /**
24
     * @var int
25
     * @ORM\Id
26
     * @ORM\GeneratedValue(strategy="IDENTITY")
27
     * @ORM\Column(name="id", type="integer", nullable=false)
28
     */
29
    protected $id;
30
31
    /**
32
     * @var string
33
     *
34
     * @ORM\Column(name="category_key", type="string", length=255, nullable=false)
35
     */
36
    protected $categoryKey;
37
38
    /**
39
     * @var string
40
     *
41
     * @ORM\Column(name="label", type="string", length=255, nullable=false)
42
     */
43
    protected $label;
44
45
    /**
46
     * @var int
47
     *
48
     * @ORM\Column(name="shop_id", type="integer", nullable=true)
49
     */
50
    protected $shopId;
51
52
    /**
53
     * @deprecated
54
     */
55
    protected $localCategoryId;
56
57
    /**
58
     * @deprecated
59
     */
60
    protected $localCategory;
61
62
    /**
63
     * @var \Doctrine\Common\Collections\ArrayCollection
64
     *
65
     * @ORM\ManyToMany(targetEntity="Shopware\Models\Category\Category")
66
     * @ORM\JoinTable(name="s_plugin_connect_categories_to_local_categories",
67
     *      joinColumns={@ORM\JoinColumn(name="remote_category_id", referencedColumnName="id")},
68
     *      inverseJoinColumns={@ORM\JoinColumn(name="local_category_id", referencedColumnName="id")}
69
     *      )
70
     */
71
    protected $localCategories;
72
73
    public function __construct()
74
    {
75
        $this->localCategories = new \Doctrine\Common\Collections\ArrayCollection();
76
    }
77
78
    /**
79
     * @return int
80
     */
81
    public function getId()
82
    {
83
        return $this->id;
84
    }
85
86
    /**
87
     * @return string
88
     */
89
    public function getCategoryKey()
90
    {
91
        return $this->categoryKey;
92
    }
93
94
    /**
95
     * @param string $categoryKey
96
     */
97
    public function setCategoryKey($categoryKey)
98
    {
99
        $this->categoryKey = $categoryKey;
100
    }
101
102
    /**
103
     * @return string
104
     */
105
    public function getLabel()
106
    {
107
        return $this->label;
108
    }
109
110
    /**
111
     * @param string $label
112
     */
113
    public function setLabel($label)
114
    {
115
        $this->label = $label;
116
    }
117
118
    /**
119
     * @return bool
120
     */
121
    public function hasLocalCategories()
122
    {
123
        return !$this->localCategories->isEmpty();
124
    }
125
126
    /**
127
     * @return array
128
     */
129
    public function getLocalCategories()
130
    {
131
        return $this->localCategories->toArray();
132
    }
133
134
    /**
135
     * @param \Shopware\Models\Category\Category $localCategory
136
     */
137
    public function addLocalCategory(Category $localCategory)
138
    {
139
        if (!$this->localCategories->contains($localCategory)) {
140
            $this->localCategories->add($localCategory);
141
            if ($localCategory->getAttribute()) {
142
                $localCategory->getAttribute()->setConnectImportedCategory(1);
143
            } else {
144
                $attribute = new CategoryAttribute();
145
                $attribute->setConnectImportedCategory(1);
146
                $localCategory->setAttribute($attribute);
147
            }
148
        }
149
    }
150
151
    /**
152
     * @param \Shopware\Models\Category\Category $localCategory
153
     */
154
    public function removeLocalCategory(Category $localCategory)
155
    {
156
        $this->localCategories->remove($localCategory);
157
    }
158
159
    /**
160
     * @deprecated
161
     */
162
    public function getLocalCategoryId()
163
    {
164
        return $this->localCategoryId;
0 ignored issues
show
Deprecated Code introduced by
The property Shopware\CustomModels\Co...egory::$localCategoryId has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
165
    }
166
167
    /**
168
     * @param int $id
169
     * @deprecated
170
     */
171
    public function setLocalCategoryId($id)
172
    {
173
        $this->localCategoryId = $id;
0 ignored issues
show
Deprecated Code introduced by
The property Shopware\CustomModels\Co...egory::$localCategoryId has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
174
    }
175
176
    /**
177
     * @return int
178
     */
179
    public function getShopId()
180
    {
181
        return $this->shopId;
182
    }
183
184
    /**
185
     * @param int $shopId
186
     */
187
    public function setShopId($shopId)
188
    {
189
        $this->shopId = $shopId;
190
    }
191
}
192