BLUE DRAGON PHP SDK
All Classes Functions Variables Pages
A_RVP_PHP_SDK_Object Class Reference
Inheritance diagram for A_RVP_PHP_SDK_Object:
A_RVP_PHP_SDK_Data_Object A_RVP_PHP_SDK_Security_Object RVP_PHP_SDK_Place RVP_PHP_SDK_Thing RVP_PHP_SDK_User RVP_PHP_SDK_Login

Public Member Functions

 __construct ( $in_sdk_object, $in_id, $in_data=NULL, $in_detailed_data=false, $in_plugin_path='baseline')
 
 set_sdk_object ( $in_sdk_object)
 
 changes ()
 
 save_data ()
 
 id ()
 
 name ()
 
 set_name ( $in_new_value)
 
 lang ()
 
 set_lang ( $in_new_value)
 
 object_access ()
 
 set_object_access ( $in_new_read=NULL, $in_new_write=NULL)
 
 writeable ()
 
 last_access ()
 
 force_reload ( $in_parents=false)
 

Protected Member Functions

 _load_data ( $in_force=false, $in_details=false, $in_parents=false)
 
 _save_data ( $in_args='', $in_payload=NULL, $in_new_child_ids=NULL)
 
 _save_change_record ( $in_change_record_object)
 

Protected Attributes

 $_sdk_object
 This is the RVP_PHP_SDK object that "owns" this object.
 
 $_object_id
 This is the server unique ID of this object.
 
 $_object_data
 This is any data that was associated with this object (parsed JSON).
 
 $_details
 If true, then the last load was a "show details" load..
 
 $_plugin_path
 This is a string that is applied to fetches to get the object.
 
 $_changed_states
 This will contain an array of objects (of whatever class this is), that represent previous object states.
 

Detailed Description

This is an abstract base class for various data objects provided by the SDK. It deals with the "top-level" common data, like the read/write tokens, name and localization code.

This class will provide the history list, links to the SDK object, the basic JSON data object, as well as a bit of state.

It is a generic class that serves both the data and security databases.

Definition at line 36 of file a_rvp_php_sdk_object.class.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $in_sdk_object,
  $in_id,
  $in_data = NULL,
  $in_detailed_data = false,
  $in_plugin_path = 'baseline' 
)

The basic constructor for the class. You have the option of "priming" the object with information.

Parameters
$in_sdk_objectREQUIRED: The "owning" SDK object.
$in_idREQUIRED: The server ID of the object. An integer.
$in_dataOPTIONAL: Parsed JSON Data for the object. Default is NULL.
$in_detailed_dataOPTIONAL: Ignored if $in_data is NULL. Default is false. If true, then the data sent in was in "detailed" format.
$in_plugin_pathOPTIONAL: This is a path that is added to the server, to fetch data. Default is "baseline."

Definition at line 130 of file a_rvp_php_sdk_object.class.php.

135  {
136  $this->_object_id = $in_id;
137  $this->_object_data = $in_data;
138  $this->_details = (NULL != $in_data) ? $in_detailed_data : false;
139  $this->_plugin_path = $in_plugin_path;
140  $this->_changed_states = [];
141  $this->set_sdk_object($in_sdk_object);
142  }

Member Function Documentation

◆ _load_data()

_load_data (   $in_force = false,
  $in_details = false,
  $in_parents = false 
)
protected

This is the base "load some data" method. It will send a JSON GET REST request to the API in order to fetch information about this object.

Once it receives the object, it JSON-decodes it, and stores it in the _object_data internal field.

Subclasses will usually overload this, then apply their own filtering to the data after calling this parent method.

Returns
true, if it loaded the data.
Parameters
$in_forceOPTIONAL: Default is false. If true, then the load will happen, even if we already have the data.
$in_detailsOPTIONAL: Default is false. If true, then the load will be a "show details" load, which could bring in a great deal more data.
$in_parentsOPTIONAL: Default is false. If true, then the load will be a "show details" load, AND it will get the "parents," which can be a time-consuming operation. This will also "force" a load.

Definition at line 57 of file a_rvp_php_sdk_object.class.php.

60  {
61  $ret = false;
62 
63  if ($in_force || $in_parents || (NULL == $this->_object_data) || ($in_details && !$this->_details)) {
64  $this->_details = $in_details;
65  $fetched_data = $this->_sdk_object->fetch_data('json/'.$this->_plugin_path.'/'.$this->_object_id, $in_details ? 'show_details'.($in_parents ? '&show_parents' : '') : NULL);
66  $this->_object_data = (NULL != $fetched_data) ? json_decode($fetched_data) : NULL;
67  $ret = (NULL != $this->_object_data);
68  }
69 
70  return $ret;
71  }
$_object_data
This is any data that was associated with this object (parsed JSON).

◆ _save_data()

