BLUE DRAGON PHP SDK
All Classes Functions Variables Pages
a_rvp_php_sdk_data_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__).'/a_rvp_php_sdk_object.class.php'); // Get our base class.
27 
28 /****************************************************************************************************************************/
35  /************************************************************************************************************************/
36  /*#################################################### INTERNAL METHODS ################################################*/
37  /************************************************************************************************************************/
38  /***********************/
42  protected function _save_data( $in_args = '',
43  $in_payload = NULL,
44  $in_new_child_ids = NULL
45  ) {
46  $owner_id = isset($this->_object_data->owner_id) ? intval($this->_object_data->owner_id) : 0;
47  $latitude = isset($this->_object_data->raw_latitude) ? floatval($this->_object_data->raw_latitude) : (isset($this->_object_data->latitude) ? floatval($this->_object_data->latitude) : NULL);
48  $longitude = isset($this->_object_data->raw_longitude) ? floatval($this->_object_data->raw_longitude) : (isset($this->_object_data->longitude) ? floatval($this->_object_data->longitude) : NULL);
49  $fuzz_factor = isset($this->_object_data->fuzz_factor) ? floatval($this->_object_data->fuzz_factor) : NULL;
50  $can_see_through_the_fuzz = isset($this->_object_data->can_see_through_the_fuzz) ? intval($this->_object_data->can_see_through_the_fuzz) : NULL;
51 
52  $put_args = '&owner_id='.$owner_id.(isset($latitude) ? ('&latitude='.$latitude) : '').(isset($longitude) ? ('&longitude='.$longitude) : '').(isset($fuzz_factor) ? '&fuzz_factor='.$fuzz_factor : '').(isset($can_see_through_the_fuzz) ? '&can_see_through_the_fuzz='.$can_see_through_the_fuzz : '');
53 
54  if (isset($in_new_child_ids) && is_array($in_new_child_ids) && count($in_new_child_ids)) {
55  $in_new_child_ids = array_filter(array_map('intval', $in_new_child_ids), function($i) { return 0 != intval($i); });
56  if (count($in_new_child_ids)) {
57  $put_args .= '&child_ids='.implode(',', $in_new_child_ids);
58  }
59  }
60 
61  $payload = isset($in_payload) ? $in_payload : NULL;
62 
63  $ret = parent::_save_data($put_args.$in_args, $payload);
64 
65  return $ret;
66  }
67 
68  /************************************************************************************************************************/
69  /*#################################################### PUBLIC METHODS ##################################################*/
70  /************************************************************************************************************************/
71 
72  /***********************/
76  function __construct( $in_sdk_object,
77  $in_id,
78  $in_data = NULL,
79  $in_detailed_data = false,
80  $in_plugin_path = 'baseline'
81  ) {
82  parent::__construct($in_sdk_object, $in_id, $in_data, $in_detailed_data, $in_plugin_path);
83  }
84 
85  /***********************/
91  function coords() {
92  $ret = NULL;
93 
94  $this->_load_data();
95 
96  if (isset($this->_object_data) && isset($this->_object_data->coords)) {
97  $temp = explode(',', $this->_object_data->coords);
98  if (isset($temp) && is_array($temp) && (1 < count($temp))) {
99  $ret = [];
100  $ret['latitude'] = floatval($temp[0]);
101  $ret['longitude'] = floatval($temp[1]);
102  }
103  }
104 
105  return $ret;
106  }
107 
108  /***********************/
114  function set_coords( $in_latitude,
115  $in_longitude
116  ) {
117  $ret = false;
118 
119  $this->_load_data(false, true);
120 
121  if (isset($this->_object_data)) {
122  if ((isset($this->_object_data->raw_latitude) && isset($this->_object_data->raw_longitude)) || (isset($this->_object_data->fuzzy) && $this->_object_data->fuzzy)) {
123  $this->_object_data->raw_latitude = $in_latitude;
124  $this->_object_data->raw_longitude = $in_longitude;
125  } else {
126  $this->_object_data->latitude = $in_latitude;
127  $this->_object_data->longitude = $in_longitude;
128  }
129 
130  $ret = $this->save_data();
131  }
132 
133  return $ret;
134  }
135 
136  /***********************/
142  function distance() {
143  $ret = 0;
144 
145  $this->_load_data(false, true);
146 
147  if (isset($this->_object_data) && isset($this->_object_data->distance_in_km)) {
148  $ret = floatval($this->_object_data->distance_in_km);
149  }
150 
151  return $ret;
152  }
153 
154  /***********************/
160  function is_fuzzy() {
161  $ret = false;
162 
163  $this->_load_data(false, true);
164 
165  if (isset($this->_object_data) && isset($this->_object_data->fuzzy) && $this->_object_data->fuzzy) {
166  $ret = true;
167  }
168 
169  return $ret;
170  }
171 
172  /***********************/
178  function fuzz_factor() {
179  $ret = 0;
180 
181  $this->_load_data(false, true);
182 
183  if (isset($this->_object_data) && isset($this->_object_data->fuzz_factor) && floatval($this->_object_data->fuzz_factor)) {
184  $ret = floatval($this->_object_data->fuzz_factor);
185  }
186 
187  return $ret;
188  }
189 
190  /***********************/
198  function set_fuzz_factor( $in_new_factor
199  ) {
200  $this->_load_data(false, true);
201 
202  $this->_object_data->fuzz_factor = $in_new_factor;
203 
204  $ret = $this->save_data();
205 
206  if ($ret) { // We force a reload, because fuzz.
207  $this->_load_data(true, true);
208  }
209 
210  return $ret;
211  }
212 
213  /***********************/
221  function set_can_see_through_the_fuzz( $in_token_id
222  ) {
223  $this->_load_data(false, true);
224 
225  $this->_object_data->can_see_through_the_fuzz = $in_token_id;
226 
227  $ret = $this->save_data();
228 
229  if ($ret) { // We force a reload, because fuzz.
230  $this->_load_data(true, true);
231  }
232 
233  return $ret;
234  }
235 
236  /***********************/
242  function raw_coords() {
243  $ret = NULL;
244 
245  $this->_load_data(false, true);
246 
247  if (isset($this->_object_data) && isset($this->_object_data->raw_latitude) && isset($this->_object_data->raw_longitude)) {
248  $ret = [];
249  $ret['latitude'] = floatval($this->_object_data->raw_latitude);
250  $ret['longitude'] = floatval($this->_object_data->raw_longitude);
251  }
252 
253  return $ret;
254  }
255 
256  /***********************/
262  function payload() {
263  $ret = NULL;
264 
265  $this->_load_data(false, true);
266 
267  if (isset($this->_object_data) && isset($this->_object_data->payload)) {
268  $payload_data = base64_decode($this->_object_data->payload);
269 
270  // We make sure that this was already Base64 before decoding.
271  if (base64_encode(base64_decode($payload_data)) == $payload_data) {
272  $payload_data = base64_decode($payload_data);
273  }
274 
275  $ret = ['data' => $payload_data];
276 
277  if (isset($this->_object_data->payload_type)) {
278  $ret['type'] = str_replace(';base64', '', $this->_object_data->payload_type);
279  }
280  }
281 
282  return $ret;
283  }
284 
285  /***********************/
291  function set_payload( $in_payload_data
292  ) {
293  $payload = NULL;
294  $args = '';
295 
296  // We figure out the payload type by uploading to a file, then checking the file type.
297  if ($in_payload_data) {
298  $temp_file = tempnam(sys_get_temp_dir(), 'RVP');
299  file_put_contents($temp_file , $in_payload_data);
300  $finfo = finfo_open(FILEINFO_MIME_TYPE);
301  $content_type = finfo_file($finfo, $temp_file);
302  unlink($temp_file);
303  $this->_object_data->payload_type = $content_type;
304  $payload = ['data' => $in_payload_data, 'type' => $content_type];
305  } else {
306  $args = '&remove_payload';
307  }
308 
309  // We circumvent our caller for this one.
310  $ret = $this->_save_change_record(self::_save_data($args, $payload));
311 
312  if ($ret) {
313  $ret = $this->_load_data(true, true);
314  } else {
315  $this->_load_data(true, true);
316  }
317 
318  return $ret;
319  }
320 
321  /***********************/
327  function children_ids() {
328  $ret = [];
329 
330  $this->_load_data(false, true);
331 
332  if (isset($this->_object_data) && isset($this->_object_data->children)) {
333  $child_data = (array)$this->_object_data->children;
334 
335  if (count($child_data)) {
336  $ret = $child_data;
337  }
338  }
339 
340  return $ret;
341  }
342 
343  /***********************/
349  function set_new_children_ids( $in_child_ids
356  ) {
357  $ret = false;
358  // We circumvent our caller for this one.
359  $ret = $this->_save_change_record(self::_save_data('', NULL, $in_child_ids));
360 
361  if ($ret) {
362  $ret = $this->force_reload();
363  } else { // If there was an error, then we don't send back the result (it may also be an error).
364  $this->force_reload();
365  }
366  return $ret;
367  }
368 
369  /***********************/
377  function parent_ids() {
378  $ret = NULL;
379 
380  $this->_load_data(false, true, true);
381 
382  if (isset($this->_object_data) && isset($this->_object_data->parents)) {
383  $parent_data = $this->_object_data->parents;
384 
385  if (isset($parent_data) && is_array($parent_data) && count($parent_data)) {
386  $ret = $parent_data;
387  }
388  }
389 
390  return $ret;
391  }
392 
393  /***********************/
401  function get_hierarchy() {
402  $ret = ['object' => $this];
403 
404  $this->_load_data(false, true);
405 
406  if (isset($this->_object_data) && isset($this->_object_data->children)) {
407  $child_data = (array)$this->_object_data->children;
408 
409  if (count($child_data)) {
410  $ret['children'] = [];
411  foreach ($child_data as $plugin) {
412  if (count($plugin)) {
413  $objects = $this->_sdk_object->get_objects($plugin);
414 
415  if (is_array($objects) && count($objects)) {
416  foreach ($objects as $object) {
417  if (method_exists($object, 'get_hierarchy')) {
418  $ret['children'][] = $object->get_hierarchy();
419  }
420  }
421  }
422  }
423  }
424  }
425  }
426 
427  return $ret;
428  }
429 };
_save_data( $in_args='', $in_payload=NULL, $in_new_child_ids=NULL)
set_coords( $in_latitude, $in_longitude)
__construct( $in_sdk_object, $in_id, $in_data=NULL, $in_detailed_data=false, $in_plugin_path='baseline')