Mixin_ElementText

class Mixin_ElementText

Package: Record\Mixin

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

property _textsByNaturalOrder

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

property _textsByElementId

ElementText records indexed by the element_id.

property _elementsBySet

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

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

property _elementsById

Element records indexed by ID.

property _elementsOnForm

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 _textsToSave

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

property _recordsAreLoaded

Whether the elements and texts have been loaded yet.

property _elementsByRecordType

Sets of Element records indexed by record type.

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 (unknown) –
_getDb()

Get the database object from the associated record.

Returns:Omeka_Db
_getRecordType()

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

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

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 setname.

Parameters:
  • $reload (boolean) – Whether or not reload all the data that was previously loaded.
Returns:

void

_loadElements($reload =)
Parameters:
  • $reload (unknown) –
_getElementTextRecords()

Retrieve all of the ElementText records for the given record.

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

Retrieve all of the Element records for the given record.

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

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

Parameters:
Returns:

array Set of ElementText records.

getElementTexts(string $elementSetName, string $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.

getAllElementTexts()

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

Returns:array Set of ElementText records.
getElementsBySetName($elementSetName)

Retrieve the Element records for the given ElementSet.

Parameters:
  • $elementSetName (unknown) –
Returns:

array Set of Element records

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
getElement(string $elementSetName, string $elementName)

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

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

Element

getElementById(int $elementId)

Retrieve the Element with the given ID.

Parameters:
  • $elementId (int) –
Returns:

Element

_indexTextsByElementId(array $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.

_indexElementsBySet(array $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

_indexElementsById($elementRecords)

Indexes the elements returned by element ID.

Parameters:
  • $elementRecords (unknown) –
Returns:

array

addTextForElement(Element $element, string $elementText, bool $isHtml =)

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 elementtexts 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
addElementTextsByArray($elementTexts)

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

'Element Set Name' =>
    array('Element Name' =>
        array(array('text' => 'foo', 'html' => false)))

Since 1.4, the array can also be formatted thusly:

array(
    array('element_id' => 1,
          'text' => 'foo',
          'html' => false)
)
Parameters:
  • $elementTexts (unknown) –
_addTextsByElementName($elementTexts)
Parameters:
  • $elementTexts (unknown) –
_addTextsByElementId($texts)
Parameters:
  • $texts (unknown) –
beforeSaveElements($post)

The application flow is thus:

  1. Build ElementText objects from the POST.2) Validate the ElementText objects and assign error messages ifnecessary.3) After the item saves correctly, delete all the ElementText recordsfor the Item.4) Save the new ElementText objects to the database.
Parameters:
  • $post (unknown) –
_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 (unknown) –
getTextStringFromFormPost($postArray, $element)

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

Parameters:
  • $postArray (unknown) –
  • $element (unknown) –
Returns:

string

_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.

_elementTextIsValid(ElementText $elementTextRecord)

Return whether the given ElementText record is valid.

Parameters:
Returns:

boolean

saveElementTexts()

Save all ElementText records that were associated with a record.

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

deleteElementTextsByElementId($elementIdArray = Array)

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

Parameters:
  • $elementIdArray (unknown) –
Returns:

boolean

deleteElementTexts()

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

Returns:boolean
hasElementText(string $elementSetName, string $elementName)

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

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

boolean

getElementTextCount(string $elementSetName, string $elementName)

Returns the number of element texts for the record

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

boolean