_save_data (   $in_args = '',
  $in_payload = NULL,
  $in_new_child_ids = NULL 
)
protected

This actually sends the data through the API to the server, and returns the response object.

Returns
the JSON change object. NULL if not successful.
Parameters
$in_argsOPTIONAL: Default is an empty string. This is any previous arguments. This will be appeneded to the end of the list, so it should begin with an ampersand (&), and be url-encoded.
$in_payloadOPTIONAL: Any payload to be asociated with this object. Must be an associative array (['data' => data, 'type' => MIME Type string]).
$in_new_child_idsIGNORED. Just here to suppress PHP warnings.

Definition at line 79 of file a_rvp_php_sdk_object.class.php.

82  {
83  $ret = NULL;
84  $put_args = '';
85 
86  $name = isset($this->_object_data->name) ? $this->_object_data->name : NULL;
87  $lang = isset($this->_object_data->lang) ? $this->_object_data->lang : NULL;
88  $read_token = isset($this->_object_data->read_token) ? intval($this->_object_data->read_token) : NULL;
89  $write_token = isset($this->_object_data->write_token) ? ((0 < intval($this->_object_data->write_token)) ? intval($this->_object_data->write_token) : $this->_sdk_object->my_info()['login']->id()) : NULL;
90 
91  if (isset($name)) {
92  $put_args .= '&name='.urlencode($name);
93  }
94 
95  if (isset($lang)) {
96  $put_args .= '&lang='.urlencode($lang);
97  }
98 
99  if (isset($read_token)) {
100  $put_args .= '&read_token='.intval($read_token);
101  }
102 
103  if (isset($write_token)) {
104  $put_args .= '&write_token='.intval($write_token);
105  }
106 
107  $result = json_decode($this->_sdk_object->put_data('/json/'.$this->_plugin_path.'/'.$this->id(), $put_args.$in_args, $in_payload));
108 
109  return $result;
110  }

◆ _save_change_record()

_save_change_record (   $in_change_record_object)
abstractprotected

This is called after a successful save. It has the change record[s], and the subclass should take care of parsing that record to save in the object's change record.

It's important that subclasses apply their own parsing, as the response data is different, between people, places and things.

Returns
true, if the save was successful.
Parameters
$in_change_record_objectREQUIRED: The change response, as a parsed object.

◆ set_sdk_object()

set_sdk_object (   $in_sdk_object)

Simple accessor to set the "owning" SDK object.

Parameters
$in_sdk_objectREQUIRED: The "owning" SDK object.

Definition at line 148 of file a_rvp_php_sdk_object.class.php.

149  {
150  $this->_sdk_object = $in_sdk_object; // This is the RVP_PHP_SDK object that "owns" this user.
151  }

◆ changes()

changes ( )
Returns
an array of instances, representing the "before" state of this object, prior to any changes made. It should be noted that the lifetime of these changes are dependent on the lifetime of this instance.

Definition at line 157 of file a_rvp_php_sdk_object.class.php.

157  {
158  return isset($this->_changed_states) ? $this->_changed_states : [];
159  }

◆ save_data()

save_data ( )
Returns
true, if the save was successful.

Definition at line 165 of file a_rvp_php_sdk_object.class.php.

165  {
166  $ret = false;
167 
168  $ret = $this->_save_change_record($this->_save_data());
169 
170  return $ret;
171  }
_save_change_record( $in_change_record_object)
_save_data( $in_args='', $in_payload=NULL, $in_new_child_ids=NULL)

◆ id()

id ( )
Returns
the integer ID of the object; unique in the object's database.

Definition at line 177 of file a_rvp_php_sdk_object.class.php.

177  {
178  return $this->_object_id;
179  }
$_object_id
This is the server unique ID of this object.

◆ name()

name ( )

This requires a load, but not a "detailed" load.

Returns
the string name of the object. This is the generic "object_name" column that all records have.

Definition at line 187 of file a_rvp_php_sdk_object.class.php.

187  {
188  $ret = NULL;
189 
190  $this->_load_data();
191 
192  if (isset($this->_object_data) && isset($this->_object_data->name)) {
193  $ret = $this->_object_data->name;
194  }
195 
196  return $ret;
197  }
_load_data( $in_force=false, $in_details=false, $in_parents=false)

◆ set_name()

set_name (   $in_new_value)

This sets the name of the object.

Returns
true, if the save worked.
Parameters
$in_new_valueREQUIRED: A new value for the name.

Definition at line 205 of file a_rvp_php_sdk_object.class.php.

206  {
207  $ret = false;
208 
209  $this->_load_data(false, true);
210 
211  if (isset($this->_object_data)) {
212  $this->_object_data->name = $in_new_value;
213 
214  $ret = $this->save_data();
215  }
216 
217  return $ret;
218  }
_load_data( $in_force=false, $in_details=false, $in_parents=false)

◆ lang()

lang ( )

