PHRAS-752 #time 4h

fix : tf-* (phraseanet) admin / field / source does not says "invalid"
add : better completion for field source : now can type things like "phr:tim" to match namespace(s) and tagname(s)
This commit is contained in:
Jean-Yves Gaulier
2015-10-13 17:23:52 +02:00
parent cb98ac8216
commit bb67a1a4bc
3 changed files with 64 additions and 39 deletions

View File

@@ -119,26 +119,40 @@ class FieldsController extends Controller
public function searchTag(Request $request) public function searchTag(Request $request)
{ {
$term = trim(strtolower($request->query->get('term'))); $term = str_replace(['/', ':', '.'], ' ', strtolower($request->query->get('term')));
$res = []; $res = [];
if ($term) { $term = explode(' ', $term, 2);
if(($term[0] = trim($term[0])) != '') {
if( ($nparts = count($term)) == 2) {
$term[1] = trim($term[1]);
}
$provider = new TagProvider(); $provider = new TagProvider();
foreach ($provider->getLookupTable() as $namespace => $tags) { foreach ($provider->getLookupTable() as $namespace => $tags) {
$ns = strpos($namespace, $term); $match_ns = (strpos($namespace, $term[0]) !== false);
if($nparts == 2 && !$match_ns) {
// with "abc:xyz", "abc" MUST match the namespace
continue;
}
foreach ($tags as $tagname => $datas) { foreach ($tags as $tagname => $datas) {
if ($ns === false && strpos($tagname, $term) === false) { if($nparts == 1) {
continue; // "abc" can match the namespace OR the tagname
$match = $match_ns || (strpos($tagname, $term[0]) !== false);
}
else {
// match "abc:xyz" against namespace (already true) AND tagname
$match = ($term[1] == '' || strpos($tagname, $term[1]) !== false);
} }
$res[] = [ if($match) {
'id' => $namespace . '/' . $tagname, $res[] = [
/** @Ignore */ 'id' => $namespace . '/' . $tagname,
'label' => $datas['namespace'] . ' / ' . $datas['tagname'], /** @Ignore */
'value' => $datas['namespace'] . ':' . $datas['tagname'], 'label' => $datas['namespace'] . ' / ' . $datas['tagname'],
]; 'value' => $datas['namespace'] . ':' . $datas['tagname'],
];
}
} }
} }
} }

View File

@@ -10,43 +10,54 @@
namespace Alchemy\Phrasea\Metadata; namespace Alchemy\Phrasea\Metadata;
use PHPExiftool\Driver\TagFactory as BaseTagFactory; use PHPExiftool\Driver\TagFactory as BaseTagFactory;
use PHPExiftool\Exception\TagUnknown;
class TagFactory extends BaseTagFactory class TagFactory extends BaseTagFactory
{ {
protected static $knownClasses = [ protected static $knownClasses = [
'pdf-text' => 'Alchemy\Phrasea\Metadata\Tag\PdfText', 'pdftext' => 'Alchemy\Phrasea\Metadata\Tag\PdfText',
'tf-archivedate' => 'Alchemy\Phrasea\Metadata\Tag\TfArchivedate', 'tfarchivedate' => 'Alchemy\Phrasea\Metadata\Tag\TfArchivedate',
'tf-atime' => 'Alchemy\Phrasea\Metadata\Tag\TfAtime', 'tfatime' => 'Alchemy\Phrasea\Metadata\Tag\TfAtime',
'tf-basename' => 'Alchemy\Phrasea\Metadata\Tag\TfBasename', 'tfbasename' => 'Alchemy\Phrasea\Metadata\Tag\TfBasename',
'tf-bits' => 'Alchemy\Phrasea\Metadata\Tag\TfBits', 'tfbits' => 'Alchemy\Phrasea\Metadata\Tag\TfBits',
'tf-channels' => 'Alchemy\Phrasea\Metadata\Tag\TfChannels', 'tfchannels' => 'Alchemy\Phrasea\Metadata\Tag\TfChannels',
'tf-ctime' => 'Alchemy\Phrasea\Metadata\Tag\TfCtime', 'tfctime' => 'Alchemy\Phrasea\Metadata\Tag\TfCtime',
'tf-dirname' => 'Alchemy\Phrasea\Metadata\Tag\TfDirname', 'tfdirname' => 'Alchemy\Phrasea\Metadata\Tag\TfDirname',
'tf-duration' => 'Alchemy\Phrasea\Metadata\Tag\TfDuration', 'tfduration' => 'Alchemy\Phrasea\Metadata\Tag\TfDuration',
'tf-editdate' => 'Alchemy\Phrasea\Metadata\Tag\TfEditdate', 'tfeditdate' => 'Alchemy\Phrasea\Metadata\Tag\TfEditdate',
'tf-extension' => 'Alchemy\Phrasea\Metadata\Tag\TfExtension', 'tfextension' => 'Alchemy\Phrasea\Metadata\Tag\TfExtension',
'tf-filename' => 'Alchemy\Phrasea\Metadata\Tag\TfFilename', 'tffilename' => 'Alchemy\Phrasea\Metadata\Tag\TfFilename',
'tf-filepath' => 'Alchemy\Phrasea\Metadata\Tag\TfFilepath', 'tffilepath' => 'Alchemy\Phrasea\Metadata\Tag\TfFilepath',
'tf-height' => 'Alchemy\Phrasea\Metadata\Tag\TfHeight', 'tfheight' => 'Alchemy\Phrasea\Metadata\Tag\TfHeight',
'tf-mimetype' => 'Alchemy\Phrasea\Metadata\Tag\TfMimetype', 'tfmimetype' => 'Alchemy\Phrasea\Metadata\Tag\TfMimetype',
'tf-mtime' => 'Alchemy\Phrasea\Metadata\Tag\TfMtime', 'tfmtime' => 'Alchemy\Phrasea\Metadata\Tag\TfMtime',
'tf-quarantine' => 'Alchemy\Phrasea\Metadata\Tag\TfQuarantine', 'tfquarantine' => 'Alchemy\Phrasea\Metadata\Tag\TfQuarantine',
'tf-recordid' => 'Alchemy\Phrasea\Metadata\Tag\TfRecordid', 'tfrecordid' => 'Alchemy\Phrasea\Metadata\Tag\TfRecordid',
'tf-size' => 'Alchemy\Phrasea\Metadata\Tag\TfSize', 'tfsize' => 'Alchemy\Phrasea\Metadata\Tag\TfSize',
'tf-width' => 'Alchemy\Phrasea\Metadata\Tag\TfWidth', 'tfwidth' => 'Alchemy\Phrasea\Metadata\Tag\TfWidth',
]; ];
public static function getFromTagname($tagname)
{
$classname = static::classnameFromTagname($tagname);
if ( ! class_exists($classname)) {
throw new TagUnknown(sprintf('Unknown tag %s', $tagname));
}
return new $classname;
}
protected static function classnameFromTagname($tagname) protected static function classnameFromTagname($tagname)
{ {
$tagname = str_replace('rdf:RDF/rdf:Description/', '', $tagname); $tagname = str_replace('rdf:RDF/rdf:Description/', '', $tagname);
if ('Phraseanet:' === substr($tagname, 0, 11)) { $parts = explode(':', strtolower($tagname), 2);
$parts = explode(':', $tagname, 2); if (count($parts) == 2 && $parts[0] == 'phraseanet' && isset(self::$knownClasses[$parts[1]])) {
if (isset(self::$knownClasses[$parts[1]])) { // a specific phraseanet fieldname
return self::$knownClasses[$parts[1]]; return self::$knownClasses[$parts[1]];
}
} }
// another (exiftool) fieldname ?
return parent::classnameFromTagname($tagname); return parent::classnameFromTagname($tagname);
} }
} }

View File

@@ -468,7 +468,7 @@ class databox_field implements cache_cacheableInterface
} }
try { try {
return TagFactory::getFromRDFTagname($tagName); return TagFactory::getFromTagname($tagName);
} catch (TagUnknown $exception) { } catch (TagUnknown $exception) {
if ($throwException) { if ($throwException) {
throw new NotFoundHttpException(sprintf("Tag %s not found", $tagName), $exception); throw new NotFoundHttpException(sprintf("Tag %s not found", $tagName), $exception);