Merge branch 4.0

This commit is contained in:
Thibaud Fabre
2016-12-05 15:26:48 +01:00
parent f6700fbe12
commit b5bbb1851f
315 changed files with 6552 additions and 29445 deletions

View File

@@ -564,6 +564,18 @@ class databox_field implements cache_cacheableInterface
return $this;
}
/**
*
* @param boolean $bool
* @return databox_field
*/
public function set_multi($bool)
{
$this->multi = (bool)$bool;
$this->separator = self::checkMultiSeparator($this->separator, $this->multi);
return $this;
}
/**
* Set a vocabulary
*
@@ -892,7 +904,7 @@ class databox_field implements cache_cacheableInterface
*
* @throws \Exception_InvalidArgument
*/
public static function create(Application $app, databox $databox, $name, $multi)
public static function create(Application $app, databox $databox, $name)
{
$sorter = 0;
@@ -911,8 +923,8 @@ class databox_field implements cache_cacheableInterface
`thumbtitle`, `multi`, `business`, `aggregable`,
`report`, `sorter`, `separator`)
VALUES (null, :name, '', 0, 0, 1, 'string', '',
null, :multi,
0, 0, 1, :sorter, '')";
null, 0, 0, 0,
1, :sorter, '')";
$name = self::generateName($name);
@@ -920,10 +932,8 @@ class databox_field implements cache_cacheableInterface
throw new \Exception_InvalidArgument();
}
$multi = $multi ? 1 : 0;
$stmt = $databox->get_connection()->prepare($sql);
$stmt->execute([':name' => $name, ':sorter' => $sorter, ':multi' => $multi]);
$stmt->execute([':name' => $name, ':sorter' => $sorter]);
$id = $databox->get_connection()->lastInsertId();
$stmt->closeCursor();

View File

