From 8ff146b21564114a19c02dbff497bf011c6b20bc Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Fri, 21 Sep 2012 15:01:03 +0200 Subject: [PATCH] Update caption --- lib/classes/caption/Field/Value.class.php | 38 ++++++++++++----------- lib/classes/caption/field.class.php | 12 ++++--- lib/classes/caption/interface.class.php | 4 ++- lib/classes/caption/record.class.php | 24 ++++++-------- 4 files changed, 41 insertions(+), 37 deletions(-) diff --git a/lib/classes/caption/Field/Value.class.php b/lib/classes/caption/Field/Value.class.php index 604bdb739b..03e4d71f5e 100644 --- a/lib/classes/caption/Field/Value.class.php +++ b/lib/classes/caption/Field/Value.class.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -use \Alchemy\Phrasea\Vocabulary; +use Alchemy\Phrasea\Application; +use Alchemy\Phrasea\Core\Configuration; +use Alchemy\Phrasea\Vocabulary; /** * @@ -53,6 +55,7 @@ class caption_Field_Value implements cache_cacheableInterface * @var record_adapter */ protected $record; + protected $app; protected static $localCache = array(); @@ -63,11 +66,12 @@ class caption_Field_Value implements cache_cacheableInterface * @param type $id * @return \caption_Field_Value */ - public function __construct(databox_field $databox_field, record_adapter $record, $id) + public function __construct(Application $app, databox_field $databox_field, record_adapter $record, $id) { $this->id = (int) $id; $this->databox_field = $databox_field; $this->record = $record; + $this->app = $app; $this->retrieveValues(); } @@ -78,7 +82,7 @@ class caption_Field_Value implements cache_cacheableInterface $datas = $this->get_data_from_cache(); $this->value = $datas['value']; - $this->VocabularyType = $datas['vocabularyType'] ? Vocabulary\Controller::get($datas['vocabularyType']) : null; + $this->VocabularyType = $datas['vocabularyType'] ? Vocabulary\Controller::get($this->app, $datas['vocabularyType']) : null; $this->VocabularyId = $datas['vocabularyId']; return $this; @@ -99,7 +103,7 @@ class caption_Field_Value implements cache_cacheableInterface $this->value = $row ? $row['value'] : null; try { - $this->VocabularyType = $row['VocabularyType'] ? Vocabulary\Controller::get($row['VocabularyType']) : null; + $this->VocabularyType = $row['VocabularyType'] ? Vocabulary\Controller::get($this->app, $row['VocabularyType']) : null; $this->VocabularyId = $row['VocabularyId']; } catch (\Exception $e) { @@ -191,10 +195,10 @@ class caption_Field_Value implements cache_cacheableInterface $this->record->get_caption()->delete_data_from_cache(); try { - $registry = registry::get_instance(); + $registry = $this->app['phraseanet.registry']; $sphinx_rt = sphinxrt::get_instance($registry); - $sbas_params = phrasea::sbas_params(); + $sbas_params = phrasea::sbas_params($this->app); if (isset($sbas_params[$sbas_id])) { $params = $sbas_params[$sbas_id]; @@ -275,10 +279,10 @@ class caption_Field_Value implements cache_cacheableInterface $this->delete_data_from_cache(); try { - $registry = registry::get_instance(); + $registry = $this->app['phraseanet.registry']; $sphinx_rt = sphinxrt::get_instance($registry); - $sbas_params = phrasea::sbas_params(); + $sbas_params = phrasea::sbas_params($this->app); if (isset($sbas_params[$sbas_id])) { $params = $sbas_params[$sbas_id]; @@ -305,9 +309,9 @@ class caption_Field_Value implements cache_cacheableInterface $this->record->get_caption()->delete_data_from_cache(); $sbas_id = $this->databox_field->get_databox()->get_sbas_id(); try { - $registry = registry::get_instance(); + $registry = $this->app['phraseanet.registry']; - $sbas_params = phrasea::sbas_params(); + $sbas_params = phrasea::sbas_params($this->app); if (isset($sbas_params[$sbas_id])) { $params = $sbas_params[$sbas_id]; @@ -326,7 +330,7 @@ class caption_Field_Value implements cache_cacheableInterface , $this->databox_field->get_id() , $this->record->get_record_id() , $sbas_id - , phrasea::collFromBas($this->record->get_base_id()) + , phrasea::collFromBas($this->app, $this->record->get_base_id()) , ($this->record->is_grouping() ? '1' : '0') , $this->record->get_type() , $value @@ -348,7 +352,7 @@ class caption_Field_Value implements cache_cacheableInterface $sphinx_rt->replace_in_documents( "docs_realtime" . $sbas_crc, //$this->id, - $this->record->get_record_id(), $all_datas, $sbas_id, phrasea::collFromBas($this->record->get_base_id()), ($this->record->is_grouping() ? '1' : '0'), $this->record->get_type(), $this->record->get_creation_date() + $this->record->get_record_id(), $all_datas, $sbas_id, phrasea::collFromBas($this->app, $this->record->get_base_id()), ($this->record->is_grouping() ? '1' : '0'), $this->record->get_type(), $this->record->get_creation_date() ); } } catch (Exception $e) { @@ -358,7 +362,7 @@ class caption_Field_Value implements cache_cacheableInterface return $this; } - public static function create(databox_field &$databox_field, record_Interface $record, $value, Vocabulary\ControlProvider\ControlProviderInterface $vocabulary = null, $vocabularyId = null) + public static function create(Application $app, databox_field &$databox_field, record_Interface $record, $value, Vocabulary\ControlProvider\ControlProviderInterface $vocabulary = null, $vocabularyId = null) { $connbas = $databox_field->get_connection(); @@ -403,7 +407,7 @@ class caption_Field_Value implements cache_cacheableInterface $stmt_ins->closeCursor(); $meta_id = $connbas->lastInsertId(); - $caption_field_value = new self($databox_field, $record, $meta_id); + $caption_field_value = new self($app, $databox_field, $record, $meta_id); $caption_field_value->update_cache_value($value); $record->get_caption()->delete_data_from_cache(); @@ -431,8 +435,6 @@ class caption_Field_Value implements cache_cacheableInterface return $value; } - $appbox = appbox::get_instance(\bootstrap::getCore()); - $session = $appbox->get_session(); $unicode = new unicode(); $DOM_branchs = $XPATH_thesaurus->query($tbranch); @@ -455,7 +457,7 @@ class caption_Field_Value implements cache_cacheableInterface if ($nodes->length > 0) { $lngfound = false; foreach ($nodes as $node) { - if ($node->getAttribute("lng") == $session->get_I18n()) { + if ($node->getAttribute("lng") == $this->app['locale.I18n']) { // le terme est dans la bonne langue, on le rend cliquable list($term, $context) = $this->splitTermAndContext($fvalue); $term = str_replace(array("", ""), array("", ""), $term); @@ -470,7 +472,7 @@ class caption_Field_Value implements cache_cacheableInterface break; } - $synonyms = $XPATH_thesaurus->query("sy[@lng='" . $session->usr_i18 . "']", $node->parentNode); + $synonyms = $XPATH_thesaurus->query("sy[@lng='" . $this->app['locale.I18n'] . "']", $node->parentNode); foreach ($synonyms as $synonym) { $k = $synonym->getAttribute("k"); if ($synonym->getAttribute("w") != $term_noacc || $k != $context_noacc) { diff --git a/lib/classes/caption/field.class.php b/lib/classes/caption/field.class.php index 21876ffa2d..5140a1d845 100644 --- a/lib/classes/caption/field.class.php +++ b/lib/classes/caption/field.class.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Alchemy\Phrasea\Application; + /** * * @package caption @@ -34,6 +36,7 @@ class caption_field implements cache_cacheableInterface * @var record */ protected $record; + protected $app; protected static $localCache = array(); @@ -44,8 +47,9 @@ class caption_field implements cache_cacheableInterface * @param int $id * @return caption_field */ - public function __construct(databox_field &$databox_field, record_Interface $record) + public function __construct(Application $app, databox_field &$databox_field, record_Interface $record) { + $this->app = $app; $this->record = $record; $this->databox_field = $databox_field; $this->values = array(); @@ -53,7 +57,7 @@ class caption_field implements cache_cacheableInterface $rs = $this->get_metadatas_ids(); foreach ($rs as $row) { - $this->values[$row['id']] = new caption_Field_Value($databox_field, $record, $row['id']); + $this->values[$row['id']] = new caption_Field_Value($this->app, $databox_field, $record, $row['id']); /** * Inconsistent, should not happen @@ -337,7 +341,7 @@ class caption_field implements cache_cacheableInterface return; } - public static function delete_all_metadatas(databox_field $databox_field) + public static function delete_all_metadatas(Application $app, databox_field $databox_field) { $sql = 'SELECT count(id) as count_id FROM metadatas WHERE meta_struct_id = :meta_struct_id'; @@ -373,7 +377,7 @@ class caption_field implements cache_cacheableInterface foreach ($rs as $row) { try { $record = $databox_field->get_databox()->get_record($row['record_id']); - $caption_field = new caption_field($databox_field, $record); + $caption_field = new caption_field($app, $databox_field, $record); $caption_field->delete(); $record->set_metadatas(array()); unset($caption_field); diff --git a/lib/classes/caption/interface.class.php b/lib/classes/caption/interface.class.php index 67dfac02df..361e1795a3 100644 --- a/lib/classes/caption/interface.class.php +++ b/lib/classes/caption/interface.class.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Alchemy\Phrasea\Application; + /** * * @package caption @@ -18,7 +20,7 @@ interface caption_interface { - public function __construct(record_Interface &$record, databox &$databox); + public function __construct(Application $app, record_Interface &$record, databox &$databox); public function get_highlight_fields($highlight = '', Array $grep_fields = null, searchEngine_adapter $searchEngine = null); } diff --git a/lib/classes/caption/record.class.php b/lib/classes/caption/record.class.php index 6aa7686f21..f43017632e 100644 --- a/lib/classes/caption/record.class.php +++ b/lib/classes/caption/record.class.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Alchemy\Phrasea\Application; + /** * * @package caption @@ -36,6 +38,7 @@ class caption_record implements caption_interface, cache_cacheableInterface protected $record; protected $dces_elements = array(); protected $databox; + protected $app; const SERIALIZE_XML = 'xml'; const SERIALIZE_YAML = 'yaml'; @@ -46,8 +49,9 @@ class caption_record implements caption_interface, cache_cacheableInterface * @param databox $databox * @return caption_record */ - public function __construct(record_Interface &$record, databox &$databox) + public function __construct(Application $app, record_Interface &$record, databox &$databox) { + $this->app = $app; $this->sbas_id = $record->get_sbas_id(); $this->record = $record; $this->databox = $databox; @@ -156,8 +160,8 @@ class caption_record implements caption_interface, cache_cacheableInterface $rec_fields = array(); foreach ($fields as $row) { - $databox_meta_struct = databox_field::get_instance($this->databox, $row['structure_id']); - $metadata = new caption_field($databox_meta_struct, $this->record); + $databox_meta_struct = databox_field::get_instance($this->app, $this->databox, $row['structure_id']); + $metadata = new caption_field($this->app, $databox_meta_struct, $this->record); $rec_fields[$databox_meta_struct->get_id()] = $metadata; $dces_element = $metadata->get_databox_field()->get_dces_element(); @@ -303,10 +307,7 @@ class caption_record implements caption_interface, cache_cacheableInterface */ public function get_data_from_cache($option = null) { - $appbox = \appbox::get_instance(\bootstrap::getCore()); - $databox = $appbox->get_databox($this->record->get_sbas_id()); - - return $databox->get_data_from_cache($this->get_cache_key($option)); + return $this->record->get_databox()->get_data_from_cache($this->get_cache_key($option)); } /** @@ -319,10 +320,7 @@ class caption_record implements caption_interface, cache_cacheableInterface */ public function set_data_to_cache($value, $option = null, $duration = 0) { - $appbox = \appbox::get_instance(\bootstrap::getCore()); - $databox = $appbox->get_databox($this->record->get_sbas_id()); - - return $databox->set_data_to_cache($value, $this->get_cache_key($option), $duration); + return $this->record->get_databox()->set_data_to_cache($value, $this->get_cache_key($option), $duration); } /** @@ -333,10 +331,8 @@ class caption_record implements caption_interface, cache_cacheableInterface */ public function delete_data_from_cache($option = null) { - $appbox = \appbox::get_instance(\bootstrap::getCore()); - $databox = $appbox->get_databox($this->record->get_sbas_id()); $this->fields = null; - return $databox->delete_data_from_cache($this->get_cache_key($option)); + return $this->record->get_databox()->delete_data_from_cache($this->get_cache_key($option)); } }