BAOBAB
tCO_Collection Class Reference
Inheritance diagram for tCO_Collection:
Collaboration diagram for tCO_Collection:

Public Member Functions

 reload_collection ()
 
 insertElement ( $in_element, $in_before_index=-1, $dont_update=false)
 
 insertElements ( $in_element_array, $in_before_index=-1)
 
 deleteElements ( $in_first_index, $in_deletion_length)
 
 deleteElement ( $in_index)
 
 deleteThisElement ( $in_element)
 
 appendElement ( $in_element)
 
 appendElements ( $in_element_array)
 
 deleteAllChildren ()
 
 indexOfThisElement ( $in_element)
 
 whosYourDaddy ( $in_element)
 
 areYouMyDaddy ( $in_element, $full_hierachy=true)
 
 map ( $in_function)
 
 recursiveMap ( $in_function, $in_hierarchy_level=0, $in_parent_object=NULL, $loop_stopper=Array())
 
 count ( $is_recursive=false)
 
 children ()
 
 children_ids ( $in_raw=false)
 
 set_children_ids ( $in_new_ids)
 
 who_are_my_parents ()
 
 getHierarchy ( $loop_stopper=Array())
 

Protected Member Functions

 _scrub ()
 
 _set_up_container ()
 

Protected Attributes

 $_container
 This contains instances of the records referenced by the IDs stored in the object. More...
 

Detailed Description

This is a trait for the basic "collection" aggregator functionality.

Yes, I know that a lot of the code could do with some refactoring, and we should do that, but what we have here does work, and having pretty code is less important than having effective, tested, working code. We have a lot on our plate.

Definition at line 37 of file tco_collection.interface.php.

Member Function Documentation

◆ _scrub()

tCO_Collection::_scrub ( )
protected

