Bitrix-D7  20.0.0
main/lib/orm/objectify/collection.php
См. документацию.
1 <?php
2 /**
3  * Bitrix Framework
4  * @package bitrix
5  * @subpackage main
6  * @copyright 2001-2018 Bitrix
7  */
8 
10 
23 
24 /**
25  * Collection of entity objects. Used to hold 1:N and N:M object collections.
26  *
27  * @property-read \Bitrix\Main\ORM\Entity $entity
28  *
29  * @package bitrix
30  * @subpackage main
31  */
32 abstract class Collection implements \ArrayAccess, \Iterator, \Countable
33 {
34  /**
35  * Entity Table class. Read-only property.
36  * @var DataManager
37  */
38  static public $dataClass;
39 
40  /** @var Entity */
41  protected $_entity;
42 
43  /** @var EntityObject */
44  protected $_objectClass;
45 
46  /** @var EntityObject[] */
47  protected $_objects = [];
48 
49  /** @var bool */
50  protected $_isFilled = false;
51 
52  /** @var bool */
53  protected $_isSinglePrimary;
54 
55  /** @var array [SerializedPrimary => OBJECT_CHANGE_CODE] */
56  protected $_objectsChanges;
57 
58  /** @var EntityObject[] */
59  protected $_objectsRemoved;
60 
61  /** @var EntityObject[] Used for Iterator interface, allows to delete elements during foreach loop */
62  protected $_iterableObjects;
63 
64  /** @var int Code for $objectsChanged */
65  const OBJECT_ADDED = 1;
66 
67  /** @var int Code for $objectsChanged */
68  const OBJECT_REMOVED = 2;
69 
70  /**
71  * Collection constructor.
72  *
73  * @param Entity $entity
74  *
75  * @throws ArgumentException
76  * @throws SystemException
77  */
78  final public function __construct(Entity $entity = null)
79  {
80  if (empty($entity))
81  {
82  if (__CLASS__ !== get_called_class())
83  {
84  // custom collection class
85  $dataClass = static::$dataClass;
86  $this->_entity = $dataClass::getEntity();
87  }
88  else
89  {
90  throw new ArgumentException('Entity required when constructing collection');
91  }
92  }
93  else
94  {
95  $this->_entity = $entity;
96  }
97 
98  $this->_objectClass = $this->_entity->getObjectClass();
99  $this->_isSinglePrimary = count($this->_entity->getPrimaryArray()) == 1;
100  }
101 
102  /**
103  * @param EntityObject $object
104  *
105  * @throws ArgumentException
106  * @throws SystemException
107  */
108  final public function add(EntityObject $object)
109  {
110  // check object class
111  if (!($object instanceof $this->_objectClass))
112  {
113  throw new ArgumentException(sprintf(
114  'Invalid object class %s for %s collection, expected "%s".',
115  get_class($object), get_class($this), $this->_objectClass
116  ));
117  }
118 
119  $srPrimary = $this->sysGetPrimaryKey($object);
120 
121  if (!$object->sysHasPrimary())
122  {
123  // object is new and there is no primary yet
124  $object->sysAddOnPrimarySetListener([$this, 'sysOnObjectPrimarySet']);
125  }
126 
127  if (empty($this->_objects[$srPrimary])
128  && (!isset($this->_objectsChanges[$srPrimary]) || $this->_objectsChanges[$srPrimary] != static::OBJECT_REMOVED))
129  {
130  $this->_objects[$srPrimary] = $object;
131  $this->_objectsChanges[$srPrimary] = static::OBJECT_ADDED;
132  }
133  elseif (isset($this->_objectsChanges[$srPrimary]) && $this->_objectsChanges[$srPrimary] == static::OBJECT_REMOVED)
134  {
135  // silent add for removed runtime
136  $this->_objects[$srPrimary] = $object;
137 
138  unset($this->_objectsChanges[$srPrimary]);
139  unset($this->_objectsRemoved[$srPrimary]);
140  }
141  }
142 
143  /**
144  * @param EntityObject $object
145  *
146  * @return bool
147  * @throws ArgumentException
148  * @throws SystemException
149  */
150  final public function has(EntityObject $object)
151  {
152  // check object class
153  if (!($object instanceof $this->_objectClass))
154  {
155  throw new ArgumentException(sprintf(
156  'Invalid object class %s for %s collection, expected "%s".',
157  get_class($object), get_class($this), $this->_objectClass
158  ));
159  }
160 
161  return array_key_exists($this->sysGetPrimaryKey($object), $this->_objects);
162  }
163 
164  /**
165  * @param $primary
166  *
167  * @return bool
168  * @throws ArgumentException
169  */
170  final public function hasByPrimary($primary)
171  {
172  $normalizedPrimary = $this->sysNormalizePrimary($primary);
173  return array_key_exists($this->sysSerializePrimaryKey($normalizedPrimary), $this->_objects);
174  }
175 
176  /**
177  * @param $primary
178  *
179  * @return EntityObject
180  * @throws ArgumentException
181  */
182  final public function getByPrimary($primary)
183  {
184  $normalizedPrimary = $this->sysNormalizePrimary($primary);
185  return $this->_objects[$this->sysSerializePrimaryKey($normalizedPrimary)];
186  }
187 
188  /**
189  * @return EntityObject[]
190  */
191  final public function getAll()
192  {
193  return array_values($this->_objects);
194  }
195 
196  /**
197  * @param EntityObject $object
198  *
199  * @return void
200  * @throws ArgumentException
201  * @throws SystemException
202  */
203  final public function remove(EntityObject $object)
204  {
205  // check object class
206  if (!($object instanceof $this->_objectClass))
207  {
208  throw new ArgumentException(sprintf(
209  'Invalid object class %s for %s collection, expected "%s".',
210  get_class($object), get_class($this), $this->_objectClass
211  ));
212  }
213 
214  // ignore deleted objects
215  if ($object->state === State::DELETED)
216  {
217  return;
218  }
219 
220  $srPrimary = $this->sysGetPrimaryKey($object);
221  $this->sysRemove($srPrimary);
222  }
223 
224  /**
225  * @param $primary
226  *
227  * @throws ArgumentException
228  */
229  final public function removeByPrimary($primary)
230  {
231  $normalizedPrimary = $this->sysNormalizePrimary($primary);
232  $srPrimary = $this->sysSerializePrimaryKey($normalizedPrimary);
233 
234  $this->sysRemove($srPrimary);
235  }
236 
237  public function sysRemove($srPrimary)
238  {
239  $object = $this->_objects[$srPrimary];
240  unset($this->_objects[$srPrimary]);
241 
242  if (!isset($this->_objectsChanges[$srPrimary]) || $this->_objectsChanges[$srPrimary] != static::OBJECT_ADDED)
243  {
244  // regular remove
245  $this->_objectsChanges[$srPrimary] = static::OBJECT_REMOVED;
246  $this->_objectsRemoved[$srPrimary] = $object;
247  }
248  elseif (isset($this->_objectsChanges[$srPrimary]) && $this->_objectsChanges[$srPrimary] == static::OBJECT_ADDED)
249  {
250  // silent remove for added runtime
251  unset($this->_objectsChanges[$srPrimary]);
252  unset($this->_objectsRemoved[$srPrimary]);
253  }
254  }
255 
256  /**
257  * Fills all the values and relations of object
258  *
259  * @param int|string[] $fields Names of fields to fill
260  *
261  * @throws ArgumentException
262  * @throws SystemException
263  */
264  final public function fill($fields = FieldTypeMask::ALL)
265  {
266  $entityPrimary = $this->_entity->getPrimaryArray();
267 
268  $primaryValues = [];
269  $fieldsToSelect = [];
270 
271  // if field is the only one
272  if (is_scalar($fields) && !is_numeric($fields))
273  {
274  $fields = [$fields];
275  }
276 
277  // collect custom fields to select
278  foreach ($this->_objects as $object)
279  {
280  $idleFields = is_array($fields)
281  ? $object->sysGetIdleFields($fields)
282  : $object->sysGetIdleFieldsByMask($fields);
283 
284  if (!empty($idleFields))
285  {
286  $fieldsToSelect = array_unique(array_merge($fieldsToSelect, $idleFields));
287 
288  // add object to query
289  $objectPrimary = $object->sysRequirePrimary();
290 
291  $primaryValues[] = count($objectPrimary) == 1
292  ? current($objectPrimary)
293  : $objectPrimary;
294  }
295  }
296 
297  // add primary to select
298  if (!empty($fieldsToSelect))
299  {
300  $fieldsToSelect = array_unique(array_merge($entityPrimary, $fieldsToSelect));
301 
302  // build primary filter
303  $primaryFilter = Query::filter();
304 
305  if (count($entityPrimary) == 1)
306  {
307  // IN for single-primary objects
308  $primaryFilter->whereIn($entityPrimary[0], $primaryValues);
309  }
310  else
311  {
312  // OR for multi-primary objects
313  $primaryFilter->logic('or');
314 
315  foreach ($primaryValues as $objectPrimary)
316  {
317  // add each object as a separate condition
318  $oneObjectFilter = Query::filter();
319 
320  foreach ($objectPrimary as $primaryName => $primaryValue)
321  {
322  $oneObjectFilter->where($primaryName, $primaryValue);
323  }
324 
325  $primaryFilter->where($oneObjectFilter);
326  }
327  }
328 
329  // build query
330  $dataClass = $this->_entity->getDataClass();
331  $result = $dataClass::query()->setSelect($fieldsToSelect)->where($primaryFilter)->exec();
332 
333  // set object to identityMap of result, and it will be partially completed by fetch
334  $im = new IdentityMap;
335 
336  foreach ($this->_objects as $object)
337  {
338  $im->put($object);
339  }
340 
341  $result->setIdentityMap($im);
342  $result->fetchCollection();
343  }
344 
345  // return field value it it was only one
346  if (is_array($fields) && count($fields) == 1 && $this->entity->hasField(current($fields)))
347  {
348  $fieldName = current($fields);
349  $field = $this->entity->getField($fieldName);
350 
351  return ($field instanceof Relation)
352  ? $this->sysGetCollection($fieldName)
353  : $this->sysGetList($fieldName);
354  }
355  }
356 
357  final public function save($ignoreEvents = false)
358  {
359  $result = new Result;
360 
361  /** @var EntityObject[] $addObjects */
362  $addObjects = [];
363 
364  /** @var EntityObject[] $updateObjects */
365  $updateObjects = [];
366 
367  foreach ($this->_objects as $object)
368  {
369  if ($object->sysGetState() === State::RAW)
370  {
371  $addObjects[] = ['__object' => $object];
372  }
373  elseif ($object->sysGetState() === State::CHANGED)
374  {
375  $updateObjects[] = $object;
376  }
377  }
378 
379  $dataClass = static::$dataClass;
380 
381  // multi add
382  if (!empty($addObjects))
383  {
384  $result = $dataClass::addMulti($addObjects, $ignoreEvents);
385  }
386 
387  // multi update
388  if (!empty($updateObjects))
389  {
390  $areEqual = true;
391  $primaries = [];
392 
393  $dataSample = $updateObjects[0]->collectValues(Values::CURRENT, FieldTypeMask::SCALAR | FieldTypeMask::USERTYPE);
394  asort($dataSample);
395 
396  // get only scalar & uf data and check its uniqueness
397  foreach ($updateObjects as $object)
398  {
399  $objectData = $object->collectValues(Values::CURRENT, FieldTypeMask::SCALAR | FieldTypeMask::USERTYPE);
400  asort($objectData);
401 
402  if ($dataSample !== $objectData)
403  {
404  $areEqual = false;
405  break;
406  }
407 
408  $primaries[] = $object->primary;
409  }
410 
411  if ($areEqual)
412  {
413  // one query
414  $result = $dataClass::updateMulti($primaries, $dataSample, $ignoreEvents);
415 
416  // post save
417  foreach ($updateObjects as $object)
418  {
419  $object->sysSaveRelations($result);
420  $object->sysPostSave();
421  }
422  }
423  else
424  {
425  // each object separately
426  foreach ($updateObjects as $object)
427  {
428  $objectResult = $object->save();
429 
430  if (!$objectResult->isSuccess())
431  {
432  $result->addErrors($objectResult->getErrors());
433  }
434  }
435  }
436  }
437 
438  return $result;
439  }
440 
441  /**
442  * Constructs set of existing objects from pre-selected data, including references and relations.
443  *
444  * @param $rows
445  *
446  * @return array|static
447  * @throws ArgumentException
448  * @throws SystemException
449  */
450  final public static function wakeUp($rows)
451  {
452  // define object class
453  $dataClass = static::$dataClass;
454  $objectClass = $dataClass::getObjectClass();
455 
456  // complete collection
457  $collection = new static;
458 
459  foreach ($rows as $row)
460  {
461  $collection->sysAddActual($objectClass::wakeUp($row));
462  }
463 
464  return $collection;
465  }
466 
467  /**
468  * Magic read-only properties
469  *
470  * @param $name
471  *
472  * @return array|Entity
473  * @throws SystemException
474  */
475  public function __get($name)
476  {
477  switch ($name)
478  {
479  case 'entity':
480  return $this->_entity;
481  case 'dataClass':
482  throw new SystemException('Property `dataClass` should be received as static.');
483  }
484 
485  throw new SystemException(sprintf(
486  'Unknown property `%s` for collection `%s`', $name, get_called_class()
487  ));
488  }
489 
490  /**
491  * Magic read-only properties
492  *
493  * @param $name
494  * @param $value
495  *
496  * @throws SystemException
497  */
498  public function __set($name, $value)
499  {
500  switch ($name)
501  {
502  case 'entity':
503  case 'dataClass':
504  throw new SystemException(sprintf(
505  'Property `%s` for collection `%s` is read-only', $name, get_called_class()
506  ));
507  }
508 
509  throw new SystemException(sprintf(
510  'Unknown property `%s` for collection `%s`', $name, get_called_class()
511  ));
512  }
513 
514  /**
515  * Magic to handle getters, setters etc.
516  *
517  * @param $name
518  * @param $arguments
519  *
520  * @return array
521  * @throws ArgumentException
522  * @throws SystemException
523  */
524  public function __call($name, $arguments)
525  {
526  $first3 = substr($name, 0, 3);
527  $last4 = substr($name, -4);
528 
529  // group getter
530  if ($first3 == 'get' && $last4 == 'List')
531  {
532  $fieldName = EntityObject::sysMethodToFieldCase(substr($name, 3, -4));
533 
534  if (!strlen($fieldName))
535  {
536  $fieldName = StringHelper::strtoupper($arguments[0]);
537 
538  // check if custom method exists
539  $personalMethodName = $first3.EntityObject::sysFieldToMethodCase($fieldName).$last4;
540 
541  if (method_exists($this, $personalMethodName))
542  {
543  return $this->$personalMethodName(...array_slice($arguments, 1));
544  }
545 
546  // hard field check
547  $this->entity->getField($fieldName);
548  }
549 
550  // check if field exists
551  if ($this->_entity->hasField($fieldName))
552  {
553  return $this->sysGetList($fieldName);
554  }
555  }
556 
557  $last10 = substr($name, -10);
558 
559  if ($first3 == 'get' && $last10 == 'Collection')
560  {
561  $fieldName = EntityObject::sysMethodToFieldCase(substr($name, 3, -10));
562 
563  if (!strlen($fieldName))
564  {
565  $fieldName = StringHelper::strtoupper($arguments[0]);
566 
567  // check if custom method exists
568  $personalMethodName = $first3.EntityObject::sysFieldToMethodCase($fieldName).$last10;
569 
570  if (method_exists($this, $personalMethodName))
571  {
572  return $this->$personalMethodName(...array_slice($arguments, 1));
573  }
574 
575  // hard field check
576  $this->entity->getField($fieldName);
577  }
578 
579  // check if field exists
580  if ($this->_entity->hasField($fieldName) && $this->_entity->getField($fieldName) instanceof Relation)
581  {
582  return $this->sysGetCollection($fieldName);
583  }
584  }
585 
586  $first4 = substr($name, 0, 4);
587 
588  // filler
589  if ($first4 == 'fill')
590  {
591  $fieldName = EntityObject::sysMethodToFieldCase(substr($name, 4));
592 
593  // check if field exists
594  if ($this->_entity->hasField($fieldName))
595  {
596  return $this->fill([$fieldName]);
597  }
598  }
599 
600  throw new SystemException(sprintf(
601  'Unknown method `%s` for object `%s`', $name, get_called_class()
602  ));
603  }
604 
605  /**
606  * @internal For internal system usage only.
607  *
608  * @param \Bitrix\Main\ORM\Objectify\EntityObject $object
609  *
610  * @throws ArgumentException
611  * @throws SystemException
612  */
613  public function sysAddActual(EntityObject $object)
614  {
615  $this->_objects[$this->sysGetPrimaryKey($object)] = $object;
616  }
617 
618  /**
619  * Callback for object event when it gets primary
620  *
621  * @param $object
622  */
623  public function sysOnObjectPrimarySet($object)
624  {
625  $srHash = spl_object_hash($object);
626  $srPrimary = $this->sysSerializePrimaryKey($object->primary);
627 
628  if (isset($this->_objects[$srHash]))
629  {
630  // rewrite object
631  unset($this->_objects[$srHash]);
632  $this->_objects[$srPrimary] = $object;
633 
634  // rewrite changes
635  if (isset($this->_objectsChanges[$srHash]))
636  {
637  $this->_objectsChanges[$srPrimary] = $this->_objectsChanges[$srHash];
638  unset($this->_objectsChanges[$srHash]);
639  }
640 
641  // rewrite removed registry
642  if (isset($this->_objectsRemoved[$srHash]))
643  {
644  $this->_objectsRemoved[$srPrimary] = $this->_objectsRemoved[$srHash];
645  unset($this->_objectsRemoved[$srHash]);
646  }
647  }
648  }
649 
650  /**
651  * @internal For internal system usage only.
652  *
653  * @return bool
654  */
655  public function sysIsFilled()
656  {
657  return $this->_isFilled;
658  }
659 
660  /**
661  * @internal For internal system usage only.
662  *
663  * @return bool
664  */
665  public function sysIsChanged()
666  {
667  return !empty($this->_objectsChanges);
668  }
669 
670  /**
671  * @internal For internal system usage only.
672  *
673  * @return array
674  * @throws SystemException
675  */
676  public function sysGetChanges()
677  {
678  $changes = [];
679 
680  foreach ($this->_objectsChanges as $srPrimary => $changeCode)
681  {
682  if (isset($this->_objects[$srPrimary]))
683  {
684  $changedObject = $this->_objects[$srPrimary];
685  }
686  elseif (isset($this->_objectsRemoved[$srPrimary]))
687  {
688  $changedObject = $this->_objectsRemoved[$srPrimary];
689  }
690  else
691  {
692  $changedObject = null;
693  }
694 
695  if (empty($changedObject))
696  {
697  throw new SystemException(sprintf(
698  'Object with primary `%s` was not found in `%s` collection', $srPrimary, get_class($this)
699  ));
700  }
701 
702  $changes[] = [$changedObject, $changeCode];
703  }
704 
705  return $changes;
706  }
707 
708  /**
709  * @internal For internal system usage only.
710  *
711  * @param bool $rollback
712  */
713  public function sysResetChanges($rollback = false)
714  {
715  if ($rollback)
716  {
717  foreach ($this->_objectsChanges as $srPrimary => $changeCode)
718  {
719  if ($changeCode === static::OBJECT_ADDED)
720  {
721  unset($this->_objects[$srPrimary]);
722  }
723  elseif ($changeCode === static::OBJECT_REMOVED)
724  {
725  $this->_objects[$srPrimary] = $this->_objectsRemoved[$srPrimary];
726  }
727  }
728  }
729 
730  $this->_objectsChanges = [];
731  $this->_objectsRemoved = [];
732  }
733 
734  /**
735  * @param $fieldName
736  *
737  * @return array
738  * @throws SystemException
739  */
740  protected function sysGetList($fieldName)
741  {
742  $values = [];
743 
744  // collect field values
745  foreach ($this->_objects as $objectPrimary => $object)
746  {
747  $values[] = $object->sysGetValue($fieldName);
748  }
749 
750  return $values;
751  }
752 
753  /**
754  * @param $fieldName
755  *
756  * @return array|null
757  * @throws ArgumentException
758  * @throws SystemException
759  */
760  protected function sysGetCollection($fieldName)
761  {
762  /** @var Relation $field */
763  $field = $this->_entity->getField($fieldName);
764 
765  $values = $field->getRefEntity()->createCollection();
766 
767  // collect field values
768  foreach ($this->_objects as $objectPrimary => $object)
769  {
770  $value = $object->sysGetValue($fieldName);
771 
772  if ($value instanceof EntityObject)
773  {
774  $values[] = $value;
775  }
776  elseif ($value instanceof Collection)
777  {
778  foreach ($value->getAll() as $remoteObject)
779  {
780  $values[] = $remoteObject;
781  }
782  }
783  }
784 
785  return $values;
786  }
787 
788  /**
789  * @internal For internal system usage only.
790  */
791  public function sysReviseDeletedObjects()
792  {
793  // clear from deleted objects
794  foreach ($this->_objects as $k => $object)
795  {
796  if ($object->state === State::DELETED)
797  {
798  unset($this->_objects[$k]);
799  }
800  }
801  }
802 
803  /**
804  * @internal For internal system usage only.
805  *
806  * @param bool $value
807  */
808  public function sysSetFilled($value = true)
809  {
810  $this->_isFilled = $value;
811  }
812 
813  /**
814  * @internal For internal system usage only.
815  *
816  * @param $primary
817  *
818  * @return array
819  * @throws ArgumentException
820  */
821  protected function sysNormalizePrimary($primary)
822  {
823  // normalize primary
824  $primaryNames = $this->_entity->getPrimaryArray();
825 
826  if (!is_array($primary))
827  {
828  if (count($primaryNames) > 1)
829  {
830  throw new ArgumentException(sprintf(
831  'Only one value of primary found, when entity %s has %s primary keys',
832  $this->_entity->getDataClass(), count($primaryNames)
833  ));
834  }
835 
836  $primary = [$primaryNames[0] => $primary];
837  }
838 
839  // check in $this->objects
840  $normalizedPrimary = [];
841 
842  foreach ($primaryNames as $primaryName)
843  {
844  /** @var ScalarField $field */
845  $field = $this->_entity->getField($primaryName);
846  $normalizedPrimary[$primaryName] = $field->cast($primary[$primaryName]);
847  }
848 
849  return $normalizedPrimary;
850  }
851 
852  /**
853  * @internal For internal system usage only.
854  *
855  * @param \Bitrix\Main\ORM\Objectify\EntityObject $object
856  *
857  * @return false|mixed|string
858  * @throws ArgumentException
859  * @throws SystemException
860  */
861  protected function sysGetPrimaryKey(EntityObject $object)
862  {
863  if ($object->sysHasPrimary())
864  {
865  return $this->sysSerializePrimaryKey($object->primary);
866  }
867  else
868  {
869  return spl_object_hash($object);
870  }
871  }
872 
873  /**
874  * @internal For internal system usage only.
875  *
876  * @param $primary
877  *
878  * @return false|mixed|string
879  * @throws ArgumentException
880  */
881  protected function sysSerializePrimaryKey($primary)
882  {
883  if ($this->_isSinglePrimary)
884  {
885  return current($primary);
886  }
887 
888  return Json::encode(array_values($primary));
889  }
890 
891  /**
892  * ArrayAccess implementation
893  *
894  * @param mixed $offset
895  * @param mixed $value
896  *
897  * @throws ArgumentException
898  * @throws SystemException
899  */
900  public function offsetSet($offset, $value)
901  {
902  $this->add($value);
903  }
904 
905  /**
906  * ArrayAccess implementation
907  *
908  * @param mixed $offset
909  *
910  * @return bool|void
911  * @throws NotImplementedException
912  */
913  public function offsetExists($offset)
914  {
915  throw new NotImplementedException;
916  }
917 
918  /**
919  * ArrayAccess implementation
920  *
921  * @param mixed $offset
922  *
923  * @throws NotImplementedException
924  */
925  public function offsetUnset($offset)
926  {
927  throw new NotImplementedException;
928  }
929 
930  /**
931  * ArrayAccess implementation
932  *
933  * @param mixed $offset
934  *
935  * @return mixed|void
936  * @throws NotImplementedException
937  */
938  public function offsetGet($offset)
939  {
940  throw new NotImplementedException;
941  }
942 
943  /**
944  * Iterator implementation
945  */
946  public function rewind()
947  {
948  $this->_iterableObjects = $this->_objects;
949  reset($this->_iterableObjects);
950  }
951 
952  /**
953  * Iterator implementation
954  *
955  * @return EntityObject|mixed
956  */
957  public function current()
958  {
959  if ($this->_iterableObjects === null)
960  {
961  $this->_iterableObjects = $this->_objects;
962  }
963 
964  return current($this->_iterableObjects);
965  }
966 
967  /**
968  * Iterator implementation
969  *
970  * @return int|mixed|null|string
971  */
972  public function key()
973  {
974  return key($this->_iterableObjects);
975  }
976 
977  /**
978  * Iterator implementation
979  */
980  public function next()
981  {
982  next($this->_iterableObjects);
983  }
984 
985  /**
986  * Iterator implementation
987  *
988  * @return bool
989  */
990  public function valid()
991  {
992  return key($this->_iterableObjects) !== null;
993  }
994 
995  /**
996  * Countable implementation
997  *
998  * @return int
999  */
1000  public function count()
1001  {
1002  return count($this->_objects);
1003  }
1004 }
Bitrix\Main\ORM\Objectify\Collection\hasByPrimary
hasByPrimary($primary)
Definition: main/lib/orm/objectify/collection.php:170
Bitrix\Main\ORM\Objectify\Collection\has
has(EntityObject $object)
Definition: main/lib/orm/objectify/collection.php:150
Bitrix\Main\ORM\Objectify\Collection\fill
fill($fields=FieldTypeMask::ALL)
Fills all the values and relations of object.
Definition: main/lib/orm/objectify/collection.php:264
Bitrix\Main\ORM\Data\DataManager
Base entity data manager.
Definition: main/lib/orm/data/datamanager.php:32
Bitrix\Main\Text\StringHelper
Definition: stringhelper.php:16
Bitrix\Main\ORM\Objectify\Collection\__call
__call($name, $arguments)
Magic to handle getters, setters etc.
Definition: main/lib/orm/objectify/collection.php:524
Bitrix\Main\ORM\Objectify\Collection\sysSerializePrimaryKey
sysSerializePrimaryKey($primary)
Definition: main/lib/orm/objectify/collection.php:881
Bitrix\Main\ORM\Fields\FieldTypeMask\ALL
const ALL
Definition: fieldtypemask.php:27
Bitrix\Main\ORM\Objectify\Collection\add
add(EntityObject $object)
Definition: main/lib/orm/objectify/collection.php:108
Bitrix\Main\ORM\Objectify\Collection\sysGetPrimaryKey
sysGetPrimaryKey(EntityObject $object)
Definition: main/lib/orm/objectify/collection.php:861
Bitrix\Main\ORM\Objectify\Collection\offsetExists
offsetExists($offset)
ArrayAccess implementation.
Definition: main/lib/orm/objectify/collection.php:913
Bitrix\Main\ORM\Objectify\Collection\$_entity
$_entity
Definition: main/lib/orm/objectify/collection.php:41
Bitrix\Main\ORM\Objectify\Collection\OBJECT_REMOVED
const OBJECT_REMOVED
Definition: main/lib/orm/objectify/collection.php:68
Bitrix\Main\ORM\Objectify\State\RAW
const RAW
Definition: main/lib/orm/objectify/state.php:18
Bitrix\Main\ORM\Objectify\State\CHANGED
const CHANGED
Definition: main/lib/orm/objectify/state.php:20
Bitrix\Main\ORM\Objectify\EntityObject
Definition: entityobject.php:47
Bitrix\Main\ORM\Objectify\Collection\key
key()
Iterator implementation.
Definition: main/lib/orm/objectify/collection.php:972
Bitrix\Main\ORM\Objectify\Collection\valid
valid()
Iterator implementation.
Definition: main/lib/orm/objectify/collection.php:990
Bitrix\Main\ORM\Objectify\Collection\OBJECT_ADDED
const OBJECT_ADDED
Definition: main/lib/orm/objectify/collection.php:65
Bitrix\Main\ORM\Objectify\Collection
Definition: main/lib/orm/objectify/collection.php:32
Bitrix\Main\ORM\Objectify\Collection\sysAddActual
sysAddActual(EntityObject $object)
Definition: main/lib/orm/objectify/collection.php:613
Bitrix\Main\ORM\Objectify\Collection\__construct
__construct(Entity $entity=null)
Collection constructor.
Definition: main/lib/orm/objectify/collection.php:78
Bitrix\Main\Web\Json\encode
static encode($data, $options=null)
Returns a string containing the JSON representation of $data.
Definition: web/json.php:22
Bitrix\Main\ORM\Objectify\Collection\next
next()
Iterator implementation.
Definition: main/lib/orm/objectify/collection.php:980
Bitrix\Main\ORM\Fields\ScalarField
Definition: scalarfield.php:18
Bitrix\Main\ORM\Objectify\Collection\offsetSet
offsetSet($offset, $value)
ArrayAccess implementation.
Definition: main/lib/orm/objectify/collection.php:900
Bitrix\Main\ORM\Objectify\IdentityMap
Definition: identitymap.php:19
Bitrix\Main\ORM\Entity
Base entity.
Definition: main/lib/orm/entity.php:25
Bitrix\Main\ORM\Objectify\Collection\removeByPrimary
removeByPrimary($primary)
Definition: main/lib/orm/objectify/collection.php:229
Bitrix\Main\ORM\Objectify\Collection\$_iterableObjects
$_iterableObjects
Definition: main/lib/orm/objectify/collection.php:62
Bitrix\Main\ORM\Query\Query\filter
static filter()
Returns new instance of Filter.
Definition: main/lib/orm/query/query.php:756
Bitrix\Main\ORM\Objectify\Collection\getByPrimary
getByPrimary($primary)
Definition: main/lib/orm/objectify/collection.php:182
Bitrix\Main\ORM\Objectify\Collection\sysReviseDeletedObjects
sysReviseDeletedObjects()
Definition: main/lib/orm/objectify/collection.php:791
Bitrix\Main\ORM\Objectify\Collection\$_isSinglePrimary
$_isSinglePrimary
Definition: main/lib/orm/objectify/collection.php:53
Bitrix\Main\ORM\Objectify\Collection\$_objects
$_objects
Definition: main/lib/orm/objectify/collection.php:47
Bitrix\Main\ORM\Objectify\Collection\sysIsFilled
sysIsFilled()
Definition: main/lib/orm/objectify/collection.php:655
Bitrix\Main\ORM\Objectify\Collection\sysSetFilled
sysSetFilled($value=true)
Definition: main/lib/orm/objectify/collection.php:808
Bitrix\Main\ArgumentException
Exception is thrown when function argument is not valid.
Definition: main/lib/exception.php:33
Bitrix\Main\ORM\Objectify\Collection\offsetGet
offsetGet($offset)
ArrayAccess implementation.
Definition: main/lib/orm/objectify/collection.php:938
Bitrix\Main\ORM\Objectify\Collection\__get
__get($name)
Magic read-only properties.
Definition: main/lib/orm/objectify/collection.php:475
Bitrix\Main\ORM\Objectify\Collection\rewind
rewind()
Iterator implementation.
Definition: main/lib/orm/objectify/collection.php:946
Bitrix\Main\ORM\Query\Query
Definition: main/lib/orm/query/query.php:112
Bitrix\Main\SystemException
Base class for fatal exceptions.
Definition: main/lib/exception.php:7
Bitrix\Main\ORM\Objectify\Values\CURRENT
const CURRENT
Definition: values.php:19
Bitrix\Main\Text\StringHelper\strtoupper
static strtoupper($str)
Regular uppercase with result cache.
Definition: stringhelper.php:25
Bitrix\Main\Web\Json
Definition: web/json.php:8
Bitrix\Main\ORM\Objectify\Collection\sysRemove
sysRemove($srPrimary)
Definition: main/lib/orm/objectify/collection.php:237
Bitrix\Main\ORM\Objectify\Collection\sysGetChanges
sysGetChanges()
Definition: main/lib/orm/objectify/collection.php:676
Bitrix\Main\ORM\Objectify\Collection\sysResetChanges
sysResetChanges($rollback=false)
Definition: main/lib/orm/objectify/collection.php:713
Bitrix\Main\ORM\Fields\FieldTypeMask\USERTYPE
const USERTYPE
Definition: fieldtypemask.php:19
Bitrix\Main\ORM\Objectify
Definition: main/lib/orm/objectify/collection.php:9
Bitrix\Main\ORM\Objectify\Collection\sysOnObjectPrimarySet
sysOnObjectPrimarySet($object)
Callback for object event when it gets primary.
Definition: main/lib/orm/objectify/collection.php:623
Bitrix\Main\ORM\Fields\FieldTypeMask
Definition: fieldtypemask.php:15
Bitrix\Main\ORM\Objectify\IdentityMap\put
put($object)
Definition: identitymap.php:45
Bitrix\Main\ORM\Objectify\Collection\$_objectClass
$_objectClass
Definition: main/lib/orm/objectify/collection.php:44
Bitrix\Main\ORM\Objectify\Collection\$_objectsRemoved
$_objectsRemoved
Definition: main/lib/orm/objectify/collection.php:59
Bitrix\Main\ORM\Fields\FieldTypeMask\SCALAR
const SCALAR
Definition: fieldtypemask.php:17
Bitrix\Main\ORM\Fields\Relations\Relation
Definition: main/lib/orm/fields/relations/relation.php:25
Bitrix\Main\ORM\Objectify\Collection\sysGetList
sysGetList($fieldName)
Definition: main/lib/orm/objectify/collection.php:740
Bitrix\Main\ORM\Objectify\Collection\sysIsChanged
sysIsChanged()
Definition: main/lib/orm/objectify/collection.php:665
Bitrix\Main\ORM\Objectify\State\DELETED
const DELETED
Definition: main/lib/orm/objectify/state.php:21
Bitrix\Main\ORM\Objectify\Collection\$dataClass
static $dataClass
Definition: main/lib/orm/objectify/collection.php:38
Bitrix\Main\ORM\Objectify\Collection\getAll
getAll()
Definition: main/lib/orm/objectify/collection.php:191
Bitrix\Main\ORM\Objectify\Collection\$_objectsChanges
$_objectsChanges
Definition: main/lib/orm/objectify/collection.php:56
Bitrix\Main\ORM\Objectify\Collection\count
count()
Countable implementation.
Definition: main/lib/orm/objectify/collection.php:1000
Bitrix\Main\ORM\Data\Result
Definition: main/lib/orm/data/result.php:15
Bitrix\Main\ORM\Objectify\Collection\sysGetCollection
sysGetCollection($fieldName)
Definition: main/lib/orm/objectify/collection.php:760
Bitrix\Main\ORM\Objectify\Collection\current
current()
Iterator implementation.
Definition: main/lib/orm/objectify/collection.php:957
Bitrix\Main\ORM\Objectify\Collection\wakeUp
static wakeUp($rows)
Constructs set of existing objects from pre-selected data, including references and relations.
Definition: main/lib/orm/objectify/collection.php:450
Bitrix\Main\ORM\Objectify\Collection\save
save($ignoreEvents=false)
Definition: main/lib/orm/objectify/collection.php:357
Bitrix\Main\ORM\Objectify\Collection\$_isFilled
$_isFilled
Definition: main/lib/orm/objectify/collection.php:50
Bitrix\Main\ORM\Objectify\Collection\offsetUnset
offsetUnset($offset)
ArrayAccess implementation.
Definition: main/lib/orm/objectify/collection.php:925
Bitrix\Main\ORM\Objectify\Collection\__set
__set($name, $value)
Magic read-only properties.
Definition: main/lib/orm/objectify/collection.php:498
Bitrix\Main\NotImplementedException
Exception is thrown when operation is not implemented but should be.
Definition: main/lib/exception.php:146
Bitrix\Main\ORM\Objectify\Collection\sysNormalizePrimary
sysNormalizePrimary($primary)
Definition: main/lib/orm/objectify/collection.php:821