26 defined(
'LGV_DBF_CATCHER' ) or die ( 'Cannot Execute Directly' );
28 require_once(CO_Config::db_classes_class_dir().'/co_ll_location.class.php');
46 if (isset($this->context[
'children_ids'])) {
47 $children_ids = $this->context[
'children_ids'];
49 if (isset($children_ids) && is_array($children_ids) && count($children_ids)) {
51 foreach ($children_ids as $id) {
53 if ($this->get_access_object()->item_exists($id)) {
57 $new_ids = array_unique($new_ids);
59 $this->context[
'children_ids'] = $new_ids;
63 $this->_container = Array();
74 if (isset($this->context[
'children_ids'])) {
75 $children_ids = $this->context[
'children_ids'];
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);
89 $this->_set_up_container();
103 $in_before_index = -1,
109 if ($this->user_can_write() ) {
110 if (!(method_exists($in_element,
'insertElement') && $this->areYouMyDaddy($in_element))) {
111 $id = intval($in_element->id());
112 if (!isset($this->_container) || !is_array($this->_container)) {
113 $this->_container = [];
116 if (!isset($this->context[
'children_ids']) || !is_array($this->context[
'children_ids'])) {
117 $this->context[
'children_ids'] = [];
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);
125 $before_array = Array();
127 if ($in_before_index) {
128 $before_array = array_slice($this->_container, 0, $in_before_index,
false);
131 $after_array = Array();
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);
138 $element_array = Array($in_element);
140 $merged = array_merge($before_array, $element_array, $after_array);
142 $this->_container = $merged;
145 if (!isset($this->context[
'children_ids'])) {
146 $this->context[
'children_ids'] = Array();
149 $ids = array_map(
'intval', $this->context[
'children_ids']);
150 if (!in_array($id, $ids)) {
152 $ids = array_unique($ids);
154 $this->context[
'children_ids'] = $ids;
159 if ($ret && !$dont_update) {
160 $ret = $this->update_db();
183 $in_before_index = -1
187 if ($this->user_can_write() ) {
188 $i_have_a_daddy =
false;
190 if (is_array($in_element_array) && count($in_element_array)) {
191 foreach ($in_element_array as $element) {
193 if (method_exists($element,
'insertElement') && $this->areYouMyDaddy($element)) {
194 $i_have_a_daddy =
true;
200 if (!$i_have_a_daddy) {
201 if (!isset($this->_container) || !is_array($this->_container)) {
202 $this->_container = Array();
205 if ((-1 == $in_before_index) || (NULL == $in_before_index) || !isset($in_before_index)) {
206 $in_before_index = count($this->_container);
209 $before_array = Array();
211 if ($in_before_index) {
212 $before_array = array_slice($this->_container, 0, $in_before_index,
false);
215 $after_array = Array();
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);
222 if (!isset($in_element_array) || !is_array($in_element_array) || !count($in_element_array)) {
223 $in_element_array = [];
226 $merged = array_merge($before_array, $in_element_array, $after_array);
230 if (is_array($merged) && count($merged)) {
231 foreach ($merged as $current) {
232 if (!in_array($current, $unique)) {
233 $unique[] = $current;
238 $this->_container = $unique;
242 if (!isset($this->context[
'children_ids'])) {
243 $this->context[
'children_ids'] = Array();
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)) {
251 $ids = array_unique($ids);
253 $this->context[
'children_ids'] = $ids;
259 $ret = $this->update_db();
284 if ($this->user_can_write() ) {
285 $element_ids = Array();
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);
294 $last_index_plus_one = min(count($this->_container), $in_first_index + $in_deletion_length);
297 for ($i = $in_first_index; $i < $last_index_plus_one; $i++) {
298 $element = $this->_container[$i];
299 $element_ids[] = $element->id();
302 if ($in_deletion_length == count($element_ids)) {
303 $new_container = Array();
306 foreach ($this->_container as $element) {
307 $element_id = $element->id();
309 if (!in_array($element_id, $element_ids)) {
310 $new_container[] = $element_id;
317 while ($element_id = array_shift($this->context[
'children_ids'])) {
318 if (!in_array($element_id, $element_ids)) {
319 $new_list[] = $element_id;
323 $new_list = array_unique($new_list);
325 $this->context[
'children_ids'] = $new_list;
327 $ret = $this->update_db();
328 if (!$this->_batch_mode) {
350 return $this->deleteElements($in_index, 1);
363 $index = $this->indexOfThisElement($in_element);
365 if (
false !== $index) {
366 $ret = $this->deleteElement(intval($index));
385 return $this->insertElement($in_element, -1);
398 return $this->insertElements($in_element_array, -1);
409 if ($this->user_can_write() ) {
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) {
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;
421 $this->_children = Array();
422 $this->context[
'children_ids'] = $new_list;
423 return $this->update_db();
435 return array_search($in_element, $this->children());
448 $id = intval($in_element->id());
450 $ret_array = $this->recursiveMap(
function($instance, $hierarchy_level, $parent){
451 $id = intval($instance->id());
452 return Array($id, $parent);
455 if (isset($ret_array) && is_array($ret_array) && count($ret_array)) {
457 foreach ($ret_array as $item) {
458 if ($item[0] == $id) {
474 $full_hierachy =
true
478 $children = $this->children();
480 if (isset($children) && is_array($children) && count($children)) {
481 foreach ($children as $object) {
482 if ($object == $in_element) {
486 if ($full_hierachy && method_exists($object,
'areYouMyDaddy')) {
487 if ($object->areYouMyDaddy($in_element)) {
506 public function map( $in_function
510 $children = $this->children();
512 foreach ($children as $child) {
513 $result = $in_function($child);
528 $in_hierarchy_level = 0,
529 $in_parent_object = NULL,
530 $loop_stopper = Array()
537 $in_hierarchy_level = intval($in_hierarchy_level);
538 $ret = Array($in_function($this, $in_hierarchy_level, $in_parent_object));
539 $children = $this->children();
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);
548 $result = Array($in_function($child, ++$in_hierarchy_level, $this));
550 $ret = array_merge($ret, $result);
564 public function count( $is_recursive =
false
566 $children = $this->children();
569 if (isset($children) && is_array($children)) {
570 $my_count = count($children);
573 foreach ($children as $child) {
574 if (method_exists($child,
'count')) {
575 $my_count += $child->count($is_recursive);
592 if (!isset($this->_container) || !$this->_container || (!count($this->_container))) {
594 $this->_set_up_container();
596 return $this->_container;
609 if ($in_raw && $this->get_access_object()->god_mode()) {
610 if (isset($this->context[
'children'])) {
611 return (array_map(
'intval', explode(
',', $this->context[
'children'])));
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()) {
623 foreach ($ids as $id) {
624 if ($this->get_access_object()->item_exists($id,
true)) {
625 $ret[] = intval($id);
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();
661 $result = $this->get_access_object()->generic_search(Array(
'access_class' => Array(
'%_Collection%',
'use_like' => 1)));
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)) {
692 $instance = Array(
'object' => $this);
694 if (method_exists($this,
'children') && count($this->children())) {
695 $children = $this->children();
696 $instance[
'children'] = Array();
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);
705 $instance[
'children'][] = Array(
'object' => $child);
appendElements( $in_element_array)
set_children_ids( $in_new_ids)
areYouMyDaddy( $in_element, $full_hierachy=true)
getHierarchy( $loop_stopper=Array())
deleteElements( $in_first_index, $in_deletion_length)
children_ids( $in_raw=false)
whosYourDaddy( $in_element)
deleteElement( $in_index)
count( $is_recursive=false)
$_container
This contains instances of the records referenced by the IDs stored in the object.
indexOfThisElement( $in_element)
appendElement( $in_element)
insertElement( $in_element, $in_before_index=-1, $dont_update=false)
deleteThisElement( $in_element)
insertElements( $in_element_array, $in_before_index=-1)
recursiveMap( $in_function, $in_hierarchy_level=0, $in_parent_object=NULL, $loop_stopper=Array())
static $co_collection_error_code_user_not_authorized
static $co_collection_error_desc_user_not_authorized
static $co_collection_error_name_user_not_authorized
This class provides a general error report, with file, method and error information.