27 defined(
'LGV_BASALT_CATCHER' ) or die ( 'Cannot Execute Directly' );
39 return $this->_process_xsd(dirname(__FILE__).
'/schema.xsd');
49 $in_show_parents =
false
51 $ret = parent::_get_long_description($in_object, $in_show_parents);
53 if (isset($in_object->tags()[0]) && trim($in_object->tags()[0])) {
54 $ret[
'key'] = trim($in_object->tags()[0]);
57 if (isset($in_object->tags()[1]) && trim($in_object->tags()[1])) {
58 $ret[
'description'] = trim($in_object->tags()[1]);
61 for ($tag = 2; $tag < 10; $tag++) {
62 if (isset($in_object->tags()[$tag]) && (NULL != $in_object->tags()[$tag])) {
63 $ret[
'tag'.$tag] = trim($in_object->tags()[$tag]);
79 $ret = parent::_process_parameters($in_andisol_instance, $in_query);
81 if (isset($in_query) && is_array($in_query)) {
82 if (isset($in_query[
'key'])) {
83 $ret[
'key'] = trim(strval($in_query[
'key']));
86 if (isset($in_query[
'description'])) {
87 $ret[
'description'] = trim(strval($in_query[
'description']));
90 for ($tag = 2; $tag < 10; $tag++) {
91 if (isset($in_query[
'tag'.$tag])) {
92 $ret[
'tag'.$tag] = trim(strval($in_query[
'tag'.$tag]));
112 $thing_key = (isset($in_path) && is_array($in_path) && count($in_path) && (
false === strpos(
',', $in_path[0])) && !ctype_digit($in_path[0])) ? trim($in_path[0]) : NULL;
114 $parameters = $this->_process_parameters($in_andisol_instance, $in_query);
117 $parameters[
'key'] = $thing_key;
120 if ($in_andisol_instance->logged_in() && isset($parameters[
'payload']) && isset($parameters[
'key']) && $parameters[
'key'] && (
false === strpos($parameters[
'key'],
','))) {
121 if (!$in_andisol_instance->key_is_unique($parameters[
'key'])) {
122 header(
'HTTP/1.1 400 Invalid Key');
126 if ($in_andisol_instance->set_value_for_key($parameters[
'key'], $parameters[
'payload'])) {
127 $new_record = $in_andisol_instance->get_object_for_key($parameters[
'key']);
129 unset($parameters[
'payload']);
130 $result = $this->_process_thing_put($in_andisol_instance, [$new_record], $in_path, $in_query);
132 $ret[
'new_thing'] = $result[
'changed_things'][0][
'after'];
134 header(
'HTTP/1.1 400 Resource Not Created');
138 header(
'HTTP/1.1 400 Resource Not Created');
141 } elseif ($in_andisol_instance->logged_in() && isset($parameters[
'key']) && !isset($parameters[
'payload'])) {
142 header(
'HTTP/1.1 400 Invalid Payload');
144 } elseif ($in_andisol_instance->logged_in() && isset($parameters[
'key'])) {
145 header(
'HTTP/1.1 400 Invalid Resource Key');
148 header(
'HTTP/1.1 403 Forbidden');
162 $in_object_list = [],
163 $in_data_only =
false,
164 $in_show_details =
false,
165 $in_show_parents =
false,
166 $in_search_count_only =
false,
167 $in_search_ids_only =
false,
173 if ($in_search_count_only) {
174 $ret[
'count'] = intval($in_object_list);
175 } elseif (isset($in_object_list) && is_array($in_object_list) && (0 < count($in_object_list))) {
176 if ($in_search_ids_only) {
177 $ret[
'ids'] = $in_object_list;
179 foreach ($in_object_list as $thing) {
180 if ($in_show_details) {
181 $ret[] = $this->_get_long_thing_description($thing, $in_show_parents);
182 } elseif ($in_data_only) {
183 $payload = $thing->get_payload();
184 $temp_file = tempnam(sys_get_temp_dir(),
'RVP');
185 file_put_contents($temp_file , $payload);
186 $finfo = finfo_open(FILEINFO_MIME_TYPE);
187 $content_type = finfo_file($finfo, $temp_file);
188 $payload_type = $content_type.
';base64,';
189 $ret = $payload_type.base64_encode($payload);
191 $ret[] = $this->_get_short_description($thing);
207 $in_object_list = [],
208 $in_show_parents =
false
212 if ($in_andisol_instance->logged_in()) {
213 if (isset($in_object_list) && is_array($in_object_list) && (0 < count($in_object_list))) {
214 foreach ($in_object_list as $thing) {
215 $to_be_deleted = $this->_get_long_thing_description($thing, $in_show_parents);
216 if ($thing->user_can_write() && $thing->delete_from_db()) {
217 $ret[
'deleted_things'][] = $to_be_deleted;
222 header(
'HTTP/1.1 403 Forbidden');
236 $in_object_list = [],
239 $in_show_parents =
false
241 if ($in_andisol_instance->logged_in()) {
243 $fuzz_factor = isset($in_query) && is_array($in_query) && isset($in_query[
'fuzz_factor']) ? floatval($in_query[
'fuzz_factor']) : 0;
245 $parameters = $this->_process_parameters($in_andisol_instance, $in_query);
246 if (isset($parameters) && is_array($parameters) && count($parameters) && isset($in_object_list) && is_array($in_object_list) && count($in_object_list)) {
254 $change_reports = [];
256 foreach ($in_object_list as $thing) {
257 if ($thing->user_can_write()) {
258 $thing->set_batch_mode();
260 $changed_thing = [
'before' => $this->_get_long_thing_description($thing, $in_show_parents)];
264 if ($result && isset($parameters[
'key']) && (
false === strpos(
',', $parameters[
'key']))) {
265 $result = $thing->set_key($parameters[
'key']);
266 unset($parameters[
'key']);
269 if ($result && isset($parameters[
'name'])) {
270 $result = $thing->set_name($parameters[
'name']);
273 if ($result && isset($parameters[
'write_token'])) {
274 $result = $thing->set_write_security_id($parameters[
'write_token']);
277 if ($result && isset($parameters[
'lang'])) {
278 $result = $thing->set_lang($parameters[
'lang']);
281 if ($result && isset($parameters[
'longitude'])) {
282 $result = $thing->set_longitude($parameters[
'longitude']);
285 if ($result && isset($parameters[
'latitude'])) {
286 $result = $thing->set_latitude($parameters[
'latitude']);
289 if ($result && isset($parameters[
'fuzz_factor'])) {
290 $result = $thing->set_fuzz_factor($parameters[
'fuzz_factor']);
293 if ($result && isset($parameters[
'can_see_through_the_fuzz'])) {
294 $result = $thing->set_can_see_through_the_fuzz($parameters[
'can_see_through_the_fuzz']);
297 if ($result && isset($parameters[
'description'])) {
298 $result = $thing->set_tag(1, $parameters[
'description']);
301 if ($result && isset($parameters[
'tag2'])) {
302 $result = $thing->set_tag(2, $parameters[
'tag2']);
305 if ($result && isset($parameters[
'tag3'])) {
306 $result = $thing->set_tag(3, $parameters[
'tag3']);
309 if ($result && isset($parameters[
'tag4'])) {
310 $result = $thing->set_tag(4, $parameters[
'tag4']);
313 if ($result && isset($parameters[
'tag5'])) {
314 $result = $thing->set_tag(5, $parameters[
'tag5']);
317 if ($result && isset($parameters[
'tag6'])) {
318 $result = $thing->set_tag(6, $parameters[
'tag6']);
321 if ($result && isset($parameters[
'tag7'])) {
322 $result = $thing->set_tag(7, $parameters[
'tag7']);
325 if ($result && isset($parameters[
'tag8'])) {
326 $result = $thing->set_tag(8, $parameters[
'tag8']);
329 if ($result && isset($parameters[
'tag9'])) {
330 $result = $thing->set_tag(9, $parameters[
'tag9']);
333 if ($result && isset($parameters[
'remove_payload'])) {
334 $result = $thing->set_payload(NULL);
335 } elseif ($result && isset($parameters[
'payload'])) {
336 $result = $thing->set_payload($parameters[
'payload']);
340 if ($result && isset($parameters[
'child_ids'])) {
341 $add = $parameters[
'child_ids'][
'add'];
342 $remove = $parameters[
'child_ids'][
'remove'];
344 foreach ($remove as $id) {
345 if ($id != $thing->id()) {
346 $child = $in_andisol_instance->get_single_data_record_by_id($id);
348 $result = $thing->deleteThisElement($child);
358 foreach ($add as $id) {
359 if ($id != $thing->id()) {
360 $child = $in_andisol_instance->get_single_data_record_by_id($id);
362 $result = $thing->appendElement($child);
374 if ($result && isset($parameters[
'read_token'])) {
375 $result = $thing->set_read_security_id($parameters[
'read_token']);
379 $changed_thing[
'after'] = $this->_get_long_thing_description($thing, $in_show_parents);
380 $change_reports[] = [
'object' => $thing,
'report' => $changed_thing];
386 if ($result && count($change_reports)) {
387 $ret[
'changed_things'] = [];
388 foreach ($change_reports as $value) {
389 $result = $value[
'object']->clear_batch_mode();
391 $ret[
'changed_things'][] = $value[
'report'];
399 header(
'HTTP/1.1 403 Forbidden');
412 return [
'CO_Collection',
'CO_KeyValue_CO_Collection'];
438 if (
'POST' == $in_http_method) {
439 $ret = $this->_process_thing_post($in_andisol_instance, $in_path, $in_query);
441 $show_parents = isset($in_query) && is_array($in_query) && isset($in_query[
'show_parents']);
442 $show_details = $show_parents || (isset($in_query) && is_array($in_query) && isset($in_query[
'show_details']));
443 $data_only = (isset($in_query) && is_array($in_query) && isset($in_query[
'data_only']));
444 $writeable = isset($in_query) && is_array($in_query) && isset($in_query[
'writeable']);
445 $search_count_only = isset($in_query) && is_array($in_query) && isset($in_query[
'search_count_only']);
446 $search_ids_only = isset($in_query) && is_array($in_query) && isset($in_query[
'search_ids_only']);
447 $search_page_size = isset($in_query) && is_array($in_query) && isset($in_query[
'search_page_size']) ? abs(intval($in_query[
'search_page_size'])) : 0;
448 $search_page_number = isset($in_query) && is_array($in_query) && isset($in_query[
'search_page_number']) ? abs(intval($in_query[
'search_page_number'])) : 0;
453 if (0 == count($in_path)) {
454 $radius = isset($in_query) && is_array($in_query) && isset($in_query[
'search_radius']) && (0.0 < floatval($in_query[
'search_radius'])) ? floatval($in_query[
'search_radius']) : NULL;
455 $longitude = isset($in_query) && is_array($in_query) && isset($in_query[
'search_longitude']) ? floatval($in_query[
'search_longitude']) : NULL;
456 $latitude = isset($in_query) && is_array($in_query) && isset($in_query[
'search_latitude']) ? floatval($in_query[
'search_latitude']) : NULL;
458 $location_search = NULL;
460 if (isset($radius) && isset($longitude) && isset($latitude)) {
461 $location_search = Array(
'radius' => $radius,
'longitude' => $longitude,
'latitude' => $latitude);
464 $class_search = Array(
'%_KeyValue_CO_Collection',
'use_like' => 1);
466 $search_array = [
'access_class' => $class_search];
468 if (isset($location_search)) {
469 $search_array[
'location'] = $location_search;
472 $search_name = isset($in_query) && is_array($in_query) && isset($in_query[
'search_name']) ? trim($in_query[
'search_name']) : NULL;
474 if (isset($search_name)) {
475 $search_array[
'name'] = Array($search_name,
'use_like' => 1);
480 $in_query[
'search_tag1'] = isset($in_query) && is_array($in_query) && isset($in_query[
'search_description']) ? trim($in_query[
'search_description']) : NULL;
483 for ($tag = 1; $tag < 10; $tag++) {
484 $tag_string =
'search_tag'.$tag;
485 $tag_value = isset($in_query) && is_array($in_query) && isset($in_query[$tag_string]) ? trim($in_query[$tag_string]) : NULL;
486 if ($tag_value !== NULL) {
489 $tags[] = $tag_value;
494 $search_array[
'tags'] = $tags;
495 $search_array[
'tags'][
'use_like'] = 1;
498 $thinglist = $in_andisol_instance->generic_search($search_array,
false, $search_page_size, $search_page_number, $writeable, $search_count_only, $search_ids_only);
500 $thing_id_list = array_unique(explode(
',', $in_path[0]));
503 $thing_id_list = [$thing_id_list[0]];
506 foreach ($thing_id_list as $id) {
509 if (ctype_digit($id) && (0 < intval($id))) {
510 $thing = $in_andisol_instance->get_single_data_record_by_id($id);
514 $id = urldecode($id);
515 $thing = $in_andisol_instance->get_object_for_key($id);
519 $thinglist[] = $thing;
528 if (
'GET' == $in_http_method) {
529 $ret = $this->_process_thing_get($in_andisol_instance, $thinglist, $data_only, $show_details, $show_parents, $search_count_only, $search_ids_only, $in_path, $in_query);
530 } elseif (
'DELETE' == $in_http_method) {
531 $ret = $this->_process_thing_delete($in_andisol_instance, $thinglist, $show_parents);
533 $ret = $this->_process_thing_put($in_andisol_instance, $thinglist, $in_path, $in_query, $show_parents);
537 return $data_only ? $ret : $this->_condition_response($in_response_type, $ret);
_get_long_thing_description( $in_object, $in_show_parents=false)
process_command( $in_andisol_instance, $in_http_method, $in_response_type, $in_path=[], $in_query=[])
_process_thing_get( $in_andisol_instance, $in_object_list=[], $in_data_only=false, $in_show_details=false, $in_show_parents=false, $in_search_count_only=false, $in_search_ids_only=false, $in_path=[], $in_query=[])
_process_thing_post( $in_andisol_instance, $in_path=[], $in_query=[])
_process_thing_put( $in_andisol_instance, $in_object_list=[], $in_path=[], $in_query=[], $in_show_parents=false)
_process_thing_delete( $in_andisol_instance, $in_object_list=[], $in_show_parents=false)
_process_parameters( $in_andisol_instance, $in_query)