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

Public Member Functions

 adopt_child ( $in_object_to_own)
 
 count ()
 
 children_ids ()
 
 children ()
 
 generic_search ( $in_search_parameters=NULL, $page_size=0, $initial_page=0, $and_writeable=false, $count_only=false, $ids_only=false)
 

Public Attributes

 $my_owner_id = NULL
 This is the ID We will use for the "owner." If left NULL, then the instance ID is used instead. More...
 

Protected Attributes

 $_cached_ids = NULL
 This will contain our "owned" IDs after we load. More...
 

Detailed Description

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

Owners are VERY simple aggregates. They only allow a very rough "pre-filter" for searches. If you want to get fancier, use a collection (but you won't be able to handle as many children).

Definition at line 36 of file tco_owner.interface.php.

Member Function Documentation

◆ adopt_child()

tCO_Owner::adopt_child (   $in_object_to_own)

This method will change a given object to have this as its owner.

Returns
true, if the object's owner changed successfully.
Parameters
$in_object_to_ownThe instance that will be "owned" by this instance. The user must have write privileges on the onject.

Definition at line 46 of file tco_owner.interface.php.

47  {
48  $ret = false;
49 
50  $my_owner_id = intval($this->my_owner_id) ? intval($this->my_owner_id) : $this->id();
51  if ($in_object_to_own->owner_id() != $my_owner_id) {
52  if ($in_object->user_can_write()) {
53  $ret = $in_object->set_owner_id($my_owner_id);
54  } else {
58  }
59  }
60 
61  return $ret;
62  }
$my_owner_id
This is the ID We will use for the "owner." If left NULL, then the instance ID is used instead.
static $co_owner_error_code_user_not_authorized
Definition: common.inc.php:61
static $co_owner_error_desc_user_not_authorized
Definition: en.php:46
static $co_owner_error_name_user_not_authorized
These apply to the Owner classes.
Definition: en.php:45
This class provides a general error report, with file, method and error information.
Definition: error.class.php:32

References CO_CHAMELEON_Lang_Common\$co_owner_error_code_user_not_authorized, CO_CHAMELEON_Lang\$co_owner_error_desc_user_not_authorized, and CO_CHAMELEON_Lang\$co_owner_error_name_user_not_authorized.

◆ children()

tCO_Owner::children ( )

WARNING: Since the "owner" object is for big, fat datasets, this could blow up memory!

Returns
an array of instances, comprising all "owned" instances. This could recurse, inside the "child" objects.

Definition at line 96 of file tco_owner.interface.php.

96  {
97  $children_ids = $this->children_ids();
98  return $this->get_access_object()->get_multiple_data_records_by_id($children_ids);
99  }

◆ children_ids()

tCO_Owner::children_ids ( )
Returns
an array of integers, with the "owned" object IDs.

Definition at line 81 of file tco_owner.interface.php.

81  {
82  if (!((isset($this->_cached_ids) && is_array($this->_cached_ids) && count($this->_cached_ids)))) {
83  $my_owner_id = intval($this->my_owner_id) ? intval($this->my_owner_id) : $this->id();
84  $this->_cached_ids = $this->get_access_object()->generic_search(Array('owner' => $my_owner_id), false, 0, 0, false, false, true);
85  }
86 
87  return $this->_cached_ids;
88  }
$_cached_ids
This will contain our "owned" IDs after we load.

◆ count()

tCO_Owner::count ( )

This counts the direct children of this collection, and returns that count.

Returns
the number of children.

Definition at line 70 of file tco_owner.interface.php.

70  {
71  $children_ids = $this->children_ids();
72  $my_count = isset($children_ids) && is_array($children_ids) ? count($children_ids) : 0;
73 
74  return $my_count;
75  }

◆ generic_search()

tCO_Owner::generic_search (   $in_search_parameters = NULL,
  $page_size = 0,
  $initial_page = 0,
  $and_writeable = false,
  $count_only = false,
  $ids_only = false 
)

This is a "generic" data database search. It can be called from external user contexts, and allows a fairly generalized search of the "data" database. Sorting will be done for the "owner" and "location" values. "owner" will be sorted by the ID of the returned records, and "location" will be by distance from the center. This will ignore any "owner" parameters, and will only look for this specific owner. There is no "OR" search. It is always "AND."

It is "security-safe."

Returns
an array of instances that match the search parameters. If $count_only is true, then it will be a single integer, with the count of responses to the search (if a page, then only the number of items on that page).
Parameters
$in_search_parametersThis is an associative array of terms to define the search. The keys should be:
  • 'id' This should be accompanied by an array of one or more integers, representing specific item IDs. These can only be ones "owned" by this instance.
  • 'access_class' This should be accompanied by an array, containing one or more PHP class names.
  • 'name' This will contain a case-insensitive array of strings to check against the object_name column.
  • 'tags' This should be accompanied by an array (up to 10 elements) of one or more case-insensitive strings, representing specific tag values.
  • 'location' This requires that the parameter be a 3-element associative array of floating-point numbers:
    • 'longtude' This is the search center location longitude, in degrees.
    • 'latitude' This is the search center location latitude, in degrees.
    • 'radius' This is the search radius, in Kilometers.
$page_sizeIf specified with a 1-based integer, this denotes the size of a "page" of results. NOTE: This is only applicable to MySQL or Postgres, and will be ignored if the DB is not MySQL or Postgres.
$initial_pageThis is ignored unless $page_size is greater than 0. If so, then this 0-based index will specify which page of results to return.
$and_writeableIf true, then we only want records we can modify.
$count_onlyIf true (default is false), then only a single integer will be returned, with the count of items that fit the search.
$ids_onlyIf true (default is false), then the return array will consist only of integers (the object IDs). If $count_only is true, this is ignored.

Definition at line 112 of file tco_owner.interface.php.

135  {
136  $my_owner_id = intval($this->my_owner_id) ? intval($this->my_owner_id) : $this->id();
137  $in_search_parameters['owner'] = $my_owner_id;
138  return $this->get_access_object()->generic_search($in_search_parameters, false, $page_size, $initial_page, $and_writeable, $count_only, $ids_only);
139 
140  return $ret;
141  }

Member Data Documentation

◆ $_cached_ids

tCO_Owner::$_cached_ids = NULL
protected

This will contain our "owned" IDs after we load.

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

◆ $my_owner_id

tCO_Owner::$my_owner_id = NULL

This is the ID We will use for the "owner." If left NULL, then the instance ID is used instead.

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