This is a "garbage collection" method. This checks each of the contained items, and removes the ID if the item does not actually exist (security is not taken into account, so it's an accurate check).

Definition at line 45 of file tco_collection.interface.php.

45  {
46  if (isset($this->context['children_ids'])) {
47  $children_ids = $this->context['children_ids'];
48 
49  if (isset($children_ids) && is_array($children_ids) && count($children_ids)) {
50  $new_ids = Array();
51  foreach ($children_ids as $id) {
52  $id = intval($id); // Belt and suspenders.
53  if ($this->get_access_object()->item_exists($id)) {
54  $new_ids[] = $id;
55  }
56  }
57  $new_ids = array_unique($new_ids);
58  sort($new_ids);
59  $this->context['children_ids'] = $new_ids;
60  $this->update_db();
61  }
62  } else {
63  $this->_container = Array();
64  }
65  }
count( $is_recursive=false)

◆ _set_up_container()

tCO_Collection::_set_up_container ( )
protected

This method simply sets up the internal container from the object's tags. The tags already need to be loaded when this is called, so it should be called towards the end of the object's constructor.

Definition at line 73 of file tco_collection.interface.php.

73  {
74  if (isset($this->context['children_ids'])) {
75  $children_ids = $this->context['children_ids'];
76 
77  if (isset($children_ids) && is_array($children_ids) && count($children_ids)) {
78  $this->_container = $this->get_access_object()->get_multiple_data_records_by_id($children_ids);
79  }
80  }
81  }

Referenced by CO_User_Collection\load_from_db().

Here is the caller graph for this function:

◆ appendElement()

tCO_Collection::appendElement (   $in_element)

This appends one record to the end of the collection. The element cannot be already in the collection at any level, as that could cause a loop. The logged-in user must have write access to the collection object (not the data object) in order to add the item. You can opt out of the automatic database update.

Returns
true, if the data was successfully added. If a DB update was done, then the response is the one from the update.
Parameters
$in_elementThe database record to add.

Definition at line 383 of file tco_collection.interface.php.

384  {
385  return $this->insertElement($in_element, -1);
386  }
insertElement( $in_element, $in_before_index=-1, $dont_update=false)

◆ appendElements()

tCO_Collection::appendElements (   $in_element_array)

This appends multiple elements (passed as an array). The logged-in user must have write access to the collection object (not the data object) in order to add the items.

Returns
true, if the data was successfully updated in the DB. false, if none of the items were added.
Parameters
$in_element_arrayAn array of database element instances to be appended.

Definition at line 396 of file tco_collection.interface.php.

397  {
398  return $this->insertElements($in_element_array, -1);
399  }
insertElements( $in_element_array, $in_before_index=-1)

◆ areYouMyDaddy()

tCO_Collection::areYouMyDaddy (   $in_element,
  $full_hierachy = true 
)

This takes an element, and checks to see if it already exists in our hierarchy (anywhere).

Returns
true, if this instance already has the presented object.
Parameters
$in_elementThe element to check. This can be an array, in which case, each element is checked.
$full_hierachyIf false, then only this level (not the full hierarchy) will be searched. Default is true.

Definition at line 473 of file tco_collection.interface.php.

475  {
476  $ret = false;
477 
478  $children = $this->children();
479 
480  if (isset($children) && is_array($children) && count($children)) {
481  foreach ($children as $object) {
482  if ($object == $in_element) {
483  $ret = true;
484  break;
485  } else {
486  if ($full_hierachy && method_exists($object, 'areYouMyDaddy')) {
487  if ($object->areYouMyDaddy($in_element)) {
488  $ret = true;
489  break;
490  }
491  }
492  }
493  }
494  }
495 
496  return $ret;
497  }

◆ children()

tCO_Collection::children ( )

This is an accessor for the child object array (instances). It should be noted that this may not be the same as the 'children' context variable, because the user may not be allowed to see all of the items.

Returns
the child objects array.

Definition at line 591 of file tco_collection.interface.php.

591  {
592  if (!isset($this->_container) || !$this->_container || (!count($this->_container))) {
593  $this->_scrub();
594  $this->_set_up_container();
595  }
596  return $this->_container;
597  }
$_container
This contains instances of the records referenced by the IDs stored in the object.

Referenced by CO_User_Collection\delete_from_db().

Here is the caller graph for this function:

◆ children_ids()

tCO_Collection::children_ids (   $in_raw = false)

This is an accessor that returns a list of IDs for the direct children of this instance. This is "security vetted," so only IDs of children visible to the logged-in user are returned.

Returns
the child ids array (array of integer).
Parameters
$in_rawThis is only valid for "God Mode." If true, then the array is returned with no scrub, and no checks.

Definition at line 606 of file tco_collection.interface.php.

607  {
608  $ret = [];
609  if ($in_raw && $this->get_access_object()->god_mode()) { // God gets it all.
610  if (isset($this->context['children'])) {
611  return (array_map('intval', explode(',', $this->context['children'])));
612  } else {
613  return [];
614  }
615  }
616 
617  $this->_scrub();
618  if (isset($this->context['children_ids']) && is_array($this->context['children_ids']) && count ($this->context['children_ids'])) {
619  $ids = $this->context['children_ids'];
620  if ($this->get_access_object()->god_mode()) { // God gets it all.
621  $ret = $ids;
622  } else {
623  foreach ($ids as $id) {
624  if ($this->get_access_object()->item_exists($id, true)) {
625  $ret[] = intval($id);
626  }
627  }
628  }
629  }
630 
631  return $ret;
632  }

◆ count()

tCO_Collection::count (   $is_recursive = false)

This counts the direct children of this collection, and returns that count. If recursive, then it counts everything inside, including owners. Remember that this is "security-aware." The collection may have children that are not visible to the current login.

Returns
the number of direct children.
Parameters
$is_recursiveIf true, then this will also count all "child" collections. Default is false.

Definition at line 564 of file tco_collection.interface.php.

565  {
566  $children = $this->children();
567  $my_count = 0;
568 
569  if (isset($children) && is_array($children)) {
570  $my_count = count($children);
571 
572  if ($is_recursive) {
573  foreach ($children as $child) {
574  if (method_exists($child, 'count')) {
575  $my_count += $child->count($is_recursive);
576  }
577  }
578  }
579  }
580 
581  return $my_count;
582  }

Referenced by CO_User_Collection\is_god(), CO_User_Collection\set_tag(), and CO_User_Collection\set_tags().

Here is the caller graph for this function:

◆ deleteAllChildren()

tCO_Collection::deleteAllChildren ( )

This deletes all children of the container. However, the container may have children we can't see, so we don't delete those. We only delete the ones we know about (which could be all of them).

Returns
true, if the new configuration was successfully updated in the DB.

Definition at line 408 of file tco_collection.interface.php.

408  {
409  if ($this->user_can_write() ) { // You cannot delete from a collection if you don't have write privileges.
410  $new_list = [];
411 
412  if (isset($this->context['children_ids']) && is_array($this->context['children_ids']) && count($this->context['children_ids'])) {
413  foreach ($this->context['children_ids'] as $child_id) {
414  // We save items in the list that we can't see.
415  if ($this->get_access_object()->item_exists($child_id) && !$this->get_access_object()->can_i_see_this_data_record($child_id)) {
416  $new_list[] = $child_id;
417  }
418  }
419  }
420 
421  $this->_children = Array();
422  $this->context['children_ids'] = $new_list;
423  return $this->update_db();
424  }
425 
426  return false;
427  }

◆ deleteElement()

tCO_Collection::deleteElement (   $in_index)

Deletes a single element, by its 0-based index (not recursive). It should be noted that this does not delete the element from the database, and it is not recursive.

Returns
true, if the element was successfully removed from the collection.
Parameters
$in_indexThe 0-based index of the element we want to delete.

Definition at line 348 of file tco_collection.interface.php.

349  {
350  return $this->deleteElements($in_index, 1);
351  }
deleteElements( $in_first_index, $in_deletion_length)

◆ deleteElements()

tCO_Collection::deleteElements (   $in_first_index,
  $in_deletion_length 
)

Deletes multiple elements from the collection. It should be noted that this does not delete the elements from the database, and it is not recursive. This is an atomic operation. If any of the elements can't be removed, then non of the elements can be removed. The one exception is that the deletion length can extend past the boundaries of the collection. It will be truncated.

Returns
true, if the elements were successfully removed from the collection.
Parameters
$in_first_indexThe starting 0-based index of the first element to be removed from the collection.
$in_deletion_lengthThe number of elements to remove (including the first one). If this is negative, then elements will be removed from the index, backwards (-1 is the same as 1).

Definition at line 279 of file tco_collection.interface.php.

281  {
282  $ret = false;
283 
284  if ($this->user_can_write() ) { // You cannot add to a collection if you don't have write privileges.
285  $element_ids = Array(); // We will keep track of which IDs we delete, so we can delete them from our context variable.
286 
287  // If negative, we're going backwards.
288  if (0 > $in_deletion_length) {
289  $in_deletion_length = abs($in_deletion_length);
290  $in_first_index -= ($in_deletion_length - 1);
291  $in_first_index = max(0, $in_first_index); // Make sure we stay within the lane markers.
292  }
293 
294  $last_index_plus_one = min(count($this->_container), $in_first_index + $in_deletion_length);
295 
296  // We simply record the IDs of each of the elements we'll be deleting.
297  for ($i = $in_first_index; $i < $last_index_plus_one; $i++) {
298  $element = $this->_container[$i];
299  $element_ids[] = $element->id();
300  }
301 
302  if ($in_deletion_length == count($element_ids)) { // Belt and suspenders. Make sure we are actually deleting the requested elements.
303  $new_container = Array();
304 
305  // We build a new container that doesn't have the deleted elements.
306  foreach ($this->_container as $element) {
307  $element_id = $element->id();
308 
309  if (!in_array($element_id, $element_ids)) {
310  $new_container[] = $element_id;
311  }
312  }
313 
314  $new_list = Array();
315 
316  // We build a new list that doesn't have the deleted element IDs.
317  while ($element_id = array_shift($this->context['children_ids'])) {
318  if (!in_array($element_id, $element_ids)) {
319  $new_list[] = $element_id;
320  }
321  }
322 
323  $new_list = array_unique($new_list);
324  sort($new_list);
325  $this->context['children_ids'] = $new_list;
326 
327  $ret = $this->update_db();
328  if (!$this->_batch_mode) {
329  $this->_scrub();
330  }
331  }
332  } else {
336  }
337 
338  return $ret;
339  }
static $co_collection_error_code_user_not_authorized
Definition: common.inc.php:60
static $co_collection_error_desc_user_not_authorized
Definition: en.php:42
static $co_collection_error_name_user_not_authorized
Definition: en.php:41
This class provides a general error report, with file, method and error information.
Definition: error.class.php:32

References CO_CHAMELEON_Lang_Common\$co_collection_error_code_user_not_authorized, CO_CHAMELEON_Lang\$co_collection_error_desc_user_not_authorized, and CO_CHAMELEON_Lang\$co_collection_error_name_user_not_authorized.

◆ deleteThisElement()

tCO_Collection::deleteThisElement (   $in_element)

Deletes a single element, by its actual object reference (not recursive). It should be noted that this does not delete the element from the database, and it is not recursive.

Returns
true, if the element was successfully removed from the collection.
Parameters
$in_elementThe element we want to delete.

Definition at line 360 of file tco_collection.interface.php.

361  {
362  $ret = false;
363  $index = $this->indexOfThisElement($in_element);
364 
365  if (false !== $index) {
366  $ret = $this->deleteElement(intval($index));
367  }
368 
369  return $ret;
370  }
indexOfThisElement( $in_element)

◆ getHierarchy()

tCO_Collection::getHierarchy (   $loop_stopper = Array())
Returns
an instance "map" of the collection. It returns an array of associative arrays. Each associative array has the following elements:
  • 'object' (Required). This is the actual instance that maps to this object.
  • 'children' (optional -may not be instantiated). This is an array of the same associative arrays for any "child objects" of the current object.
Parameters
$loop_stopperThis is used to prevent "hierarchy loops." As we descend into recursion, we save the collection ID here. If the ID shows up in a "lower" collection, we don't add that collection. This shouldn't happen anyway, as were're not supposed to have been able to add embedded collections, but we can't be too careful. There can only be one...

Definition at line 683 of file tco_collection.interface.php.

689  {
690  $this->_scrub();
691 
692  $instance = Array('object' => $this);
693 
694  if (method_exists($this, 'children') && count($this->children())) {
695  $children = $this->children();
696  $instance['children'] = Array();
697 
698  foreach ($children as $child) {
699  if (method_exists($child, 'getHierarchy')) {
700  if (!in_array($child->id(), $loop_stopper)) {
701  $loop_stopper[] = $child->id();
702  $instance['children'][] = $child->getHierarchy($loop_stopper);
703  }
704  } else {
705  $instance['children'][] = Array('object' => $child);
706  }
707  }
708  }
709 
710  return $instance;
711  }

◆ indexOfThisElement()

tCO_Collection::indexOfThisElement (   $in_element)
Returns
the 0-based index of the given element, or false, if the element is not in the collection (This is not recursive).
Parameters
$in_elementThe element we're looking for.

Definition at line 433 of file tco_collection.interface.php.

434  {
435  return array_search($in_element, $this->children());
436  }

◆ insertElement()

tCO_Collection::insertElement (   $in_element,
  $in_before_index = -1,
  $dont_update = false 
)

This inserts one record to just before the indexed item (0-based index). If the index is -1, the length of the collection or larger, then the item will be appeneded. Collection elements cannot be already in the collection at any level, as that could cause a loop. We also don't allow duplicates of any instance in the same level of a collection. Only the first instance is retained. Subsequent copies are removed. The logged-in user must have write access to the collection object (not the data object) in order to add the item. You can opt out of the automatic database update.

Returns
true, if the data was successfully added. If a DB update was done, then the response is the one from the update.
Parameters
$in_elementThe database record to add.
$in_before_indexThe index of the element (in the current list) BEFORE which the insertion will be made. Default is -1 (append).
$dont_updatetrue, if we are to skip the DB update (default is false).

Definition at line 102 of file tco_collection.interface.php.

105  {
106  $ret = false;
107 
108  if ($in_element instanceof A_CO_DB_Table_Base) {
109  if ($this->user_can_write() ) { // You cannot add to a collection if you don't have write privileges.
110  if (!(method_exists($in_element, 'insertElement') && $this->areYouMyDaddy($in_element))) { // Make sure that a collection isn't already in the woodpile somewhere.
111  $id = intval($in_element->id());
112  if (!isset($this->_container) || !is_array($this->_container)) {
113  $this->_container = [];
114  }
115 
116  if (!isset($this->context['children_ids']) || !is_array($this->context['children_ids'])) {
117  $this->context['children_ids'] = [];
118  }
119 
120  if (!in_array($id, $this->context['children_ids'])) {
121  if ((-1 == $in_before_index) || (NULL == $in_before_index) || !isset($in_before_index)) {
122  $in_before_index = count($this->_container);
123  }
124 
125  $before_array = Array();
126 
127  if ($in_before_index) {
128  $before_array = array_slice($this->_container, 0, $in_before_index, false);
129  }
130 
131  $after_array = Array();
132 
133  if ($in_before_index < count($this->_container)) {
134  $end_count = count($this->_container) - $in_before_index;
135  $after_array = array_slice($this->_container, $end_count, false);
136  }
137 
138  $element_array = Array($in_element);
139 
140  $merged = array_merge($before_array, $element_array, $after_array);
141 
142  $this->_container = $merged;
143 
144  $ret = true;
145  if (!isset($this->context['children_ids'])) {
146  $this->context['children_ids'] = Array();
147  }
148 
149  $ids = array_map('intval', $this->context['children_ids']);
150  if (!in_array($id, $ids)) {
151  $ids[] = $id;
152  $ids = array_unique($ids);
153  sort($ids);
154  $this->context['children_ids'] = $ids;
155  }
156  }
157  }
158 
159  if ($ret && !$dont_update) {
160  $ret = $this->update_db();
161  }
162  } else {
166  }
167  }
168 
169  return $ret;
170  }
areYouMyDaddy( $in_element, $full_hierachy=true)

References CO_CHAMELEON_Lang_Common\$co_collection_error_code_user_not_authorized, CO_CHAMELEON_Lang\$co_collection_error_desc_user_not_authorized, and CO_CHAMELEON_Lang\$co_collection_error_name_user_not_authorized.

◆ insertElements()

tCO_Collection::insertElements (   $in_element_array,
  $in_before_index = -1 
)

This inserts multiple records to just before the indexed item (0-based index). If the index is -1, the length of the collection or larger, then the items will be appeneded. Collection elements cannot be already in the collection at any level, as that could cause a loop. We also don't allow duplicates of any class in the same level of a collection. Only the first instance is retained. Subsequent copies are removed. The logged-in user must have write access to the collection object (not the data objects) in order to add the items. You can opt out of the automatic database update.

Returns
true, if the data was successfully updated in the DB. false, if none of the items were added.
Parameters
$in_element_arrayAn array of database element instances to be inserted.
$in_before_indexThe index of the element (in the current list) BEFORE which the insertion will be made. Default is -1 (append).

Definition at line 182 of file tco_collection.interface.php.

184  {
185  $ret = false;
186 
187  if ($this->user_can_write() ) { // You cannot add to a collection if you don't have write privileges.
188  $i_have_a_daddy = false;
189 
190  if (is_array($in_element_array) && count($in_element_array)) {
191  foreach ($in_element_array as $element) {
192  // We can't insert nested collections.
193  if (method_exists($element, 'insertElement') && $this->areYouMyDaddy($element)) {
194  $i_have_a_daddy = true;
195  break;
196  }
197  }
198  }
199 
200  if (!$i_have_a_daddy) { // DON'T CROSS THE STREAMS!
201  if (!isset($this->_container) || !is_array($this->_container)) {
202  $this->_container = Array();
203  }
204 
205  if ((-1 == $in_before_index) || (NULL == $in_before_index) || !isset($in_before_index)) {
206  $in_before_index = count($this->_container);
207  }
208 
209  $before_array = Array();
210 
211  if ($in_before_index) {
212  $before_array = array_slice($this->_container, 0, $in_before_index, false);
213  }
214 
215  $after_array = Array();
216 
217  if ($in_before_index < count($this->_container)) {
218  $end_count = count($this->_container) - $in_before_index;
219  $after_array = array_slice($this->_container, $end_count, false);
220  }
221 
222  if (!isset($in_element_array) || !is_array($in_element_array) || !count($in_element_array)) {
223  $in_element_array = [];
224  }
225 
226  $merged = array_merge($before_array, $in_element_array, $after_array);
227 
228  $unique = array();
229 
230  if (is_array($merged) && count($merged)) {
231  foreach ($merged as $current) {
232  if (!in_array($current, $unique)) {
233  $unique[] = $current;
234  }
235  }
236  }
237 
238  $this->_container = $unique;
239 
240  $ret = true;
241 
242  if (!isset($this->context['children_ids'])) {
243  $this->context['children_ids'] = Array();
244  }
245 
246  foreach ($in_element_array as $element) {
247  $id = intval($element->id());
248  $ids = array_map('intval', $this->context['children_ids']);
249  if (!in_array($id, $ids)) {
250  $ids[] = $id;
251  $ids = array_unique($ids);
252  sort($ids);
253  $this->context['children_ids'] = $ids;
254  }
255  }
256  }
257 
258  if ($ret) {
259  $ret = $this->update_db();
260  }
261  } else {
265  }
266 
267  return $ret;
268  }

References CO_CHAMELEON_Lang_Common\$co_collection_error_code_user_not_authorized, CO_CHAMELEON_Lang\$co_collection_error_desc_user_not_authorized, and CO_CHAMELEON_Lang\$co_collection_error_name_user_not_authorized.

◆ map()

tCO_Collection::map (   $in_function)

This applies a given function to each of the elements in the child list. The function needs to have a signature of function mixed map_func(mixed $item);

Returns
a flat array of function results. The array maps to the children array.
Parameters
$in_functionThe function to be applied to each element.

Definition at line 506 of file tco_collection.interface.php.

507  {
508  $ret = Array();
509 
510  $children = $this->children();
511 
512  foreach ($children as $child) {
513  $result = $in_function($child);
514  $ret[] = $result;
515  }
516 
517  return self::class;
518  }

◆ recursiveMap()

tCO_Collection::recursiveMap (   $in_function,
  $in_hierarchy_level = 0,
  $in_parent_object = NULL,
  $loop_stopper = Array() 
)

This applies a given function to each of the elements in the child list, and any embedded (recursive) ones. The function needs to have a signature of function mixed map_func(mixed $item, integer $hierarchy_level, mixed $parent_object);

Returns
a flat array of function results. This array may be larger than the children array, as it will also contain any nested collections.
Parameters
$in_functionThis is the function to be applied to all elements.
$in_hierarchy_levelThis is a 0-based integer that tells the callback how many "levels deep" the function is.
$in_parent_objectThis is the collection object that is the "parent" of the current array.
$loop_stopperThis is used to prevent "hierarchy loops." As we descend into recursion, we save the collection ID here. If the ID shows up in a "lower" collection, we don't add that collection. This shouldn't happen anyway, as were're not supposed to have been able to add embedded collections, but we can't be too careful. There can only be one...

Definition at line 527 of file tco_collection.interface.php.

536  {
537  $in_hierarchy_level = intval($in_hierarchy_level);
538  $ret = Array($in_function($this, $in_hierarchy_level, $in_parent_object));
539  $children = $this->children();
540 
541  foreach ($children as $child) {
542  if (method_exists($child, 'recursiveMap')) {
543  if (!in_array($child->id(), $loop_stopper)) {
544  $loop_stopper[] = $child->id();
545  $result = $child->recursiveMap($in_function, ++$in_hierarchy_level, $this, $loop_stopper);
546  }
547  } else {
548  $result = Array($in_function($child, ++$in_hierarchy_level, $this));
549  }
550  $ret = array_merge($ret, $result);
551  }
552 
553  return $ret;
554  }

◆ reload_collection()

tCO_Collection::reload_collection ( )

This method forces a reload of the collection data.

Definition at line 87 of file tco_collection.interface.php.

87  {
88  $this->_scrub(); // Garbage collection.
89  $this->_set_up_container();
90  }

◆ set_children_ids()

tCO_Collection::set_children_ids (   $in_new_ids)

This is a "God Mode-only" method that is used to wholesale replace the entire children array.

Returns
true, if the operation was allowed and successful.
Parameters
$in_new_idsThis is an array of integers, with the IDs of new children. This entirely replaces the current array.

Definition at line 640 of file tco_collection.interface.php.

641  {
642  $ret = false;
643 
644  if ($this->get_access_object()->god_mode()) {
645  $this->_children = Array();
646  $this->context['children'] = implode(',', $in_new_ids);
647  unset($this->context['children_ids']);
648  $ret = $this->update_db();
649  }
650 
651  return $ret;
652  }

◆ who_are_my_parents()

tCO_Collection::who_are_my_parents ( )
Returns
an array of any direct parents of the current object. The returned objects will be collection instances. An empty array will be returned if no parents found.

Definition at line 658 of file tco_collection.interface.php.

658  {
659  $ret = [];
660 
661  $result = $this->get_access_object()->generic_search(Array('access_class' => Array('%_Collection%', 'use_like' => 1)));
662 
663  if (isset($result) && is_array($result) && count($result)) {
664  foreach ($result as $object) {
665  if (($object instanceof CO_Main_DB_Record) && method_exists($object, 'areYouMyDaddy')) {
666  if ($object->areYouMyDaddy($this, false)) {
667  $ret[] = $object;
668  }
669  }
670  }
671  }
672 
673  return $ret;
674  }

◆ whosYourDaddy()

tCO_Collection::whosYourDaddy (   $in_element)

This takes an element, and returns its parent collection object (if available). This only checks the current collection and its "child" collection objects.

Returns
an array of instances of a collection class, if that instance is the "parent" of the presented object. It may be this instance, or a "child" instance of this class.
Parameters
$in_elementThe element to check.

Definition at line 445 of file tco_collection.interface.php.

446  {
447  $ret = NULL;
448  $id = intval($in_element->id());
449 
450  $ret_array = $this->recursiveMap(function($instance, $hierarchy_level, $parent){
451  $id = intval($instance->id());
452  return Array($id, $parent);
453  });
454 
455  if (isset($ret_array) && is_array($ret_array) && count($ret_array)) {
456  $ret = Array();
457  foreach ($ret_array as $item) {
458  if ($item[0] == $id) {
459  $ret[] = $item[1];
460  }
461  }
462  }
463 
464  return $ret;
465  }
recursiveMap( $in_function, $in_hierarchy_level=0, $in_parent_object=NULL, $loop_stopper=Array())

Member Data Documentation

◆ $_container

tCO_Collection::$_container
protected

This contains instances of the records referenced by the IDs stored in the object.

Definition at line 38 of file tco_collection.interface.php.