diff --git a/lib/classes/Feed/XML/Abstract.class.php b/lib/classes/Feed/XML/Abstract.class.php index 1010c81520..29e431f18f 100644 --- a/lib/classes/Feed/XML/Abstract.class.php +++ b/lib/classes/Feed/XML/Abstract.class.php @@ -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); diff --git a/lib/classes/Feed/XML/Cooliris.class.php b/lib/classes/Feed/XML/Cooliris.class.php index 1e8c106b89..178b1410cc 100644 --- a/lib/classes/Feed/XML/Cooliris.class.php +++ b/lib/classes/Feed/XML/Cooliris.class.php @@ -367,8 +367,10 @@ class Feed_XML_Cooliris extends Feed_XML_Abstract implements Feed_XML_Interface //add item node to channel node $item = $this->addTag($document, $node, 'item'); + + $caption = $content->get_record()->get_caption(); - $title_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Title); + $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 { diff --git a/lib/classes/caption/Field/Value.class.php b/lib/classes/caption/Field/Value.class.php index 27e53dde7e..73f14dd430 100644 --- a/lib/classes/caption/Field/Value.class.php +++ b/lib/classes/caption/Field/Value.class.php @@ -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(); @@ -83,7 +100,7 @@ class caption_Field_Value $this->VocabularyType = $row['VocabularyType'] ? Vocabulary\Controller::get($row['VocabularyType']) : null; $this->VocabularyId = $row['VocabularyId']; } catch (\Exception $e) { - + } @@ -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; } @@ -254,7 +279,7 @@ class caption_Field_Value $sphinx_rt->delete(array("documents" . $sbas_crc, "documents" . $sbas_crc . "_stemmed_fr", "documents" . $sbas_crc . "_stemmed_en"), "", $this->record->get_record_id()); } } catch (Exception $e) { - + } $this->update_cache_value($value); @@ -347,7 +372,7 @@ class caption_Field_Value return $caption_field_value; } catch (\Exception $e) { - + } } @@ -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)); + } }