BAOBAB
co_keyvalue_co_collection.class.php
Go to the documentation of this file.
1 <?php
2 /***************************************************************************************************************************/
26 defined( 'LGV_DBF_CATCHER' ) or die ( 'Cannot Execute Directly' ); // Makes sure that this file is in the correct context.
27 
28 require_once(dirname(__FILE__).'/co_collection.class.php');
29 
30 /***************************************************************************************************************************/
41 
42  /***********************************************************************************************************************/
43  /***********************/
47  public function __construct( $in_db_object = NULL,
48  $in_db_result = NULL,
49  $in_key = NULL,
50  $in_value = NULL
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  }
61 
62  /***********************/
68  public function load_from_db( $in_db_result
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  }
79 
80  /***********************/
87  function set_key( $in_key,
88  $in_value = NULL
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  }
116 
117  /***********************/
121  function get_key() {
122  return $this->tags[0];
123  }
124 
125  /***********************/
129  function get_value() {
130  return $this->get_payload();
131  }
132 
133  /***********************/
137  function get_key_value_array() {
138  return Array($this->get_key(), $this->get_value());
139  }
140 
141  /***********************/
145  function get_key_value_assoc() {
146  return Array($this->get_key() => $this->get_value());
147  }
148 
149  /***********************/
153  function set_value( $in_value
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  }
167 };
__construct( $in_db_object=NULL, $in_db_result=NULL, $in_key=NULL, $in_value=NULL)
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
This class provides a general error report, with file, method and error information.
Definition: error.class.php:32