@@ -1,5 +1,4 @@
<?php
/*
* This file is part of Phraseanet
*
@@ -9,18 +8,37 @@
* file that was distributed with this source code.
*/
use Alchemy\Phrasea\Media\Subdef\Image;
use Alchemy\Phrasea\Media\Subdef\Audio;
use Alchemy\Phrasea\Media\Subdef\Video;
use Alchemy\Phrasea\Media\Subdef\FlexPaper;
use Alchemy\Phrasea\Media\Subdef\Gif;
use Alchemy\Phrasea\Media\Subdef\Image;
use Alchemy\Phrasea\Media\Subdef\Subdef as SubdefSpecs;
use Alchemy\Phrasea\Media\Subdef\Video;
use Alchemy\Phrasea\Media\Type\Type as SubdefType;
use MediaAlchemyst\Specification\SpecificationInterface;
use Symfony\Component\Translation\TranslatorInterface;
class databox_subdef
{
const CLASS_THUMBNAIL = 'thumbnail';
const CLASS_PREVIEW = 'preview';
const CLASS_DOCUMENT = 'document';
const DEVICE_ALL = 'all';
const DEVICE_HANDHELD = 'handheld';
const DEVICE_PRINT = 'print';
const DEVICE_PROJECTION = 'projection';
const DEVICE_SCREEN = 'screen';
const DEVICE_TV = 'tv';
protected static $mediaTypeToSubdefTypes = [
SubdefType::TYPE_AUDIO => [SubdefSpecs::TYPE_IMAGE, SubdefSpecs::TYPE_AUDIO],
SubdefType::TYPE_DOCUMENT => [SubdefSpecs::TYPE_IMAGE, SubdefSpecs::TYPE_FLEXPAPER],
SubdefType::TYPE_FLASH => [SubdefSpecs::TYPE_IMAGE],
SubdefType::TYPE_IMAGE => [SubdefSpecs::TYPE_IMAGE],
SubdefType::TYPE_VIDEO => [SubdefSpecs::TYPE_IMAGE, SubdefSpecs::TYPE_VIDEO, SubdefSpecs::TYPE_ANIMATION],
];
/**
* The class type of the subdef
* Is null or one of the CLASS_* constants
@@ -33,37 +51,23 @@ class databox_subdef
protected $path;
protected $subdef_group;
protected $labels = [];
protected $downloadable;
protected $translator;
/**
* @var bool
*/
private $requiresMetadataUpdate;
protected $downloadable;
protected $translator;
protected static $mediaTypeToSubdefTypes = [
SubdefType::TYPE_AUDIO => [SubdefSpecs::TYPE_IMAGE, SubdefSpecs::TYPE_AUDIO],
SubdefType::TYPE_DOCUMENT => [SubdefSpecs::TYPE_IMAGE, SubdefSpecs::TYPE_FLEXPAPER],
SubdefType::TYPE_FLASH => [SubdefSpecs::TYPE_IMAGE],
SubdefType::TYPE_IMAGE => [SubdefSpecs::TYPE_IMAGE],
SubdefType::TYPE_VIDEO => [SubdefSpecs::TYPE_IMAGE, SubdefSpecs::TYPE_VIDEO, SubdefSpecs::TYPE_ANIMATION],
];
const CLASS_THUMBNAIL = 'thumbnail';
const CLASS_PREVIEW = 'preview';
const CLASS_DOCUMENT = 'document';
const DEVICE_ALL = 'all';
const DEVICE_HANDHELD = 'handheld';
const DEVICE_PRINT = 'print';
const DEVICE_PROJECTION = 'projection';
const DEVICE_SCREEN = 'screen';
const DEVICE_TV = 'tv';
/**
*
* @param SubdefType $type
* @var bool
*/
private $orderable;
/**
* @param SubdefType $type
* @param SimpleXMLElement $sd
*
* @return databox_subdef
* @param TranslatorInterface $translator
*/
public function __construct(SubdefType $type, SimpleXMLElement $sd, TranslatorInterface $translator)
{
@@ -77,6 +81,7 @@ class databox_subdef
$this->name = strtolower($sd->attributes()->name);
$this->downloadable = p4field::isyes($sd->attributes()->downloadable);
$this->orderable = isset($sd->attributes()->orderable) ? p4field::isyes($sd->attributes()->orderable) : true;
$this->path = trim($sd->path) !== '' ? p4string::addEndSlash(trim($sd->path)) : '';
$this->requiresMetadataUpdate = p4field::isyes((string) $sd->meta);
@@ -110,7 +115,130 @@ class databox_subdef
}
/**
* Build Image Subdef object depending the SimpleXMLElement
*
* @param SimpleXMLElement $sd
* @return Image
*/
protected function buildImageSubdef(SimpleXMLElement $sd)
{
$image = new Image($this->translator);
if ($sd->icodec) {
$image->setOptionValue(Image::OPTION_ICODEC, (string) $sd->icodec);
}
if ($sd->size) {
$image->setOptionValue(Image::OPTION_SIZE, (int) $sd->size);
}
if ($sd->quality) {
$image->setOptionValue(Image::OPTION_QUALITY, (int) $sd->quality);
}
if ($sd->strip) {
$image->setOptionValue(Image::OPTION_STRIP, p4field::isyes($sd->strip));
}
if ($sd->dpi) {
$image->setOptionValue(Image::OPTION_RESOLUTION, (int) $sd->dpi);
}
if ($sd->flatten) {
$image->setOptionValue(Image::OPTION_FLATTEN, p4field::isyes($sd->flatten));
}
return $image;
}
/**
* Build Audio Subdef object depending the SimpleXMLElement
*
* @param SimpleXMLElement $sd
* @return Audio
*/
protected function buildAudioSubdef(SimpleXMLElement $sd)
{
$audio = new Audio($this->translator);
if ($sd->acodec) {
$audio->setOptionValue(Audio::OPTION_ACODEC, (string) $sd->acodec);
}
if ($sd->audiobitrate) {
$audio->setOptionValue(Audio::OPTION_AUDIOBITRATE, (int) $sd->audiobitrate);
}
if ($sd->audiosamplerate) {
$audio->setOptionValue(Audio::OPTION_AUDIOSAMPLERATE, (int) $sd->audiosamplerate);
}
return $audio;
}
/**
* Build Video Subdef object depending the SimpleXMLElement
*
* @param SimpleXMLElement $sd
* @return Video
*/
protected function buildVideoSubdef(SimpleXMLElement $sd)
{
$video = new Video($this->translator);
if ($sd->size) {
$video->setOptionValue(Video::OPTION_SIZE, (int) $sd->size);
}
if ($sd->acodec) {
$video->setOptionValue(Video::OPTION_ACODEC, (string) $sd->acodec);
}
if ($sd->vcodec) {
$video->setOptionValue(Video::OPTION_VCODEC, (string) $sd->vcodec);
}
if ($sd->fps) {
$video->setOptionValue(Video::OPTION_FRAMERATE, (int) $sd->fps);
}
if ($sd->bitrate) {
$video->setOptionValue(Video::OPTION_BITRATE, (int) $sd->bitrate);
}
if ($sd->audiobitrate) {
$video->setOptionValue(Video::OPTION_AUDIOBITRATE, (int) $sd->audiobitrate);
}
if ($sd->audiosamplerate) {
$video->setOptionValue(Video::OPTION_AUDIOSAMPLERATE, (int) $sd->audiosamplerate);
}
if ($sd->GOPsize) {
$video->setOptionValue(Video::OPTION_GOPSIZE, (int) $sd->GOPsize);
}
return $video;
}
/**
* Build GIF Subdef object depending the SimpleXMLElement
*
* @param SimpleXMLElement $sd
* @return Gif
*/
protected function buildGifSubdef(SimpleXMLElement $sd)
{
$gif = new Gif($this->translator);
if ($sd->size) {
$gif->setOptionValue(Gif::OPTION_SIZE, (int) $sd->size);
}
if ($sd->delay) {
$gif->setOptionValue(Gif::OPTION_DELAY, (int) $sd->delay);
}
return $gif;
}
/**
* Build Flexpaper Subdef object depending the SimpleXMLElement
*
* @param SimpleXMLElement $sd
* @return FlexPaper
*/
protected function buildFlexPaperSubdef(SimpleXMLElement $sd)
{
return new FlexPaper($this->translator);
}
/**
* @return string
*/
public function get_class()
@@ -119,7 +247,6 @@ class databox_subdef
}
/**
*
* @return string
*/
public function get_path()
@@ -130,7 +257,7 @@ class databox_subdef
/**
* The devices matching this subdefinition
*
* @return Array
* @return array
*/
public function getDevices()
{
@@ -140,7 +267,7 @@ class databox_subdef
/**
* The current SubdefType the subdef converts documents
*
* @return Alchemy\Phrasea\Media\Subdef\Subdef
* @return \Alchemy\Phrasea\Media\Subdef\Subdef
*/
public function getSubdefType()
{
@@ -160,7 +287,7 @@ class databox_subdef
/**
* An associative label ; keys are i18n languages
*
* @return Array
* @return array
*/
public function get_labels()
{
@@ -179,15 +306,31 @@ class databox_subdef
}
/**
* boolean
* The name of the subdef
*
* @return type
* @return string
*/
public function is_downloadable()
public function get_name()
{
return $this->name;
}
/**
* @return bool
*/
public function isDownloadable()
{
return $this->downloadable;
}
/**
* @return bool
*/
public function isOrderable()
{
return $this->orderable;
}
/**
* Get an array of Alchemy\Phrasea\Media\Subdef\Subdef available for the current Media Type
*
@@ -254,16 +397,6 @@ class databox_subdef
return $this->requiresMetadataUpdate;
}
/**
* The name of the subdef
*
* @return string
*/
public function get_name()
{
return $this->name;
}
/**
* Get the MediaAlchemyst specs for the current subdef
*
@@ -283,128 +416,4 @@ class databox_subdef
{
return $this->subdef_type->getOptions();
}
/**
* Build Image Subdef object depending the SimpleXMLElement
*
* @param SimpleXMLElement $sd
* @return Image
*/
protected function buildImageSubdef(SimpleXMLElement $sd)
{
$image = new Image($this->translator);
if ($sd->icodec) {
$image->setOptionValue(Image::OPTION_ICODEC, (string) $sd->icodec);
}
if ($sd->size) {
$image->setOptionValue(Image::OPTION_SIZE, (int) $sd->size);
}
if ($sd->quality) {
$image->setOptionValue(Image::OPTION_QUALITY, (int) $sd->quality);
}
if ($sd->strip) {
$image->setOptionValue(Image::OPTION_STRIP, p4field::isyes($sd->strip));
}
if ($sd->dpi) {
$image->setOptionValue(Image::OPTION_RESOLUTION, (int) $sd->dpi);
}
if ($sd->flatten) {
$image->setOptionValue(Image::OPTION_FLATTEN, p4field::isyes($sd->flatten));
}
return $image;
}
/**
* Build Audio Subdef object depending the SimpleXMLElement
*
* @param SimpleXMLElement $sd
* @return Audio
*/
protected function buildAudioSubdef(SimpleXMLElement $sd)
{
$audio = new Audio($this->translator);
if ($sd->acodec) {
$audio->setOptionValue(Audio::OPTION_ACODEC, (string) $sd->acodec);
}
if ($sd->audiobitrate) {
$audio->setOptionValue(Audio::OPTION_AUDIOBITRATE, (int) $sd->audiobitrate);
}
if ($sd->audiosamplerate) {
$audio->setOptionValue(Audio::OPTION_AUDIOSAMPLERATE, (int) $sd->audiosamplerate);
}
return $audio;
}
/**
* Build Flexpaper Subdef object depending the SimpleXMLElement
*
* @param SimpleXMLElement $sd
* @return \Alchemy\Phrasea\Media\Subdef\Video
*/
protected function buildFlexPaperSubdef(SimpleXMLElement $sd)
{
return new FlexPaper($this->translator);
}
/**
* Build GIF Subdef object depending the SimpleXMLElement
*
* @param SimpleXMLElement $sd
* @return Gif
*/
protected function buildGifSubdef(SimpleXMLElement $sd)
{
$gif = new Gif($this->translator);
if ($sd->size) {
$gif->setOptionValue(Gif::OPTION_SIZE, (int) $sd->size);
}
if ($sd->delay) {
$gif->setOptionValue(Gif::OPTION_DELAY, (int) $sd->delay);
}
return $gif;
}
/**
* Build Video Subdef object depending the SimpleXMLElement
*
* @param SimpleXMLElement $sd
* @return Video
*/
protected function buildVideoSubdef(SimpleXMLElement $sd)
{
$video = new Video($this->translator);
if ($sd->size) {
$video->setOptionValue(Video::OPTION_SIZE, (int) $sd->size);
}
if ($sd->acodec) {
$video->setOptionValue(Video::OPTION_ACODEC, (string) $sd->acodec);
}
if ($sd->vcodec) {
$video->setOptionValue(Video::OPTION_VCODEC, (string) $sd->vcodec);
}
if ($sd->fps) {
$video->setOptionValue(Video::OPTION_FRAMERATE, (int) $sd->fps);
}
if ($sd->bitrate) {
$video->setOptionValue(Video::OPTION_BITRATE, (int) $sd->bitrate);
}
if ($sd->audiobitrate) {
$video->setOptionValue(Video::OPTION_AUDIOBITRATE, (int) $sd->audiobitrate);
}
if ($sd->audiosamplerate) {
$video->setOptionValue(Video::OPTION_AUDIOSAMPLERATE, (int) $sd->audiosamplerate);
}
if ($sd->GOPsize) {
$video->setOptionValue(Video::OPTION_GOPSIZE, (int) $sd->GOPsize);
}
return $video;
}
}

View File

@@ -10,6 +10,7 @@
use Alchemy\Phrasea\Databox\SubdefGroup;
use Alchemy\Phrasea\Media\MediaTypeFactory;
use Assert\Assertion;
use Symfony\Component\Translation\TranslatorInterface;
class databox_subdefsStructure implements IteratorAggregate, Countable
@@ -215,6 +216,25 @@ class databox_subdefsStructure implements IteratorAggregate, Countable
return $this;
}
/**
* @param SubdefGroup[] $groups
*/
public function updateSubdefGroups($groups)
{
Assertion::allIsInstanceOf($groups, SubdefGroup::class);
$dom_xp = $this->databox->get_xpath_structure();
foreach ($groups as $group) {
$nodes = $dom_xp->query('//record/subdefs/subdefgroup[@name="' . $group->getName() . '"]');
/** @var DOMElement $node */
foreach ($nodes as $node) {
$node->setAttribute('document_orderable', ($group->isDocumentOrderable() ? 'true' : 'false'));
}
}
}
/**
* @param string $group
* @param string $name
@@ -222,10 +242,11 @@ class databox_subdefsStructure implements IteratorAggregate, Countable
* @param boolean $downloadable
* @param array $options
* @param array $labels
* @param bool $orderable
* @return databox_subdefsStructure
* @throws Exception
*/
public function set_subdef($group, $name, $class, $downloadable, $options, $labels)
public function set_subdef($group, $name, $class, $downloadable, $options, $labels, $orderable = true)
{
$dom_struct = $this->databox->get_dom_structure();
@@ -233,6 +254,7 @@ class databox_subdefsStructure implements IteratorAggregate, Countable
$subdef->setAttribute('class', $class);
$subdef->setAttribute('name', mb_strtolower($name));
$subdef->setAttribute('downloadable', ($downloadable ? 'true' : 'false'));
$subdef->setAttribute('orderable', ($orderable ? 'true' : 'false'));
foreach ($labels as $code => $label) {
$child = $dom_struct->createElement('label');