Bitrix-D7  20.0.0
collectableentity.php
См. документацию.
1 <?php
2 namespace Bitrix\Sale\Internals;
3 
4 use Bitrix\Main;
7 
8 /**
9  * Class CollectableEntity
10  * @package Bitrix\Sale\Internals
11  */
12 abstract class CollectableEntity
13  extends Internals\Entity
14 {
15  /** @var EntityCollection */
16  protected $collection;
17 
18  protected $internalIndex = null;
19 
20  protected $isClone = false;
21 
22  /**
23  * @param string $name
24  * @param mixed $oldValue
25  * @param mixed $value
26  *
27  * @return Result
28  */
29  protected function onFieldModify($name, $oldValue, $value)
30  {
31  $collection = $this->getCollection();
32  return $collection->onItemModify($this, $name, $oldValue, $value);
33  }
34 
35  /**
36  * @param EntityCollection $collection
37  */
39  {
40  $this->collection = $collection;
41  }
42 
43  /**
44  * @return EntityCollection
45  */
46  public function getCollection()
47  {
48  return $this->collection;
49  }
50 
51  /**
52  * @throws Main\ArgumentOutOfRangeException
53  * @throws Main\ObjectNotFoundException
54  */
55  public function delete()
56  {
57  $collection = $this->getCollection();
58  if (!$collection)
59  {
60  throw new Main\ObjectNotFoundException('Entity "CollectableEntity" not found');
61  }
62 
63  /** @var Result $r */
64  $collection->deleteItem($this->getInternalIndex());
65 
66  return new Result();
67  }
68 
69  /**
70  * @internal
71  *
72  * @param $index
73  * @throws Main\ArgumentTypeException
74  */
75  public function setInternalIndex($index)
76  {
77  $this->internalIndex = $index;
78  }
79 
80  /**
81  * @return null|int
82  */
83  public function getInternalIndex()
84  {
85  return $this->internalIndex;
86  }
87 
88  /**
89  * @param bool $isMeaningfulField
90  * @return bool
91  */
92  public function isStartField($isMeaningfulField = false)
93  {
94  $parent = $this->getCollection();
95  if ($parent == null)
96  return false;
97 
98  return $parent->isStartField($isMeaningfulField);
99  }
100 
101  /**
102  * @return bool
103  */
104  public function clearStartField()
105  {
106  $parent = $this->getCollection();
107  if ($parent == null)
108  return false;
109 
110  return $parent->clearStartField();
111  }
112 
113  /**
114  * @return bool
115  */
116  public function hasMeaningfulField()
117  {
118  $parent = $this->getCollection();
119  if ($parent == null)
120  return false;
121 
122  return $parent->hasMeaningfulField();
123  }
124 
125  public function doFinalAction($hasMeaningfulField = false)
126  {
127  $parent = $this->getCollection();
128  if ($parent == null)
129  {
130  return false;
131  }
132 
133  return $parent->doFinalAction($hasMeaningfulField);
134  }
135 
136  /**
137  * @param bool|false $value
138  * @return bool
139  */
140  public function setMathActionOnly($value = false)
141  {
142  $parent = $this->getCollection();
143  if ($parent == null)
144  {
145  return false;
146  }
147 
148  return $parent->setMathActionOnly($value);
149  }
150 
151  /**
152  * @return bool
153  */
154  public function isMathActionOnly()
155  {
156  $parent = $this->getCollection();
157  if ($parent == null)
158  return false;
159 
160  return $parent->isMathActionOnly();
161  }
162 
163  /**
164  * @return bool
165  */
166  public function isClone()
167  {
168  return $this->isClone;
169  }
170 
171  /**
172  * @internal
173  * @param \SplObjectStorage $cloneEntity
174  *
175  * @return CollectableEntity
176  */
177  public function createClone(\SplObjectStorage $cloneEntity)
178  {
179  if ($this->isClone() && $cloneEntity->contains($this))
180  {
181  return $cloneEntity[$this];
182  }
183 
184  $collectableEntity = clone $this;
185  $collectableEntity->isClone = true;
186 
187  /** @var Internals\Fields $fields */
188  if ($fields = $this->fields)
189  {
190  $collectableEntity->fields = $fields->createClone($cloneEntity);
191  }
192 
193  if (!$cloneEntity->contains($this))
194  {
195  $cloneEntity[$this] = $collectableEntity;
196  }
197 
198  if ($collection = $this->getCollection())
199  {
200  if (!$cloneEntity->contains($collection))
201  {
202  $cloneEntity[$collection] = $collection->createClone($cloneEntity);
203  }
204 
205  if ($cloneEntity->contains($collection))
206  {
207  $collectableEntity->collection = $cloneEntity[$collection];
208  }
209  }
210 
211  return $collectableEntity;
212  }
213 }
Bitrix\Sale\Internals\CollectableEntity\createClone
createClone(\SplObjectStorage $cloneEntity)
Definition: collectableentity.php:177
Bitrix\Sale\Internals\CollectableEntity
Definition: collectableentity.php:12
Bitrix\Sale\Internals\CollectableEntity\getInternalIndex
getInternalIndex()
Definition: collectableentity.php:83
Bitrix\Sale\Internals\CollectableEntity\setCollection
setCollection(EntityCollection $collection)
Definition: collectableentity.php:38
Bitrix\Sale\Internals\CollectableEntity\doFinalAction
doFinalAction($hasMeaningfulField=false)
Definition: collectableentity.php:125
Bitrix\Main\ORM\Entity\$fields
$fields
Definition: main/lib/orm/entity.php:44
Bitrix\Sale\Internals\CollectableEntity\getCollection
getCollection()
Definition: collectableentity.php:46
Bitrix\Main
Bitrix\Main\ObjectNotFoundException
Exception is thrown when an object is not present.
Definition: main/lib/exception.php:202
Bitrix\Sale\Internals\CollectableEntity\setInternalIndex
setInternalIndex($index)
Definition: collectableentity.php:75
Bitrix\Sale\Internals\CollectableEntity\setMathActionOnly
setMathActionOnly($value=false)
Definition: collectableentity.php:140
Bitrix\Sale\Internals\CollectableEntity\isStartField
isStartField($isMeaningfulField=false)
Definition: collectableentity.php:92
Bitrix\Main\DB\Result
Definition: main/lib/db/result.php:18
Bitrix\Sale\Internals\CollectableEntity\isClone
isClone()
Definition: collectableentity.php:166
Bitrix\Sale\Internals
Definition: accountnumber.php:3
Bitrix\Sale\Internals\CollectableEntity\$internalIndex
$internalIndex
Definition: collectableentity.php:18
Bitrix\Sale\Internals\CollectableEntity\hasMeaningfulField
hasMeaningfulField()
Definition: collectableentity.php:116
Bitrix\Main\ORM\Entity
Base entity.
Definition: main/lib/orm/entity.php:25
Bitrix\Sale\Internals\CollectableEntity\$isClone
$isClone
Definition: collectableentity.php:20
Bitrix\Sale\Internals\CollectableEntity\isMathActionOnly
isMathActionOnly()
Definition: collectableentity.php:154
Bitrix\Sale\Internals\CollectableEntity\onFieldModify
onFieldModify($name, $oldValue, $value)
Definition: collectableentity.php:29
Bitrix\Sale\Internals\EntityCollection
Definition: entitycollection.php:11
Bitrix\Sale\Internals\CollectableEntity\clearStartField
clearStartField()
Definition: collectableentity.php:104
Bitrix\Sale\Internals\CollectableEntity\$collection
$collection
Definition: collectableentity.php:16
Bitrix\Main\ORM\Entity\$name
$name
Definition: main/lib/orm/entity.php:32