-
Notifications
You must be signed in to change notification settings - Fork 0
/
TransferFileTextPlugin.php
44 lines (35 loc) · 1.15 KB
/
TransferFileTextPlugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/**
* Transfer File Text plugin.
*/
class TransferFileTextPlugin extends Omeka_Plugin_AbstractPlugin
{
protected $_hooks = array('after_save_item','install');
protected $_filters = array();
public function hookInstall() {
$items = $this->_db->getTable('Item');
$item = $items->findFirst();
while($item != NULL){
$this->transferFileText($item);
$item = $items->findNext($item);
}
}
private function transferFileText($item){
$item_text_element = $item->getElement('Item Type Metadata', 'Text');
$item->deleteElementTextsByElementId(array($item_text_element->id));
$files = $item->getFiles();
foreach($files as $file){
$file_texts = $file->getElementTexts('PDF Text', 'Text');
foreach($file_texts as $text){
$item->addTextForElement($item_text_element, $text);
}
}
$item->saveElementTexts();
}
// Note the order of execution.
public function hookAfterSaveItem($args)
{
$item = $args['record'];
$this->transferFileText($item);
}
}