Completed
Pull Request — master (#387)
by Stefan
04:18
created

RemoteCategory::addLocalCategory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
eloc 3
c 1
b 1
f 0
nc 2
nop 1
dl 0
loc 6
rs 9.4285
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
14
/**
15
 * Describes Shopware Connect categories
16
 *
17
 * @ORM\Table(name="s_plugin_connect_categories")
18
 * @ORM\Entity(repositoryClass="RemoteCategoryRepository")
19
 */
20
class RemoteCategory extends ModelEntity
21
{
22
    /**
23
     * @var int
24
     * @ORM\Id
25
     * @ORM\GeneratedValue(strategy="IDENTITY")
26
     * @ORM\Column(name="id", type="integer", nullable=false)
27
     */
28
    protected $id;
29
30
    /**
31
     * @var string
32
     *
33
     * @ORM\Column(name="category_key", type="string", length=255, unique=true, nullable=false)
34
     */
35
    protected $categoryKey;
36
37
    /**
38
     * @var string
39
     *
40
     * @ORM\Column(name="label", type="string", length=255, nullable=false)
41
     */
42
    protected $label;
43
44
    /**
45
     * @deprecated
46
     */
47
    protected $localCategoryId;
48
49
    /**
50
     * @deprecated
51
     */
52
    protected $localCategory;
53
54
    /**
55
     * @var \Doctrine\Common\Collections\ArrayCollection
56
     *
57
     * @ORM\ManyToMany(targetEntity="Shopware\Models\Category\Category")
58
     * @ORM\JoinTable(name="s_plugin_connect_categories_to_local_categories",
59
     *      joinColumns={@ORM\JoinColumn(name="remote_category_id", referencedColumnName="id")},
60
     *      inverseJoinColumns={@ORM\JoinColumn(name="local_category_id", referencedColumnName="id")}
61
     *      )
62
     */
63
    protected $localCategories;
64
65
    public function __construct()
66
    {
67
        $this->localCategories = new \Doctrine\Common\Collections\ArrayCollection();
68
    }
69
70
    /**
71
     * @return int
72
     */
73
    public function getId()
74
    {
75
        return $this->id;
76
    }
77
78
    /**
79
     * @return string
80
     */
81
    public function getCategoryKey()
82
    {
83
        return $this->categoryKey;
84
    }
85
86
    /**
87
     * @param string $categoryKey
88
     */
89
    public function setCategoryKey($categoryKey)
90
    {
91
        $this->categoryKey = $categoryKey;
92
    }
93
94
    /**
95
     * @return string
96
     */
97
    public function getLabel()
98
    {
99
        return $this->label;
100
    }
101
102
    /**
103
     * @param string $label
104
     */
105
    public function setLabel($label)
106
    {
107
        $this->label = $label;
108
    }
109
110
    /**
111
     * @return bool
112
     */
113
    public function hasLocalCategories()
114
    {
115
        return !$this->localCategories->isEmpty();
116
    }
117
118
    /**
119
     * @return array
120
     */
121
    public function getLocalCategories()
122
    {
123
        return $this->localCategories->toArray();
124
    }
125
126
    /**
127
     * @param \Shopware\Models\Category\Category $localCategory
128
     */
129
    public function addLocalCategory(Category $localCategory)
130
    {
131
        if (!$this->localCategories->contains($localCategory)) {
132
            $this->localCategories->add($localCategory);
133
        }
134
    }
135
136
    /**
137
     * @param \Shopware\Models\Category\Category $localCategory
138
     */
139
    public function removeLocalCategory(Category $localCategory)
140
    {
141
        $this->localCategories->remove($localCategory);
142
    }
143
144
    /**
145
     * @deprecated
146
     */
147
    public function getLocalCategoryId()
148
    {
149
        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...
150
    }
151
152
    /**
153
     * @param int $id
154
     * @deprecated
155
     */
156
    public function setLocalCategoryId($id)
157
    {
158
        $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...
159
    }
160
}
161