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

Public Member Functions

 __construct ( $in_db_object=NULL, $in_db_result=NULL, $in_owner_id=NULL, $in_tags_array=NULL)
 
 load_from_db ( $in_db_result)
 
 get_login_instance ()
 
 has_login ()
 
 has_login_i_cant_see ()
 
 is_god ()
 
 is_manager ()
 
 set_tags ( $in_tags_array)
 
 set_tag ( $in_tag_index, $in_tag_value)
 
 get_surname ()
 
 set_surname ( $in_surname)
 
 get_middle_name ()
 
 set_middle_name ( $in_middle_name)
 
 get_given_name ()
 
 set_given_name ( $in_given_name)
 
 get_prefix ()
 
 set_prefix ( $in_prefix)
 
 get_suffix ()
 
 set_suffix ( $in_suffix)
 
 get_nickname ()
 
 set_nickname ( $in_nickname)
 
 set_login ( $in_login_id_integer)
 
 get_lang ()
 
 delete_from_db ( $with_extreme_prejudice=false, $delete_login_object_too=false)
 
- Public Member Functions inherited from CO_LL_Location
 __construct ( $in_db_object=NULL, $in_db_result=NULL, $in_owner_id=NULL, $in_tags_array=NULL, $in_longitude=NULL, $in_latitude=NULL, $in_fuzz_factor=NULL, $in_can_see_through_the_fuzz=NULL)
 
 update_db ()
 
 set_longitude ( $in_new_value)
 
 set_latitude ( $in_new_value)
 
 fuzz_factor ()
 
 is_fuzzy ()
 
 set_fuzz_factor ( $in_new_value)
 
 raw_longitude ()
 
 raw_latitude ()
 
 longitude ()
 
 latitude ()
 
 set_can_see_through_the_fuzz ( $in_id)
 
 can_see_through_the_fuzz ()
 
 i_can_see_clearly_now ()
 
- Public Member Functions inherited from CO_Main_DB_Record
 set_owner_id ( $in_new_id)
 
 get_payload ()
 
 set_payload ( $in_payload)
 
 owner_id ()
 
 tags ()
 
- Public Member Functions inherited from A_CO_DB_Table_Base
 __construct ( $in_db_object=NULL, $in_db_result=NULL)
 
 set_batch_mode ()
 
 clear_batch_mode ()
 
 id ()
 
 lock ()
 
 locked ()
 
 danger_will_robinson_danger_clear_id ()
 
 user_can_read ()
 
 user_can_write ()
 
 set_read_security_id ($in_new_id)
 
 set_write_security_id ($in_new_id)
 
 set_name ($in_new_value)
 
 delete_from_db ()
 
 reload_from_db ()
 
 get_access_object ()
 
 set_lang ( $in_lang_id=NULL)
 
- Public Member Functions inherited from tCO_Collection
 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

 _load_login ()
 
- Protected Member Functions inherited from CO_LL_Location
 _default_setup ()
 
 _build_parameter_array ()
 
 _km_per_degree ()
 
 _fuzz_me ()
 
- Protected Member Functions inherited from A_CO_DB_Table_Base
 _badger_serialize ( $in_data)
 
 _badger_unserialize ( $in_data)
 
 _write_to_db ()
 
 _seppuku ()
 
- Protected Member Functions inherited from tCO_Collection
 _scrub ()
 
 _set_up_container ()
 

Private Attributes

 $_login_object = NULL
 The Security DB COBRA login instance associated with this user. More...
 

Additional Inherited Members

- Public Attributes inherited from A_CO_DB_Table_Base
 $class_description
 This is a description of the class (not the instance). More...
 
 $instance_description
 This is a description that describes the instance. More...
 
 $last_access
 This is a UNIX epoch date that describes the last modification. The default is UNIX Day Two (in case of UTC timezone issues). More...
 
 $name
 This is the "object_name" string field. More...
 
 $read_security_id
 This is a single integer, defining the security ID required to view the record. If it is 0, then it is "open.". More...
 
 $write_security_id
 This is a single integer, defining the required security token to modify the record. If it is 0, then any logged-in user can modify. More...
 
 $context
 This is a mixed associative array, containing fields for the object. More...
 
 $error
 If there is an error, it is contained here, in a LGV_Error instance. More...
 