This requires a load, but not a "detailed" load.

Returns
the string for the object's "lang" (language code) field.

Definition at line 226 of file a_rvp_php_sdk_object.class.php.

226  {
227  $ret = NULL;
228 
229  $this->_load_data();
230 
231  if (isset($this->_object_data) && isset($this->_object_data->lang)) {
232  $ret = $this->_object_data->lang;
233  }
234 
235  return $ret;
236  }
_load_data( $in_force=false, $in_details=false, $in_parents=false)

◆ set_lang()

set_lang (   $in_new_value)

This sets the language ID of the object.

Returns
true, if the save worked.
Parameters
$in_new_valueREQUIRED: A new value for the language ID.

Definition at line 244 of file a_rvp_php_sdk_object.class.php.

245  {
246  $ret = false;
247 
248  $this->_load_data(false, true);
249 
250  if (isset($this->_object_data)) {
251  $this->_object_data->lang = $in_new_value;
252 
253  $ret = $this->save_data();
254  }
255 
256  return $ret;
257  }
_load_data( $in_force=false, $in_details=false, $in_parents=false)

◆ object_access()

object_access ( )

This requires a load, but not a "detailed" load.

Returns
an associative array ('read' => integer, 'write' => integer), with the tokens for the object. The tokens will only be available if they are visible to the current user, or NULL, if there are no tokens (should never happen).

Definition at line 265 of file a_rvp_php_sdk_object.class.php.

265  {
266  $ret = NULL;
267  $read_token = NULL;
268  $write_token = NULL;
269 
270  $this->_load_data();
271 
272  if (isset($this->_object_data) && isset($this->_object_data->read_token)) {
273  $read_token = intval($this->_object_data->read_token);
274  }
275 
276  if (isset($this->_object_data) && isset($this->_object_data->write_token)) {
277  $write_token = intval($this->_object_data->write_token);
278  }
279 
280  if ($read_token || $write_token) {
281  $ret = [];
282 
283  if ($read_token) {
284  $ret['read'] = $read_token;
285  }
286 
287  if ($write_token) {
288  $ret['write'] = $write_token;
289  }
290  }
291 
292  return $ret;
293  }
_load_data( $in_force=false, $in_details=false, $in_parents=false)

◆ set_object_access()

set_object_access (   $in_new_read = NULL,
  $in_new_write = NULL 
)

This sets the read and write tokens of the object.

The current login must have at least read access to each of the tokens. If a token is NULL, then the token is not changed.

Returns
true, if the save worked.
Parameters
$in_new_readOPTIONAL: A new read token. Default is NULL (no change).
$in_new_writeOPTIONAL: A new write token. Default is NULL (no change).

Definition at line 303 of file a_rvp_php_sdk_object.class.php.

305  {
306  $ret = false;
307 
308  $this->_load_data(false, true);
309 
310  if (isset($this->_object_data)) {
311  $this->_object_data->read_token = isset($in_new_read) ? intval($in_new_read) : $this->_object_data->read_token;
312  $this->_object_data->write_token = isset($in_new_write) ? intval($in_new_write) : $this->_object_data->write_token;
313 
314  $ret = $this->save_data();
315  }
316 
317  return $ret;
318  }
_load_data( $in_force=false, $in_details=false, $in_parents=false)

◆ writeable()

writeable ( )

This requires a load, but not a "detailed" load.

Returns
true, if the current login can write/modify this object.

Definition at line 326 of file a_rvp_php_sdk_object.class.php.

326  {
327  $ret = false;
328 
329  $this->_load_data();
330 
331  if (isset($this->_object_data) && isset($this->_object_data->writeable) && $this->_object_data->writeable) {
332  $ret = true;
333  }
334 
335  return $ret;
336  }
_load_data( $in_force=false, $in_details=false, $in_parents=false)

◆ last_access()

last_access ( )

This requires a load, but not a "detailed" load.

Returns
the last access date, as a timedate integer.

Definition at line 344 of file a_rvp_php_sdk_object.class.php.

344  {
345  $ret = NULL;
346 
347  $this->_load_data();
348 
349  if (isset($this->_object_data) && isset($this->_object_data->last_access)) {
350  $ret = strtotime($this->_object_data->last_access);
351  }
352 
353  return $ret;
354  }
_load_data( $in_force=false, $in_details=false, $in_parents=false)

◆ force_reload()

force_reload (   $in_parents = false)

This forces at least a detailed load.

This reloads the information, refreshing the object, if necessary.

Returns
true, if successful.
Parameters
$in_parentsOPTIONAL: Default is false. If true, then the parent info is also loaded.

Definition at line 364 of file a_rvp_php_sdk_object.class.php.

365  {
366  return $this->_load_data(true, true, $in_parents);
367  }
_load_data( $in_force=false, $in_details=false, $in_parents=false)

The documentation for this class was generated from the following file: