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

Public Member Functions

 __construct ( $in_db_object=NULL, $in_db_result=NULL, $in_key=NULL, $in_value=NULL)
 
 load_from_db ( $in_db_result)
 
 set_key ( $in_key, $in_value=NULL)
 
 get_key ()
 
 get_value ()
 
 get_key_value_array ()
 
 get_key_value_assoc ()
 
 set_value ( $in_value)
 
- Public Member Functions inherited from CO_Collection
 delete_from_db ( $with_extreme_prejudice=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)
 
 set_tags ( $in_tags_array)
 
 set_tag ( $in_tag_index, $in_tag_value)
 
 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 ()
 
 get_lang ()
 
 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())
 

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 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 ()
 
- 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 simple key/value class. It uses the Tag 0 object as a "key" (So the key needs to be a string), and the payload to store the value (so the value can be fairly big).

There can only be one.

The uniqueness is determined by a combination of the access_class and tag0 fields. That means that a subclass of this class could have the same key as a parent, but two instances of the same class cannot have duplicate keys.

Definition at line 40 of file co_keyvalue_co_collection.class.php.

Constructor & Destructor Documentation

◆ __construct()

CO_KeyValue_CO_Collection::__construct (   $in_db_object = NULL,
  $in_db_result = NULL,
  $in_key = NULL,
  $in_value = 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_keyThe key to be used for this instance (overrides anything in the DB record).
$in_valueThe value to be used for this instance (overrides anything in the DB record).

Reimplemented from CO_Collection.

Definition at line 47 of file co_keyvalue_co_collection.class.php.

51  {
52  parent::__construct($in_db_object, $in_db_result);
53  $this->class_description = "This is a class for doing \"key/value\" storage.";
54 
55  if (NULL != $in_key) {
56  $this->set_key($in_key, $value);
57  } elseif (NULL != $in_value) {
58  $this->set_value($in_key, $value);
59  }
60  }

Member Function Documentation

◆ get_key()

CO_KeyValue_CO_Collection::get_key ( )
Returns
the instance key.

Definition at line 121 of file co_keyvalue_co_collection.class.php.

121  {
122  return $this->tags[0];
123  }

◆ get_key_value_array()

CO_KeyValue_CO_Collection::get_key_value_array ( )
Returns
the instance key and value, in a 2-element indexed array, with element 0 being the key, and element 1 being the value.

Definition at line 137 of file co_keyvalue_co_collection.class.php.

◆ get_key_value_assoc()

CO_KeyValue_CO_Collection::get_key_value_assoc ( )
Returns
the instance key and value, in a 1-element associative array, with the key being the key, and the value being the value.

Definition at line 145 of file co_keyvalue_co_collection.class.php.

145  {
146  return Array($this->get_key() => $this->get_value());
147  }

◆ get_value()

CO_KeyValue_CO_Collection::get_value ( )
Returns
the payload for this instance.

Definition at line 129 of file co_keyvalue_co_collection.class.php.

129  {
130  return $this->get_payload();
131  }

◆ load_from_db()

CO_KeyValue_CO_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_Collection.

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

69  {
70  $ret = parent::load_from_db($in_db_result);
71 
72  if ($ret) {
73  $this->class_description = "This is a class for doing \"key/value\" storage.";
74  $this->instance_description = $this->name;
75  }
76 
77  return $ret;
78  }
$name
This is the "object_name" string field.

◆ set_key()

CO_KeyValue_CO_Collection::set_key (   $in_key,
  $in_value = NULL 
)

This method will set the key for this instance. It checks the database, as the key needs to be unique for the access class and tag 0.

Returns
true, if the key was successfully set and updated in the database.
Parameters
$in_keyThe key to be applied to this object.
$in_valueWe can associate a value.

Definition at line 87 of file co_keyvalue_co_collection.class.php.

89  {
90  $ret = false;
91 
92  if ($this->user_can_write()) { //< Must have write access
93  // We need to make sure that the key doesn't already exist, or if it does, that the object associated with it is us. Must be writeable.
94  $instance_list = $this->get_access_object()->generic_search(Array('access_class' => get_class($this), 'tags' => Array($in_key)));
95 
96  if (!isset($instance_list) || !is_array($instance_list) || !count($instance_list) || (1 == count($instance_list) && ($instance_list[0] === $this))) {
97  // If there is no change, then we don't do anything, and report a success.
98  if (isset($instance_list) && is_array($instance_list) && (1 == count($instance_list) && ($instance_list[0] === $this))) {
99  $ret = true;
100  } else {
101  $ret = $this->set_tag(0, $in_key); // We assume that our claim to be writeable is true. If not, this will fail. Remember we are untrusting bastards.
102  }
103 
104  if ($ret && (NULL != $in_value)) {
105  return $this->set_value($in_value);
106  }
107  }
108  } else {
112  }
113 
114  return $ret;
115  }
count( $is_recursive=false)
static $co_key_value_error_code_user_not_authorized
Definition: common.inc.php:62
static $co_key_value_error_name_user_not_authorized
These apply to the KeyValue classes.
Definition: en.php:49
static $co_key_value_error_desc_user_not_authorized
Definition: en.php:50
set_tag( $in_tag_index, $in_tag_value)
This class provides a general error report, with file, method and error information.
Definition: error.class.php:32

References CO_CHAMELEON_Lang_Common\$co_key_value_error_code_user_not_authorized, CO_CHAMELEON_Lang\$co_key_value_error_desc_user_not_authorized, and CO_CHAMELEON_Lang\$co_key_value_error_name_user_not_authorized.

◆ set_value()

CO_KeyValue_CO_Collection::set_value (   $in_value)
Returns
true, if the value was successfully set and updated in the database.

Definition at line 153 of file co_keyvalue_co_collection.class.php.

154  {
155  $ret = false;
156 
157  if ($this->user_can_write()) { //< Must have write access
158  $ret = $this->set_payload($in_value);
159  } else {
163  }
164 
165  return $ret;
166  }

References CO_CHAMELEON_Lang_Common\$co_key_value_error_code_user_not_authorized, CO_CHAMELEON_Lang\$co_key_value_error_desc_user_not_authorized, and CO_CHAMELEON_Lang\$co_key_value_error_name_user_not_authorized.