From 479fdc4a5722ef45d49568f5458755a2e843603d Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 1 Nov 2020 21:24:04 +0100 Subject: [PATCH] add virtual paths --- Admin/Install/db.json | 5 +++++ Models/Template.php | 34 ++++++++++++++++++++++++++++++++++ Models/TemplateMapper.php | 21 +++++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/Admin/Install/db.json b/Admin/Install/db.json index ea02226..9abcf1c 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -44,6 +44,11 @@ "type": "TEXT", "null": false }, + "helper_template_virtual": { + "name": "helper_template_virtual", + "type": "VARCHAR(255)", + "null": false + }, "helper_template_media": { "name": "helper_template_media", "type": "INT", diff --git a/Models/Template.php b/Models/Template.php index 01146d0..4842f14 100755 --- a/Models/Template.php +++ b/Models/Template.php @@ -144,6 +144,14 @@ class Template implements \JsonSerializable */ private array $tags = []; + /** + * Path for organizing. + * + * @var string + * @since 1.0.0 + */ + private string $virtualPath = '/'; + /** * Constructor * @@ -239,6 +247,32 @@ class Template implements \JsonSerializable return $this->name; } + /** + * Get the path + * + * @return string + * + * @since 1.0.0 + */ + public function getVirtualPath() : string + { + return $this->virtualPath; + } + + /** + * Set the path if file + * + * @param string $path Path to file + * + * @return mixed + * + * @since 1.0.0 + */ + public function setVirtualPath(string $path) + { + $this->virtualPath = $path; + } + /** * Set description * diff --git a/Models/TemplateMapper.php b/Models/TemplateMapper.php index fd0ee78..4eacdba 100755 --- a/Models/TemplateMapper.php +++ b/Models/TemplateMapper.php @@ -19,6 +19,7 @@ use Modules\Media\Models\CollectionMapper; use Modules\Organization\Models\UnitMapper; use Modules\Tag\Models\TagMapper; use phpOMS\DataStorage\Database\DataMapperAbstract; +use phpOMS\DataStorage\Database\RelationType; /** * Report mapper class. @@ -46,6 +47,7 @@ final class TemplateMapper extends DataMapperAbstract 'helper_template_desc' => ['name' => 'helper_template_desc', 'type' => 'string', 'internal' => 'description'], 'helper_template_desc_raw' => ['name' => 'helper_template_desc_raw', 'type' => 'string', 'internal' => 'descriptionRaw'], 'helper_template_media' => ['name' => 'helper_template_media', 'type' => 'int', 'internal' => 'source'], + 'helper_template_virtual' => ['name' => 'helper_template_virtual', 'type' => 'string', 'internal' => 'virtualPath'], 'helper_template_creator' => ['name' => 'helper_template_creator', 'type' => 'int', 'internal' => 'createdBy'], 'helper_template_unit' => ['name' => 'helper_template_unit', 'type' => 'int', 'internal' => 'unit'], 'helper_template_created' => ['name' => 'helper_template_created', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt'], @@ -125,4 +127,23 @@ final class TemplateMapper extends DataMapperAbstract * @since 1.0.0 */ protected static string $primaryField = 'helper_template_id'; + + /** + * Get editor doc based on virtual path. + * + * @param string $virtualPath Virtual path + * @param int $account Account id + * + * @return array + * + * @since 1.0.0 + */ + public static function getByVirtualPath(string $virtualPath = '/') : array + { + $depth = 3; + $query = self::getQuery(); + $query->where(self::$table . '_' . $depth . '.helper_template_virtual', '=', $virtualPath); + + return self::getAllByQuery($query, RelationType::ALL, $depth); + } }