Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Concreteize RecordMetadataList helper (see #115).

  • Loading branch information...
commit ab65d5366ac7a68899d6c2da55ee77a4781ed754 1 parent 5ae9234
@zerocrates zerocrates authored
View
15 application/views/helpers/FileMetadataList.php
@@ -3,14 +3,11 @@
* @copyright Roy Rosenzweig Center for History and New Media, 2009
* @license http://www.gnu.org/licenses/gpl-3.0.txt
* @package Omeka
- * @access private
*/
/**
* Retrieve the list of all available metadata for a specific file.
*
- * @internal This implements Omeka internals and is not part of the public API.
- * @access private
* @package Omeka
* @copyright Roy Rosenzweig Center for History and New Media, 2009
*/
@@ -28,7 +25,7 @@ class Omeka_View_Helper_FileMetadataList extends Omeka_View_Helper_RecordMetadat
public function fileMetadataList(File $file, array $options = array())
{
- return $this->_getList($file, $options);
+ return $this->recordMetadataList($file, $options);
}
protected function _getElementsBySet()
@@ -44,14 +41,4 @@ protected function _getElementsBySet()
return $elementsBySet;
}
-
- protected function _loadViewPartial($vars = array())
- {
- return common('item-metadata', $vars, 'items');
- }
-
- protected function _getFormattedElementText($record, $elementSetName, $elementName)
- {
- return $this->view->recordMetadata($record, $elementSetName, $elementName, 'all');
- }
}
View
23 application/views/helpers/ItemMetadataList.php
@@ -4,14 +4,11 @@
* @license http://www.gnu.org/licenses/gpl-3.0.txt
* @package Omeka_ThemeHelpers
* @subpackage Omeka_View_Helper
- * @access private
*/
/**
* Helper that writes XHTML containing metadata about an item.
*
- * @internal This implements Omeka internals and is not part of the public API.
- * @access private
* @see show_item_metadata()
* @package Omeka_ThemeHelpers
* @subpackage Omeka_View_Helper
@@ -41,7 +38,7 @@ class Omeka_View_Helper_ItemMetadataList extends Omeka_View_Helper_RecordMetadat
*/
public function itemMetadataList(Item $item, array $options = array())
{
- return $this->_getList($item, $options);
+ return $this->recordMetadataList($item, $options);
}
/**
@@ -79,22 +76,4 @@ protected function _getElementsBySet()
return $elementsBySet;
}
-
- /**
- * @todo Could pass the name of the partial in as an argument rather than hard
- * coding it. That would allow us to use arbitrary partials for purposes such as
- * repackaging the data for RSS/XML or other data formats.
- *
- * @param array
- * @return void
- */
- protected function _loadViewPartial($vars = array())
- {
- return common('item-metadata', $vars, 'items');
- }
-
- protected function _getFormattedElementText($record, $elementSetName, $elementName)
- {
- return $this->view->recordMetadata($record, $elementSetName, $elementName, 'all');
- }
}
View
4 application/views/helpers/RecordMetadata.php
@@ -4,16 +4,12 @@
* @license http://www.gnu.org/licenses/gpl-3.0.txt
* @package Omeka
* @subpackage Omeka_View_Helper
- * @access private
*/
/**
* Helper used to retrieve metadata for a record that makes use of element
* texts.
- * Currently limited to items and files.
*
- * @internal This implements Omeka internals and is not part of the public API.
- * @access private
* @package Omeka
* @subpackage Omeka_View_Helper
* @copyright Roy Rosenzweig Center for History and New Media, 2007-2010
View
103 .../Omeka/View/Helper/RecordMetadataList.php → ...tion/views/helpers/RecordMetadataList.php
@@ -1,83 +1,80 @@
-<?php
+<?php
/**
* @copyright Roy Rosenzweig Center for History and New Media, 2009-2010
* @license http://www.gnu.org/licenses/gpl-3.0.txt
* @package Omeka
* @subpackage Omeka_View_Helper
- * @access private
*/
/**
- * Abstract class that encapsulates default behavior for retrieving lists of
- * metadata for any record that uses ActsAsElementText.
+ * View helper for retrieving lists of metadata for any record that
+ * uses ActsAsElementText.
*
- * @internal This implements Omeka internals and is not part of the public API.
- * @access private
* @package Omeka
* @subpackage Omeka_View_Helper
* @copyright Roy Rosenzweig Center for History and New Media, 2009-2010
*/
-abstract class Omeka_View_Helper_RecordMetadataList extends Zend_View_Helper_Abstract
-{
+class Omeka_View_Helper_RecordMetadataList extends Zend_View_Helper_Abstract
+{
const RETURN_HTML = 'html';
const RETURN_ARRAY = 'array';
-
+
/**
* The Item object.
* @var object
*/
protected $_record;
-
+
/**
* Flag to indicate whether to show elements that do not have text.
* @see self::$_emptyElementString
* @var boolean
*/
protected $_showEmptyElements = true;
-
+
/**
* String to display if elements without text are shown.
* @see self::$_showEmptyElements
* @var string
*/
protected $_emptyElementString;
-
+
/**
* Element sets to list.
*
* @var array
*/
protected $_elementSetsToShow = array();
-
+
/**
* Type of data to return.
*
* @var string
*/
protected $_returnType = self::RETURN_HTML;
-
+
/**
* Get the record metadata list.
- *
+ *
* @param Omeka_Record $record Record to retrieve metadata from.
* @param array $options
* Available options:
- * - show_empty_elements' => bool|string Whether to show elements that
- * do not contain text. A string will set self::$_showEmptyElements to
+ * - show_empty_elements' => bool|string Whether to show elements that
+ * do not contain text. A string will set self::$_showEmptyElements to
* true and set self::$_emptyElementString to the provided string.
* - 'show_element_sets' => array List of names of element sets to display.
* - 'return_type' => string 'array', 'html'. Defaults to 'html'.
* @since 1.0 Added 'show_element_sets' and 'return_type' options.
- * @return string|array
+ * @return string|array
*/
- protected function _getList(Omeka_Record $record, array $options = array())
+ public function recordMetadataList(Omeka_Record $record, array $options = array())
{
$this->_record = $record;
$this->_setOptions($options);
$output = $this->_getOutput();
return $output;
}
-
+
/**
* Set the options.
*
@@ -89,7 +86,7 @@ protected function _setOptions(array $options)
// Set a default for show_empty_elements based on site setting
$this->_showEmptyElements = (bool) get_option('show_empty_elements');
$this->_emptyElementString = __('[no text]');
-
+
// Handle show_empty_elements option
if (array_key_exists('show_empty_elements', $options)) {
if (is_string($options['show_empty_elements'])) {
@@ -98,7 +95,7 @@ protected function _setOptions(array $options)
$this->_showEmptyElements = (bool) $options['show_empty_elements'];
}
}
-
+
if (array_key_exists('show_element_sets', $options)) {
$namesOfElementSetsToShow = $options['show_element_sets'];
if (is_string($namesOfElementSetsToShow)) {
@@ -107,15 +104,15 @@ protected function _setOptions(array $options)
$this->_elementSetsToShow = $namesOfElementSetsToShow;
}
}
-
+
if (array_key_exists('return_type', $options)) {
$this->_returnType = (string)$options['return_type'];
}
}
-
+
/**
* Get an array of all element sets containing their respective elements.
- *
+ *
* @uses Item::getAllElementsBySet()
* @uses Item::getItemTypeElements()
* @return array
@@ -123,15 +120,15 @@ protected function _setOptions(array $options)
protected function _getElementsBySet()
{
$elementsBySet = $this->_record->getAllElementsBySet();
-
+
// Only show the element sets that are passed in as options.
if (!empty($this->_elementSetsToShow)) {
$elementsBySet = array_intersect_key($elementsBySet, array_flip($this->_elementSetsToShow));
}
-
+
return $elementsBySet;
}
-
+
/**
* Get an array of all texts belonging to the provided element.
* @uses Item::getTextsByElement()
@@ -142,36 +139,36 @@ protected function _getTextsByElement(Element $element)
{
return $this->_record->getTextsByElement($element);
}
-
+
/**
- * Determine if an element is allowed to be shown. This method also caches
- * the current Element object and the array of the current ElementText
+ * Determine if an element is allowed to be shown. This method also caches
+ * the current Element object and the array of the current ElementText
* objects. This caching occurs to avoid complexity in the output methods.
- * @todo Maybe separate caching here so it's not hiding in a seemingly
- * unassociated method. Though, doing so would require an extra step in the
+ * @todo Maybe separate caching here so it's not hiding in a seemingly
+ * unassociated method. Though, doing so would require an extra step in the
* output methods (i.e. <?php $this->_cache($element); ?>).
* @param Element $element
* @param array $texts
* @return boolean
*/
protected function _elementIsShowable(Element $element, $texts)
- {
+ {
// If the condidtions are met, this element is showable.
- if (!empty($texts)
+ if (!empty($texts)
|| (empty($texts) && $this->_showEmptyElements)) {
return true;
}
// This element is not showable.
return false;
}
-
+
/**
* Output the default format for displaying record metadata.
- * @return void
+ * @return void
*/
protected function _getOutputAsHtml()
{
- // Prepare the metadata for display on the partial. There should be no
+ // Prepare the metadata for display on the partial. There should be no
// need for method calls by default in the view partial.
$elementSets = $this->_getElementsBySet();
foreach ($elementSets as $setName => $elementsInSet) {
@@ -188,19 +185,19 @@ protected function _getOutputAsHtml()
$elementsInSet[$key]['texts'] = $elementTexts;
if ($setIsEmpty && !$elementsInSet[$key]['isEmpty']) {
$setIsEmpty = false;
- }
+ }
}
$elementSets[$setName] = $elementsInSet;
-
+
// We're done preparing the data for display, so display it.
if (!$setIsEmpty || $this->_showEmptyElements){
- $varsToInject = array('elementSets'=>$elementSets, 'setName'=>$setName,
+ $varsToInject = array('elementSets'=>$elementSets, 'setName'=>$setName,
'elementsInSet'=>$elementsInSet, 'record'=>$this->_record);
$this->_loadViewPartial($varsToInject);
}
}
}
-
+
/**
* Return a formatted version of the requested element.
*
@@ -209,8 +206,11 @@ protected function _getOutputAsHtml()
* @param string $elementName
* @return string
*/
- abstract protected function _getFormattedElementText($record, $elementSetName, $elementName);
-
+ protected function _getFormattedElementText($record, $elementSetName, $elementName)
+ {
+ return $this->view->recordMetadata($record, $elementSetName, $elementName, array('all' => true));
+ }
+
/**
* Get the metadata list as a PHP array.
*
@@ -232,7 +232,7 @@ protected function _getOutputAsArray()
}
return $outputArray;
}
-
+
/**
* Get the metadata list.
*
@@ -256,16 +256,19 @@ protected function _getOutput()
break;
}
}
-
+
/**
* Load a view partial to display the data.
*
- * @todo Could pass the name of the partial in as an argument rather than
- * hardcoding it. That would allow us to use arbitrary partials for
+ * @todo Could pass the name of the partial in as an argument rather than
+ * hardcoding it. That would allow us to use arbitrary partials for
* purposes such as repackaging the data for RSS/XML or other data formats.
- *
+ *
* @param array $vars
* @return void
*/
- abstract protected function _loadViewPartial($vars = array());
+ protected function _loadViewPartial($vars = array())
+ {
+ return common('record-metadata', $vars);
+ }
}
View
0  ...ion/views/scripts/items/item-metadata.php → .../views/scripts/common/record-metadata.php
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.