Completed
Pull Request — master (#364)
by Jonas
04:02
created

RemoteCategory::addLocalCategory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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