diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Description.php b/lib/Alchemy/Phrasea/Controller/Admin/Description.php index 2fc6ac1edc..153acc906f 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Description.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Description.php @@ -32,6 +32,131 @@ class Description implements ControllerProviderInterface $controllers = new ControllerCollection(); + $controllers->get('/metadatas/search/', function(Application $app, Request $request) { + + $term = trim(strtolower($request->get('term'))); + $res = array(); + + if ($term) { + $provider = new \PHPExiftool\Driver\TagProvider(); + + $table = $provider->getLookupTable(); + $table['phraseanet'] = array( + 'pdftext' => array( + 'tagname' => 'PdfText', + 'classname' => '\\Alchemy\\Phrasea\\Metadata\\Tag\\PdfText', + 'namespace' => 'Phraseanet'), + 'tfarchivedate' => array( + 'tagname' => 'TfArchivedate', + 'classname' => '\\Alchemy\\Phrasea\\Metadata\\Tag\\TfArchivedate', + 'namespace' => 'Phraseanet' + ), + 'tfatime' => array( + 'tagname' => 'TfAtime', + 'classname' => '\\Alchemy\\Phrasea\\Metadata\\Tag\\TfAtime', + 'namespace' => 'Phraseanet' + ), + 'tfbits' => array( + 'tagname' => 'TfBits', + 'classname' => '\\Alchemy\\Phrasea\\Metadata\\Tag\\TfBits', + 'namespace' => 'Phraseanet' + ), + 'tfbasename' => array( + 'tagname' => 'TfBasename', + 'classname' => '\\Alchemy\\Phrasea\\Metadata\\Tag\\TfBasename', + 'namespace' => 'Phraseanet'), + 'tfchannels' => array( + 'tagname' => 'TfChannels', + 'classname' => '\\Alchemy\\Phrasea\\Metadata\\Tag\\TfChannels', + 'namespace' => 'Phraseanet' + ), + 'tTfCtime' => array( + 'tagname' => 'TfCtime', + 'classname' => '\\Alchemy\\Phrasea\\Metadata\\Tag\\TfCtime', + 'namespace' => 'Phraseanet' + ), + 'tfduration' => array( + 'tagname' => 'TfDuration', + 'classname' => '\\Alchemy\\Phrasea\\Metadata\\Tag\\TfDuration', + 'namespace' => 'Phraseanet' + ), + 'tfeditdate' => array( + 'tagname' => 'TfEditdate', + 'classname' => '\\Alchemy\\Phrasea\\Metadata\\Tag\\TfEditdate', + 'namespace' => 'Phraseanet' + ), + 'tfextension' => array( + 'tagname' => 'TfExtension', + 'classname' => '\\Alchemy\\Phrasea\\Metadata\\Tag\\TfExtension', + 'namespace' => 'Phraseanet' + ), + 'tffilename' => array( + 'tagname' => 'TfFilename', + 'classname' => '\\Alchemy\\Phrasea\\Metadata\\Tag\\TfFilename', + 'namespace' => 'Phraseanet' + ), + 'tffilepath' => array( + 'tagname' => 'TfFilepath', + 'classname' => '\\Alchemy\\Phrasea\\Metadata\\Tag\\TfFilepath', + 'namespace' => 'Phraseanet' + ), + 'tfheight' => array( + 'tagname' => 'TfHeight', + 'classname' => '\\Alchemy\\Phrasea\\Metadata\\Tag\\TfHeight', + 'namespace' => 'Phraseanet' + ), + 'tfmimetype' => array( + 'tagname' => 'TfMimetype', + 'classname' => '\\Alchemy\\Phrasea\\Metadata\\Tag\\TfMimetype', + 'namespace' => 'Phraseanet' + ), + 'tfmtime' => array( + 'tagname' => 'TfMtime', + 'classname' => '\\Alchemy\\Phrasea\\Metadata\\Tag\\TfMtime', + 'namespace' => 'Phraseanet' + ), + 'tfdirname' => array( + 'tagname' => 'TfDirname', + 'classname' => '\\Alchemy\\Phrasea\\Metadata\\Tag\\TfDirname', + 'namespace' => 'Phraseanet' + ), + 'tfrecordid' => array( + 'tagname' => 'TfRecordid', + 'classname' => '\\Alchemy\\Phrasea\\Metadata\\Tag\\TfRecordid', + 'namespace' => 'Phraseanet' + ), + 'tfsize' => array( + 'tagname' => 'TfSize', + 'classname' => '\\Alchemy\\Phrasea\\Metadata\\Tag\\TfSize', + 'namespace' => 'Phraseanet' + ), + 'tfwidth' => array( + 'tagname' => 'TfWidth', + 'classname' => '\\Alchemy\\Phrasea\\Metadata\\Tag\\TfWidth', + 'namespace' => 'Phraseanet' + ), + ); + + foreach ($table as $namespace => $tags) { + $ns = strpos($namespace, $term); + + foreach ($tags as $tagname => $datas) { + if ($ns === false && strpos($tagname, $term) === false) { + continue; + } + + $res[] = array( + 'id' => $namespace . '/' . $tagname, + 'label' => $datas['namespace'] . ' / ' . $datas['tagname'], + 'value' => $datas['namespace'] . ':' . $datas['tagname'], + ); + } + } + } + + return new \Symfony\Component\HttpFoundation\JsonResponse($res); + }); + $controllers->post('/{sbas_id}/', function(Application $app, $sbas_id) { $Core = $app['Core']; $user = $Core->getAuthenticatedUser(); @@ -44,7 +169,6 @@ class Description implements ControllerProviderInterface $databox = \databox::get_instance((int) $sbas_id); $fields = $databox->get_meta_structure(); - $available_fields = \databox::get_available_metadatas(); $available_dc_fields = $databox->get_available_dcfields(); @@ -76,7 +200,7 @@ class Description implements ControllerProviderInterface $field->setVocabularyControl($vocabulary); $field->setVocabularyRestricted($request->get('vocabularyrestricted_' . $id)); } catch (\Exception $e) { - + } $dces_element = null; @@ -103,7 +227,7 @@ class Description implements ControllerProviderInterface $field = \databox_field::get_instance($databox, $id); $field->delete(); } catch (\Exception $e) { - + } } } @@ -132,14 +256,12 @@ class Description implements ControllerProviderInterface $databox = \databox::get_instance((int) $sbas_id); $fields = $databox->get_meta_structure(); - $available_fields = \databox::get_available_metadatas(); $available_dc_fields = $databox->get_available_dcfields(); $params = array( 'databox' => $databox, 'fields' => $fields, - 'available_fields' => $available_fields, 'available_dc_fields' => $available_dc_fields, 'vocabularies' => \Alchemy\Phrasea\Vocabulary\Controller::getAvailable(), ); diff --git a/lib/classes/databox.class.php b/lib/classes/databox.class.php index 1945d6aeb5..1a6b1a16cd 100644 --- a/lib/classes/databox.class.php +++ b/lib/classes/databox.class.php @@ -649,44 +649,6 @@ class databox extends base return sprintf("%s@%s:%s (MySQL %s)", $this->dbname, $this->host, $this->port, $this->get_connection()->server_info()); } - /** - * Return an array of available metadata objects - * - * @return Array - */ - public static function get_available_metadatas() - { - $provider = new PHPExiftool\Driver\TagProvider(); - - $available = $provider->getAll(); - - $available['Phraseanet'] = array( - 'PdfText' => new \Alchemy\Phrasea\Metadata\Tag\PdfText(), - 'TfArchivedate' => new \Alchemy\Phrasea\Metadata\Tag\TfArchivedate(), - 'TfAtime' => new \Alchemy\Phrasea\Metadata\Tag\TfAtime(), - 'TfBits' => new \Alchemy\Phrasea\Metadata\Tag\TfBits(), - 'TfBasename' => new \Alchemy\Phrasea\Metadata\Tag\TfBasename(), - 'TfChannels' => new \Alchemy\Phrasea\Metadata\Tag\TfChannels(), - 'TfCtime' => new \Alchemy\Phrasea\Metadata\Tag\TfCtime(), - 'TfDuration' => new \Alchemy\Phrasea\Metadata\Tag\TfDuration(), - 'TfEditdate' => new \Alchemy\Phrasea\Metadata\Tag\TfEditdate(), - 'TfExtension' => new \Alchemy\Phrasea\Metadata\Tag\TfExtension(), - 'TfFilename' => new \Alchemy\Phrasea\Metadata\Tag\TfFilename(), - 'TfFilepath' => new \Alchemy\Phrasea\Metadata\Tag\TfFilepath(), - 'TfHeight' => new \Alchemy\Phrasea\Metadata\Tag\TfHeight(), - 'TfMimetype' => new \Alchemy\Phrasea\Metadata\Tag\TfMimetype(), - 'TfMtime' => new \Alchemy\Phrasea\Metadata\Tag\TfMtime(), - 'TfDirname' => new \Alchemy\Phrasea\Metadata\Tag\TfDirname(), - 'TfRecordid' => new \Alchemy\Phrasea\Metadata\Tag\TfRecordid(), - 'TfSize' => new \Alchemy\Phrasea\Metadata\Tag\TfSize(), - 'TfWidth' => new \Alchemy\Phrasea\Metadata\Tag\TfWidth(), - ); - - ksort($available); - - return $available; - } - public function get_available_dcfields() { return array( diff --git a/templates/web/admin/databox/doc_structure.twig b/templates/web/admin/databox/doc_structure.twig index 7d7bf200bc..e2f480222c 100644 --- a/templates/web/admin/databox/doc_structure.twig +++ b/templates/web/admin/databox/doc_structure.twig @@ -1,379 +1,350 @@ - {% macro dces_selector(available_dc_sources, selected_field) %} - {% set disabled = '' %} - {% if selected_field.is_on_error() %} - {% set disabled = 'disabled="disabled"' %} - {% endif %} - + {% set disabled = '' %} + {% if selected_field.is_on_error() %} + {% set disabled = 'disabled="disabled"' %} + {% endif %} + {% endmacro %} {% macro thumbtitle_selector(title) %} - - - - - - + + + + + + {% endmacro %} - - - - - - - + + + + - - + + - + -
+
+
-
-
+ + - - - - - - - - - - - - - - - - - - - - - - {% for field in fields %} - {% set disabled = '' %} - {% if field.is_on_error() %} - {% set disabled = 'disabled="disabled"' %} - {% endif %} - - - - - - - + + + + + + + + + + + + + + + + + + + + + + {% for field in fields %} + {% set disabled = '' %} + {% if field.is_on_error() %} + {% set disabled = 'disabled="disabled"' %} + {% endif %} + + + + + + + - - + + - - - - - - - - - - {% endfor %} - -
- - {% trans 'Nom' %} - - {% trans 'Source' %}Source - - DCES - - {% trans 'Multivalue' %} - - {% trans 'Indexable' %} - - {% trans 'Vocabulary Type' %} - - {% trans 'Vocabulary restricted' %} - - {% trans 'Required' %} - - {% trans 'Lecture seule' %} - - {% trans 'Type' %} - - {% trans 'Separateur' %} - - {% trans 'Branche Thesaurus' %} - - {% trans 'Affiche dans report' %} - - {% trans 'Afficher en titre' %} - - {% trans 'Business Field' %} -
- - - - - - {{ field.get_tag().getGroupName() }} / {{ field.get_tag().getName() }} change - - - {{_self.dces_selector(available_dc_fields, field)}} - - - - - - -
{% trans 'Nom' %}{% trans 'Source' %}SourceDCES{% trans 'Multivalue' %}{% trans 'Indexable' %}{% trans 'Vocabulary Type' %}{% trans 'Vocabulary restricted' %}{% trans 'Required' %}{% trans 'Lecture seule' %}{% trans 'Type' %}{% trans 'Separateur' %}{% trans 'Branche Thesaurus' %}{% trans 'Affiche dans report' %}{% trans 'Afficher en titre' %}{% trans 'Business Field' %}
+ + + + + + + + + {{ field.get_tag().getGroupName() }}:{{ field.get_tag().getName() }} change + + + {{ _self.dces_selector(available_dc_fields, field) }} + + + + + + + - {% if field.is_multi() %} - - {% endif %} - - - + {% if field.is_multi() %} + + {% endif %} + + + - - - - - - - - - - - - - - - - - -
- -
- - + + + + + + + + + + + + + + + + + + + + + + + + + + + + {% endfor %} + + + + + + diff --git a/tests/Alchemy/Phrasea/Controller/Admin/DescriptionTest.php b/tests/Alchemy/Phrasea/Controller/Admin/DescriptionTest.php index 3dc51c2d3d..0c97f210b3 100644 --- a/tests/Alchemy/Phrasea/Controller/Admin/DescriptionTest.php +++ b/tests/Alchemy/Phrasea/Controller/Admin/DescriptionTest.php @@ -242,4 +242,23 @@ class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->client->request("GET", "/description/" . $databox->get_sbas_id() . "/"); $this->assertTrue($this->client->getResponse()->isOk()); } + + public function testGetMetadatas() + { + $appbox = appbox::get_instance(\bootstrap::getCore()); + $databox = array_shift($appbox->get_databoxes()); + + $this->client->request("GET", "/description/metadatas/search/", array('term'=>'')); + $this->assertTrue($this->client->getResponse()->isOk()); + + $datas = json_decode($this->client->getResponse()->getContent(), true); + $this->assertEquals(array(), $datas); + + $this->client->request("GET", "/description/metadatas/search/", array('term'=>'xmp')); + $this->assertTrue($this->client->getResponse()->isOk()); + + $datas = json_decode($this->client->getResponse()->getContent(), true); + $this->assertTrue(is_array($datas)); + $this->assertGreaterThan(0, count($datas)); + } }