Mixin_ElementText

Package: Record\Mixin

class Mixin_ElementText

extends Omeka_Record_Mixin_AbstractMixin

Record mixin class for associating elements, element texts and their corresponding behaviors to a record.

property Mixin_ElementText::$_textsByNaturalOrder

protected array

ElementText records stored in the order they were retrieved from the database.

property Mixin_ElementText::$_textsByElementId

protected array

ElementText records indexed by the element_id.

property Mixin_ElementText::$_elementsBySet

protected array

Element records indexed by set name and element name, so it looks like:

$elements[‘Dublin Core’][‘Title’] = Element instance;

property Mixin_ElementText::$_elementsById

protected array

Element records indexed by ID.

property Mixin_ElementText::$_elementsOnForm

protected array

List of elements that were output on the form. This can be used to determine the DELETE SQL to use to reset the elements when saving the form.

property Mixin_ElementText::$_textsToSave

protected array

Set of ElementText records to save when submitting the form. These will only be saved to the database if they successfully validate.

property Mixin_ElementText::$_recordsAreLoaded

protected bool

Whether the elements and texts have been loaded yet.

property Mixin_ElementText::$_replaceElementTexts

protected bool

Flag to indicate whether elements added to this save will replace existing element texts, not add them.

Mixin_ElementText::afterSave($args)

Omeka_Record_AbstractRecord callback for afterSave. Saves the ElementText records once the associated record is saved. Adds the record’s element texts to the search text.

Parameters:
  • $args
Mixin_ElementText::_getDb()

Get the database object from the associated record.

Returns:Omeka_Db
Mixin_ElementText::_getRecordType()

Get the class name of the associated record (Item, File, etc.).

Returns:string Type of record
Mixin_ElementText::loadElementsAndTexts($reload = false)

Load all the ElementText records for the given record (Item, File, etc.). These will be indexed by [element_id].

Also load all the Element records and index those by their name and set name.

Parameters:
  • $reload (bool) – Whether or not reload all the data that was previously loaded.
Mixin_ElementText::_loadElements($reload = false)
Parameters:
  • $reload
Mixin_ElementText::_getElementTextRecords()

Retrieve all of the ElementText records for the given record.

Returns:array Set of ElementText records for the record.
Mixin_ElementText::_getElementRecords()

Retrieve all of the Element records for the given record.

Returns:array All Elements that apply to the record’s type.
Mixin_ElementText::getElementTextsByRecord($element)

Retrieve all of the record’s ElementTexts for the given Element.

Parameters:
Returns:

array Set of ElementText records.

Mixin_ElementText::getElementTexts($elementSetName, $elementName)

Retrieve all of the record’s ElementTexts for the given element name and element set name.

Parameters:
  • $elementSetName (string) – Element set name
  • $elementName (string) – Element name
Returns:

array Set of ElementText records.

Mixin_ElementText::getAllElementTexts()

Retrieve all of the record’s ElementTexts, in order.

Returns:array Set of ElementText records.
Mixin_ElementText::getAllElementTextsByElement()

Retrieve all of the record’s ElementTexts, indexed by element ID.

Returns:array Set of ElementText records, indexed by element_id.
Mixin_ElementText::getElementsBySetName($elementSetName)

Retrieve the Element records for the given ElementSet.

Parameters:
  • $elementSetName
Returns:

array Set of Element records

Mixin_ElementText::getAllElements()

Retrieve ALL the Element records for the object, organized by ElementSet. For example, $elements[‘Dublin Core’] = array(Element instance, Element instance, …)

Returns:array Set of Element records
Mixin_ElementText::getElement($elementSetName, $elementName)

Retrieve the Element record corresponding to the given element name and element set name.

Parameters:
  • $elementSetName (string) –
  • $elementName (string) –
Returns:

Element

Mixin_ElementText::getElementById($elementId)

Retrieve the Element with the given ID.

Parameters:
  • $elementId (int) –
Returns:

Element

Mixin_ElementText::_indexTextsByElementId($textRecords)

Index a set of ElementTexts based on element ID.

Parameters:
  • $textRecords (array) – Set of ElementText records
Returns:

array The provided ElementTexts, indexed by element ID.

Mixin_ElementText::_indexElementsBySet($elementRecords)

Index a set of Elements based on their name. The result is a doubly associative array, with the first key being element set name and the second being element name.

