mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-12 04:23:19 +00:00
Add localized labels to databox fields
This commit is contained in:
@@ -333,6 +333,10 @@ class Fields implements ControllerProviderInterface
|
|||||||
->setVocabularyControl(null)
|
->setVocabularyControl(null)
|
||||||
->setVocabularyRestricted(false);
|
->setVocabularyRestricted(false);
|
||||||
|
|
||||||
|
foreach ($data['labels'] as $code => $label) {
|
||||||
|
$field->set_label($code, $label);
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($data['sorter'])) {
|
if (isset($data['sorter'])) {
|
||||||
$field->set_position($data['sorter']);
|
$field->set_position($data['sorter']);
|
||||||
}
|
}
|
||||||
@@ -361,7 +365,7 @@ class Fields implements ControllerProviderInterface
|
|||||||
return array(
|
return array(
|
||||||
'name', 'multi', 'thumbtitle', 'tag', 'business', 'indexable',
|
'name', 'multi', 'thumbtitle', 'tag', 'business', 'indexable',
|
||||||
'required', 'separator', 'readonly', 'type', 'tbranch', 'report',
|
'required', 'separator', 'readonly', 'type', 'tbranch', 'report',
|
||||||
'vocabulary-type', 'vocabulary-restricted', 'dces-element'
|
'vocabulary-type', 'vocabulary-restricted', 'dces-element', 'labels'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1783,6 +1783,12 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
'meta_id' => $value->getId(),
|
'meta_id' => $value->getId(),
|
||||||
'meta_structure_id' => $field->get_meta_struct_id(),
|
'meta_structure_id' => $field->get_meta_struct_id(),
|
||||||
'name' => $field->get_name(),
|
'name' => $field->get_name(),
|
||||||
|
'labels' => array(
|
||||||
|
'fr' => $field->get_databox_field()->get_label('fr'),
|
||||||
|
'en' => $field->get_databox_field()->get_label('en'),
|
||||||
|
'de' => $field->get_databox_field()->get_label('de'),
|
||||||
|
'nl' => $field->get_databox_field()->get_label('nl'),
|
||||||
|
),
|
||||||
'value' => $value->getValue(),
|
'value' => $value->getValue(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -2074,6 +2080,12 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
'source' => $databox_field->get_tag()->getTagname(),
|
'source' => $databox_field->get_tag()->getTagname(),
|
||||||
'tagname' => $databox_field->get_tag()->getName(),
|
'tagname' => $databox_field->get_tag()->getName(),
|
||||||
'name' => $databox_field->get_name(),
|
'name' => $databox_field->get_name(),
|
||||||
|
'labels' => array(
|
||||||
|
'fr' => $databox_field->get_label('fr'),
|
||||||
|
'en' => $databox_field->get_label('en'),
|
||||||
|
'de' => $databox_field->get_label('de'),
|
||||||
|
'nl' => $databox_field->get_label('nl'),
|
||||||
|
),
|
||||||
'separator' => $databox_field->get_separator(),
|
'separator' => $databox_field->get_separator(),
|
||||||
'thesaurus_branch' => $databox_field->get_tbranch(),
|
'thesaurus_branch' => $databox_field->get_tbranch(),
|
||||||
'type' => $databox_field->get_type(),
|
'type' => $databox_field->get_type(),
|
||||||
|
@@ -280,8 +280,9 @@ class caption_record implements caption_interface, cache_cacheableInterface
|
|||||||
);
|
);
|
||||||
|
|
||||||
$fields[$field->get_name()] = array(
|
$fields[$field->get_name()] = array(
|
||||||
'value' => $value
|
'value' => $value,
|
||||||
, 'separator' => $field->get_databox_field()->get_separator()
|
'label' => $field->get_databox_field()->get_label($this->app['locale.I18n']),
|
||||||
|
'separator' => $field->get_databox_field()->get_separator(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,6 +16,7 @@ use Alchemy\Phrasea\Metadata\Tag\Nosource;
|
|||||||
use PHPExiftool\Driver\TagInterface;
|
use PHPExiftool\Driver\TagInterface;
|
||||||
use PHPExiftool\Driver\TagFactory;
|
use PHPExiftool\Driver\TagFactory;
|
||||||
use PHPExiftool\Exception\TagUnknown;
|
use PHPExiftool\Exception\TagUnknown;
|
||||||
|
use Alchemy\Phrasea\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -111,6 +112,12 @@ class databox_field implements cache_cacheableInterface
|
|||||||
*/
|
*/
|
||||||
protected $thumbtitle;
|
protected $thumbtitle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $labels = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var boolean
|
* @var boolean
|
||||||
@@ -178,7 +185,8 @@ class databox_field implements cache_cacheableInterface
|
|||||||
$sql = "SELECT `thumbtitle`, `separator`, `dces_element`, `tbranch`,
|
$sql = "SELECT `thumbtitle`, `separator`, `dces_element`, `tbranch`,
|
||||||
`type`, `report`, `multi`, `required`, `readonly`, `indexable`,
|
`type`, `report`, `multi`, `required`, `readonly`, `indexable`,
|
||||||
`name`, `src`, `business`, `VocabularyControlType`,
|
`name`, `src`, `business`, `VocabularyControlType`,
|
||||||
`RestrictToVocabularyControl`, `sorter`
|
`RestrictToVocabularyControl`, `sorter`,
|
||||||
|
`label_en`, `label_fr`, `label_de`, `label_nl`
|
||||||
FROM metadatas_structure WHERE id=:id";
|
FROM metadatas_structure WHERE id=:id";
|
||||||
|
|
||||||
$stmt = $connbas->prepare($sql);
|
$stmt = $connbas->prepare($sql);
|
||||||
@@ -198,6 +206,10 @@ class databox_field implements cache_cacheableInterface
|
|||||||
$this->on_error = true;
|
$this->on_error = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (array('en', 'fr', 'de', 'nl') as $code) {
|
||||||
|
$this->labels[$code] = $row['label_' . $code];
|
||||||
|
}
|
||||||
|
|
||||||
$this->name = $row['name'];
|
$this->name = $row['name'];
|
||||||
$this->indexable = (Boolean) $row['indexable'];
|
$this->indexable = (Boolean) $row['indexable'];
|
||||||
$this->readonly = (Boolean) $row['readonly'];
|
$this->readonly = (Boolean) $row['readonly'];
|
||||||
@@ -357,7 +369,11 @@ class databox_field implements cache_cacheableInterface
|
|||||||
`sorter` = :position,
|
`sorter` = :position,
|
||||||
`thumbtitle` = :thumbtitle,
|
`thumbtitle` = :thumbtitle,
|
||||||
`VocabularyControlType` = :VocabularyControlType,
|
`VocabularyControlType` = :VocabularyControlType,
|
||||||
`RestrictToVocabularyControl` = :RestrictVocab
|
`RestrictToVocabularyControl` = :RestrictVocab,
|
||||||
|
`label_en` = :label_en,
|
||||||
|
`label_fr` = :label_fr,
|
||||||
|
`label_de` = :label_de,
|
||||||
|
`label_nl` = :label_nl
|
||||||
WHERE id = :id';
|
WHERE id = :id';
|
||||||
|
|
||||||
$params = array(
|
$params = array(
|
||||||
@@ -376,7 +392,11 @@ class databox_field implements cache_cacheableInterface
|
|||||||
':thumbtitle' => $this->thumbtitle,
|
':thumbtitle' => $this->thumbtitle,
|
||||||
':VocabularyControlType' => $this->Vocabulary ? $this->Vocabulary->getType() : null,
|
':VocabularyControlType' => $this->Vocabulary ? $this->Vocabulary->getType() : null,
|
||||||
':RestrictVocab' => $this->Vocabulary ? ($this->VocabularyRestriction ? '1' : '0') : '0',
|
':RestrictVocab' => $this->Vocabulary ? ($this->VocabularyRestriction ? '1' : '0') : '0',
|
||||||
':id' => $this->id
|
':id' => $this->id,
|
||||||
|
':label_en' => isset($this->labels['en']) ? $this->labels['en'] : null,
|
||||||
|
':label_fr' => isset($this->labels['fr']) ? $this->labels['fr'] : null,
|
||||||
|
':label_de' => isset($this->labels['de']) ? $this->labels['de'] : null,
|
||||||
|
':label_nl' => isset($this->labels['nl']) ? $this->labels['nl'] : null
|
||||||
);
|
);
|
||||||
|
|
||||||
$stmt = $connbas->prepare($sql);
|
$stmt = $connbas->prepare($sql);
|
||||||
@@ -431,6 +451,45 @@ class databox_field implements cache_cacheableInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a localized label for the field.
|
||||||
|
*
|
||||||
|
* @param string $code
|
||||||
|
* @param null|string $value
|
||||||
|
*
|
||||||
|
* @return \databox_field
|
||||||
|
*
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function set_label($code, $value)
|
||||||
|
{
|
||||||
|
if (!array_key_exists($code, $this->labels)) {
|
||||||
|
throw new InvalidArgumentException(sprintf('Code %s is not defined', $code));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->labels[$code] = $value;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a localized label for the field.
|
||||||
|
*
|
||||||
|
* @param string $code
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function get_label($code)
|
||||||
|
{
|
||||||
|
if (!array_key_exists($code, $this->labels)) {
|
||||||
|
throw new InvalidArgumentException(sprintf('Code %s is not defined', $code));
|
||||||
|
}
|
||||||
|
|
||||||
|
return isset($this->labels[$code]) ? $this->labels[$code] : $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
@@ -850,6 +909,7 @@ class databox_field implements cache_cacheableInterface
|
|||||||
return array(
|
return array(
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'sbas-id' => $this->sbas_id,
|
'sbas-id' => $this->sbas_id,
|
||||||
|
'labels' => $this->labels,
|
||||||
'name' => $this->name,
|
'name' => $this->name,
|
||||||
'tag' => $this->tag->getTagname(),
|
'tag' => $this->tag->getTagname(),
|
||||||
'business' => $this->Business,
|
'business' => $this->Business,
|
||||||
|
@@ -4620,6 +4620,38 @@
|
|||||||
<default>0</default>
|
<default>0</default>
|
||||||
<comment></comment>
|
<comment></comment>
|
||||||
</field>
|
</field>
|
||||||
|
<field>
|
||||||
|
<name>label_en</name>
|
||||||
|
<type>char(128)</type>
|
||||||
|
<null>YES</null>
|
||||||
|
<extra></extra>
|
||||||
|
<default></default>
|
||||||
|
<comment></comment>
|
||||||
|
</field>
|
||||||
|
<field>
|
||||||
|
<name>label_fr</name>
|
||||||
|
<type>char(128)</type>
|
||||||
|
<null>YES</null>
|
||||||
|
<extra></extra>
|
||||||
|
<default></default>
|
||||||
|
<comment></comment>
|
||||||
|
</field>
|
||||||
|
<field>
|
||||||
|
<name>label_de</name>
|
||||||
|
<type>char(128)</type>
|
||||||
|
<null>YES</null>
|
||||||
|
<extra></extra>
|
||||||
|
<default></default>
|
||||||
|
<comment></comment>
|
||||||
|
</field>
|
||||||
|
<field>
|
||||||
|
<name>label_nl</name>
|
||||||
|
<type>char(128)</type>
|
||||||
|
<null>YES</null>
|
||||||
|
<extra></extra>
|
||||||
|
<default></default>
|
||||||
|
<comment></comment>
|
||||||
|
</field>
|
||||||
</fields>
|
</fields>
|
||||||
<indexes>
|
<indexes>
|
||||||
<index>
|
<index>
|
||||||
|
@@ -721,6 +721,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
|||||||
$this->assertArrayHasKey('separator', $metadatas);
|
$this->assertArrayHasKey('separator', $metadatas);
|
||||||
$this->assertArrayHasKey('thesaurus_branch', $metadatas);
|
$this->assertArrayHasKey('thesaurus_branch', $metadatas);
|
||||||
$this->assertArrayHasKey('type', $metadatas);
|
$this->assertArrayHasKey('type', $metadatas);
|
||||||
|
$this->assertArrayHasKey('labels', $metadatas);
|
||||||
$this->assertArrayHasKey('indexable', $metadatas);
|
$this->assertArrayHasKey('indexable', $metadatas);
|
||||||
$this->assertArrayHasKey('multivalue', $metadatas);
|
$this->assertArrayHasKey('multivalue', $metadatas);
|
||||||
$this->assertArrayHasKey('readonly', $metadatas);
|
$this->assertArrayHasKey('readonly', $metadatas);
|
||||||
@@ -729,11 +730,14 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
|||||||
$this->assertTrue(is_int($metadatas['id']));
|
$this->assertTrue(is_int($metadatas['id']));
|
||||||
$this->assertTrue(is_string($metadatas['namespace']));
|
$this->assertTrue(is_string($metadatas['namespace']));
|
||||||
$this->assertTrue(is_string($metadatas['name']));
|
$this->assertTrue(is_string($metadatas['name']));
|
||||||
|
$this->assertTrue(is_array($metadatas['labels']));
|
||||||
$this->assertTrue(is_null($metadatas['source']) || is_string($metadatas['source']));
|
$this->assertTrue(is_null($metadatas['source']) || is_string($metadatas['source']));
|
||||||
$this->assertTrue(is_string($metadatas['tagname']));
|
$this->assertTrue(is_string($metadatas['tagname']));
|
||||||
$this->assertTrue((strlen($metadatas['name']) > 0));
|
$this->assertTrue((strlen($metadatas['name']) > 0));
|
||||||
$this->assertTrue(is_string($metadatas['separator']));
|
$this->assertTrue(is_string($metadatas['separator']));
|
||||||
|
|
||||||
|
$this->assertEquals(array('fr', 'en', 'de', 'nl'), array_keys($metadatas['labels']));
|
||||||
|
|
||||||
if ($metadatas['multivalue']) {
|
if ($metadatas['multivalue']) {
|
||||||
$this->assertTrue((strlen($metadatas['separator']) > 0));
|
$this->assertTrue((strlen($metadatas['separator']) > 0));
|
||||||
}
|
}
|
||||||
@@ -2489,6 +2493,10 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
|||||||
$this->assertArrayHasKey('name', $meta);
|
$this->assertArrayHasKey('name', $meta);
|
||||||
$this->assertTrue(is_string($meta['name']));
|
$this->assertTrue(is_string($meta['name']));
|
||||||
$this->assertArrayHasKey('value', $meta);
|
$this->assertArrayHasKey('value', $meta);
|
||||||
|
$this->assertArrayHasKey('labels', $meta);
|
||||||
|
$this->assertTrue(is_array($meta['labels']));
|
||||||
|
|
||||||
|
$this->assertEquals(array('fr', 'en', 'de', 'nl'), array_keys($meta['labels']));
|
||||||
|
|
||||||
if (is_array($meta['value'])) {
|
if (is_array($meta['value'])) {
|
||||||
foreach ($meta['value'] as $val) {
|
foreach ($meta['value'] as $val) {
|
||||||
|
@@ -223,6 +223,12 @@ class ControllerFieldsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
|||||||
'business' => false,
|
'business' => false,
|
||||||
'indexable' => true,
|
'indexable' => true,
|
||||||
'required' => true,
|
'required' => true,
|
||||||
|
'labels' => array(
|
||||||
|
'en' => 'Label',
|
||||||
|
'fr' => 'Libellé',
|
||||||
|
'de' => null,
|
||||||
|
'nl' => null,
|
||||||
|
),
|
||||||
'separator' => '=;',
|
'separator' => '=;',
|
||||||
'readonly' => false,
|
'readonly' => false,
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Application;
|
||||||
|
|
||||||
class databox_fieldTest extends PhraseanetPHPUnitAbstract
|
class databox_fieldTest extends PhraseanetPHPUnitAbstract
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -336,6 +338,54 @@ class databox_fieldTest extends PhraseanetPHPUnitAbstract
|
|||||||
$this->assertFalse($this->object_multi->is_on_error());
|
$this->assertFalse($this->object_multi->is_on_error());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider provideLanguageCodes
|
||||||
|
*/
|
||||||
|
public function testGetSetLabel($code)
|
||||||
|
{
|
||||||
|
$this->object_mono->set_label($code, 'value')->save();
|
||||||
|
$this->assertSame('value', $this->object_mono->get_label($code));
|
||||||
|
|
||||||
|
$this->object_mono->set_label($code, null)->save();
|
||||||
|
$this->assertEquals($this->object_mono->get_name(), $this->object_mono->get_label($code));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideLanguageCodes()
|
||||||
|
{
|
||||||
|
$codes = array();
|
||||||
|
|
||||||
|
foreach (Application::getAvailableLanguages() as $code => $language) {
|
||||||
|
$data = explode('_', $code);
|
||||||
|
$codes[] = array($data[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $codes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException Alchemy\Phrasea\Exception\InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testGetInvalidCodeLabel()
|
||||||
|
{
|
||||||
|
$this->object_mono->get_label('gloubi');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException Alchemy\Phrasea\Exception\InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testSetNullInvalidCodeLabel()
|
||||||
|
{
|
||||||
|
$this->object_mono->set_label('gloubi', null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException Alchemy\Phrasea\Exception\InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testSetInvalidCodeLabel()
|
||||||
|
{
|
||||||
|
$this->object_mono->set_label('gloubi', 'value');
|
||||||
|
}
|
||||||
|
|
||||||
public function testRenameField()
|
public function testRenameField()
|
||||||
{
|
{
|
||||||
$AddedValue = 'scalar value';
|
$AddedValue = 'scalar value';
|
||||||
|
Reference in New Issue
Block a user