- Static Public Attributes inherited from CO_Main_DB_Record
static $s_table_name = 'co_data_nodes'
 
- Protected Attributes inherited from CO_LL_Location
 $_longitude
 
 $_latitude
 
- Protected Attributes inherited from CO_Main_DB_Record
 $_owner_id
 
 $_tags
 
- Protected Attributes inherited from A_CO_DB_Table_Base
 $_db_object
 This is the actual database object that "owns" this instance. It should not be exposed beyond this class or subclasses, thereof. More...
 
 $_id
 This is the within-table unique ID of this record. More...
 
 $_batch_mode
 If this is true, then the write_record call will not be made in update_db. It will be done when clear_batch_mode() is called, instead. More...
 
- Protected Attributes inherited from tCO_Collection
 $_container
 This contains instances of the records referenced by the IDs stored in the object. More...
 

Detailed Description

This is a container, meant to define a user.

A user is a collection, with various data items attached to it.

The first seven tags are reserved for the class:

  • Tag 0, which is the ID of an associated login. This can only be changed if the logged-in user has write permissions on this object, and at least read permissions on the login.
  • Tag 1, the user's surname (family name).
  • Tag 2, the user's middle name.
  • Tag 3, the user's given (first) name.
  • Tag 4, the user's prefix (Mr., Mrs., Dr., etc.).
  • Tag 5, the user's suffix (Ph.D., LCSW, Jr., III, etc.).
  • Tag 6, the user's nickname.

It also has a single link to a login (which can be NULL, if the user is not one that can log into the system).

As with other login-related classes, only login managers that have access to security tokens (which are also IDs of login and other security DB items) can set certain IDs as tokens.

Definition at line 68 of file co_user_collection.class.php.

Constructor & Destructor Documentation

◆ __construct()

CO_User_Collection::__construct (   $in_db_object = NULL,
  $in_db_result = NULL,
  $in_owner_id = NULL,
  $in_tags_array = NULL 
)

Constructor (Initializer)

Parameters
$in_db_objectThe database object for this instance.
$in_db_resultThe database row for this instance (associative array, with database keys).
$in_owner_idThe ID of the object (in the database) that "owns" this instance.
$in_tags_arrayAn array of strings, up to ten elements long, for the tags. Tag 0 MUST be a single integer (as a string), with the ID of the login object associated with this instance.

Reimplemented from CO_Main_DB_Record.

Definition at line 122 of file co_user_collection.class.php.

127  {
128 
129  $this->_container = Array();
130  $this->_login_object = NULL;
131 
132  parent::__construct($in_db_object, $in_db_result, $in_owner_id, $in_tags_array);
133 
134  $this->class_description = "This is a 'Collection' Class for Users.";

Member Function Documentation

◆ _load_login()

CO_User_Collection::_load_login ( )
protected
Returns
true, if the instance was able to set itself up to the internal login ID.

Definition at line 76 of file co_user_collection.class.php.

77  {
78  $ret = false;
79  // Tag 0 contains the ID of the user login (in the security DB) for this user.
80  $login_id = isset($this->tags()[0]) ? intval($this->tags()[0]) : 0;
81 
82  if (0 < $login_id) {
83  $my_login_object = $this->get_access_object()->get_single_security_record_by_id($login_id);
84 
85  if (isset($my_login_object) && ($my_login_object instanceof CO_Security_Login)) {
86  $this->_login_object = $my_login_object;
87  $ret = true;
88  } elseif (!($my_login_object instanceof CO_Security_Login)) {
92  __FILE__,
93  __LINE__,
94  __METHOD__
95  );
96  } else {
100  __FILE__,
101  __LINE__,
102  __METHOD__
103  );
104  }
105  } else {
109  __FILE__,
110  __LINE__,
111  __METHOD__
112  );
113  }
114 
115  return $ret;
static $user_error_code_invalid_class
Definition: common.inc.php:67
static $user_error_code_invalid_id
Definition: common.inc.php:66
static $user_error_code_user_not_authorized
Definition: common.inc.php:65
static $user_error_name_invalid_class
Definition: en.php:59
static $user_error_name_user_not_authorized
Definition: en.php:55
static $user_error_name_invalid_id
Definition: en.php:57
static $user_error_desc_invalid_id
Definition: en.php:58
static $user_error_desc_invalid_class
Definition: en.php:60
static $user_error_desc_user_not_authorized
Definition: en.php:56
This class provides a general error report, with file, method and error information.
Definition: error.class.php:32

