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

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)
 
 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 ()
 
 update_db ()
 
 reload_from_db ()
 
 get_access_object ()
 
 get_lang ()
 
 set_lang ( $in_lang_id=NULL)
 

Static Public Attributes

static $s_table_name = 'co_data_nodes'
 

Protected Member Functions

 _default_setup ()
 
 _build_parameter_array ()
 
- Protected Member Functions inherited from A_CO_DB_Table_Base
 _badger_serialize ( $in_data)
 
 _badger_unserialize ( $in_data)
 
 _write_to_db ()
 
 _seppuku ()
 

Protected Attributes

 $_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...
 

Private Attributes

 $_raw_payload
 

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

Detailed Description

This is the main instance base class for records in the main "data" database.

Definition at line 38 of file co_main_db_record.class.php.

Constructor & Destructor Documentation

◆ __construct()

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

The 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.

Reimplemented in CO_User_Collection, CO_Collection, and CO_KeyValue_CO_Collection.

Definition at line 95 of file co_main_db_record.class.php.

99  {
100  $this->_owner_id = intval($in_owner_id);
101  $this->_tags = (isset($in_tags_array) && is_array($in_tags_array) && count($in_tags_array)) ? array_map(function($in) { return strval($in); }, $in_tags_array) : Array();
102  parent::__construct($in_db_object, $in_db_result);
103  $this->class_description = 'Base Class for Main Database Records.';
104  $this->name = (isset($this->name) && trim($this->name)) ? trim($this->name) : "Base Class Instance ($this->_id)";
105  }

Member Function Documentation

◆ _build_parameter_array()

CO_Main_DB_Record::_build_parameter_array ( )
protected

This adds our data to the saved parameter associative array.

Returns
an associative array of instance values, using the database keys.

Reimplemented from A_CO_DB_Table_Base.

Reimplemented in CO_LL_Location.

Definition at line 72 of file co_main_db_record.class.php.

72  {
73  $ret = parent::_build_parameter_array(); // Start with the base class.
74 
75  $ret['owner'] = intval($this->_owner_id);
76  for ($tag_no = 0; $tag_no < 10; $tag_no++) {
77  $key = "tag$tag_no";
78  if (isset($this->_tags[$tag_no])) {
79  $ret[$key] = $this->_tags[$tag_no];
80  } else {
81  $ret[$key] = '';
82  }
83  }
84 
85  $ret['payload'] = base64_encode($this->_raw_payload);
86 
87  return $ret;
88  }

◆ _default_setup()

CO_Main_DB_Record::_default_setup ( )
protected

This prepares an associative array of database values for the object.

Returns
an associative array of default values, using the database keys.

Reimplemented from A_CO_DB_Table_Base.

Reimplemented in CO_LL_Location.

Definition at line 53 of file co_main_db_record.class.php.

53  {
54  $default_setup = parent::_default_setup();
55  $default_setup['owner_id'] = $this->_owner_id;
56 
57  for ($tag_no = 0; $tag_no < 10; $tag_no++) {
58  $key = "tag$tag_no";
59  $tag_val = (isset($this->_tags) && is_array($this->_tags) && ($tag_no < count($this->_tags))) ? $this->_tags[$tag_no] : '';
60  $default_setup[$key] = $tag_val;
61  }
62 
63  return $default_setup;
64  }

References $_owner_id.

◆ get_payload()

CO_Main_DB_Record::get_payload ( )

Returns the payload.

Returns
the payload, in whatever form it takes.

Definition at line 232 of file co_main_db_record.class.php.

232  {
233  return $this->_raw_payload;
234  }

References $_raw_payload.

◆ load_from_db()

CO_Main_DB_Record::load_from_db (   $in_db_result)

This sets up the instance, based on a supplied associative array of database values and keys.

Returns
true, if sucessful.
Parameters
$in_db_resultThis is the associative array of database values.

Reimplemented from A_CO_DB_Table_Base.

Reimplemented in CO_User_Collection, CO_US_Place_Collection, CO_Place_Collection, CO_KeyValue_CO_Collection, CO_Collection, and CO_LL_Location.

Definition at line 113 of file co_main_db_record.class.php.

