mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-10 11:33:17 +00:00
Refactor caption_field
This commit is contained in:
@@ -1080,7 +1080,10 @@ class API_V1_adapter extends API_V1_Abstract
|
||||
$ret = array();
|
||||
foreach ($caption->get_fields() as $field)
|
||||
{
|
||||
$ret[$field->get_meta_id()] = $this->list_record_caption_field($field);
|
||||
foreach($field->get_values as $value)
|
||||
{
|
||||
$ret[$value->getId()] = $this->list_record_caption_field($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
@@ -1092,17 +1095,17 @@ class API_V1_adapter extends API_V1_Abstract
|
||||
* @param caption_field $field
|
||||
* @return array
|
||||
*/
|
||||
protected function list_record_caption_field(caption_field $field)
|
||||
protected function list_record_caption_field(caption_Field_Value $value, caption_field $field)
|
||||
{
|
||||
/**
|
||||
* @todo ajouter une option pour avoir les values serialisées
|
||||
* dans un cas multi
|
||||
*/
|
||||
return array(
|
||||
'meta_id' => $field->get_meta_id()
|
||||
'meta_id' => $value->getId()
|
||||
, 'meta_structure_id' => $field->get_meta_struct_id()
|
||||
, 'name' => $field->get_name()
|
||||
, 'value' => $field->get_value()
|
||||
, 'value' => $value->getValue()
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -235,7 +235,7 @@ abstract class Feed_XML_Abstract
|
||||
$title_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Title);
|
||||
if ($title_field)
|
||||
{
|
||||
$str_title = $title_field->get_value(true, ' ');
|
||||
$str_title = $title_field->get_serialized_values(' ');
|
||||
$title = $this->addTag($document, $group, 'media:title', $str_title);
|
||||
$title->setAttribute('type', 'plain');
|
||||
}
|
||||
@@ -243,7 +243,7 @@ abstract class Feed_XML_Abstract
|
||||
$desc_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Description);
|
||||
if ($desc_field)
|
||||
{
|
||||
$str_desc = $desc_field->get_value(true, ' ');
|
||||
$str_desc = $desc_field->get_serialized_values(' ');
|
||||
$desc = $this->addTag($document, $group, 'media:description', $str_desc);
|
||||
$desc->setAttribute('type', 'plain');
|
||||
}
|
||||
@@ -251,7 +251,7 @@ abstract class Feed_XML_Abstract
|
||||
$contrib_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Contributor);
|
||||
if ($contrib_field)
|
||||
{
|
||||
$str_contrib = $contrib_field->get_value(true, ' ');
|
||||
$str_contrib = $contrib_field->get_serialized_values(' ');
|
||||
$contrib = $this->addTag($document, $group, 'media:credit', $str_contrib);
|
||||
$contrib->setAttribute('role', 'contributor');
|
||||
$contrib->setAttribute('scheme', 'urn:ebu');
|
||||
@@ -260,7 +260,7 @@ abstract class Feed_XML_Abstract
|
||||
$director_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Creator);
|
||||
if ($director_field)
|
||||
{
|
||||
$str_director = $director_field->get_value(true, ' ');
|
||||
$str_director = $director_field->get_serialized_values(' ');
|
||||
$director = $this->addTag($document, $group, 'media:credit', $str_director);
|
||||
$director->setAttribute('role', 'director');
|
||||
$director->setAttribute('scheme', 'urn:ebu');
|
||||
@@ -269,7 +269,7 @@ abstract class Feed_XML_Abstract
|
||||
$publisher_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Publisher);
|
||||
if ($publisher_field)
|
||||
{
|
||||
$str_publisher = $publisher_field->get_value(true, ' ');
|
||||
$str_publisher = $publisher_field->get_serialized_values(' ');
|
||||
$publisher = $this->addTag($document, $group, 'media:credit', $str_publisher);
|
||||
$publisher->setAttribute('role', 'publisher');
|
||||
$publisher->setAttribute('scheme', 'urn:ebu');
|
||||
@@ -278,14 +278,14 @@ abstract class Feed_XML_Abstract
|
||||
$rights_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Rights);
|
||||
if ($rights_field)
|
||||
{
|
||||
$str_rights = $rights_field->get_value(true, ' ');
|
||||
$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);
|
||||
if ($keyword_field)
|
||||
{
|
||||
$str_keywords = $keyword_field->get_value(true, ', ');
|
||||
$str_keywords = $keyword_field->get_serialized_values(', ');
|
||||
$keywords = $this->addTag($document, $group, 'media:keywords', $str_keywords);
|
||||
}
|
||||
|
||||
|
@@ -381,7 +381,7 @@ class Feed_XML_Cooliris extends Feed_XML_Abstract implements Feed_XML_Interface
|
||||
$title_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Title);
|
||||
if ($title_field)
|
||||
{
|
||||
$str_title = $title_field->get_value(true, ' ');
|
||||
$str_title = $title_field->get_serialized_values(' ');
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -394,7 +394,7 @@ class Feed_XML_Cooliris extends Feed_XML_Abstract implements Feed_XML_Interface
|
||||
$desc_field = $content->get_record()->get_caption()->get_dc_field(databox_Field_DCESAbstract::Description);
|
||||
if ($desc_field)
|
||||
{
|
||||
$str_desc = $desc_field->get_value(true, ' ');
|
||||
$str_desc = $desc_field->get_serialized_values(' ');
|
||||
}
|
||||
else
|
||||
{
|
||||
|
236
lib/classes/caption/Field/Value.class.php
Normal file
236
lib/classes/caption/Field/Value.class.php
Normal file
@@ -0,0 +1,236 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class caption_Field_Value
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $value;
|
||||
/**
|
||||
*
|
||||
* @var databox_field
|
||||
*/
|
||||
protected $databox_field;
|
||||
/**
|
||||
*
|
||||
* @var record_adapter
|
||||
*/
|
||||
protected $record;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param databox_field $databox_field
|
||||
* @param record_adapter $record
|
||||
* @param type $id
|
||||
* @return \caption_Field_Value
|
||||
*/
|
||||
public function __construct(databox_field $databox_field, record_adapter $record, $id)
|
||||
{
|
||||
$this->id = (int) $id;
|
||||
$this->databox_field = $databox_field;
|
||||
$this->record = $record;
|
||||
|
||||
$connbas = $databox_field->get_databox()->get_connection();
|
||||
|
||||
$sql = 'SELECT record_id, value FROM metadatas WHERE id = :id';
|
||||
|
||||
$stmt = $connbas->prepare($sql);
|
||||
$stmt->execute(array(':id' => $id));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->value = $row ? $row['value'] : null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getValue() {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function getDatabox_field() {
|
||||
return $this->databox_field;
|
||||
}
|
||||
|
||||
public function getRecord() {
|
||||
return $this->record;
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$connbas = $this->databox_field->get_connection();
|
||||
|
||||
$sql = 'DELETE FROM metadatas WHERE id = :id';
|
||||
$stmt = $connbas->prepare($sql);
|
||||
$stmt->execute(array(':id' => $this->id));
|
||||
$stmt->closeCursor();
|
||||
$this->delete_data_from_cache();
|
||||
|
||||
$sbas_id = $this->record->get_sbas_id();
|
||||
$this->record->get_caption()->delete_data_from_cache();
|
||||
|
||||
try
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
$sphinx_rt = sphinxrt::get_instance($registry);
|
||||
|
||||
$sbas_params = phrasea::sbas_params();
|
||||
|
||||
if (isset($sbas_params[$sbas_id]))
|
||||
{
|
||||
$params = $sbas_params[$sbas_id];
|
||||
$sbas_crc = crc32(str_replace(array('.', '%'), '_', sprintf('%s_%s_%s_%s', $params['host'], $params['port'], $params['user'], $params['dbname'])));
|
||||
$sphinx_rt->delete(array("metadatas" . $sbas_crc, "metadatas" . $sbas_crc . "_stemmed_fr", "metadatas" . $sbas_crc . "_stemmed_en"), "metas_realtime" . $sbas_crc, $this->id);
|
||||
$sphinx_rt->delete(array("documents" . $sbas_crc, "documents" . $sbas_crc . "_stemmed_fr", "documents" . $sbas_crc . "_stemmed_en"), "docs_realtime" . $sbas_crc, $this->record->get_record_id());
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
unset($e);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function set_value($value)
|
||||
{
|
||||
$sbas_id = $this->databox_field->get_databox()->get_sbas_id();
|
||||
$connbas = $this->databox_field->get_connection();
|
||||
|
||||
$params = array(
|
||||
':meta_id' => $this->id
|
||||
, ':value' => $value
|
||||
);
|
||||
|
||||
$sql_up = 'UPDATE metadatas SET value = :value WHERE id = :meta_id';
|
||||
$stmt_up = $connbas->prepare($sql_up);
|
||||
$stmt_up->execute($params);
|
||||
$stmt_up->closeCursor();
|
||||
|
||||
try
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
$sphinx_rt = sphinxrt::get_instance($registry);
|
||||
|
||||
$sbas_params = phrasea::sbas_params();
|
||||
|
||||
if (isset($sbas_params[$sbas_id]))
|
||||
{
|
||||
$params = $sbas_params[$sbas_id];
|
||||
$sbas_crc = crc32(str_replace(array('.', '%'), '_', sprintf('%s_%s_%s_%s', $params['host'], $params['port'], $params['user'], $params['dbname'])));
|
||||
$sphinx_rt->delete(array("metadatas" . $sbas_crc, "metadatas" . $sbas_crc . "_stemmed_fr", "metadatas" . $sbas_crc . "_stemmed_en"), "", $this->id);
|
||||
$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);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $value
|
||||
* @return caption_field
|
||||
*/
|
||||
public function update_cache_value($value)
|
||||
{
|
||||
// $this->delete_data_from_cache();
|
||||
$this->record->get_caption()->delete_data_from_cache();
|
||||
$sbas_id = $this->databox_field->get_databox()->get_sbas_id();
|
||||
try
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
|
||||
$sbas_params = phrasea::sbas_params();
|
||||
|
||||
if (isset($sbas_params[$sbas_id]))
|
||||
{
|
||||
$params = $sbas_params[$sbas_id];
|
||||
$sbas_crc = crc32(str_replace(array('.', '%'), '_', sprintf('%s_%s_%s_%s', $params['host'], $params['port'], $params['user'], $params['dbname'])));
|
||||
|
||||
$sphinx_rt = sphinxrt::get_instance($registry);
|
||||
$sphinx_rt->replace_in_metas(
|
||||
"metas_realtime" . $sbas_crc, $this->id, $this->databox_field->get_id(), $this->record->get_record_id(), $sbas_id, phrasea::collFromBas($this->record->get_base_id()), ($this->record->is_grouping() ? '1' : '0'), $this->record->get_type(), $value, $this->record->get_creation_date()
|
||||
);
|
||||
|
||||
$all_datas = array();
|
||||
foreach ($this->record->get_caption()->get_fields() as $field)
|
||||
{
|
||||
if (!$field->is_indexable())
|
||||
continue;
|
||||
$all_datas[] = $field->get_value(true);
|
||||
}
|
||||
$all_datas = implode(' ', $all_datas);
|
||||
|
||||
$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()
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
unset($e);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function create(databox_field &$databox_field, record_Interface $record, $value)
|
||||
{
|
||||
|
||||
$sbas_id = $databox_field->get_databox()->get_sbas_id();
|
||||
$connbas = $databox_field->get_connection();
|
||||
|
||||
$sql_ins = 'INSERT INTO metadatas (id, record_id, meta_struct_id, value)
|
||||
VALUES
|
||||
(null, :record_id, :field, :value)';
|
||||
$stmt_ins = $connbas->prepare($sql_ins);
|
||||
$stmt_ins->execute(
|
||||
array(
|
||||
':record_id' => $record->get_record_id(),
|
||||
':field' => $databox_field->get_id(),
|
||||
':value' => $value
|
||||
)
|
||||
);
|
||||
$stmt_ins->closeCursor();
|
||||
$meta_id = $connbas->lastInsertId();
|
||||
|
||||
$caption_field_value = new self($databox_field, $record, $meta_id);
|
||||
$caption_field_value->update_cache_value($value);
|
||||
|
||||
// $record->get_caption()->delete_data_from_cache();
|
||||
|
||||
return $caption_field_value;
|
||||
}
|
||||
}
|
@@ -15,7 +15,7 @@
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class caption_field implements cache_cacheableInterface
|
||||
class caption_field //implements cache_cacheableInterface
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -28,13 +28,13 @@ class caption_field implements cache_cacheableInterface
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $value;
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
// /**
|
||||
// *
|
||||
// * @var int
|
||||
// */
|
||||
// protected $id;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -49,45 +49,53 @@ class caption_field implements cache_cacheableInterface
|
||||
* @param int $id
|
||||
* @return caption_field
|
||||
*/
|
||||
public function __construct(databox_field &$databox_field, record_Interface $record, $id)
|
||||
public function __construct(databox_field &$databox_field, record_Interface $record)
|
||||
{
|
||||
$this->record = $record;
|
||||
$this->id = (int) $id;
|
||||
|
||||
$row = false;
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
$row = $this->get_data_from_cache();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
// $this->id = (int) $id;
|
||||
$this->databox_field = $databox_field;
|
||||
$this->values = array();
|
||||
|
||||
$connbas = $databox_field->get_connection();
|
||||
|
||||
$sql = 'SELECT record_id, value FROM metadatas WHERE id = :id';
|
||||
$stmt = $connbas->prepare($sql);
|
||||
$stmt->execute(array(':id' => $id));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
$this->set_data_to_cache($row);
|
||||
unset($e);
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
unset($e);
|
||||
}
|
||||
if (!$row)
|
||||
throw new Exception('Unknown metadata');
|
||||
$sql = 'SELECT id FROM metadatas
|
||||
WHERE record_id = :record_id
|
||||
AND meta_struct_id = :meta_struct_id';
|
||||
|
||||
$this->databox_field = $databox_field;
|
||||
$this->value = $row['value'];
|
||||
$params = array(
|
||||
':record_id' => $record->get_record_id()
|
||||
, ':meta_struct_id' => $databox_field->get_id()
|
||||
);
|
||||
|
||||
$stmt = $connbas->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if (!$databox_field->is_multi() && count($rs) > 1)
|
||||
{
|
||||
/**
|
||||
* TRIGG CORRECTION;
|
||||
*/
|
||||
}
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
$this->values[$row['id']] = new caption_Field_Value($databox_field, $record, $row['id']);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return record_adapter
|
||||
*/
|
||||
public function get_record()
|
||||
{
|
||||
return $this->record;
|
||||
}
|
||||
|
||||
public function is_required()
|
||||
{
|
||||
return $this->databox_field->is_required();
|
||||
@@ -103,108 +111,108 @@ class caption_field implements cache_cacheableInterface
|
||||
return $this->databox_field->is_readonly();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return caption_field
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$connbas = $this->databox_field->get_connection();
|
||||
|
||||
$sql = 'DELETE FROM metadatas WHERE id = :id';
|
||||
$stmt = $connbas->prepare($sql);
|
||||
$stmt->execute(array(':id' => $this->id));
|
||||
$stmt->closeCursor();
|
||||
$this->delete_data_from_cache();
|
||||
|
||||
$sbas_id = $this->record->get_sbas_id();
|
||||
$this->record->get_caption()->delete_data_from_cache();
|
||||
|
||||
try
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
$sphinx_rt = sphinxrt::get_instance($registry);
|
||||
|
||||
$sbas_params = phrasea::sbas_params();
|
||||
|
||||
if (isset($sbas_params[$sbas_id]))
|
||||
{
|
||||
$params = $sbas_params[$sbas_id];
|
||||
$sbas_crc = crc32(str_replace(array('.', '%'), '_', sprintf('%s_%s_%s_%s', $params['host'], $params['port'], $params['user'], $params['dbname'])));
|
||||
$sphinx_rt->delete(array("metadatas" . $sbas_crc, "metadatas" . $sbas_crc . "_stemmed_fr", "metadatas" . $sbas_crc . "_stemmed_en"), "metas_realtime" . $sbas_crc, $this->id);
|
||||
$sphinx_rt->delete(array("documents" . $sbas_crc, "documents" . $sbas_crc . "_stemmed_fr", "documents" . $sbas_crc . "_stemmed_en"), "docs_realtime" . $sbas_crc, $this->record->get_record_id());
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
unset($e);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Part of the cache_cacheableInterface
|
||||
*
|
||||
* @param string $option
|
||||
* @return string
|
||||
*/
|
||||
public function get_cache_key($option = null)
|
||||
{
|
||||
return 'captionfield_' . $this->record->get_serialize_key()
|
||||
. $this->id . ($option ? '_' . $option : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Part of the cache_cacheableInterface
|
||||
*
|
||||
* @param string $option
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_data_from_cache($option = null)
|
||||
{
|
||||
$databox = databox::get_instance($this->record->get_sbas_id());
|
||||
|
||||
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 = 0)
|
||||
{
|
||||
$databox = databox::get_instance($this->record->get_sbas_id());
|
||||
$databox->set_data_to_cache($value, $this->get_cache_key($option), $duration);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Part of the cache_cacheableInterface
|
||||
*
|
||||
* @param string $option
|
||||
* @return caption_field
|
||||
*/
|
||||
public function delete_data_from_cache($option = null)
|
||||
{
|
||||
$databox = databox::get_instance($this->record->get_sbas_id());
|
||||
$databox->delete_data_from_cache($this->get_cache_key($option));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $value
|
||||
* @param databox_field $databox_field
|
||||
* @return string
|
||||
*/
|
||||
protected static function serialize_value(Array $value, $separator)
|
||||
// /**
|
||||
// *
|
||||
// * @return caption_field
|
||||
// */
|
||||
// public function delete()
|
||||
// {
|
||||
// $connbas = $this->databox_field->get_connection();
|
||||
//
|
||||
// $sql = 'DELETE FROM metadatas WHERE id = :id';
|
||||
// $stmt = $connbas->prepare($sql);
|
||||
// $stmt->execute(array(':id' => $this->id));
|
||||
// $stmt->closeCursor();
|
||||
// $this->delete_data_from_cache();
|
||||
//
|
||||
// $sbas_id = $this->record->get_sbas_id();
|
||||
// $this->record->get_caption()->delete_data_from_cache();
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// $registry = registry::get_instance();
|
||||
// $sphinx_rt = sphinxrt::get_instance($registry);
|
||||
//
|
||||
// $sbas_params = phrasea::sbas_params();
|
||||
//
|
||||
// if (isset($sbas_params[$sbas_id]))
|
||||
// {
|
||||
// $params = $sbas_params[$sbas_id];
|
||||
// $sbas_crc = crc32(str_replace(array('.', '%'), '_', sprintf('%s_%s_%s_%s', $params['host'], $params['port'], $params['user'], $params['dbname'])));
|
||||
// $sphinx_rt->delete(array("metadatas" . $sbas_crc, "metadatas" . $sbas_crc . "_stemmed_fr", "metadatas" . $sbas_crc . "_stemmed_en"), "metas_realtime" . $sbas_crc, $this->id);
|
||||
// $sphinx_rt->delete(array("documents" . $sbas_crc, "documents" . $sbas_crc . "_stemmed_fr", "documents" . $sbas_crc . "_stemmed_en"), "docs_realtime" . $sbas_crc, $this->record->get_record_id());
|
||||
// }
|
||||
// }
|
||||
// catch (Exception $e)
|
||||
// {
|
||||
// unset($e);
|
||||
// }
|
||||
//
|
||||
// return $this;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Part of the cache_cacheableInterface
|
||||
// *
|
||||
// * @param string $option
|
||||
// * @return string
|
||||
// */
|
||||
// public function get_cache_key($option = null)
|
||||
// {
|
||||
// return 'captionfield_' . $this->record->get_serialize_key()
|
||||
// . $this->id . ($option ? '_' . $option : '');
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Part of the cache_cacheableInterface
|
||||
// *
|
||||
// * @param string $option
|
||||
// * @return mixed
|
||||
// */
|
||||
// public function get_data_from_cache($option = null)
|
||||
// {
|
||||
// $databox = databox::get_instance($this->record->get_sbas_id());
|
||||
//
|
||||
// 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 = 0)
|
||||
// {
|
||||
// $databox = databox::get_instance($this->record->get_sbas_id());
|
||||
// $databox->set_data_to_cache($value, $this->get_cache_key($option), $duration);
|
||||
//
|
||||
// return $this;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Part of the cache_cacheableInterface
|
||||
// *
|
||||
// * @param string $option
|
||||
// * @return caption_field
|
||||
// */
|
||||
// public function delete_data_from_cache($option = null)
|
||||
// {
|
||||
// $databox = databox::get_instance($this->record->get_sbas_id());
|
||||
// $databox->delete_data_from_cache($this->get_cache_key($option));
|
||||
//
|
||||
// return $this;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// *
|
||||
// * @param array $value
|
||||
// * @param databox_field $databox_field
|
||||
// * @return string
|
||||
// */
|
||||
protected static function serialize_value(Array $values, $separator)
|
||||
{
|
||||
if (strlen($separator) > 1)
|
||||
$separator = $separator[0];
|
||||
@@ -214,97 +222,104 @@ class caption_field implements cache_cacheableInterface
|
||||
else
|
||||
$separator = ' ' . $separator . ' ';
|
||||
|
||||
return implode($separator, $value);
|
||||
}
|
||||
$array_values = array();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $value
|
||||
* @return caption_field
|
||||
*/
|
||||
public function set_value(Array $value)
|
||||
foreach($values as $value)
|
||||
{
|
||||
$sbas_id = $this->databox_field->get_databox()->get_sbas_id();
|
||||
$connbas = $this->databox_field->get_connection();
|
||||
|
||||
$sql_up = 'UPDATE metadatas SET value = :value WHERE id = :meta_id';
|
||||
$stmt_up = $connbas->prepare($sql_up);
|
||||
$stmt_up->execute(array(':meta_id' => $this->get_meta_id(), ':value' => self::serialize_value($value, $this->databox_field->get_separator())));
|
||||
$stmt_up->closeCursor();
|
||||
|
||||
try
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
$sphinx_rt = sphinxrt::get_instance($registry);
|
||||
|
||||
$sbas_params = phrasea::sbas_params();
|
||||
|
||||
if (isset($sbas_params[$sbas_id]))
|
||||
{
|
||||
$params = $sbas_params[$sbas_id];
|
||||
$sbas_crc = crc32(str_replace(array('.', '%'), '_', sprintf('%s_%s_%s_%s', $params['host'], $params['port'], $params['user'], $params['dbname'])));
|
||||
$sphinx_rt->delete(array("metadatas" . $sbas_crc, "metadatas" . $sbas_crc . "_stemmed_fr", "metadatas" . $sbas_crc . "_stemmed_en"), "", $this->get_meta_id());
|
||||
$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)
|
||||
{
|
||||
|
||||
$array_values[] = $value->get_value();
|
||||
}
|
||||
|
||||
$this->update_cache_value($value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $value
|
||||
* @return caption_field
|
||||
*/
|
||||
public function update_cache_value(Array $value)
|
||||
{
|
||||
$this->delete_data_from_cache();
|
||||
$this->record->get_caption()->delete_data_from_cache();
|
||||
$sbas_id = $this->databox_field->get_databox()->get_sbas_id();
|
||||
try
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
|
||||
$sbas_params = phrasea::sbas_params();
|
||||
|
||||
if (isset($sbas_params[$sbas_id]))
|
||||
{
|
||||
$params = $sbas_params[$sbas_id];
|
||||
$sbas_crc = crc32(str_replace(array('.', '%'), '_', sprintf('%s_%s_%s_%s', $params['host'], $params['port'], $params['user'], $params['dbname'])));
|
||||
|
||||
$sphinx_rt = sphinxrt::get_instance($registry);
|
||||
$sphinx_rt->replace_in_metas(
|
||||
"metas_realtime" . $sbas_crc, $this->id, $this->databox_field->get_id(), $this->record->get_record_id(), $sbas_id, phrasea::collFromBas($this->record->get_base_id()), ($this->record->is_grouping() ? '1' : '0'), $this->record->get_type(), $value, $this->record->get_creation_date()
|
||||
);
|
||||
|
||||
$all_datas = array();
|
||||
foreach ($this->record->get_caption()->get_fields() as $field)
|
||||
{
|
||||
if (!$field->is_indexable())
|
||||
continue;
|
||||
$all_datas[] = $field->get_value(true);
|
||||
}
|
||||
$all_datas = implode(' ', $all_datas);
|
||||
|
||||
$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()
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
unset($e);
|
||||
}
|
||||
|
||||
return $this;
|
||||
return implode($separator, $array_values);
|
||||
}
|
||||
//
|
||||
// /**
|
||||
// *
|
||||
// * @param array $value
|
||||
// * @return caption_field
|
||||
// */
|
||||
// public function set_value(Array $value)
|
||||
// {
|
||||
// $sbas_id = $this->databox_field->get_databox()->get_sbas_id();
|
||||
// $connbas = $this->databox_field->get_connection();
|
||||
//
|
||||
// $sql_up = 'UPDATE metadatas SET value = :value WHERE id = :meta_id';
|
||||
// $stmt_up = $connbas->prepare($sql_up);
|
||||
// $stmt_up->execute(array(':meta_id' => $this->get_meta_id(), ':value' => self::serialize_value($value, $this->databox_field->get_separator())));
|
||||
// $stmt_up->closeCursor();
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// $registry = registry::get_instance();
|
||||
// $sphinx_rt = sphinxrt::get_instance($registry);
|
||||
//
|
||||
// $sbas_params = phrasea::sbas_params();
|
||||
//
|
||||
// if (isset($sbas_params[$sbas_id]))
|
||||
// {
|
||||
// $params = $sbas_params[$sbas_id];
|
||||
// $sbas_crc = crc32(str_replace(array('.', '%'), '_', sprintf('%s_%s_%s_%s', $params['host'], $params['port'], $params['user'], $params['dbname'])));
|
||||
// $sphinx_rt->delete(array("metadatas" . $sbas_crc, "metadatas" . $sbas_crc . "_stemmed_fr", "metadatas" . $sbas_crc . "_stemmed_en"), "", $this->get_meta_id());
|
||||
// $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);
|
||||
//
|
||||
// return $this;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// *
|
||||
// * @param array $value
|
||||
// * @return caption_field
|
||||
// */
|
||||
// public function update_cache_value(Array $value)
|
||||
// {
|
||||
// $this->delete_data_from_cache();
|
||||
// $this->record->get_caption()->delete_data_from_cache();
|
||||
// $sbas_id = $this->databox_field->get_databox()->get_sbas_id();
|
||||
// try
|
||||
// {
|
||||
// $registry = registry::get_instance();
|
||||
//
|
||||
// $sbas_params = phrasea::sbas_params();
|
||||
//
|
||||
// if (isset($sbas_params[$sbas_id]))
|
||||
// {
|
||||
// $params = $sbas_params[$sbas_id];
|
||||
// $sbas_crc = crc32(str_replace(array('.', '%'), '_', sprintf('%s_%s_%s_%s', $params['host'], $params['port'], $params['user'], $params['dbname'])));
|
||||
//
|
||||
// $sphinx_rt = sphinxrt::get_instance($registry);
|
||||
// $sphinx_rt->replace_in_metas(
|
||||
// "metas_realtime" . $sbas_crc, $this->id, $this->databox_field->get_id(), $this->record->get_record_id(), $sbas_id, phrasea::collFromBas($this->record->get_base_id()), ($this->record->is_grouping() ? '1' : '0'), $this->record->get_type(), $value, $this->record->get_creation_date()
|
||||
// );
|
||||
//
|
||||
// $all_datas = array();
|
||||
// foreach ($this->record->get_caption()->get_fields() as $field)
|
||||
// {
|
||||
// if (!$field->is_indexable())
|
||||
// continue;
|
||||
// $all_datas[] = $field->get_value(true);
|
||||
// }
|
||||
// $all_datas = implode(' ', $all_datas);
|
||||
//
|
||||
// $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()
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// catch (Exception $e)
|
||||
// {
|
||||
// unset($e);
|
||||
// }
|
||||
//
|
||||
// return $this;
|
||||
// }
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -312,62 +327,93 @@ class caption_field implements cache_cacheableInterface
|
||||
* @param record_Interface $record
|
||||
* @param array $value
|
||||
* @return caption_field
|
||||
*/
|
||||
public static function create(databox_field &$databox_field, record_Interface $record, Array $value)
|
||||
// */
|
||||
// public static function create(databox_field &$databox_field, record_Interface $record, Array $value)
|
||||
// {
|
||||
//
|
||||
// $sbas_id = $databox_field->get_databox()->get_sbas_id();
|
||||
// $connbas = $databox_field->get_connection();
|
||||
// $sql_ins = 'INSERT INTO metadatas (id, record_id, meta_struct_id, value)
|
||||
// VALUES
|
||||
// (null, :record_id, :field, :value)';
|
||||
// $stmt_ins = $connbas->prepare($sql_ins);
|
||||
// $stmt_ins->execute(
|
||||
// array(
|
||||
// ':record_id' => $record->get_record_id(),
|
||||
// ':field' => $databox_field->get_id(),
|
||||
// ':value' => self::serialize_value($value, $databox_field->get_separator())
|
||||
// )
|
||||
// );
|
||||
// $stmt_ins->closeCursor();
|
||||
// $meta_id = $connbas->lastInsertId();
|
||||
//
|
||||
// $caption_field = new self($databox_field, $record, $meta_id);
|
||||
// $caption_field->update_cache_value($value);
|
||||
//
|
||||
// $record->get_caption()->delete_data_from_cache();
|
||||
//
|
||||
// return $caption_field;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * @return string
|
||||
// */
|
||||
// public function get_value($as_string = false, $custom_separator = false)
|
||||
// {
|
||||
// if ($this->databox_field->is_multi() === true)
|
||||
// {
|
||||
// if ($as_string === true && $custom_separator === false)
|
||||
// {
|
||||
// return $this->value;
|
||||
// }
|
||||
// $separator = $this->databox_field->get_separator();
|
||||
// $array_values = self::get_multi_values($this->value, $separator);
|
||||
//
|
||||
// if ($as_string === true && $custom_separator !== false)
|
||||
// return self::serialize_value($array_values, $custom_separator);
|
||||
// else
|
||||
// return $array_values;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return $this->value;
|
||||
// }
|
||||
// }
|
||||
|
||||
public function get_values()
|
||||
{
|
||||
|
||||
$sbas_id = $databox_field->get_databox()->get_sbas_id();
|
||||
$connbas = $databox_field->get_connection();
|
||||
$sql_ins = 'INSERT INTO metadatas (id, record_id, meta_struct_id, value)
|
||||
VALUES
|
||||
(null, :record_id, :field, :value)';
|
||||
$stmt_ins = $connbas->prepare($sql_ins);
|
||||
$stmt_ins->execute(
|
||||
array(
|
||||
':record_id' => $record->get_record_id(),
|
||||
':field' => $databox_field->get_id(),
|
||||
':value' => self::serialize_value($value, $databox_field->get_separator())
|
||||
)
|
||||
);
|
||||
$stmt_ins->closeCursor();
|
||||
$meta_id = $connbas->lastInsertId();
|
||||
|
||||
$caption_field = new self($databox_field, $record, $meta_id);
|
||||
$caption_field->update_cache_value($value);
|
||||
|
||||
$record->get_caption()->delete_data_from_cache();
|
||||
|
||||
return $caption_field;
|
||||
return $this->values;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value($as_string = false, $custom_separator = false)
|
||||
public function get_value($meta_id)
|
||||
{
|
||||
return $this->values[$meta_id];
|
||||
}
|
||||
|
||||
public function get_serialized_values($custom_separator = false)
|
||||
{
|
||||
if ($this->databox_field->is_multi() === true)
|
||||
{
|
||||
if ($as_string === true && $custom_separator === false)
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
if($custom_separator !== false)
|
||||
$separator = $custom_separator;
|
||||
else
|
||||
$separator = $this->databox_field->get_separator();
|
||||
$array_values = self::get_multi_values($this->value, $separator);
|
||||
|
||||
if ($as_string === true && $custom_separator !== false)
|
||||
|
||||
return self::serialize_value($array_values, $custom_separator);
|
||||
else
|
||||
|
||||
return $array_values;
|
||||
return self::serialize_value($this->values, $separator);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->value;
|
||||
foreach($this->values as $value)
|
||||
{
|
||||
/* @var $value Caption_Field_Value */
|
||||
return $value->get_value();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
@@ -395,14 +441,14 @@ class caption_field implements cache_cacheableInterface
|
||||
return $this->databox_field->is_indexable();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_meta_id()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
// /**
|
||||
// *
|
||||
// * @return int
|
||||
// */
|
||||
// public function get_meta_id()
|
||||
// {
|
||||
// return $this->id;
|
||||
// }
|
||||
|
||||
/**
|
||||
*
|
||||
|
@@ -85,7 +85,7 @@ class caption_record implements caption_interface, cache_cacheableInterface
|
||||
try
|
||||
{
|
||||
$databox_meta_struct = databox_field::get_instance($this->databox, $row['structure_id']);
|
||||
$metadata = new caption_field($databox_meta_struct, $this->record, $row['meta_id']);
|
||||
$metadata = new caption_field($databox_meta_struct, $this->record);
|
||||
|
||||
$rec_fields[$databox_meta_struct->get_id()] = $metadata;
|
||||
$dces_element = $metadata->get_databox_field()->get_dces_element();
|
||||
|
@@ -140,7 +140,6 @@ class record_adapter implements record_Interface, cache_cacheableInterface
|
||||
const CACHE_GROUPING = 'grouping';
|
||||
const CACHE_STATUS = 'status';
|
||||
|
||||
|
||||
protected static $_regfields;
|
||||
|
||||
/**
|
||||
@@ -784,16 +783,17 @@ class record_adapter implements record_Interface, cache_cacheableInterface
|
||||
|
||||
foreach ($caption->get_fields() as $field)
|
||||
{
|
||||
if ($field->is_multi())
|
||||
$values = $field->get_value();
|
||||
else
|
||||
$values = array($field->get_value());
|
||||
$values = $field->get_values();
|
||||
// if ($field->is_multi())
|
||||
// $values = $field->get_value();
|
||||
// else
|
||||
// $values = array($field->get_value());
|
||||
|
||||
foreach ($values as $value)
|
||||
{
|
||||
$elem = $dom_doc->createElement($field->get_name());
|
||||
$elem->appendChild($dom_doc->createTextNode($value));
|
||||
$elem->setAttribute('meta_id', $field->get_meta_id());
|
||||
$elem->appendChild($dom_doc->createTextNode($value->getValue()));
|
||||
$elem->setAttribute('meta_id', $value->getId());
|
||||
$elem->setAttribute('meta_struct_id', $field->get_meta_struct_id());
|
||||
$description->appendChild($elem);
|
||||
}
|
||||
@@ -836,14 +836,27 @@ class record_adapter implements record_Interface, cache_cacheableInterface
|
||||
continue;
|
||||
}
|
||||
|
||||
/* @var $field caption_field */
|
||||
/**
|
||||
* Replacing original name in multi values is non sense
|
||||
*/
|
||||
if (!$field->is_multi())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
$value = array_pop($field->get_values());
|
||||
|
||||
$this->set_metadatas(
|
||||
array(
|
||||
'meta_struct_id' => $field->get_meta_struct_id()
|
||||
, 'meta_id' => get_meta_id
|
||||
, 'meta_id' => $value->getId()
|
||||
, 'value' => array($original_name)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$sql = 'UPDATE record
|
||||
SET originalname = :originalname WHERE record_id = :record_id';
|
||||
@@ -955,9 +968,12 @@ class record_adapter implements record_Interface, cache_cacheableInterface
|
||||
|
||||
foreach ($desc->get_fields() as $caption_field)
|
||||
{
|
||||
/* @var $caption_field caption_field */
|
||||
$meta_struct_id = $caption_field->get_meta_struct_id();
|
||||
if (array_key_exists($meta_struct_id, $array))
|
||||
$fields[$array[$meta_struct_id]] = $caption_field->get_value();
|
||||
{
|
||||
$fields[$array[$meta_struct_id]] = $caption_field->get_serialized_values();
|
||||
}
|
||||
}
|
||||
|
||||
return $fields;
|
||||
@@ -1251,29 +1267,32 @@ class record_adapter implements record_Interface, cache_cacheableInterface
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_array($params['value']))
|
||||
throw new Exception();
|
||||
if (!is_scalar($params['value']))
|
||||
throw new Exception('Metadata value should be scalar');
|
||||
|
||||
$databox_field = databox_field::get_instance($databox, $params['meta_struct_id']);
|
||||
|
||||
$caption_field = new caption_field($databox_field, $this);
|
||||
|
||||
if (trim($params['meta_id']) !== '')
|
||||
{
|
||||
$tmp_val = trim(implode('', $params['value']));
|
||||
$caption_field = new caption_field($databox_field, $this, $params['meta_id']);
|
||||
$tmp_val = trim($params['value']);
|
||||
|
||||
$caption_field_value = $caption_field->get_value($params['meta_id']);
|
||||
|
||||
if ($tmp_val === '')
|
||||
{
|
||||
$caption_field->delete();
|
||||
unset($caption_field);
|
||||
$caption_field_value->delete();
|
||||
unset($caption_field_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
$caption_field->set_value($params['value']);
|
||||
$caption_field_value->set_value($params['value']);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$caption_field = caption_field::create($databox_field, $this, $params['value']);
|
||||
$caption_field_value = caption_Field_Value::create($databox_field, $this, $params['value']);
|
||||
}
|
||||
|
||||
$this->caption_record = null;
|
||||
|
Reference in New Issue
Block a user