References CO_CHAMELEON_Lang_Common\$user_error_code_invalid_class, CO_CHAMELEON_Lang_Common\$user_error_code_invalid_id, CO_CHAMELEON_Lang_Common\$user_error_code_user_not_authorized, CO_CHAMELEON_Lang\$user_error_desc_invalid_class, CO_CHAMELEON_Lang\$user_error_desc_invalid_id, CO_CHAMELEON_Lang\$user_error_desc_user_not_authorized, CO_CHAMELEON_Lang\$user_error_name_invalid_class, CO_CHAMELEON_Lang\$user_error_name_invalid_id, CO_CHAMELEON_Lang\$user_error_name_user_not_authorized, A_CO_DB_Table_Base\get_access_object(), and CO_Main_DB_Record\tags().

Referenced by get_login_instance(), and is_manager().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ delete_from_db()

CO_User_Collection::delete_from_db (   $with_extreme_prejudice = false,
  $delete_login_object_too = false 
)

We override this, because we want to see if they want us to delete associated objects.

Returns
true, if the deletion was successful.
Parameters
$with_extreme_prejudiceIf true (Default is false), then we will attempt to delete all contained children. Remember that this could cause problems if other collections can see the children!
$delete_login_object_tooIf true (Default is false), then we will attempt to delete any associated login object, as well.

Definition at line 448 of file co_user_collection.class.php.

