/** * Get all element sets, elements, and element texts associated with the * provided record. * * @param Omeka_Record_AbstractRecord $record The record from which to * extract metadata. * @param bool $getItemType Whether to get the item type metadata. * @return stdClass A list of element sets or an item type. */ protected function _getElemetSetsByElementTexts(Omeka_Record_AbstractRecord $record, $getItemType = false) { $elementSets = array(); $itemType = array(); // Get all element texts associated with the provided record. $elementTexts = $record->getAllElementTexts(); foreach ($elementTexts as $elementText) { // Get associated element and element set records. $element = get_db()->getTable('Element')->find($elementText->element_id); // Skip texts where we can't find their Element. if (!$element) { continue; } $elementSet = get_db()->getTable('ElementSet')->find($element->element_set_id); // Also skip if we can find the Element but not the Set (less likely) if (!$elementSet) { continue; } // Differentiate between the element sets and the "Item Type // Metadata" pseudo element set. if (ElementSet::ITEM_TYPE_NAME == $elementSet->name) { $itemType['elements'][$element->id]['name'] = $element->name; $itemType['elements'][$element->id]['description'] = $element->description; $itemType['elements'][$element->id]['elementTexts'][$elementText->id]['text'] = $elementText->text; } else { $elementSets[$elementSet->id]['name'] = $elementSet->name; $elementSets[$elementSet->id]['description'] = $elementSet->description; $elementSets[$elementSet->id]['elements'][$element->id]['name'] = $element->name; $elementSets[$elementSet->id]['elements'][$element->id]['description'] = $element->description; $elementSets[$elementSet->id]['elements'][$element->id]['elementTexts'][$elementText->id]['text'] = $elementText->text; } } // Return the item type metadata. if ($getItemType) { $itemType['id'] = $record->Type->id; $itemType['name'] = $record->Type->name; $itemType['description'] = $record->Type->description; return $itemType; } // Return the element sets metadata. return $elementSets; }
/** * Get unfiltered representations of element texts belonging to a record. * * Note the HTML flag in the representation. This indicates to the consumer * that the representation is unfiltered. * * @param Omeka_Record_AbstractRecord $record * @return array */ protected function _getUnfilteredElementTextRepresentations(Omeka_Record_AbstractRecord $record) { $representations = array(); // Get the record's element texts from the ElementText mixin, as opposed // to the AllElementTexts view helper. foreach ($record->getAllElementTexts() as $elementText) { // Cache information about elements and element sets to avoid // unnecessary database queries. if (!isset($this->_elementsCache[$elementText->element_id])) { $element = get_db()->getTable('Element')->find($elementText->element_id); if (!$element) { continue; } $this->_elementsCache[$element->id] = array('id' => $element->id, 'element_set_id' => $element->element_set_id, 'name' => $element->name); } $element = $this->_elementsCache[$elementText->element_id]; if (!isset($this->_elementSetsCache[$element['element_set_id']])) { $elementSet = get_db()->getTable('ElementSet')->find($element['element_set_id']); if (!$elementSet) { continue; } $this->_elementSetsCache[$elementSet->id] = array('id' => $elementSet->id, 'name' => $elementSet->name); } $elementSet = $this->_elementSetsCache[$element['element_set_id']]; // Build the representation. $representation = array('html' => (bool) $elementText->html, 'text' => $elementText->text, 'element_set' => array('id' => $elementSet['id'], 'url' => $this->getResourceUrl("/element_sets/{$elementSet['id']}"), 'name' => $elementSet['name'], 'resource' => 'element_sets'), 'element' => array('id' => $element['id'], 'url' => $this->getResourceUrl("/elements/{$element['id']}"), 'name' => $element['name'], 'resource' => 'elements')); $representations[] = $representation; } return $representations; }