diff --git a/lib/Alchemy/Phrasea/Controller/Admin/SubdefsController.php b/lib/Alchemy/Phrasea/Controller/Admin/SubdefsController.php index 840feca115..98f5bb8773 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/SubdefsController.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/SubdefsController.php @@ -80,6 +80,7 @@ class SubdefsController extends Controller $class = $request->request->get($post_sub . '_class'); $downloadable = $request->request->get($post_sub . '_downloadable'); + $orderable = $request->request->get($post_sub . '_orderable'); $defaults = ['path', 'meta', 'mediatype']; @@ -107,7 +108,7 @@ class SubdefsController extends Controller $labels = $request->request->get($post_sub . '_label', []); - $subdefs->set_subdef($group, $name, $class, $downloadable, $options, $labels); + $subdefs->set_subdef($group, $name, $class, $downloadable, $options, $labels, $orderable); } } diff --git a/lib/classes/databox/subdef.php b/lib/classes/databox/subdef.php index 653ac83a1e..cd46f04714 100644 --- a/lib/classes/databox/subdef.php +++ b/lib/classes/databox/subdef.php @@ -1,5 +1,4 @@ [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); @@ -107,12 +112,130 @@ class databox_subdef $this->subdef_type = $this->buildFlexPaperSubdef($sd); break; } - - return $this; } /** + * Build Image Subdef object depending the SimpleXMLElement * + * @param SimpleXMLElement $sd + * @return Image + */ + protected function buildImageSubdef(SimpleXMLElement $sd) + { + $image = new Image($this->translator); + + 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() @@ -121,7 +244,6 @@ class databox_subdef } /** - * * @return string */ public function get_path() @@ -132,7 +254,7 @@ class databox_subdef /** * The devices matching this subdefinition * - * @return Array + * @return array */ public function getDevices() { @@ -142,7 +264,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() { @@ -162,7 +284,7 @@ class databox_subdef /** * An associative label ; keys are i18n languages * - * @return Array + * @return array */ public function get_labels() { @@ -181,15 +303,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 * @@ -256,16 +394,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 * @@ -285,125 +413,4 @@ class databox_subdef { return $this->subdef_type->getOptions(); } - - /** - * Build Image Subdef object depending the SimpleXMLElement - * - * @param SimpleXMLElement $sd - * @return \Alchemy\Phrasea\Media\Subdef\Video - */ - protected function buildImageSubdef(SimpleXMLElement $sd) - { - $image = new Image($this->translator); - - 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 \Alchemy\Phrasea\Media\Subdef\Video - */ - 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 \Alchemy\Phrasea\Media\Subdef\Video - */ - 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 \Alchemy\Phrasea\Media\Subdef\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; - } } diff --git a/lib/classes/databox/subdefsStructure.php b/lib/classes/databox/subdefsStructure.php index 58b0556451..4df1bc247d 100644 --- a/lib/classes/databox/subdefsStructure.php +++ b/lib/classes/databox/subdefsStructure.php @@ -223,10 +223,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(); @@ -234,6 +235,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'); diff --git a/lib/classes/patch/370alpha6a.php b/lib/classes/patch/370alpha6a.php index 7f3472c260..7219d0d12b 100644 --- a/lib/classes/patch/370alpha6a.php +++ b/lib/classes/patch/370alpha6a.php @@ -108,7 +108,7 @@ class patch_370alpha6a extends patchAbstract $options['meta'] = $subdef->isMetadataUpdateRequired() ? 'yes' : 'no'; $options['devices'] = [databox_subdef::DEVICE_SCREEN]; - $root->set_subdef($groupname, $subdef->get_name(), $subdef->get_class(), $subdef->is_downloadable(), $options, []); + $root->set_subdef($groupname, $subdef->get_name(), $subdef->get_class(), $subdef->isDownloadable(), $options, []); } protected function addMobileSubdefVideo($root, $baseSubdef, $groupname) diff --git a/lib/classes/record/exportElement.php b/lib/classes/record/exportElement.php index fe225f145d..62ac7ab0a8 100644 --- a/lib/classes/record/exportElement.php +++ b/lib/classes/record/exportElement.php @@ -85,11 +85,10 @@ class record_exportElement extends record_adapter $sbas_id = phrasea::sbasFromBas($this->app, $this->get_base_id()); - $subdefgroups = $this->app->findDataboxById($sbas_id)->get_subdef_structure(); - + /** @var databox_subdef[] $subdefs */ $subdefs = []; - foreach ($subdefgroups as $subdef_type => $subdefs_obj) { + foreach ($this->app->findDataboxById($sbas_id)->get_subdef_structure() as $subdef_type => $subdefs_obj) { if ($subdef_type == $this->get_type()) { $subdefs = $subdefs_obj; break; @@ -173,7 +172,7 @@ class record_exportElement extends record_adapter $downloadable[$name] = false; - $downloadable_settings = $subdef->is_downloadable(); + $downloadable_settings = $subdef->isDownloadable(); if (! $downloadable_settings || $go_dl[$class] === false) { continue; diff --git a/templates/web/admin/subdefs.html.twig b/templates/web/admin/subdefs.html.twig index 5172612eee..f677a54520 100644 --- a/templates/web/admin/subdefs.html.twig +++ b/templates/web/admin/subdefs.html.twig @@ -227,7 +227,12 @@ {% endfor %}