451  {
452  if ($with_extreme_prejudice && $this->user_can_write()) {
453  // We don't error-check this on purpose, as it's a given that there might be issues, here. This is a "due dilligence" thing.
454  $user_items_to_delete = $this->children();
455 
456  foreach ($user_items_to_delete as $child) {
457  if ($child->user_can_write()) {
458  $child->delete_from_db();
459  }
460  }
461  }
462 
463  // Again, we won't return false if this fails, but we will fetch the error.
464  if ($delete_login_object_too) {
465  $login_object = $this->get_login_instance();
466 
467  if (isset($login_object) && $login_object->user_can_write()) {
468  $login_object->delete_from_db();
469  $this->error = $login_object->error;
470  }
471  }
472 
473  return parent::delete_from_db();

References tCO_Collection\children(), get_login_instance(), and A_CO_DB_Table_Base\user_can_write().

Here is the call graph for this function:

◆ get_given_name()

CO_User_Collection::get_given_name ( )

Simple getter for the given (first) name tag (tag 3).

Returns
a string, with the given name.

Definition at line 306 of file co_user_collection.class.php.

307  {
308  return isset($this->_tags[3]) ? $this->_tags[3] : '';

◆ get_lang()

CO_User_Collection::get_lang ( )

We override this, because we see if we need to fetch our lang from the login object.

Returns
a string, with the language ID for this login.

Reimplemented from A_CO_DB_Table_Base.

Definition at line 429 of file co_user_collection.class.php.

430  {
431  $ret = parent::get_lang();
432 
433  if (!isset($this->context['lang'])) {
434  $login_object = $this->get_login_instance();
435  if (isset($login_object) && ($login_object instanceof CO_Security_Login)) {
436  $ret = $login_object->get_lang();
437  }
438  }
439 
440  return $ret;

References get_login_instance().

Here is the call graph for this function:

◆ get_login_instance()

CO_User_Collection::get_login_instance ( )

Accessor for the login object.

Note that this may return NULL, even if there is a login, as the current user may not have permission to see that login.

Returns
the login object associated with this user. It loads the object, if one is not in the cache.

Definition at line 159 of file co_user_collection.class.php.

160  {
161  if (!($this->_login_object instanceof CO_Security_Login)) {
162  $this->_load_login();
163  }
164 
165  return $this->_login_object;
$_login_object
The Security DB COBRA login instance associated with this user.

References $_login_object, and _load_login().

Referenced by delete_from_db(), get_lang(), and has_login_i_cant_see().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_middle_name()

CO_User_Collection::get_middle_name ( )

Simple getter for the middle name tag (tag 2).

Returns
a string, with the middle name.

Definition at line 285 of file co_user_collection.class.php.

286  {
287  return isset($this->_tags[2]) ? $this->_tags[2] : '';

◆ get_nickname()

CO_User_Collection::get_nickname ( )

Simple getter for the nickname tag (tag 6).

Returns
a string, with the nickname.

Definition at line 369 of file co_user_collection.class.php.

370  {
371  return isset($this->_tags[6]) ? $this->_tags[6] : '';

◆ get_prefix()

CO_User_Collection::get_prefix ( )

Simple getter for the prefix tag (tag 4).

Returns
a string, with the prefix.

Definition at line 327 of file co_user_collection.class.php.

328  {
329  return isset($this->_tags[4]) ? $this->_tags[4] : '';

◆ get_suffix()

CO_User_Collection::get_suffix ( )

Simple getter for the suffix tag (tag 5).

Returns
a string, with the suffix.

Definition at line 348 of file co_user_collection.class.php.

349  {
350  return isset($this->_tags[5]) ? $this->_tags[5] : '';

◆ get_surname()

CO_User_Collection::get_surname ( )

Simple getter for the surname tag (tag 1).

Returns
a string, with the surname.

Definition at line 264 of file co_user_collection.class.php.

265  {
266  return isset($this->_tags[1]) ? $this->_tags[1] : '';

◆ has_login()

CO_User_Collection::has_login ( )

This is a "security-safe" way of testing for an associated login object. The user may have permission to view the user, but not the login, and they should not know what the login ID is, so this masks the ID.

Returns
true, if the object has a login (regardless of whether or not they can see that login).

Definition at line 173 of file co_user_collection.class.php.

174  {
175  return (intval($this->tags()[0]) > 0);

References CO_Main_DB_Record\tags().

Here is the call graph for this function:

◆ has_login_i_cant_see()

CO_User_Collection::has_login_i_cant_see ( )

This is a "security-safe" way of testing for a login ID that the current user can't see. The user may have permission to view the user, but not the login, and they should not know what the login ID is, so this masks the ID.

Returns
true, if the object has a login ID, but the current user can't see that ID or object.

Definition at line 183 of file co_user_collection.class.php.

184  {
185  $this->get_login_instance();
186  return (!($this->_login_object instanceof CO_Security_Login) && (isset($this->tags()[0]) && intval($this->tags()[0])));

References get_login_instance(), and CO_Main_DB_Record\tags().

Here is the call graph for this function:

◆ is_god()

CO_User_Collection::is_god ( )

This is a "security-safe" way of testing for a God login ID. The user may have permission to view the user, but not the login, and they should not know what the login ID is, so this masks the ID.

Returns
true, if the "God" user.

Definition at line 194 of file co_user_collection.class.php.

195  {
196  $tags = $this->tags();
197 
198  return isset($tags) && is_array($tags) && count($tags) && (0 < intval($tags[0])) && (intval($tags[0]) == CO_Config::god_mode_id());
count( $is_recursive=false)

References tCO_Collection\count(), and CO_Main_DB_Record\tags().

Referenced by is_manager().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_manager()

CO_User_Collection::is_manager ( )
Returns
true, if we are a manager.

Definition at line 204 of file co_user_collection.class.php.

205  {
206  if (!$this->is_god() && !isset($this->_login_object)) {
207  $this->_load_login();
208  }
209 
210  return $this->is_god() || (isset($this->_login_object) && ($this->_login_object instanceof CO_Login_Manager));

References _load_login(), and is_god().

Here is the call graph for this function:

◆ load_from_db()

CO_User_Collection::load_from_db (   $in_db_result)

This function sets up this instance, according to the DB-formatted associative array passed in.

Returns
true, if the instance was able to set itself up to the provided array.
Parameters
$in_db_resultThis is an associative array, formatted as a database row response.

Reimplemented from CO_LL_Location.

Definition at line 142 of file co_user_collection.class.php.

144  {
145  $ret = parent::load_from_db($in_db_result);
146 
147  $this->class_description = "This is a 'Collection' Class for Users.";
148 
149  $this->_set_up_container();

References tCO_Collection\_set_up_container().

Here is the call graph for this function:

◆ set_given_name()

CO_User_Collection::set_given_name (   $in_given_name)

Simple setter for the given (first) tag (tag 3).

Returns
true, if successful.
Parameters
$in_given_nameA string, containing the user middle name.

Definition at line 316 of file co_user_collection.class.php.

318  {
319  return $this->set_tag(3, $in_given_name);
set_tag( $in_tag_index, $in_tag_value)

References set_tag().

Here is the call graph for this function:

◆ set_login()

CO_User_Collection::set_login (   $in_login_id_integer)

This sets the login ID, and has the object regenerate the new instance.

This can only be done by a COBRA Login Manager that has write access to the user object and the login object. The manager does not have to have write access to the login object, but it does need read access to it.

Returns
true, if the operation suceeded.
Parameters
$in_login_id_integerThe integer ID of the login object to be associated with this instance.

Definition at line 393 of file co_user_collection.class.php.

395  {
396  $ret = parent::user_can_write();
397  $in_login_id_integer = intval($in_login_id_integer);
398  // Further check to make sure that the current login is a manager.
399  if ($ret && ($this->get_access_object()->god_mode() || ($this->get_access_object()->get_login_item() instanceof CO_Login_Manager))) {
400  $login_item = $this->get_access_object()->get_login_item($in_login_id_integer);
401 
402  if ((0 == $in_login_id_integer) || ($login_item instanceof CO_Security_Login)) {
403  $tag0 = (0 == $in_login_id_integer) ? NULL : strval(intval($in_login_id_integer));
404 
405  $ret = $this->set_tag(0, $tag0);
406 
407  if ($ret) { // Make sure that we'll get a fresh login next time.
408  $this->_login_object = NULL;
409  }
410  }
411  } else {
415  __FILE__,
416  __LINE__,
417  __METHOD__
418  );
419  }
420 
421  return $ret;

References CO_CHAMELEON_Lang_Common\$user_error_code_user_not_authorized, CO_CHAMELEON_Lang\$user_error_desc_user_not_authorized, CO_CHAMELEON_Lang\$user_error_name_user_not_authorized, A_CO_DB_Table_Base\get_access_object(), and set_tag().

Here is the call graph for this function:

◆ set_middle_name()

CO_User_Collection::set_middle_name (   $in_middle_name)

Simple setter for the surname tag (tag 2).

Returns
true, if successful.
Parameters
$in_middle_nameA string, containing the user middle name.

Definition at line 295 of file co_user_collection.class.php.

297  {
298  return $this->set_tag(2, $in_middle_name);

References set_tag().

Here is the call graph for this function:

◆ set_nickname()

CO_User_Collection::set_nickname (   $in_nickname)

Simple setter for the nickname tag (tag 6).

Returns
true, if successful.
Parameters
$in_nicknameA string, containing the user nickname.

Definition at line 379 of file co_user_collection.class.php.

381  {
382  return $this->set_tag(6, $in_nickname);

References set_tag().

Here is the call graph for this function:

◆ set_prefix()

CO_User_Collection::set_prefix (   $in_prefix)

Simple setter for the prefix tag (tag 4).

Returns
true, if successful.
Parameters
$in_prefixA string, containing the user prefix.

Definition at line 337 of file co_user_collection.class.php.

339  {
340  return $this->set_tag(4, $in_prefix);

References set_tag().

Here is the call graph for this function:

◆ set_suffix()

CO_User_Collection::set_suffix (   $in_suffix)

Simple setter for the suffix tag (tag 5).

Returns
true, if successful.
Parameters
$in_suffixA string, containing the user suffix.

Definition at line 358 of file co_user_collection.class.php.

360  {
361  return $this->set_tag(5, $in_suffix);

References set_tag().

Here is the call graph for this function:

◆ set_surname()

CO_User_Collection::set_surname (   $in_surname)

Simple setter for the surname tag (tag 1).

Returns
true, if successful.
Parameters
$in_surnameA string, containing the user surname.

Definition at line 274 of file co_user_collection.class.php.

276  {
277  return $this->set_tag(1, $in_surname);

References set_tag().

Here is the call graph for this function:

◆ set_tag()

CO_User_Collection::set_tag (   $in_tag_index,
  $in_tag_value 
)

Setter for one tag, by index.

Returns
true, if successful.
Parameters
$in_tag_indexThe index (0-based -0 through 9) of the tag to set.
$in_tag_valueA string, with the tag value.

Reimplemented from CO_Main_DB_Record.

Definition at line 240 of file co_user_collection.class.php.

243  {
244  $ret = false;
245 
246  $in_tag_index = intval($in_tag_index);
247 
248  if ((10 > $in_tag_index) && $this->user_can_write()) {
249  // We cannot assign a user we don't have write permissions for
250  $id_pool = $this->get_access_object()->get_security_ids();
251  if ($this->get_access_object()->god_mode() || ((isset($id_pool) && is_array($id_pool) && count($id_pool) && ((0 <= $in_tag_index) || in_array(intval($in_tag_value), $id_pool))))) {
252  $ret = parent::set_tag($in_tag_index, $in_tag_value);
253  }
254  }
255 
256  return $ret;

References tCO_Collection\count(), A_CO_DB_Table_Base\get_access_object(), and A_CO_DB_Table_Base\user_can_write().

Referenced by set_given_name(), set_login(), set_middle_name(), set_nickname(), set_prefix(), set_suffix(), and set_surname().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_tags()

CO_User_Collection::set_tags (   $in_tags_array)

Simple setter for the tags.

Returns
true, if successful.
Parameters
$in_tags_arrayAn array of strings, up to ten elements long, for the tags.

Reimplemented from CO_Main_DB_Record.

Definition at line 218 of file co_user_collection.class.php.

220  {
221  $ret = false;
222 
223  if (isset($in_tags_array) && is_array($in_tags_array) && count($in_tags_array) && (11 > count($in_tags_array))) {
224  // We cannot assign a user we don't have write permissions for
225  $id_pool = $this->get_access_object()->get_security_ids();
226  $tag0 = intval($in_tags_array[0]);
227  if ($this->get_access_object()->god_mode() || ((isset($id_pool) && is_array($id_pool) && count($id_pool) && ((0 == $tag0) || in_array($tag0, $id_pool))))) {
228  $ret = parent::set_tags($in_tags_array);
229  }
230  }
231 
232  return $ret;

References tCO_Collection\count(), and A_CO_DB_Table_Base\get_access_object().

Here is the call graph for this function:

Member Data Documentation

◆ $_login_object

CO_User_Collection::$_login_object = NULL
private

The Security DB COBRA login instance associated with this user.

Definition at line 70 of file co_user_collection.class.php.

Referenced by get_login_instance().