Load metadata tab content when tab activate

This commit is contained in:
aina-esokia
2018-02-19 14:51:30 +04:00
parent d45c55858f
commit b36b90a403
7 changed files with 178 additions and 83 deletions

View File

@@ -55,6 +55,7 @@ class RouteLoader
'/prod/records/property' => Providers\Prod\Property::class,
'/prod/share/' => Providers\Prod\Share::class,
'/prod/story' => Providers\Prod\Story::class,
'/prod/subdefs' => Providers\Prod\Subdefs::class,
'/prod/tools/' => Providers\Prod\Tools::class,
'/prod/tooltip' => Providers\Prod\Tooltip::class,
'/prod/TOU/' => Providers\Prod\TOU::class,

View File

@@ -0,0 +1,61 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller\Prod;
use Alchemy\Phrasea\Controller\Controller;
use PHPExiftool\Driver\Metadata\Metadata;
use PHPExiftool\Driver\Metadata\MetadataBag;
use PHPExiftool\Driver\TagFactory;
use PHPExiftool\Driver\Value\Mono;
use PHPExiftool\Reader;
class SubdefsController extends Controller
{
public function metadataAction($databox_id, $record_id, $subdef_name)
{
$record = new \record_adapter($this->app, (int) $databox_id, (int) $record_id);
try {
$metadataBag = new MetadataBag();
$fileEntity = $this->getExifToolReader()
->files($record->get_subdef($subdef_name)->getRealPath())
->first();
$metadatas = $fileEntity->getMetadatas();
foreach($metadatas as $metadata){
$valuedata = $fileEntity->executeQuery($metadata->getTag()->getTagname()."[not(@rdf:datatype = 'http://www.w3.org/2001/XMLSchema#base64Binary')]");
if(empty($valuedata)){
$valuedata = new Mono($this->app->trans('Binary data'));
$tag = TagFactory::getFromRDFTagname($metadata->getTag()->getTagname());
$metadataBagElement = new Metadata($tag, $valuedata);
$metadataBag->set($metadata->getTag()->getTagname(), $metadataBagElement);
}else{
$metadataBag->set($metadata->getTag()->getTagname(), $metadata);
}
}
} catch (PHPExiftoolException $e) {
// ignore
} catch (\Exception_Media_SubdefNotFound $e) {
// ignore
}
return $this->render('prod/actions/Tools/metadata.html.twig', [
'record' => $record,
'metadatas' => $metadataBag,
]);
}
/**
* @return Reader
*/
private function getExifToolReader()
{
return $this->app['exiftool.reader'];
}
}

View File

@@ -23,11 +23,6 @@ use Alchemy\Phrasea\Record\RecordWasRotated;
use DataURI\Parser;
use MediaAlchemyst\Alchemyst;
use MediaVorus\MediaVorus;
use PHPExiftool\Driver\Metadata\Metadata;
use PHPExiftool\Driver\Metadata\MetadataBag;
use PHPExiftool\Driver\TagFactory;
use PHPExiftool\Driver\Value\Mono;
use PHPExiftool\Exception\ExceptionInterface as PHPExiftoolException;
use PHPExiftool\Reader;
use Symfony\Component\HttpFoundation\Request;
@@ -87,13 +82,7 @@ class ToolsController extends Controller
}
}
if (!$record->isStory()) {
try {
$metadatas = $this->getMetadatas($record);
} catch (PHPExiftoolException $e) {
// ignore
} catch (\Exception_Media_SubdefNotFound $e) {
// ignore
}
$metadatas = true;
}
}
$conf = $this->getConf();
@@ -434,30 +423,4 @@ class ToolsController extends Controller
unset($media);
$this->getFilesystem()->remove($fileName);
}
/**
* @param $record
* @return MetadataBag
*/
private function getMetadatas($record)
{
$metadataBag = new MetadataBag();
$fileEntity = $this->getExifToolReader()
->files($record->get_subdef('document')->getRealPath())
->first();
$metadatas = $fileEntity->getMetadatas();
foreach($metadatas as $metadata){
$valuedata = $fileEntity->executeQuery($metadata->getTag()->getTagname()."[not(@rdf:datatype = 'http://www.w3.org/2001/XMLSchema#base64Binary')]");
if(empty($valuedata)){
$valuedata = new Mono($this->app->trans('Binary data'));
$tag = TagFactory::getFromRDFTagname($metadata->getTag()->getTagname());
$metadataBagElement = new Metadata($tag, $valuedata);
$metadataBag->set($metadata->getTag()->getTagname(), $metadataBagElement);
}else{
$metadataBag->set($metadata->getTag()->getTagname(), $metadata);
}
}
return $metadataBag;
}
}

View File

@@ -80,6 +80,7 @@ class ControllerProviderServiceProvider implements ServiceProviderInterface
Prod\Root::class => [],
Prod\Share::class => [],
Prod\Story::class => [],
Prod\Subdefs::class => [],
Prod\Tools::class => [],
Prod\Tooltip::class => [],
Prod\TOU::class => [],

View File

@@ -0,0 +1,45 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\ControllerProvider\Prod;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\Prod\SubdefsController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\ControllerProviderInterface;
use Silex\ServiceProviderInterface;
use Silex\Application;
class Subdefs implements ControllerProviderInterface, ServiceProviderInterface
{
use ControllerProviderTrait;
public function register(Application $app)
{
$app['controller.prod.subdefs'] = $app->share(function (PhraseaApplication $app) {
return (new SubdefsController($app));
});
}
public function boot(Application $app)
{
// no-op
}
public function connect(Application $app)
{
$controllers = $this->createAuthenticatedCollection($app);
$controllers->get('/{databox_id}/{record_id}/metadatas/{subdef_name}/', 'controller.prod.subdefs:metadataAction')
->bind('prod_subdefs_metadata');
return $controllers;
}
}