i.e., $indexed[‘Dublin Core’][‘Creator’] = Element instance

Parameters:
  • $elementRecords (array) – Set of Element records
Returns:

array The provided Elements, indexed as described

Mixin_ElementText::_indexElementsById($elementRecords)

Indexes the elements returned by element ID.

Parameters:
  • $elementRecords
Returns:

array

Mixin_ElementText::addTextForElement($element, $elementText, $isHtml = false)

Add a string of text for an element.

Creates a new ElementText record, populates it with the specified text value and assigns it to the element.

saveElementTexts() must be called after this in order to save the element texts to the database.

Parameters:
  • $element (Element) – Element which text should be created for
  • $elementText (string) – Text to be added
  • $isHtml (bool) – Whether the text to add is HTML
Mixin_ElementText::addElementTextsByArray($elementTexts)

Add element texts for a record based on a formatted array of values. The array must be formatted as follows:

<code> ‘Element Set Name’ => array(‘Element Name’ => array(array(‘text’ => ‘foo’, ‘html’ => false))) </code>

Since 1.4, the array can also be formatted thusly:

<code> array( array(‘element_id’ => 1, ‘text’ => ‘foo’, ‘html’ => false) ) </code>

Parameters:
  • $elementTexts (array) –
Mixin_ElementText::_addTextsByElementName($elementTexts)
Parameters:
  • $elementTexts
Mixin_ElementText::_addTextsByElementId($texts)
Parameters:
  • $texts
Mixin_ElementText::beforeSaveElements($post)

The application flow is thus:

  1. Build ElementText objects from the POST.

2) Validate the ElementText objects and assign error messages if necessary. 3) After the item saves correctly, delete all the ElementText records for the Item. 4) Save the new ElementText objects to the database.

Parameters:
  • $post
Mixin_ElementText::_getElementTextsToSaveFromPost($post)

The POST should have a key called “Elements” that contains an array that is keyed to an element’s ID. That array should contain all the text values for that element. For example:

<code>

array(‘Elements’ => array( ‘50’ => array(array(‘text’ => ‘Foobar’, //element id 50, e.g. DC:Title ‘html’ => 0 )), ‘41’ => array(array(‘text’ => ‘<p>Baz baz baz</p>’, //element id 41, e.g. DC:Description ‘html’ => 1 )) ) )

</code>

Parameters:
  • $post
Mixin_ElementText::getTextStringFromFormPost($postArray, $element)

Retrieve a text string for an element from POSTed form data.

Parameters:
  • $postArray
  • $element
Returns:

string

Mixin_ElementText::_validateElementTexts()

Validate all the elements one by one. This is potentially a lot slower than batch processing the form, but it gives the added bonus of being able to encapsulate the logic for validation of Elements.

Mixin_ElementText::_elementTextIsValid($elementTextRecord)

Return whether the given ElementText record is valid.

Parameters:
Returns:

bool

Mixin_ElementText::setReplaceElementTexts($replaceElementTexts = true)

Set the flag to indicate whether elements added to this save will replace existing element texts, not add them.

Parameters:
  • $replaceElementTexts
Mixin_ElementText::saveElementTexts()

Save all ElementText records that were associated with a record.

Typically called in the afterSave() hook for a record.

Mixin_ElementText::deleteElementTextsByElementId($elementIdArray = array())

Delete all the element texts for element_id’s that have been provided.

Parameters:
  • $elementIdArray
Returns:

bool

Mixin_ElementText::deleteElementTexts()

Delete all the element texts assigned to the current record ID.

Returns:bool
Mixin_ElementText::hasElementText($elementSetName, $elementName)

Returns whether or not the record has at least 1 element text

Parameters:
  • $elementSetName (string) – Element set name
  • $elementName (string) – Element name
Returns:

bool

Mixin_ElementText::getElementTextCount($elementSetName, $elementName)

Returns the number of element texts for the record

Parameters:
  • $elementSetName (string) – Element set name
  • $elementName (string) – Element name
Returns:

bool

Mixin_ElementText::getDisplayTitle($default = null)

Return the title of this record for display/interface purposes

If no title is present or the title contains no text, returns the passed $default value. If no $default is given, returns the translated string [Untitled].

Parameters:
  • $default
Returns:

string Raw (unescaped) title string for the record.