diff --git a/src/Controller/AdminPages/FootprintController.php b/src/Controller/AdminPages/FootprintController.php index cd9c88d8..3bc41386 100644 --- a/src/Controller/AdminPages/FootprintController.php +++ b/src/Controller/AdminPages/FootprintController.php @@ -37,6 +37,7 @@ use App\Entity\Attachments\AttachmentType; use App\Entity\Attachments\FootprintAttachment; use App\Entity\Parts\Footprint; use App\Form\AdminPages\BaseEntityAdminForm; +use App\Form\AdminPages\FootprintAdminForm; use App\Services\EntityExporter; use App\Services\EntityImporter; use App\Services\StructuralElementRecursionHelper; @@ -55,7 +56,7 @@ class FootprintController extends BaseAdminController protected $entity_class = Footprint::class; protected $twig_template = 'AdminPages/FootprintAdmin.html.twig'; - protected $form_class = BaseEntityAdminForm::class; + protected $form_class = FootprintAdminForm::class; protected $route_base = 'footprint'; protected $attachment_class = FootprintAttachment::class; diff --git a/src/Entity/Attachments/Attachment.php b/src/Entity/Attachments/Attachment.php index 34770572..a3a61d07 100644 --- a/src/Entity/Attachments/Attachment.php +++ b/src/Entity/Attachments/Attachment.php @@ -53,16 +53,21 @@ abstract class Attachment extends NamedDBElement * Based on: https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types * It will be used to determine if a attachment is a picture and therefore will be shown to user as preview. */ - const PICTURE_EXTS = ['apng', 'bmp', 'gif', 'ico', 'cur', 'jpg', 'jpeg', 'jfif', 'pjpeg', 'pjp', 'png', + public const PICTURE_EXTS = ['apng', 'bmp', 'gif', 'ico', 'cur', 'jpg', 'jpeg', 'jfif', 'pjpeg', 'pjp', 'png', 'svg', 'webp']; + /** + * A list of extensions that will be treated as a 3D Model that can be shown to user directly in Part-DB. + */ + public const MODEL_EXTS = ['x3d']; + /** * When the path begins with one of this placeholders */ - const INTERNAL_PLACEHOLDER = ['%BASE%', '%MEDIA%']; + public const INTERNAL_PLACEHOLDER = ['%BASE%', '%MEDIA%']; /** @var array Placeholders for attachments which using built in files. */ - const BUILTIN_PLACEHOLDER = ['%FOOTPRINTS%', '%FOOTPRINTS3D%']; + public const BUILTIN_PLACEHOLDER = ['%FOOTPRINTS%', '%FOOTPRINTS3D%']; /** * @var bool @@ -101,7 +106,7 @@ abstract class Attachment extends NamedDBElement /** * Check if this attachement is a picture (analyse the file's extension). - * If the link is external, it is assumed that this is false. + * If the link is external, it is assumed that this is true. * * @return bool * true if the file extension is a picture extension * * otherwise false @@ -118,6 +123,23 @@ abstract class Attachment extends NamedDBElement return in_array(strtolower($extension), static::PICTURE_EXTS, true); } + /** + * Check if this attachment is a 3D model and therfore can be directly shown to user. + * If the attachment is external, false is returned (3D Models must be internal). + * @return bool + */ + public function is3DModel() : bool + { + //We just assume that 3D Models are internally saved, otherwise we get problems loading them. + if ($this->isExternal()) { + return false; + } + + $extension = pathinfo($this->getPath(), PATHINFO_EXTENSION); + + return in_array(strtolower($extension), static::MODEL_EXTS, true); + } + /** * Checks if the attachment file is externally saved (the database saves an URL) * @return bool true, if the file is saved externally diff --git a/src/Entity/Parts/Footprint.php b/src/Entity/Parts/Footprint.php index 0e9dfaf7..8df5cec4 100644 --- a/src/Entity/Parts/Footprint.php +++ b/src/Entity/Parts/Footprint.php @@ -98,7 +98,7 @@ class Footprint extends PartsContainingDBElement protected $parts; /** - * @var FootprintAttachment + * @var FootprintAttachment|null * @ORM\ManyToOne(targetEntity="App\Entity\Attachments\FootprintAttachment") * @ORM\JoinColumn(name="id_footprint_3d", referencedColumnName="id") */ @@ -120,24 +120,12 @@ class Footprint extends PartsContainingDBElement ****************************************/ /** - * Get the filename of the picture (absolute path from filesystem root). - * - * @return string the saved filename in the DB - * * an empty string if there is no picture + * Returns the 3D Model associated with this footprint. + * @return FootprintAttachment|null */ - public function getFilename(): string + public function getFootprint3d() : ?FootprintAttachment { - return $this->filename; - } - - /** - * Get the filename of the 3d model (absolute path from filesystem root). - * @return string * the absolute path to the model (from filesystem root), as a UNIX path (with slashes) - * * an empty string if there is no model - */ - public function get3dFilename(): string - { - return $this->filename_3d; + return $this->footprint_3d; } /******************************************************************************** @@ -147,27 +135,14 @@ class Footprint extends PartsContainingDBElement *********************************************************************************/ /** - * Change the filename of this footprint. - * @param string $new_filename The new file name - * @return Footprint - */ - public function setFilename(string $new_filename): self - { - $this->filename = $new_filename; - - return $this; - } - - /** - * Change the 3d model filename of this footprint. - * @param string $new_filename The new filename - * + * Sets the 3D Model associated with this footprint. + * @param FootprintAttachment|null $new_attachment * @return Footprint */ - public function set3dFilename(string $new_filename): self + public function setFootprint3d(?FootprintAttachment $new_attachment) : Footprint { - $this->filename = $new_filename; - + $this->footprint_3d = $new_attachment; return $this; } + } diff --git a/src/Form/AdminPages/FootprintAdminForm.php b/src/Form/AdminPages/FootprintAdminForm.php new file mode 100644 index 00000000..290aeaa5 --- /dev/null +++ b/src/Form/AdminPages/FootprintAdminForm.php @@ -0,0 +1,51 @@ +add('footprint_3d', MasterPictureAttachmentType::class, [ + 'required' => false, + 'disabled' => !$this->security->isGranted($entity->getID() === null ? 'create' : 'edit', $entity), + 'label' => $this->trans->trans('footprint.edit.3d_model'), + 'filter' => '3d_model', + 'entity' => $entity + ]); + } +} \ No newline at end of file diff --git a/src/Form/Type/MasterPictureAttachmentType.php b/src/Form/Type/MasterPictureAttachmentType.php index bbe093ab..3dbf29bb 100644 --- a/src/Form/Type/MasterPictureAttachmentType.php +++ b/src/Form/Type/MasterPictureAttachmentType.php @@ -58,6 +58,8 @@ class MasterPictureAttachmentType extends AbstractType if ($options['filter'] === 'picture' && !$choice->isPicture()) { $tmp += ['disabled' => 'disabled']; + } elseif ($options['filter'] === '3d_model' && !$choice->is3DModel()) { + $tmp += ['disabled' => 'disabled']; } return $tmp; @@ -85,7 +87,7 @@ class MasterPictureAttachmentType extends AbstractType } ]); - $resolver->setAllowedValues('filter', ['', 'picture', '3d_models']); + $resolver->setAllowedValues('filter', ['', 'picture', '3d_model']); } public function getParent() diff --git a/templates/AdminPages/EntityAdminBase.html.twig b/templates/AdminPages/EntityAdminBase.html.twig index 41ea95a9..69816e84 100644 --- a/templates/AdminPages/EntityAdminBase.html.twig +++ b/templates/AdminPages/EntityAdminBase.html.twig @@ -90,6 +90,9 @@
{% include "AdminPages/_attachments.html.twig" %} + {% block master_picture_block %} + {{ form_row(form.master_picture_attachment) }} + {% endblock %}
diff --git a/templates/AdminPages/FootprintAdmin.html.twig b/templates/AdminPages/FootprintAdmin.html.twig index 0b26a775..13c4519b 100644 --- a/templates/AdminPages/FootprintAdmin.html.twig +++ b/templates/AdminPages/FootprintAdmin.html.twig @@ -2,4 +2,9 @@ {% block card_title %} {% trans %}footprint.labelp{% endtrans %} +{% endblock %} + +{% block master_picture_block %} + {{ form_row(form.master_picture_attachment) }} + {{ form_row(form.footprint_3d) }} {% endblock %} \ No newline at end of file diff --git a/templates/AdminPages/_attachments.html.twig b/templates/AdminPages/_attachments.html.twig index 29394c4d..6c774ef7 100644 --- a/templates/AdminPages/_attachments.html.twig +++ b/templates/AdminPages/_attachments.html.twig @@ -67,10 +67,6 @@ {% trans %}attachment.create{% endtrans %} -{% block master_picture_block %} - {{ form_row(form.master_picture_attachment) }} -{% endblock %} -