mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
Use TechnicalDataSet in record_adapter
This commit is contained in:
@@ -1129,7 +1129,7 @@ class V1Controller extends Controller
|
|||||||
public function listRecord(Request $request, \record_adapter $record)
|
public function listRecord(Request $request, \record_adapter $record)
|
||||||
{
|
{
|
||||||
$technicalInformation = [];
|
$technicalInformation = [];
|
||||||
foreach ($record->get_technical_infos() as $name => $value) {
|
foreach ($record->get_technical_infos()->getValues() as $name => $value) {
|
||||||
$technicalInformation[] = ['name' => $name, 'value' => $value];
|
$technicalInformation[] = ['name' => $name, 'value' => $value];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -96,7 +96,7 @@ class CaptionSerializer extends AbstractSerializer
|
|||||||
|
|
||||||
$doc = $dom_doc->createElement('doc');
|
$doc = $dom_doc->createElement('doc');
|
||||||
|
|
||||||
$tc_datas = $caption->get_record()->get_technical_infos();
|
$tc_datas = $caption->get_record()->get_technical_infos()->getValues();
|
||||||
|
|
||||||
foreach ($tc_datas as $key => $data) {
|
foreach ($tc_datas as $key => $data) {
|
||||||
$doc->setAttribute($key, $data);
|
$doc->setAttribute($key, $data);
|
||||||
|
@@ -15,11 +15,9 @@ class ESRecordSerializer extends AbstractSerializer
|
|||||||
{
|
{
|
||||||
public function serialize(\record_adapter $record)
|
public function serialize(\record_adapter $record)
|
||||||
{
|
{
|
||||||
$technicalInformation = $caption = $business = $status = [];
|
$caption = $business = $status = [];
|
||||||
|
|
||||||
foreach ($record->get_technical_infos() as $name => $value) {
|
$technicalInformation = $record->get_technical_infos()->getValues();
|
||||||
$technicalInformation[$name] = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($record->get_caption()->get_fields(null, true) as $field) {
|
foreach ($record->get_caption()->get_fields(null, true) as $field) {
|
||||||
$isDate = $field->get_databox_field()->get_type() === \databox_field::TYPE_DATE;
|
$isDate = $field->get_databox_field()->get_type() === \databox_field::TYPE_DATE;
|
||||||
|
@@ -903,7 +903,7 @@ class Bridge_Api_Dailymotion extends Bridge_Api_Abstract implements Bridge_Api_I
|
|||||||
if ($record->get_duration() > self::AUTH_VIDEO_DURATION)
|
if ($record->get_duration() > self::AUTH_VIDEO_DURATION)
|
||||||
$errors["duration"] = $this->translator->trans("La taille maximale d'une video est de %duration% minutes.", ['%duration%' => self::AUTH_VIDEO_DURATION / 60]);
|
$errors["duration"] = $this->translator->trans("La taille maximale d'une video est de %duration% minutes.", ['%duration%' => self::AUTH_VIDEO_DURATION / 60]);
|
||||||
|
|
||||||
if ($record->get_technical_infos('size') > self::AUTH_VIDEO_SIZE)
|
if ($record->get_technical_infos('size')->getValue() > self::AUTH_VIDEO_SIZE)
|
||||||
$errors["size"] = $this->translator->trans("Le poids maximum d'un fichier est de %size%", ['%size%' => p4string::format_octets(self::AUTH_VIDEO_SIZE)]);
|
$errors["size"] = $this->translator->trans("Le poids maximum d'un fichier est de %size%", ['%size%' => p4string::format_octets(self::AUTH_VIDEO_SIZE)]);
|
||||||
|
|
||||||
return $errors;
|
return $errors;
|
||||||
|
@@ -807,7 +807,7 @@ class Bridge_Api_Flickr extends Bridge_Api_Abstract implements Bridge_Api_Interf
|
|||||||
$errors = [];
|
$errors = [];
|
||||||
if ( ! $record->get_hd_file() instanceof \SplFileInfo)
|
if ( ! $record->get_hd_file() instanceof \SplFileInfo)
|
||||||
$errors["file_size"] = $this->translator->trans("Le record n'a pas de fichier physique"); //Record must rely on real file
|
$errors["file_size"] = $this->translator->trans("Le record n'a pas de fichier physique"); //Record must rely on real file
|
||||||
if ($record->get_technical_infos('size') > self::AUTH_PHOTO_SIZE)
|
if ($record->get_technical_infos('size')->getValue() > self::AUTH_PHOTO_SIZE)
|
||||||
$errors["size"] = $this->translator->trans("Le poids maximum d'un fichier est de %size%", ['%size%' => p4string::format_octets(self::AUTH_VIDEO_SIZE)]);
|
$errors["size"] = $this->translator->trans("Le poids maximum d'un fichier est de %size%", ['%size%' => p4string::format_octets(self::AUTH_VIDEO_SIZE)]);
|
||||||
|
|
||||||
return $errors;
|
return $errors;
|
||||||
|
@@ -1019,7 +1019,7 @@ class Bridge_Api_Youtube extends Bridge_Api_Abstract implements Bridge_Api_Inter
|
|||||||
if ($record->get_duration() > self::AUTH_VIDEO_DURATION)
|
if ($record->get_duration() > self::AUTH_VIDEO_DURATION)
|
||||||
$errors["duration_" . $key] = $this->translator->trans("La taille maximale d'une video est de %duration% minutes.", ['%duration%' => self::AUTH_VIDEO_DURATION / 60]);
|
$errors["duration_" . $key] = $this->translator->trans("La taille maximale d'une video est de %duration% minutes.", ['%duration%' => self::AUTH_VIDEO_DURATION / 60]);
|
||||||
|
|
||||||
if ($record->get_technical_infos('size') > self::AUTH_VIDEO_SIZE)
|
if ($record->get_technical_infos('size')->getValue() > self::AUTH_VIDEO_SIZE)
|
||||||
$errors["size_" . $key] = $this->translator->trans("Le poids maximum d'un fichier est de %size%", ['%size%' => p4string::format_octets(self::AUTH_VIDEO_SIZE)]);
|
$errors["size_" . $key] = $this->translator->trans("Le poids maximum d'un fichier est de %size%", ['%size%' => p4string::format_octets(self::AUTH_VIDEO_SIZE)]);
|
||||||
|
|
||||||
return $errors;
|
return $errors;
|
||||||
|
@@ -21,6 +21,12 @@ use Alchemy\Phrasea\Core\Event\Record\RecordMetadataChangedEvent;
|
|||||||
use Alchemy\Phrasea\Core\Event\Record\RecordOriginalNameChangedEvent;
|
use Alchemy\Phrasea\Core\Event\Record\RecordOriginalNameChangedEvent;
|
||||||
use Alchemy\Phrasea\Core\Event\Record\RecordStatusChangedEvent;
|
use Alchemy\Phrasea\Core\Event\Record\RecordStatusChangedEvent;
|
||||||
use Alchemy\Phrasea\Core\PhraseaTokens;
|
use Alchemy\Phrasea\Core\PhraseaTokens;
|
||||||
|
use Alchemy\Phrasea\Media\ArrayTechnicalDataSet;
|
||||||
|
use Alchemy\Phrasea\Media\FloatTechnicalData;
|
||||||
|
use Alchemy\Phrasea\Media\IntegerTechnicalData;
|
||||||
|
use Alchemy\Phrasea\Media\StringTechnicalData;
|
||||||
|
use Alchemy\Phrasea\Media\TechnicalData;
|
||||||
|
use Alchemy\Phrasea\Media\TechnicalDataSet;
|
||||||
use Alchemy\Phrasea\Metadata\Tag\TfBasename;
|
use Alchemy\Phrasea\Metadata\Tag\TfBasename;
|
||||||
use Alchemy\Phrasea\Metadata\Tag\TfFilename;
|
use Alchemy\Phrasea\Metadata\Tag\TfFilename;
|
||||||
use Alchemy\Phrasea\Model\Entities\User;
|
use Alchemy\Phrasea\Model\Entities\User;
|
||||||
@@ -62,7 +68,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
private $creation_date;
|
private $creation_date;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $original_name;
|
private $original_name;
|
||||||
/** @var array */
|
/** @var TechnicalDataSet */
|
||||||
private $technical_data;
|
private $technical_data;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $uuid;
|
private $uuid;
|
||||||
@@ -314,7 +320,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
public function get_duration()
|
public function get_duration()
|
||||||
{
|
{
|
||||||
if (!$this->duration) {
|
if (!$this->duration) {
|
||||||
$this->duration = round($this->get_technical_infos(media_subdef::TC_DATA_DURATION));
|
$this->duration = round($this->get_technical_infos(media_subdef::TC_DATA_DURATION)->getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->duration;
|
return $this->duration;
|
||||||
@@ -587,40 +593,20 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Return a Technical data set or a specific technical data or false when not found
|
||||||
*
|
*
|
||||||
* @param string $data
|
* @param string $data
|
||||||
* @return Array
|
* @return TechnicalDataSet|TechnicalData|false
|
||||||
*/
|
*/
|
||||||
public function get_technical_infos($data = false)
|
public function get_technical_infos($data = '')
|
||||||
{
|
{
|
||||||
if (!$this->technical_data) {
|
if (!$this->technical_data && !$this->mapTechnicalDataFromCache()) {
|
||||||
try {
|
$this->technical_data = [];
|
||||||
$this->technical_data = $this->get_data_from_cache(self::CACHE_TECHNICAL_DATA);
|
$rs = $this->fetchTechnicalDataFromDb();
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->technical_data = [];
|
|
||||||
$connbas = $this->get_databox()->get_connection();
|
|
||||||
$sql = 'SELECT name, value FROM technical_datas WHERE record_id = :record_id';
|
|
||||||
$stmt = $connbas->prepare($sql);
|
|
||||||
$stmt->execute([':record_id' => $this->get_record_id()]);
|
|
||||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
$stmt->closeCursor();
|
|
||||||
|
|
||||||
foreach ($rs as $row) {
|
$this->mapTechnicalDataFromDb($rs);
|
||||||
switch (true) {
|
|
||||||
case preg_match('/[0-9]?\.[0-9]+/', $row['value']):
|
$this->set_data_to_cache($this->technical_data, self::CACHE_TECHNICAL_DATA);
|
||||||
$this->technical_data[$row['name']] = (float) $row['value'];
|
|
||||||
break;
|
|
||||||
case ctype_digit($row['value']):
|
|
||||||
$this->technical_data[$row['name']] = (int) $row['value'];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$this->technical_data[$row['name']] = $row['value'];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->set_data_to_cache($this->technical_data, self::CACHE_TECHNICAL_DATA);
|
|
||||||
unset($e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($data) {
|
if ($data) {
|
||||||
@@ -1920,7 +1906,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
/** {@inheritdoc} */
|
/** {@inheritdoc} */
|
||||||
public function getExif()
|
public function getExif()
|
||||||
{
|
{
|
||||||
return $this->get_technical_infos();
|
return $this->get_technical_infos()->getValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getStatusStructure()
|
public function getStatusStructure()
|
||||||
@@ -2024,4 +2010,56 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
|
|
||||||
return $connection->fetchAssoc($sql, [':record_id' => $this->record_id]);
|
return $connection->fetchAssoc($sql, [':record_id' => $this->record_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function mapTechnicalDataFromCache()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$technical_data = $this->get_data_from_cache(self::CACHE_TECHNICAL_DATA);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$technical_data = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!false === $technical_data) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->technical_data = $technical_data;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return false|array
|
||||||
|
*/
|
||||||
|
private function fetchTechnicalDataFromDb()
|
||||||
|
{
|
||||||
|
$sql = 'SELECT name, value FROM technical_datas WHERE record_id = :record_id';
|
||||||
|
|
||||||
|
return $this->get_databox()->get_connection()
|
||||||
|
->fetchAll($sql, ['record_id' => $this->get_record_id()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $rows
|
||||||
|
*/
|
||||||
|
private function mapTechnicalDataFromDb(array $rows)
|
||||||
|
{
|
||||||
|
$this->technical_data = new ArrayTechnicalDataSet();
|
||||||
|
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
switch (true) {
|
||||||
|
case ctype_digit($row['value']):
|
||||||
|
$this->technical_data[] = new IntegerTechnicalData($row['name'], $row['value']);
|
||||||
|
break;
|
||||||
|
case preg_match('/[0-9]?\.[0-9]+/', $row['value']):
|
||||||
|
$this->technical_data[] = new FloatTechnicalData($row['name'], $row['value']);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$this->technical_data[] = new StringTechnicalData($row['name'], $row['value']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -110,8 +110,8 @@
|
|||||||
{% set dataW = constant('media_subdef::TC_DATA_WIDTH') %}
|
{% set dataW = constant('media_subdef::TC_DATA_WIDTH') %}
|
||||||
{% set dataH = constant('media_subdef::TC_DATA_HEIGHT') %}
|
{% set dataH = constant('media_subdef::TC_DATA_HEIGHT') %}
|
||||||
|
|
||||||
{% set width = record.get_technical_infos(dataW) %}
|
{% set width = record.get_technical_infos(dataW).value %}
|
||||||
{% set height = record.get_technical_infos(dataH) %}
|
{% set height = record.get_technical_infos(dataH).value %}
|
||||||
|
|
||||||
{% if width and height %}
|
{% if width and height %}
|
||||||
{% set ratio = (width / height)|number_format(2, '.') %}
|
{% set ratio = (width / height)|number_format(2, '.') %}
|
||||||
|
@@ -243,7 +243,9 @@ class record_adapterTest extends \PhraseanetAuthenticatedTestCase
|
|||||||
|
|
||||||
public function testGet_technical_infos()
|
public function testGet_technical_infos()
|
||||||
{
|
{
|
||||||
$this->assertTrue(is_array(self::$DI['record_1']->get_technical_infos()));
|
/** @var record_adapter $record_1 */
|
||||||
|
$record_1 = self::$DI['record_1'];
|
||||||
|
$this->assertInstanceOf('array', $record_1->get_technical_infos()->getValues());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGet_caption()
|
public function testGet_caption()
|
||||||
|
Reference in New Issue
Block a user