Update caption

This commit is contained in:
Romain Neutron
2012-09-21 15:01:03 +02:00
parent 2805dc21a1
commit 8ff146b215
4 changed files with 41 additions and 37 deletions

View File

@@ -9,7 +9,9 @@
* file that was distributed with this source code. * 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 * @var record_adapter
*/ */
protected $record; protected $record;
protected $app;
protected static $localCache = array(); protected static $localCache = array();
@@ -63,11 +66,12 @@ class caption_Field_Value implements cache_cacheableInterface
* @param type $id * @param type $id
* @return \caption_Field_Value * @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->id = (int) $id;
$this->databox_field = $databox_field; $this->databox_field = $databox_field;
$this->record = $record; $this->record = $record;
$this->app = $app;
$this->retrieveValues(); $this->retrieveValues();
} }
@@ -78,7 +82,7 @@ class caption_Field_Value implements cache_cacheableInterface
$datas = $this->get_data_from_cache(); $datas = $this->get_data_from_cache();
$this->value = $datas['value']; $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']; $this->VocabularyId = $datas['vocabularyId'];
return $this; return $this;
@@ -99,7 +103,7 @@ class caption_Field_Value implements cache_cacheableInterface
$this->value = $row ? $row['value'] : null; $this->value = $row ? $row['value'] : null;
try { 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']; $this->VocabularyId = $row['VocabularyId'];
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -191,10 +195,10 @@ class caption_Field_Value implements cache_cacheableInterface
$this->record->get_caption()->delete_data_from_cache(); $this->record->get_caption()->delete_data_from_cache();
try { try {
$registry = registry::get_instance(); $registry = $this->app['phraseanet.registry'];
$sphinx_rt = sphinxrt::get_instance($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])) { if (isset($sbas_params[$sbas_id])) {
$params = $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(); $this->delete_data_from_cache();
try { try {
$registry = registry::get_instance(); $registry = $this->app['phraseanet.registry'];
$sphinx_rt = sphinxrt::get_instance($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])) { if (isset($sbas_params[$sbas_id])) {
$params = $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(); $this->record->get_caption()->delete_data_from_cache();
$sbas_id = $this->databox_field->get_databox()->get_sbas_id(); $sbas_id = $this->databox_field->get_databox()->get_sbas_id();
try { 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])) { if (isset($sbas_params[$sbas_id])) {
$params = $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->databox_field->get_id()
, $this->record->get_record_id() , $this->record->get_record_id()
, $sbas_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->is_grouping() ? '1' : '0')
, $this->record->get_type() , $this->record->get_type()
, $value , $value
@@ -348,7 +352,7 @@ class caption_Field_Value implements cache_cacheableInterface
$sphinx_rt->replace_in_documents( $sphinx_rt->replace_in_documents(
"docs_realtime" . $sbas_crc, //$this->id, "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) { } catch (Exception $e) {
@@ -358,7 +362,7 @@ class caption_Field_Value implements cache_cacheableInterface
return $this; 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(); $connbas = $databox_field->get_connection();
@@ -403,7 +407,7 @@ class caption_Field_Value implements cache_cacheableInterface
$stmt_ins->closeCursor(); $stmt_ins->closeCursor();
$meta_id = $connbas->lastInsertId(); $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); $caption_field_value->update_cache_value($value);
$record->get_caption()->delete_data_from_cache(); $record->get_caption()->delete_data_from_cache();
@@ -431,8 +435,6 @@ class caption_Field_Value implements cache_cacheableInterface
return $value; return $value;
} }
$appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session();
$unicode = new unicode(); $unicode = new unicode();
$DOM_branchs = $XPATH_thesaurus->query($tbranch); $DOM_branchs = $XPATH_thesaurus->query($tbranch);
@@ -455,7 +457,7 @@ class caption_Field_Value implements cache_cacheableInterface
if ($nodes->length > 0) { if ($nodes->length > 0) {
$lngfound = false; $lngfound = false;
foreach ($nodes as $node) { 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 // le terme est dans la bonne langue, on le rend cliquable
list($term, $context) = $this->splitTermAndContext($fvalue); list($term, $context) = $this->splitTermAndContext($fvalue);
$term = str_replace(array("<em>", "</em>"), array("", ""), $term); $term = str_replace(array("<em>", "</em>"), array("", ""), $term);
@@ -470,7 +472,7 @@ class caption_Field_Value implements cache_cacheableInterface
break; 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) { foreach ($synonyms as $synonym) {
$k = $synonym->getAttribute("k"); $k = $synonym->getAttribute("k");
if ($synonym->getAttribute("w") != $term_noacc || $k != $context_noacc) { if ($synonym->getAttribute("w") != $term_noacc || $k != $context_noacc) {

View File

@@ -9,6 +9,8 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Alchemy\Phrasea\Application;
/** /**
* *
* @package caption * @package caption
@@ -34,6 +36,7 @@ class caption_field implements cache_cacheableInterface
* @var record * @var record
*/ */
protected $record; protected $record;
protected $app;
protected static $localCache = array(); protected static $localCache = array();
@@ -44,8 +47,9 @@ class caption_field implements cache_cacheableInterface
* @param int $id * @param int $id
* @return caption_field * @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->record = $record;
$this->databox_field = $databox_field; $this->databox_field = $databox_field;
$this->values = array(); $this->values = array();
@@ -53,7 +57,7 @@ class caption_field implements cache_cacheableInterface
$rs = $this->get_metadatas_ids(); $rs = $this->get_metadatas_ids();
foreach ($rs as $row) { 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 * Inconsistent, should not happen
@@ -337,7 +341,7 @@ class caption_field implements cache_cacheableInterface
return; 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 $sql = 'SELECT count(id) as count_id FROM metadatas
WHERE meta_struct_id = :meta_struct_id'; WHERE meta_struct_id = :meta_struct_id';
@@ -373,7 +377,7 @@ class caption_field implements cache_cacheableInterface
foreach ($rs as $row) { foreach ($rs as $row) {
try { try {
$record = $databox_field->get_databox()->get_record($row['record_id']); $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(); $caption_field->delete();
$record->set_metadatas(array()); $record->set_metadatas(array());
unset($caption_field); unset($caption_field);

View File

@@ -9,6 +9,8 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Alchemy\Phrasea\Application;
/** /**
* *
* @package caption * @package caption
@@ -18,7 +20,7 @@
interface caption_interface 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); public function get_highlight_fields($highlight = '', Array $grep_fields = null, searchEngine_adapter $searchEngine = null);
} }

View File

@@ -9,6 +9,8 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Alchemy\Phrasea\Application;
/** /**
* *
* @package caption * @package caption
@@ -36,6 +38,7 @@ class caption_record implements caption_interface, cache_cacheableInterface
protected $record; protected $record;
protected $dces_elements = array(); protected $dces_elements = array();
protected $databox; protected $databox;
protected $app;
const SERIALIZE_XML = 'xml'; const SERIALIZE_XML = 'xml';
const SERIALIZE_YAML = 'yaml'; const SERIALIZE_YAML = 'yaml';
@@ -46,8 +49,9 @@ class caption_record implements caption_interface, cache_cacheableInterface
* @param databox $databox * @param databox $databox
* @return caption_record * @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->sbas_id = $record->get_sbas_id();
$this->record = $record; $this->record = $record;
$this->databox = $databox; $this->databox = $databox;
@@ -156,8 +160,8 @@ class caption_record implements caption_interface, cache_cacheableInterface
$rec_fields = array(); $rec_fields = array();
foreach ($fields as $row) { foreach ($fields as $row) {
$databox_meta_struct = databox_field::get_instance($this->databox, $row['structure_id']); $databox_meta_struct = databox_field::get_instance($this->app, $this->databox, $row['structure_id']);
$metadata = new caption_field($databox_meta_struct, $this->record); $metadata = new caption_field($this->app, $databox_meta_struct, $this->record);
$rec_fields[$databox_meta_struct->get_id()] = $metadata; $rec_fields[$databox_meta_struct->get_id()] = $metadata;
$dces_element = $metadata->get_databox_field()->get_dces_element(); $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) public function get_data_from_cache($option = null)
{ {
$appbox = \appbox::get_instance(\bootstrap::getCore()); return $this->record->get_databox()->get_data_from_cache($this->get_cache_key($option));
$databox = $appbox->get_databox($this->record->get_sbas_id());
return $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) public function set_data_to_cache($value, $option = null, $duration = 0)
{ {
$appbox = \appbox::get_instance(\bootstrap::getCore()); return $this->record->get_databox()->set_data_to_cache($value, $this->get_cache_key($option), $duration);
$databox = $appbox->get_databox($this->record->get_sbas_id());
return $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) 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; $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));
} }
} }