Relational::addSelected()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 1
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 1
b 1
f 1
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
3
namespace SpeckCatalog\Model\Builder;
4
5
use SpeckCatalog\Model\AbstractModel;
6
use SpeckCatalog\Model\Choice\Relational as Choice;
7
use SpeckCatalog\Model\Product\Relational as Product;
8
9
/*
10
 * this model does not extend another model
11
 * because it doesnt not have a db table
12
 * associated directly with it, many rows from the linker table make up one "builder"
13
 */
14
class Relational extends AbstractModel
15
{
16
    protected $choices;
17
18
    protected $product;
19
20
    protected $parent;
21
22
    protected $parentProductId;
23
24
    protected $productId;
25
26
    protected $options;
27
28
    //option_id => choice_id
29
    protected $selected = array();
30
31
    public function getChoices()
32
    {
33
        return $this->choices;
34
    }
35
36
    public function addChoice(Choice $choice)
37
    {
38
        $this->choices[] = $choice;
39
        return $this;
40
    }
41
42
    public function setChoices(array $choices = array())
43
    {
44
        $this->choices = array();
45
        foreach ($choices as $choice) {
46
            $this->addChoice($choice);
47
        }
48
        return $this;
49
    }
50
51
    public function getProduct()
52
    {
53
        return $this->product;
54
    }
55
56
    public function setProduct(Product $product)
57
    {
58
        $this->setProductId($product->getProductId());
59
        $this->product = $product;
60
        return $this;
61
    }
62
63
    public function getParent()
64
    {
65
        return $this->parent;
66
    }
67
68
    public function setParent($parent)
69
    {
70
        $this->setParentProductId($parent->getProductId());
71
        $this->parent = $parent;
72
        return $this;
73
    }
74
75
    public function getParentProductId()
76
    {
77
        return $this->parentProductId;
78
    }
79
80
    public function setParentProductId($parentProductId)
81
    {
82
        $this->parentProductId = $parentProductId;
83
        return $this;
84
    }
85
86
    public function getProductId()
87
    {
88
        return $this->productId;
89
    }
90
91
    public function setProductId($productId)
92
    {
93
        $this->productId = $productId;
94
        return $this;
95
    }
96
97
    public function getOptions()
98
    {
99
        return $this->options;
100
    }
101
102
    public function addOption($option)
103
    {
104
        $this->options[] = $option;
105
        return $this;
106
    }
107
108
    public function setOptions($options)
109
    {
110
        $this->options = array();
111
        foreach ($options as $option) {
112
            $this->addOption($option);
113
        }
114
        return $this;
115
    }
116
117
    public function getSelected()
118
    {
119
        return $this->selected;
120
    }
121
122
    public function addSelected($optionId, $choiceId)
123
    {
124
        $this->selected[$optionId] = (int) $choiceId;
125
    }
126
127
    public function setSelected(array $selected = null)
128
    {
129
        $this->selected = array();
130
        if (!is_array($selected)) {
131
            return $this;
132
        }
133
        foreach ($selected as $optionId => $choiceId) {
134
            $this->addSelected($optionId, $choiceId);
135
        }
136
        return $this;
137
    }
138
}
139