public function __call($ps_table, $pa_args) { $vo_service = new SearchJSONService($this->request, $ps_table); $va_content = $vo_service->dispatch(); if (intval($this->request->getParameter("pretty", pInteger)) > 0) { $this->view->setVar("pretty_print", true); } if ($vo_service->hasErrors()) { $this->view->setVar("errors", $vo_service->getErrors()); $this->render("json_error.php"); } else { $this->view->setVar("content", $va_content); $this->render("json.php"); } }
protected function search($pa_bundles = null) { $va_return = parent::search($pa_bundles); if ($this->getTableName() == 'ca_objects' && is_array($va_return['results']) && sizeof($va_return['results']) > 0) { $pb_only_with_likes = (bool) $this->opo_request->getParameter('likesOnly', pInteger); foreach ($va_return['results'] as $vn_k => &$va_result) { $t_object = new ca_objects($va_result['object_id']); if (!$t_object->getPrimaryKey()) { continue; } // include number of 'likes' (comments) $va_result['likes'] = (int) $t_object->getNumComments(null); if ($pb_only_with_likes && !$va_result['likes']) { unset($va_return['results'][$vn_k]); continue; } // include copyright holder $vs_copyright_holder = $t_object->get('ca_entities.preferred_labels', array('restrictToRelationshipTypes' => 'copyright')); if ($vs_copyright_holder) { $va_result['copyright_holder'] = $vs_copyright_holder; } // include urls for reference img $va_objects = $t_object->getRelatedItems('ca_objects', array('restrictToRelationshipTypes' => 'reference')); if (!is_array($va_objects) || sizeof($va_objects) != 1) { continue; } $va_object = array_shift($va_objects); $t_rel_object = new ca_objects($va_object['object_id']); $va_rep = $t_rel_object->getPrimaryRepresentation(array('preview170', 'medium', 'alhalqa1000', 'alhalqa2000')); if (!is_array($va_rep) || !is_array($va_rep['urls'])) { continue; } $va_result['reference_image_urls'] = $va_rep['urls']; } if ($this->opo_request->getParameter('sort', pString) == 'likes') { if (strtolower($this->opo_request->getParameter('sortDirection', pString)) == 'asc') { usort($va_return['results'], function ($a, $b) { return $a['likes'] - $b['likes']; }); } else { // default is desc usort($va_return['results'], function ($a, $b) { return $b['likes'] - $a['likes']; }); } } } return $va_return; }
protected function search($pa_bundles = null) { $va_return = parent::search($pa_bundles); if ($this->getTableName() == 'ca_entities' && is_array($va_return['results']) && sizeof($va_return['results']) > 0) { $o_db = new Db(); $t_element = new ca_metadata_elements(); $t_element->load(array('element_code' => 'is_index_display')); $vn_element_id = $t_element->getPrimaryKey(); if (!$vn_element_id) { return $va_return; } $vn_yes_id = caGetListItemID('yn', 'yes'); foreach ($va_return['results'] as &$va_result) { $vn_entity_id = $va_result['entity_id']; $qr_objects = $o_db->query("\n\t\t\t\t\tSELECT DISTINCT ca_objects.object_id FROM ca_entities, ca_objects_x_entities, ca_objects, ca_attributes, ca_attribute_values\n\t\t\t\t\tWHERE ca_entities.entity_id = ca_objects_x_entities.entity_id\n\t\t\t\t\tAND ca_attributes.row_id = ca_objects.object_id\n\t\t\t\t\tAND ca_attribute_values.attribute_id = ca_attributes.attribute_id\n\t\t\t\t\tAND ca_objects_x_entities.object_id = ca_objects.object_id\n\t\t\t\t\tAND ca_attribute_values.element_id = ?\n\t\t\t\t\tAND ca_entities.entity_id = ?\n\t\t\t\t\tAND ca_attribute_values.item_id = ?\n\t\t\t\t\tAND ca_objects.deleted = 0\n\t\t\t\t", $vn_element_id, $vn_entity_id, $vn_yes_id); while ($qr_objects->nextRow()) { $va_object_info = array(); $vn_object_id = $qr_objects->get('ca_objects.object_id'); if (MemoryCache::contains($vn_object_id, 'AboutDrawingServices')) { $va_object_info = MemoryCache::fetch($vn_object_id, 'AboutDrawingServices'); } else { $va_object_info['object_id'] = $vn_object_id; $qr_labels = $o_db->query("\n\t\t\t\t\t\t\tSELECT ca_object_labels.* FROM ca_object_labels, ca_objects\n\t\t\t\t\t\t\tWHERE ca_object_labels.object_id = ca_objects.object_id\n\t\t\t\t\t\t\tAND ca_objects.object_id = ?\n\t\t\t\t\t\t", $vn_object_id); $vs_label = ''; while ($qr_labels->nextRow()) { $va_object_info['labels'][] = $qr_labels->getRow(); $vs_label = $qr_labels->get('name'); // keep the last label around } $va_object_info['label'] = $vs_label; $qr_reps = $o_db->query("\n\t\t\t\t\t\t\tSELECT ca_object_representations.* FROM ca_object_representations, ca_objects_x_object_representations, ca_objects\n\t\t\t\t\t\t\tWHERE ca_object_representations.representation_id = ca_objects_x_object_representations.representation_id\n\t\t\t\t\t\t\tAND ca_objects_x_object_representations.object_id = ca_objects.object_id\n\t\t\t\t\t\t\tAND ca_objects.object_id = ?\n\t\t\t\t\t\t\tAND ca_objects.deleted = 0 AND ca_object_representations.deleted = 0\n\t\t\t\t\t\t", $vn_object_id); while ($qr_reps->nextRow()) { $va_object_info['representations'][] = array('representation_id' => $qr_reps->get('representation_id'), 'icon' => $qr_reps->getMediaUrl('media', 'icon'), 'preview170' => $qr_reps->getMediaUrl('media', 'preview170'), 'medium' => $qr_reps->getMediaUrl('media', 'medium'), 'original' => $qr_reps->getMediaUrl('media', 'original')); } MemoryCache::save($vn_object_id, $va_object_info, 'AboutDrawingServices'); } $va_result['ca_objects'][] = $va_object_info; } /* the old&simple, but very slow code $t_entity = new ca_entities($va_result['entity_id']); $va_objects = $t_entity->getRelatedItems('ca_objects'); foreach($va_objects as $va_object) { $t_object = new ca_objects($va_object['object_id']); $va_reps = $t_object->getRepresentations(array('icon', 'preview170', 'medium', 'original')); $va_representation_info = array(); foreach($va_reps as $va_rep) { $va_representation_info[] = array( 'representation_id' => $va_rep['representation_id'], 'urls' => $va_rep['urls'], ); } $va_object_info = array(); $va_object_info['object_id'] = $va_object['object_id']; $va_object_info['labels'] = $va_object['labels']; $va_object_info['label'] = $va_object['label']; $va_object_info['representations'] = $va_representation_info; $va_result['ca_objects'][] = $va_object_info; }*/ } } return $va_return; }