mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-12 04:23:19 +00:00
Caption field values are now cacheable, optimize code for Rss / atom Feeds
This commit is contained in:
@@ -237,21 +237,23 @@ abstract class Feed_XML_Abstract
|
||||
|
||||
$group = $this->addTag($document, $item, 'media:group');
|
||||
|
||||
$title_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Title);
|
||||
$caption = $content->get_record()->get_caption();
|
||||
|
||||
$title_field = $caption->get_dc_field(databox_Field_DCESAbstract::Title);
|
||||
if ($title_field) {
|
||||
$str_title = $title_field->get_serialized_values(' ');
|
||||
$title = $this->addTag($document, $group, 'media:title', $str_title);
|
||||
$title->setAttribute('type', 'plain');
|
||||
}
|
||||
|
||||
$desc_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Description);
|
||||
$desc_field = $caption->get_dc_field(databox_Field_DCESAbstract::Description);
|
||||
if ($desc_field) {
|
||||
$str_desc = $desc_field->get_serialized_values(' ');
|
||||
$desc = $this->addTag($document, $group, 'media:description', $str_desc);
|
||||
$desc->setAttribute('type', 'plain');
|
||||
}
|
||||
|
||||
$contrib_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Contributor);
|
||||
$contrib_field = $caption->get_dc_field(databox_Field_DCESAbstract::Contributor);
|
||||
if ($contrib_field) {
|
||||
$str_contrib = $contrib_field->get_serialized_values(' ');
|
||||
$contrib = $this->addTag($document, $group, 'media:credit', $str_contrib);
|
||||
@@ -259,7 +261,7 @@ abstract class Feed_XML_Abstract
|
||||
$contrib->setAttribute('scheme', 'urn:ebu');
|
||||
}
|
||||
|
||||
$director_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Creator);
|
||||
$director_field = $caption->get_dc_field(databox_Field_DCESAbstract::Creator);
|
||||
if ($director_field) {
|
||||
$str_director = $director_field->get_serialized_values(' ');
|
||||
$director = $this->addTag($document, $group, 'media:credit', $str_director);
|
||||
@@ -267,7 +269,7 @@ abstract class Feed_XML_Abstract
|
||||
$director->setAttribute('scheme', 'urn:ebu');
|
||||
}
|
||||
|
||||
$publisher_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Publisher);
|
||||
$publisher_field = $caption->get_dc_field(databox_Field_DCESAbstract::Publisher);
|
||||
if ($publisher_field) {
|
||||
$str_publisher = $publisher_field->get_serialized_values(' ');
|
||||
$publisher = $this->addTag($document, $group, 'media:credit', $str_publisher);
|
||||
@@ -275,13 +277,13 @@ abstract class Feed_XML_Abstract
|
||||
$publisher->setAttribute('scheme', 'urn:ebu');
|
||||
}
|
||||
|
||||
$rights_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Rights);
|
||||
$rights_field = $caption->get_dc_field(databox_Field_DCESAbstract::Rights);
|
||||
if ($rights_field) {
|
||||
$str_rights = $rights_field->get_serialized_values(' ');
|
||||
$rights = $this->addTag($document, $group, 'media:copyright', $str_rights);
|
||||
}
|
||||
|
||||
$keyword_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Subject);
|
||||
$keyword_field = $caption->get_dc_field(databox_Field_DCESAbstract::Subject);
|
||||
if ($keyword_field) {
|
||||
$str_keywords = $keyword_field->get_serialized_values(', ');
|
||||
$keywords = $this->addTag($document, $group, 'media:keywords', $str_keywords);
|
||||
|
@@ -368,7 +368,9 @@ class Feed_XML_Cooliris extends Feed_XML_Abstract implements Feed_XML_Interface
|
||||
//add item node to channel node
|
||||
$item = $this->addTag($document, $node, 'item');
|
||||
|
||||
$title_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Title);
|
||||
$caption = $content->get_record()->get_caption();
|
||||
|
||||
$title_field = $caption->get_dc_field(databox_Field_DCESAbstract::Title);
|
||||
if ($title_field) {
|
||||
$str_title = $title_field->get_serialized_values(' ');
|
||||
} else {
|
||||
@@ -378,7 +380,7 @@ class Feed_XML_Cooliris extends Feed_XML_Abstract implements Feed_XML_Interface
|
||||
//attach tile node to item node
|
||||
$title = $this->addTag($document, $item, 'title', $str_title);
|
||||
|
||||
$desc_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Description);
|
||||
$desc_field = $caption->get_dc_field(databox_Field_DCESAbstract::Description);
|
||||
if ($desc_field) {
|
||||
$str_desc = $desc_field->get_serialized_values(' ');
|
||||
} else {
|
||||
|
@@ -16,7 +16,7 @@ use \Alchemy\Phrasea\Vocabulary;
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class caption_Field_Value
|
||||
class caption_Field_Value implements cache_cacheableInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
@@ -67,13 +67,30 @@ class caption_Field_Value
|
||||
$this->databox_field = $databox_field;
|
||||
$this->record = $record;
|
||||
|
||||
$connbas = $databox_field->get_databox()->get_connection();
|
||||
$this->retrieveValues();
|
||||
}
|
||||
|
||||
protected function retrieveValues()
|
||||
{
|
||||
try {
|
||||
$datas = $this->get_data_from_cache();
|
||||
|
||||
$this->value = $datas['value'];
|
||||
$this->VocabularyType = $datas['vocabularyType'] ? Vocabulary\Controller::get($datas['vocabularyType']) : null;
|
||||
$this->VocabularyId = $datas['vocabularyId'];
|
||||
|
||||
return $this;
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
|
||||
$connbas = $this->databox_field->get_databox()->get_connection();
|
||||
|
||||
$sql = 'SELECT record_id, value, VocabularyType, VocabularyId
|
||||
FROM metadatas WHERE id = :id';
|
||||
|
||||
$stmt = $connbas->prepare($sql);
|
||||
$stmt->execute(array(':id' => $id));
|
||||
$stmt->execute(array(':id' => $this->id));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
@@ -111,6 +128,14 @@ class caption_Field_Value
|
||||
}
|
||||
}
|
||||
|
||||
$datas = array(
|
||||
'value' => $this->value,
|
||||
'vocabularyId' => $this->VocabularyId,
|
||||
'vocabularyType' => $this->VocabularyType ? $this->VocabularyType->getType() : null,
|
||||
);
|
||||
|
||||
$this->set_data_to_cache($datas);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -492,4 +517,57 @@ class caption_Field_Value
|
||||
|
||||
return array($term, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Part of the cache_cacheableInterface
|
||||
*
|
||||
* @param string $option
|
||||
* @return string
|
||||
*/
|
||||
public function get_cache_key($option = null)
|
||||
{
|
||||
return 'caption_fieldvalue_' . $this->record->get_serialize_key() . ($option ? '_' . $option : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Part of the cache_cacheableInterface
|
||||
*
|
||||
* @param string $option
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_data_from_cache($option = null)
|
||||
{
|
||||
$databox = $this->record->get_databox();
|
||||
|
||||
return $databox->get_data_from_cache($this->get_cache_key($option));
|
||||
}
|
||||
|
||||
/**
|
||||
* Part of the cache_cacheableInterface
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param string $option
|
||||
* @param int $duration
|
||||
* @return caption_field
|
||||
*/
|
||||
public function set_data_to_cache($value, $option = null, $duration = 360000)
|
||||
{
|
||||
$databox = $this->record->get_databox();
|
||||
|
||||
return $databox->set_data_to_cache($value, $this->get_cache_key($option), $duration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Part of the cache_cacheableInterface
|
||||
*
|
||||
* @param string $option
|
||||
* @return caption_field
|
||||
*/
|
||||
public function delete_data_from_cache($option = null)
|
||||
{
|
||||
$databox = $this->record->get_databox();
|
||||
$this->value = $this->VocabularyId = $this->VocabularyType = null;
|
||||
|
||||
return $databox->delete_data_from_cache($this->get_cache_key($option));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user