BLUE DRAGON PHP SDK
All Classes Functions Variables Pages
a_rvp_php_sdk_object.class.php
1 <?php
2 /***************************************************************************************************************************/
24 defined( 'RVP_PHP_SDK_ACCESS' ) or die ( 'Cannot Execute Directly' ); // Makes sure that this file is in the correct context.
25 
26 require_once(dirname(__FILE__).'/rvp_php_sdk.class.php'); // Make sure that we have the main SDK class in place.
27 
28 /****************************************************************************************************************************/
36 abstract class A_RVP_PHP_SDK_Object {
37  protected $_sdk_object;
38  protected $_object_id;
39  protected $_object_data;
40  protected $_details;
41  protected $_plugin_path;
42  protected $_changed_states;
43 
44  /************************************************************************************************************************/
45  /*#################################################### INTERNAL METHODS ################################################*/
46  /************************************************************************************************************************/
47  /***********************/
57  protected function _load_data( $in_force = false,
58  $in_details = false,
59  $in_parents = false
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  }
72 
73  /***********************/
79  protected function _save_data( $in_args = '',
80  $in_payload = NULL,
81  $in_new_child_ids = NULL
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  }
111 
112  /***********************/
120  protected abstract function _save_change_record( $in_change_record_object
121  );
122 
123  /************************************************************************************************************************/
124  /*#################################################### PUBLIC METHODS ##################################################*/
125  /************************************************************************************************************************/
126  /***********************/
130  function __construct( $in_sdk_object,
131  $in_id,
132  $in_data = NULL,
133  $in_detailed_data = false,
134  $in_plugin_path = 'baseline'
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  }
143 
144  /***********************/
148  function set_sdk_object( $in_sdk_object
149  ) {
150  $this->_sdk_object = $in_sdk_object; // This is the RVP_PHP_SDK object that "owns" this user.
151  }
152 
153  /***********************/
157  function changes() {
158  return isset($this->_changed_states) ? $this->_changed_states : [];
159  }
160 
161  /***********************/
165  function save_data() {
166  $ret = false;
167 
168  $ret = $this->_save_change_record($this->_save_data());
169 
170  return $ret;
171  }
172 
173  /***********************/
177  function id() {
178  return $this->_object_id;
179  }
180 
181  /***********************/
187  function name() {
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  }
198 
199  /***********************/
205  function set_name( $in_new_value
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  }
219 
220  /***********************/
226  function lang() {
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  }
237 
238  /***********************/
244  function set_lang( $in_new_value
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  }
258 
259  /***********************/
265  function object_access() {
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  }
294 
295  /***********************/
303  function set_object_access( $in_new_read = NULL,
304  $in_new_write = NULL
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  }
319 
320  /***********************/
326  function writeable() {
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  }
337 
338  /***********************/
344  function last_access() {
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  }
355 
356  /***********************/
364  function force_reload( $in_parents = false
365  ) {
366  return $this->_load_data(true, true, $in_parents);
367  }
368 };
_save_data( $in_args='', $in_payload=NULL, $in_new_child_ids=NULL)
__construct( $in_sdk_object, $in_id, $in_data=NULL, $in_detailed_data=false, $in_plugin_path='baseline')
set_object_access( $in_new_read=NULL, $in_new_write=NULL)
$_sdk_object
This is the RVP_PHP_SDK object that "owns" this object.
$_object_data
This is any data that was associated with this object (parsed JSON).
$_plugin_path
This is a string that is applied to fetches to get the object.
$_details
If true, then the last load was a "show details" load..
_load_data( $in_force=false, $in_details=false, $in_parents=false)
$_changed_states
This will contain an array of objects (of whatever class this is), that represent previous object sta...
$_object_id
This is the server unique ID of this object.