114  {
115  $ret = parent::load_from_db($in_db_result); // Start by calling the base class version.
116 
117  if ($ret) { // If that went OK, we add our own two cents...
118  $this->class_description = 'Base Class for Main Database Records.';
119  $this->name = (isset($this->name) && trim($this->name)) ? trim($this->name) : "Base Class Instance ($this->_id)";
120 
121  if ($this->_db_object) {
122  $this->_owner_id = NULL;
123  $this->_tags = array();
124  $this->_raw_payload = NULL;
125 
126  if (isset($in_db_result['owner'])) {
127  $this->_owner_id = intval($in_db_result['owner']);
128  }
129 
130  if (isset($in_db_result['payload']) ) {
131  $payload = $in_db_result['payload'];
132  $length = strlen($payload);
133  $counter = 0;
134  $new_payload = [];
135 
136  // We decode in chunks.
137  while($counter < $length) {
138  $this_chunk = substr($payload, $counter, 4096);
139  $new_payload[] = base64_decode($this_chunk);
140  $counter += 4096;
141  }
142 
143  $this->_raw_payload = implode('', $new_payload);
144  }
145 
146  for ($tag_no = 0; $tag_no < 10; $tag_no++) {
147  $key = "tag$tag_no";
148  $tag_val = (isset($in_db_result[$key])) && $in_db_result[$key] ? $in_db_result[$key] : '';
149  $this->_tags[$tag_no] = $tag_val;
150  }
151 
152  for ($i = 0; $i < 10; $i++) {
153  $tagname = 'tag'.$i;
154  $this->_tags[$i] = '';
155  if (isset($in_db_result[$tagname])) {
156  $this->_tags[$i] = $in_db_result[$tagname];
157  }
158  }
159  }
160  }
161 
162  return $ret;
163  }

◆ owner_id()

CO_Main_DB_Record::owner_id ( )
Returns
the current owner ID.

Definition at line 258 of file co_main_db_record.class.php.

258  {
259  return $this->_owner_id;
260  }

References $_owner_id.

◆ set_owner_id()

CO_Main_DB_Record::set_owner_id (   $in_new_id)

Simple setter for the owner ID.

Returns
true, if successful.
Parameters
$in_new_idThe new value

Definition at line 171 of file co_main_db_record.class.php.

172  {
173  $ret = false;
174 
175  if (isset($in_new_id) && $this->user_can_write()) {
176  $this->_owner_id = intval($in_new_id);
177  $ret = $this->update_db();
178  }
179 
180  return $ret;
181  }

References A_CO_DB_Table_Base\update_db(), and A_CO_DB_Table_Base\user_can_write().

Here is the call graph for this function:

◆ set_payload()

CO_Main_DB_Record::set_payload (   $in_payload)

Sets the payload.

Returns
true, if successful.
Parameters
$in_payloadThe raw payload to be stored.

Definition at line 242 of file co_main_db_record.class.php.

243  {
244  $ret = false;
245 
246  if ($this->user_can_write()) {
247  $this->_raw_payload = $in_payload;
248  $ret = $this->update_db();
249  }
250 
251  return $ret;
252  }

References A_CO_DB_Table_Base\update_db(), and A_CO_DB_Table_Base\user_can_write().

Here is the call graph for this function:

◆ set_tag()

CO_Main_DB_Record::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 in CO_User_Collection.

Definition at line 207 of file co_main_db_record.class.php.

209  {
210  $ret = false;
211 
212  $in_tag_index = intval($in_tag_index);
213 
214  if ((10 > $in_tag_index) && $this->user_can_write()) {
215  if (!isset($this->_tags) || !$this->_tags) {
216  $this->_tags = Array();
217  }
218 
219  $this->_tags[$in_tag_index] = (NULL != $in_tag_value) ? strval($in_tag_value) : NULL;
220  $ret = $this->update_db();
221  }
222 
223  return $ret;
224  }

References A_CO_DB_Table_Base\update_db(), and A_CO_DB_Table_Base\user_can_write().

Here is the call graph for this function:

◆ set_tags()

CO_Main_DB_Record::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 in CO_User_Collection.

Definition at line 189 of file co_main_db_record.class.php.

190  {
191  $ret = false;
192 
193  if (isset($in_tags_array) && is_array($in_tags_array) && count($in_tags_array) && (11 > count($in_tags_array)) && $this->user_can_write()) {
194  $this->_tags = array_map('strval', $in_tags_array);
195  $ret = $this->update_db();
196  }
197 
198  return $ret;
199  }

References A_CO_DB_Table_Base\update_db(), and A_CO_DB_Table_Base\user_can_write().

Referenced by CO_Place\set_tags_from_address_elements().

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

◆ tags()

CO_Main_DB_Record::tags ( )
Returns
the current tags.

Definition at line 266 of file co_main_db_record.class.php.

266  {
267  return $this->_tags;
268  }

References $_tags.

Referenced by CO_Place\__construct(), CO_User_Collection\_load_login(), CO_User_Collection\has_login(), CO_User_Collection\has_login_i_cant_see(), and CO_User_Collection\is_god().

Here is the caller graph for this function:

Member Data Documentation

◆ $_owner_id

CO_Main_DB_Record::$_owner_id
protected

Definition at line 41 of file co_main_db_record.class.php.

Referenced by _default_setup(), and owner_id().

◆ $_raw_payload

CO_Main_DB_Record::$_raw_payload
private

Definition at line 44 of file co_main_db_record.class.php.

Referenced by get_payload().

◆ $_tags

CO_Main_DB_Record::$_tags
protected

Definition at line 42 of file co_main_db_record.class.php.

Referenced by tags().

◆ $s_table_name

CO_Main_DB_Record::$s_table_name = 'co_data_nodes'
static

Definition at line 39 of file co_main_db_record.class.php.