/** * Get the REST representation of an item. * * @param Item $record * @return array */ public function getRepresentation(Omeka_Record_AbstractRecord $record) { $representation = array('id' => $record->id, 'url' => self::getResourceUrl("/items/{$record->id}"), 'public' => (bool) $record->public, 'featured' => (bool) $record->featured, 'added' => self::getDate($record->added), 'modified' => self::getDate($record->modified)); if ($record->item_type_id) { $representation['item_type'] = array('id' => $record->item_type_id, 'url' => self::getResourceUrl("/item_types/{$record->item_type_id}"), 'name' => $record->Type->name, 'resource' => 'item_types'); } else { $representation['item_type'] = null; } if ($record->collection_id) { //check that user has access to the collection $collection = $record->getCollection(); if (is_allowed($collection, 'show')) { $representation['collection'] = array('id' => $record->collection_id, 'url' => self::getResourceUrl("/collections/{$record->collection_id}"), 'resource' => 'collections'); } else { $representation['collection'] = null; } } else { $representation['collection'] = null; } if ($record->owner_id) { $representation['owner'] = array('id' => $record->owner_id, 'url' => self::getResourceUrl("/users/{$record->owner_id}"), 'resource' => 'users'); } else { $representation['owner'] = null; } $representation['files'] = array('count' => $record->getTable('File')->count(array('item_id' => $record->id)), 'url' => self::getResourceUrl("/files?item={$record->id}"), 'resource' => 'files'); $representation['tags'] = $this->getTagRepresentations($record); $representation['element_texts'] = $this->getElementTextRepresentations($record); return $representation; }
public function getRepresentation(Omeka_Record_AbstractRecord $record) { $representation = array('id' => $record->id, 'url' => self::getResourceUrl("/exhibit_pages/{$record->id}"), 'title' => $record->title, 'slug' => $record->slug, 'order' => $record->order); $representation['exhibit'] = array('id' => $record->exhibit_id, 'resource' => 'exhibits', 'url' => self::getResourceUrl("/exhibits/{$record->exhibit_id}")); if ($record->parent_id) { $representation['parent'] = array('id' => $record->parent_id, 'resource' => 'exhibit_pages', 'url' => self::getResourceUrl("/exhibit_pages/{$record->parent_id}")); } else { $representation['parent'] = null; } $pageBlocks = $record->getPageBlocks($record); $representation['page_blocks'] = array(); foreach ($pageBlocks as $pageBlock) { $blockRepresentation = array('id' => $pageBlock->id, 'page_id' => $pageBlock->page_id, 'layout' => $pageBlock->layout, 'options' => json_decode($pageBlock->options, true), 'text' => $pageBlock->text, 'order' => $pageBlock->order, 'attachments' => array()); $blockAttachments = $pageBlock->getAttachments(); foreach ($blockAttachments as $attachment) { $attachmentRepresentation = array('id' => $attachment->id, 'caption' => $attachment->caption, 'item' => array('id' => $attachment->item_id, 'resource' => 'items', 'url' => self::getResourceUrl("/items/{$attachment->item_id}"))); if ($attachment->file_id) { $attachmentRepresentation['file'] = array('id' => $attachment->file_id, 'resource' => 'files', 'url' => self::getResourceUrl("/files/{$attachment->file_id}")); } $blockRepresentation['attachments'][] = $attachmentRepresentation; } $representation['page_blocks'][] = $blockRepresentation; } return $representation; }
/** * Retrieve the set of ElementText records that correspond to a given * element set and element. Copied from Metadata View Helper. * * @param Omeka_Record_AbstractRecord $record * @param string $elementSetName * @param string $elementName * @return array Set of ElementText records. */ function rpiGetElementText($record, $elementSetName, $elementName) { $elementTexts = $record->getElementTexts($elementSetName, $elementName); // Lock the records so that they can't be accidentally saved back to the // database, since we are modifying their values directly at this point. // Also clone the record because otherwise it would be passed by // reference to all the display filters, which results in munged text. foreach ($elementTexts as $key => $textRecord) { $elementTexts[$key] = clone $textRecord; $textRecord->lock(); } return $elementTexts; }
/** * Filter the display of the Item Type element set, if present. * * @param array $elementsBySet * @return array */ protected function _filterItemTypeElements($elementsBySet) { if ($this->_record instanceof Item) { if ($this->_record->item_type_id) { // Overwrite elements assigned to the item type element set with only // those that belong to this item's particular item type. This is // necessary because, otherwise, all item type elements will be shown. $itemTypeElementSetName = $this->_record->getProperty('item_type_name') . ' ' . ElementSet::ITEM_TYPE_NAME; // Check to see if either the generic or specific Item Type element // set has been chosen, i.e. 'Item Type Metadata' or 'Document // Item Type Metadata', etc. $itemTypeElements = $this->_record->getItemTypeElements(); if (!empty($this->_elementSetsToShow)) { if (in_array($itemTypeElementSetName, $this->_elementSetsToShow) or in_array(ElementSet::ITEM_TYPE_NAME, $this->_elementSetsToShow)) { $elementsBySet[$itemTypeElementSetName] = $itemTypeElements; } } else { $elementsBySet[$itemTypeElementSetName] = $itemTypeElements; } } // Unset the existing 'Item Type' element set b/c it shows elements // for all item types. unset($elementsBySet[ElementSet::ITEM_TYPE_NAME]); } return $elementsBySet; }
public function profileElementForm(Element $element, Omeka_Record_AbstractRecord $record, $options = array()) { $divWrap = isset($options['divWrap']) ? $options['divWrap'] : true; $extraFieldCount = isset($options['extraFieldCount']) ? $options['extraFieldCount'] : null; $isUserProfilesMultiElement = get_class($element) == 'UserProfilesMultiElement' ? true : false; $this->_element = $element; $record->loadElementsAndTexts(); $this->_record = $record; // Filter the components of the element form display $labelComponent = $this->_getLabelComponent(); if ($isUserProfilesMultiElement) { $inputsComponent = $this->_getMultiComponent(); } else { $inputsComponent = $this->_getInputsComponent($extraFieldCount); } $descriptionComponent = $this->_getDescriptionComponent(); $commentComponent = $this->_getCommentComponent(); if ($isUserProfilesMultiElement) { $addInputComponent = ''; } else { $addInputComponent = $this->view->formSubmit('add_element_' . $this->_element['id'], __('Add Input'), array('class' => 'add-element')); } $components = array('label' => $labelComponent, 'inputs' => $inputsComponent, 'description' => $descriptionComponent, 'comment' => $commentComponent, 'add_input' => $addInputComponent, 'html' => null); $elementSetName = $element->getElementSet()->name; $recordType = get_class($record); $filterName = array('ElementForm', $recordType, $elementSetName, $element->name); $components = apply_filters($filterName, $components, array('record' => $record, 'element' => $element, 'options' => $options)); if ($components['html'] !== null) { return strval($components['html']); } // Compose html for element form $html = $divWrap ? '<div class="field" id="element-' . html_escape($element->id) . '">' : ''; $html .= '<div class="two columns alpha">'; $html .= $components['label']; $html .= $components['add_input']; $html .= '</div>'; $html .= '<div class="inputs five columns omega">'; $html .= $components['description']; $html .= $components['comment']; $html .= $components['inputs']; $html .= '</div>'; // Close 'inputs' div $html .= $divWrap ? '</div>' : ''; // Close 'field' div return $html; }
/** * Get a property about this collection. * * Valid properties for a Collection include: * * (int) public * * (int) featured * * (string) added * * (string) modified * * (int) owner_id * * (int) total_items * * @param string $property The property to get, always lowercase. * @return mixed The value of the property */ public function getProperty($property) { switch ($property) { case 'total_items': return $this->totalItems(); default: return parent::getProperty($property); } }
/** * Set POST data to an item type. * * @param ItemType $data * @param mixed $data */ public function setPostData(Omeka_Record_AbstractRecord $record, $data) { if (isset($data->name)) { $record->name = $data->name; } if (isset($data->description)) { $record->description = $data->description; } if (isset($data->elements) && is_array($data->elements)) { $elements = array(); foreach ($data->elements as $element) { if (!is_object($element)) { continue; } $elements[] = $record->getTable('Element')->find($element->id); } $record->addElements($elements); } }
/** * Check whether a field is unique. * * The check for unique tag names must take into account CASE SENSITIVITY, * which is accomplished via COLLATE utf8_bin sql * * @return bool */ protected function fieldIsUnique($field, $value = null) { if ($field != 'name') { return parent::fieldIsUnique($field, $value); } else { $db = $this->getDb(); $sql = "\n SELECT id \n FROM {$db->Tag} \n WHERE name COLLATE utf8_bin LIKE ?"; $res = $db->query($sql, array($value ? $value : $this->name)); return !is_array($id = $res->fetch()) || ($this->exists() and $id['id'] == $this->id); } }
public function save($throwIfInvalid = true) { //check to see if the triple already exists, from the same user if (empty($this->user_id)) { $currentUser = current_user(); $this->user_id = $currentUser->id; } $count = $this->getTable()->count(array('subject_id' => $this->subject_id, 'object_id' => $this->object_id, 'user_id' => $this->user_id, 'subject_record_type' => $this->subject_record_type, 'object_record_type' => $this->object_record_type, 'property_id' => $this->property_id)); if ($count == 0) { parent::save(); } }
/** * Set the parent element reference. * * @param Element $element The parent element. */ public function __construct($element = null) { parent::__construct(); if (!is_null($element)) { // Element reference. $this->element_id = $element->id; // Element identifier. $this->slug = $element->id; // Pubilc-facing label. $this->label = $element->name; } }
public function elementForm(Element $element, Omeka_Record_AbstractRecord $record, $options = array()) { $divWrap = isset($options['divWrap']) ? $options['divWrap'] : true; $extraFieldCount = isset($options['extraFieldCount']) ? $options['extraFieldCount'] : null; $this->_element = $element; // This will load all the Elements available for the record and fatal error // if $record does not use the ActsAsElementText mixin. $record->loadElementsAndTexts(); $this->_record = $record; // Filter the components of the element form display $labelComponent = $this->_getLabelComponent(); $inputsComponent = $this->_getInputsComponent($extraFieldCount); $descriptionComponent = $this->_getDescriptionComponent(); $commentComponent = $this->_getCommentComponent(); $addInputComponent = $this->view->formSubmit('add_element_' . $this->_element['id'], __('Add Input'), array('class' => 'add-element')); $components = array('label' => $labelComponent, 'inputs' => $inputsComponent, 'description' => $descriptionComponent, 'comment' => $commentComponent, 'add_input' => $addInputComponent, 'html' => null); $elementSetName = $element->set_name; $recordType = get_class($record); $filterName = array('ElementForm', $recordType, $elementSetName, $element->name); $components = apply_filters($filterName, $components, array('record' => $record, 'element' => $element, 'options' => $options)); if ($components['html'] !== null) { return strval($components['html']); } // Compose html for element form $html = $divWrap ? '<div class="field" id="element-' . html_escape($element->id) . '">' : ''; $html .= '<div class="two columns alpha">'; $html .= $components['label']; $html .= $components['add_input']; $html .= '</div>'; // Close div $html .= '<div class="inputs five columns omega">'; $html .= $components['description']; $html .= $components['comment']; $html .= $components['inputs']; $html .= '</div>'; // Close 'inputs' div $html .= $divWrap ? '</div>' : ''; // Close 'field' div return $html; }
/** * Get the REST API representation for a file. * * @param File $record * @return array */ public function getRepresentation(Omeka_Record_AbstractRecord $record) { $representation = array('id' => $record->id, 'url' => self::getResourceUrl("/files/{$record->id}"), 'file_urls' => array('original' => $record->getWebPath(), 'fullsize' => $record->has_derivative_image ? $record->getWebPath('fullsize') : null, 'thumbnail' => $record->has_derivative_image ? $record->getWebPath('thumbnail') : null, 'square_thumbnail' => $record->has_derivative_image ? $record->getWebPath('square_thumbnail') : null), 'added' => self::getDate($record->added), 'modified' => self::getDate($record->modified), 'filename' => $record->filename, 'authentication' => $record->authentication, 'has_derivative_image' => (bool) $record->has_derivative_image, 'mime_type' => $record->mime_type, 'order' => $record->order, 'original_filename' => $record->original_filename, 'size' => $record->size, 'stored' => (bool) $record->stored, 'type_os' => $record->type_os, 'metadata' => json_decode($record->metadata, true)); $representation['item'] = array('id' => $record->item_id, 'url' => self::getResourceUrl("/items/{$record->item_id}"), 'resource' => 'items'); $representation['element_texts'] = $this->getElementTextRepresentations($record); return $representation; }
/** * Set the properties for the record, taking care to filter based on the * $_settableProperties array. * * @param Omeka_Record_AbstractRecord $record * @return void */ private function _setRecordProperties($record) { $properties = array_intersect_key($this->getRecordMetadata(), array_flip($this->_settableProperties)); $record->setArray($properties); }
public function setArray($data) { if (empty($data['parent_comment_id'])) { $data['parent_comment_id'] = null; } parent::setArray($data); }
/** * 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 a property or special value of this record. * * @param string $property * @return mixed */ public function getProperty($property) { switch ($property) { case 'uri': return $this->getWebPath('original'); case 'fullsize_uri': return $this->getWebPath('fullsize'); case 'thumbnail_uri': return $this->getWebPath('thumbnail'); case 'square_thumbnail_uri': return $this->getWebPath('square_thumbnail'); case 'permalink': return absolute_url(array('controller' => 'files', 'action' => 'show', 'id' => $this->id)); case 'display_title': $titles = $this->getElementTexts('Dublin Core', 'Title'); if ($titles) { $title = strip_formatting($titles[0]->text); } else { $title = $this->original_filename; } return $title; default: return parent::getProperty($property); } }
public function getProperty($property) { switch ($property) { case 'added_username': $user = $this->getOwner(); return $user ? $user->username : __('Anonymous'); default: return parent::getProperty($property); } }
/** * Set data from POST to the record. * * Removes the 'password' and 'salt' entries, if passed. */ public function setPostData($post) { // potential security hole if (isset($post['password'])) { unset($post['password']); } if (array_key_exists('salt', $post)) { unset($post['salt']); } return parent::setPostData($post); }
/** * Get the REST API representation for Collection * * @param Collection $record * @return array */ public function getRepresentation(Omeka_Record_AbstractRecord $record) { $representation = array('id' => $record->id, 'url' => self::getResourceUrl("/collections/{$record->id}"), 'public' => (bool) $record->public, 'featured' => (bool) $record->featured, 'added' => self::getDate($record->added), 'modified' => self::getDate($record->modified), 'owner' => array('id' => $record->owner_id, 'url' => self::getResourceUrl("/users/{$record->owner_id}"), 'resource' => 'users'), 'items' => array('count' => $record->getTable('Item')->count(array('collection_id' => $record->id)), 'url' => self::getResourceUrl("/items?collection={$record->id}"), 'resource' => 'items'), 'element_texts' => $this->getElementTextRepresentations($record)); return $representation; }
/** * 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; }
/** * This creates the NeatlineFeature object. * * @param $item Omeka_Record The Omeka item associated with this * feature. * @param $element_text ElementText The Omeka element text that this is * associated with. If not given, it just takes the first element text for * the Coverage field. * * @return NeatlineFeature $this * @author Eric Rochester <*****@*****.**> **/ public function __construct($item = null, $element_text = null) { parent::__construct(); if (!is_null($item)) { $this->item_id = $item->id; } if (!is_null($element_text)) { $this->element_text = $element_text->id; } // Default values. if (is_null($this->is_map)) { $this->is_map = false; } if (is_null($this->added)) { $this->added = date('c'); } }
/** * Reload a record. * * @param Omeka_Record_AbstractRecord $record A record to reload. * @return Omeka_Record_AbstractRecord The reloaded record. */ protected function _reload($record) { return $record->getTable()->find($record->id); }
protected function _afterBuild(Omeka_Record_AbstractRecord $record) { $this->_test->assertTrue($record->exists()); $this->_test->ranAfterBuild = true; }
/** * Combine errors from a different Omeka_Record_AbstractRecord instance with * the errors already on this record. * * @see Item::_validateElements() * @param Omeka_Record_AbstractRecord $record * @return void */ public function addErrorsFrom(Omeka_Record_AbstractRecord $record) { $errors = $record->getErrors(); foreach ($errors->get() as $field => $error) { $this->addError($field, $error); } }
/** * Get a property for display. * * @param string $property * @return mixed */ public function getProperty($property) { switch ($property) { case 'item_type_name': if ($type = $this->Type) { return $type->name; } else { return null; } case 'collection_name': if ($collection = $this->Collection) { return strip_formatting(metadata($collection, array('Dublin Core', 'Title'))); } else { return null; } case 'permalink': return record_url($this, null, true); case 'has_files': return (bool) $this->fileCount(); case 'file_count': return $this->fileCount(); case 'has_thumbnail': return $this->hasThumbnail(); case 'citation': return $this->getCitation(); default: return parent::getProperty($property); } }
/** * Get a property or special value of this record. * * @param string $property * @return mixed */ public function getProperty($property) { switch ($property) { case 'folder': return $this->getFolder(); case 'record': return $this->getRecord(); default: return parent::getProperty($property); } }
/** * Return a valid img tag for an image. * * @param Omeka_Record_AbstractRecord $record * @param array $props Image tag attributes * @param string $format Derivative image type (thumbnail, etc.) * @return string */ public function image_tag($record, $props, $format) { if (!($record && $record instanceof Omeka_Record_AbstractRecord)) { return false; } // Use the default representative file. $file = $record->getFile(); if (!$file) { return false; } if ($file->hasThumbnail()) { $uri = $file->getWebPath($format); } else { $uri = img($this->_getFallbackImage($file)); } $props['src'] = $uri; /** * Determine alt attribute for images * Should use the following in this order: * 1. passed 'alt' prop * 2. first Dublin Core Title for $file * 3. original filename for $file */ $alt = ''; if (isset($props['alt'])) { $alt = $props['alt']; } else { if ($fileTitle = metadata($file, 'display title', array('no_escape' => true))) { $alt = $fileTitle; } } $props['alt'] = $alt; $title = ''; if (isset($props['title'])) { $title = $props['title']; } else { $title = $alt; } $props['title'] = $title; // Build the img tag return '<img ' . tag_attributes($props) . '>'; }
public function getProperty($property) { switch ($property) { case 'created_username': return $this->getCreatedByUser()->username; case 'modified_username': return $this->getModifiedByUser()->username; default: return parent::getProperty($property); } }
/** * Get the REST API representation for an element set. * * @param ElementSet $record * @return array */ public function getRepresentation(Omeka_Record_AbstractRecord $record) { $representation = array('id' => $record->id, 'url' => self::getResourceUrl("/element_sets/{$record->id}"), 'name' => $record->name, 'description' => $record->description, 'record_type' => $record->record_type, 'elements' => array('count' => $record->getTable('Element')->count(array('element_set' => $record->id)), 'url' => self::getResourceUrl("/elements?element_set={$record->id}"), 'resource' => 'elements')); return $representation; }
/** * Get a property or special value of this record. * * @param string $property * @return mixed */ public function getProperty($property) { switch ($property) { case 'uri': return $this->getWebPath('original'); case 'fullsize_uri': return $this->getWebPath('fullsize'); case 'thumbnail_uri': return $this->getWebPath('thumbnail'); case 'square_thumbnail_uri': return $this->getWebPath('square_thumbnail'); case 'permalink': return absolute_url(array('controller' => 'files', 'action' => 'show', 'id' => $this->id)); case 'display_title': return $this->getDisplayTitle(); default: return parent::getProperty($property); } }