1 | <?php |
||
5 | class Choice extends AbstractService |
||
6 | { |
||
7 | protected $entityMapper = 'speckcatalog_choice_mapper'; |
||
8 | protected $optionService; |
||
9 | protected $productService; |
||
10 | |||
11 | public function getByOptionId($optionId, $populate = false, $recursive = false) |
||
12 | { |
||
13 | $choices = $this->getEntityMapper()->getByOptionId($optionId); |
||
14 | if ($populate) { |
||
15 | foreach ($choices as $choice) { |
||
16 | $this->populate($choice, $recursive); |
||
17 | } |
||
18 | } |
||
19 | return $choices; |
||
20 | } |
||
21 | |||
22 | public function populate($choice, $recursive = false, $children = true) |
||
23 | { |
||
24 | $allChildren = ($children === true) ? true : false; |
||
25 | $children = (is_array($children)) ? $children : array(); |
||
26 | |||
27 | if ($allChildren || in_array('parent', $children)) { |
||
28 | $option = $this->getOptionService()->find(array('option_id' => $choice->getOptionId())); |
||
29 | $choice->setParent($option); |
||
30 | } |
||
31 | if ($allChildren || in_array('options', $children)) { |
||
32 | $options = $this->getOptionService()->getByParentChoiceId($choice->getChoiceId(), $recursive); |
||
33 | $choice->setOptions($options); |
||
34 | } |
||
35 | if ($allChildren || in_array('product', $children)) { |
||
36 | if ($choice->getProductId()) { |
||
37 | $product = $this->getProductService()->getFullProduct($choice->getProductId()); |
||
38 | $choice->setProduct($product); |
||
39 | } |
||
40 | } |
||
41 | } |
||
42 | |||
43 | public function addOption($choiceOrId, $optionOrId) |
||
44 | { |
||
45 | $choiceId = ( is_int($choiceOrId) ? $choiceOrId : $choiceOrId->getChoiceId() ); |
||
46 | $optionId = ( is_int($optionOrId) ? $optionOrId : $optionOrId->getOptionId() ); |
||
47 | $this->getEntityMapper()->addOption($choiceId, $optionId); |
||
48 | return $this->getOptionService()->find(array('option_id' => $optionId)); |
||
49 | } |
||
50 | |||
51 | public function persist($form) |
||
52 | { |
||
53 | $data = $form->getData(); |
||
54 | $orig = $form->getOriginalData(); |
||
55 | |||
56 | if (isset($data['choice_id']) && (int) $data['choice_id'] > 0) { |
||
57 | return $this->update($data, $orig); |
||
58 | } |
||
59 | |||
60 | $model = $this->insert($data); |
||
61 | return $model; |
||
62 | } |
||
63 | |||
64 | public function sortOptions($choiceId, $order) |
||
68 | |||
69 | public function removeOption($choiceOrId, $optionOrId) |
||
70 | { |
||
71 | $productId = ( is_int($choiceOrId) ? $choiceOrId : $choiceOrId->getProductId() ); |
||
72 | $optionId = ( is_int($optionOrId) ? $optionOrId : $optionOrId->getOptionId() ); |
||
75 | |||
76 | public function choiceFromProduct($productOrId) |
||
82 | |||
83 | /** |
||
84 | * @return optionService |
||
85 | */ |
||
86 | public function getOptionService() |
||
93 | |||
94 | /** |
||
95 | * @param $optionService |
||
96 | * @return self |
||
97 | */ |
||
98 | public function setOptionService($optionService) |
||
103 | |||
104 | /** |
||
105 | * @return productService |
||
106 | */ |
||
107 | public function getProductService() |
||
114 | |||
115 | /** |
||
116 | * @param $productService |
||
117 | * @return self |
||
118 | */ |
||
119 | public function setProductService($productService) |
||
124 | } |
||
125 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.