diff --git a/composer.json b/composer.json index 697a441..6284620 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,6 @@ "license": "MIT", "require": { "php": "^8.2", - "hrustbb2/arrayproc": "^1.0", "intervention/image": "^3.11", "laravel/framework": "^12.0", "laravel/tinker": "^2.10.1" diff --git a/composer.lock b/composer.lock index a8d6b8d..cf1b01a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5e576ac699c4de01e220426df03617e0", + "content-hash": "51576dda271759cce587475988cbe4e8", "packages": [ { "name": "brick/math", @@ -1054,56 +1054,6 @@ ], "time": "2025-02-03T10:55:03+00:00" }, - { - "name": "hrustbb2/arrayproc", - "version": "v1.0.0", - "source": { - "type": "git", - "url": "https://github.com/hrustbb2/arrayproc.git", - "reference": "5e55e374786061da44df086e9d51d02bcf77c519" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/hrustbb2/arrayproc/zipball/5e55e374786061da44df086e9d51d02bcf77c519", - "reference": "5e55e374786061da44df086e9d51d02bcf77c519", - "shasum": "" - }, - "require": { - "php": ">=5.5.0" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^2.14", - "phpunit/phpunit": "^8.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "hrustbb2\\tests\\": "tests/", - "hrustbb2\\arrayproc\\": "arrayproc/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "hrustbb2", - "email": "hrustbb2@gmail.com", - "role": "Developer" - } - ], - "description": "A PHP arrayprocessor", - "keywords": [ - "arrayprocessor", - "orm" - ], - "support": { - "issues": "https://github.com/hrustbb2/arrayproc/issues", - "source": "https://github.com/hrustbb2/arrayproc/tree/master" - }, - "time": "2020-02-27T15:58:37+00:00" - }, { "name": "intervention/gif", "version": "4.2.2", diff --git a/public/files-browser b/public/files-browser new file mode 120000 index 0000000..d23e442 --- /dev/null +++ b/public/files-browser @@ -0,0 +1 @@ +../storage/uploads/files-browser \ No newline at end of file diff --git a/src/Lib/CategoriesTree/Application/DataBuilder.php b/src/Lib/CategoriesTree/Application/DataBuilder.php deleted file mode 100755 index 7ad27ef..0000000 --- a/src/Lib/CategoriesTree/Application/DataBuilder.php +++ /dev/null @@ -1,32 +0,0 @@ -storage = $storage; - } - - public function buildData(array $requestData):array - { - $dsl = [ - 'id', 'matherial_path', - 'path' => ['id'] - ]; - $parentData = $this->storage->getById($requestData['parent-dir'], $dsl); - if($parentData){ - $requestData['parent'] = [ - $parentData['id'] => $parentData, - ]; - } - return $requestData; - } - -} \ No newline at end of file diff --git a/src/Lib/CategoriesTree/Application/Domain.php b/src/Lib/CategoriesTree/Application/Domain.php deleted file mode 100755 index 2297690..0000000 --- a/src/Lib/CategoriesTree/Application/Domain.php +++ /dev/null @@ -1,135 +0,0 @@ -validator = $validator; - } - - public function setDataBuilder(IDataBuilder $builder): void - { - $this->dataBuilder = $builder; - } - - public function setDtoFactory(IDtoFactory $factory): void - { - $this->dtoFactory = $factory; - } - - public function setPersistLayer(IPersistLayer $layer): void - { - $this->persistLayer = $layer; - } - - public function setStorage(IStorage $storage): void - { - $this->storage = $storage; - } - - public function createDir(array $data): bool - { - $this->dir = $this->dtoFactory->createResource(); - if ($this->validator->createDir($data)) { - try { - $cleanData = $this->validator->getCleanData(); - $dirData = $this->dataBuilder->buildData($cleanData); - $dirPersist = $this->dtoFactory->createPersist(); - $dirPersist->load($dirData); - $this->persistLayer->newDir($dirPersist); - $this->dir->load($dirPersist->getAttributes()); - return true; - } catch (Throwable $e) { - Log::error($e); - return false; - } - } else { - $this->errors = $this->validator->getErrors(); - $this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE; - return false; - } - } - - public function renameDir(array $data): bool - { - $this->dir = $this->dtoFactory->createResource(); - if ($this->validator->renameDir($data)) { - try { - $cleanData = $this->validator->getCleanData(); - $dirData = $this->getDirData($cleanData['id']); - $dirPersist = $this->dtoFactory->createPersist(); - $dirPersist->load($dirData); - $dirPersist->update($cleanData); - $this->persistLayer->updateDir($dirPersist); - $this->dir->load($dirPersist->getAttributes()); - return true; - } catch (Throwable $e) { - Log::error($e); - return false; - } - } else { - $this->errors = $this->validator->getErrors(); - $this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE; - return false; - } - } - - public function deleteDir(array $data): bool - { - if ($this->validator->deleteDir($data)) { - try { - $cleanData = $this->validator->getCleanData(); - $dirsIds = $this->storage->getIdsInDir($cleanData['id']); - $dirsIds[] = $cleanData['id']; - $this->persistLayer->deleteDirs($dirsIds); - return true; - } catch (Throwable $e) { - Log::error($e); - return false; - } - } else { - $this->errors = $this->validator->getErrors(); - $this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE; - return false; - } - } - - public function getDir(): IResource - { - return $this->dir; - } - - protected function getDirData(string $dirId, array $dsl = []) - { - return $this->storage->getById($dirId, $dsl); - } -} diff --git a/src/Lib/CategoriesTree/Application/Factory.php b/src/Lib/CategoriesTree/Application/Factory.php deleted file mode 100755 index c0b69cf..0000000 --- a/src/Lib/CategoriesTree/Application/Factory.php +++ /dev/null @@ -1,69 +0,0 @@ -conf[IDomain::class] = [ - 'class' => Domain::class, - ]; - $this->conf[IValidator::class] = [ - 'class' => Validator::class, - ]; - $this->conf[IDataBuilder::class] = [ - 'class' => DataBuilder::class, - ]; - array_replace($this->conf, $conf); - } - - public function setLibFactory(ILibFactory $factory): void - { - $this->libFactory = $factory; - } - - public function getDomain(): Domain - { - if ($this->domain === null) { - $this->domain = new $this->conf[IDomain::class]['class']; - $validator = $this->createValidator(); - $this->domain->setValidator($validator); - $dataBuilder = $this->createDataBuilder(); - $this->domain->setDataBuilder($dataBuilder); - $dtoFactory = $this->libFactory->getDtoFactory(); - $this->domain->setDtoFactory($dtoFactory); - $persistLayer = $this->libFactory->getInfrastructureFactory()->getPersistLayer(); - $this->domain->setPersistLayer($persistLayer); - $storage = $this->libFactory->getInfrastructureFactory()->getStorage(); - $this->domain->setStorage($storage); - } - return $this->domain; - } - - public function createValidator(): Validator - { - return new $this->conf[IValidator::class]['class']; - } - - public function createDataBuilder(): DataBuilder - { - $dataBuilder = new $this->conf[IDataBuilder::class]['class']; - $storage = $this->libFactory->getInfrastructureFactory()->getStorage(); - $dataBuilder->setStorage($storage); - return $dataBuilder; - } -} diff --git a/src/Lib/CategoriesTree/Application/Validator.php b/src/Lib/CategoriesTree/Application/Validator.php deleted file mode 100755 index ef541dd..0000000 --- a/src/Lib/CategoriesTree/Application/Validator.php +++ /dev/null @@ -1,65 +0,0 @@ - [ - 'max:36', - 'nullable', - ], - 'name' => [ - 'max:36', - 'required', - ], - ]; - $messages = [ - 'max' => 'Слишком длинная строка', - 'required' => 'Обязательное поле', - ]; - return $this->validate($data, $rules, $messages); - } - - public function renameDir(array $data):bool - { - $rules = [ - 'id' => [ - 'max:36', - 'nullable', - ], - 'name' => [ - 'max:36', - 'required', - ], - ]; - $messages = [ - 'max' => 'Слишком длинная строка', - 'required' => 'Обязательное поле', - ]; - return $this->validate($data, $rules, $messages); - } - - public function deleteDir(array $data):bool - { - $rules = [ - 'id' => [ - 'max:36', - 'nullable', - ], - ]; - $messages = [ - 'max' => 'Слишком длинная строка', - 'required' => 'Обязательное поле', - ]; - return $this->validate($data, $rules, $messages); - } - -} \ No newline at end of file diff --git a/src/Lib/CategoriesTree/Dto/Factory.php b/src/Lib/CategoriesTree/Dto/Factory.php deleted file mode 100755 index e2c62b2..0000000 --- a/src/Lib/CategoriesTree/Dto/Factory.php +++ /dev/null @@ -1,47 +0,0 @@ -conf[IPersist::class] = [ - 'class' => Persist::class, - ]; - $this->conf[IResource::class] = [ - 'class' => Resource::class, - ]; - array_replace($this->conf, $conf); - } - - public function setLibFactory(ILibFactory $factory) - { - $this->libFactory = $factory; - } - - public function createPersist():IPersist - { - $persist = new $this->conf[IPersist::class]['class']; - $persist->setDtoFactory($this); - $persist->init(); - return $persist; - } - - public function createResource():IResource - { - $resource = new $this->conf[IResource::class]['class']; - $resource->setDtoFactory($this); - return $resource; - } - -} \ No newline at end of file diff --git a/src/Lib/CategoriesTree/Factory.php b/src/Lib/CategoriesTree/Factory.php deleted file mode 100755 index e09b4d0..0000000 --- a/src/Lib/CategoriesTree/Factory.php +++ /dev/null @@ -1,108 +0,0 @@ -conf[IDtoFactory::class] = [ - 'class' => DtoFactory::class, - 'conf' => [], - ]; - $this->conf[IInfrastructureFactory::class] = [ - 'class' => InfrastructureFactory::class, - 'conf' => [], - ]; - $this->conf[IApplicationFactory::class] = [ - 'class' => ApplicationFactory::class, - 'conf' => [], - ]; - array_replace($this->conf, $conf); - } - - public function setCommonFactory(ICommonFactory $factory) - { - $this->commonFactory = $factory; - } - - public function getCommonFactory():ICommonFactory - { - return $this->commonFactory; - } - - public function loadSettings(array $settings) - { - $this->settings = $settings; - } - - public function setSetting(string $key, $val): void - { - $this->settings[$key] = $val; - } - - public function getSetting(string $key) - { - return $this->settings[$key]; - } - - public function getSettings(): array - { - return $this->settings; - } - - public function getDtoFactory():DtoFactory - { - if($this->dtoFactory === null){ - $conf = $this->conf[IDtoFactory::class]; - $this->dtoFactory = new $conf['class']; - $this->dtoFactory->init($conf['conf']); - $this->dtoFactory->setLibFactory($this); - } - return $this->dtoFactory; - } - - public function getInfrastructureFactory():InfrastructureFactory - { - if($this->infrastructureFactory === null){ - $conf = $this->conf[IInfrastructureFactory::class]; - $this->infrastructureFactory = new $conf['class']; - $this->infrastructureFactory->init($conf['conf']); - $this->infrastructureFactory->setLibFactory($this); - } - return $this->infrastructureFactory; - } - - public function getApplicationFactory():ApplicationFactory - { - if($this->applicationFactory === null){ - $conf = $this->conf[IApplicationFactory::class]; - $this->applicationFactory = new $conf['class']; - $this->applicationFactory->init($conf['conf']); - $this->applicationFactory->setLibFactory($this); - } - return $this->applicationFactory; - } - -} \ No newline at end of file diff --git a/src/Lib/CategoriesTree/Infrastructure/Factory.php b/src/Lib/CategoriesTree/Infrastructure/Factory.php deleted file mode 100755 index 7db8877..0000000 --- a/src/Lib/CategoriesTree/Infrastructure/Factory.php +++ /dev/null @@ -1,68 +0,0 @@ -conf[IQuery::class] = [ - 'class' => Query::class, - ]; - $this->conf[IStorage::class] = [ - 'class' => Storage::class, - ]; - $this->conf[IPersistLayer::class] = [ - 'class' => PersistLayer::class, - ]; - array_replace($this->conf, $conf); - } - - public function setLibFactory(ILibFactory $factory) - { - $this->libFactory = $factory; - } - - protected function createQuery(): Query - { - $query = new $this->conf[IQuery::class]['class']; - $tableName = $this->libFactory->getSetting(ILibFactory::TABLE_NAME); - $query->setTableName($tableName); - return $query; - } - - public function getStorage(): IStorage - { - if ($this->storage === null) { - $this->storage = new $this->conf[IStorage::class]['class']; - $query = $this->createQuery(); - $this->storage->setQuery($query); - } - return $this->storage; - } - - public function getPersistLayer(): IPersistLayer - { - if ($this->persistLayer === null) { - $this->persistLayer = new $this->conf[IPersistLayer::class]['class']; - $tableName = $this->libFactory->getSetting(ILibFactory::TABLE_NAME); - $this->persistLayer->setTableName($tableName); - } - return $this->persistLayer; - } -} diff --git a/src/Lib/CategoriesTree/Infrastructure/Query.php b/src/Lib/CategoriesTree/Infrastructure/Query.php deleted file mode 100755 index 7d76237..0000000 --- a/src/Lib/CategoriesTree/Infrastructure/Query.php +++ /dev/null @@ -1,113 +0,0 @@ -tableName = $tableName; - } - - protected function reset() - { - $this->queryBuilder = DB::table($this->tableName); - $this->isParentJoined = false; - } - - protected function getSelectSection(array $fields, array $allowFields, string $table, string $prefix = ''): array - { - $segments = $this->baseGetSelectSection($fields, $allowFields, $table, $prefix); - $result = []; - foreach($segments as $field=>$alias){ - $result[] = $field . ' AS ' . $alias; - } - return $result; - } - - public function select(array $fields) - { - $this->reset(); - $selectSection = $this->getSelectSection($fields, ['id', 'matherial_path', 'parent_id', 'name'], $this->tableName, 'category_'); - $this->queryBuilder->select($selectSection); - $this->arrayProcConf = ['prefix' => 'category_']; - return $this; - } - - public function whereId($id) - { - $this->queryBuilder->where($this->tableName . '.id', '=', $id); - return $this; - } - - public function whereIdIn(array $ids) - { - $this->queryBuilder->whereIn($this->tableName . '.id', $ids); - return $this; - } - - public function whereParentId($parentId) - { - $this->queryBuilder->where($this->tableName . '.parent_id', '=', $parentId); - return $this; - } - - public function whereInPath(string $matherialPath) - { - $this->queryBuilder->where($this->tableName . '.matherial_path', 'like', $matherialPath . '%'); - return $this; - } - - public function withParent(array $fields) - { - $this->joinParend(); - $selectSection = $this->getSelectSection($fields, ['id', 'matherial_path', 'parent_id', 'name'], $this->tableName, 'parent_'); - $this->queryBuilder->addSelect($selectSection); - $this->arrayProcConf['parent'] = ['prefix' => 'parent_']; - return $this; - } - - protected function joinParend() - { - if(!$this->isParentJoined){ - $first = $this->tableName . '.id'; - $two = $this->tableName . '.parent_id'; - $this->queryBuilder->leftJoin($this->tableName . ' AS parent', $first, '=', $two); - $this->isParentJoined = true; - } - } - - public function all(): array - { - $arrayProc = new ArrayProcessor(); - $data = $this->queryBuilder->get()->toArray(); - return $arrayProc->process($this->arrayProcConf, $data)->resultArray(); - } - - public function one(): array - { - $arrayProc = new ArrayProcessor(); - $data = $this->queryBuilder->get()->toArray(); - $d = $arrayProc->process($this->arrayProcConf, $data)->resultArray(); - return array_pop($d) ?? []; - } - -} \ No newline at end of file diff --git a/src/Lib/CategoriesTree/Infrastructure/Storage.php b/src/Lib/CategoriesTree/Infrastructure/Storage.php deleted file mode 100755 index e312866..0000000 --- a/src/Lib/CategoriesTree/Infrastructure/Storage.php +++ /dev/null @@ -1,53 +0,0 @@ -query = $query; - } - - public function getById($id, array $dsl = []):array - { - $this->query->select($dsl)->whereId($id); - if(key_exists('parent', $dsl)){ - $this->query->withParent($dsl['parent']); - } - $data = $this->query->one(); - if(key_exists('path', $dsl) && isset($data['matherial_path'])){ - $ids = explode('|', $data['matherial_path']); - $path = $this->query->select($dsl['path'])->whereIdIn($ids)->all(); - $data['path'] = $path; - } - return $data; - } - - public function getByParentId($parentId, array $dsl = []):array - { - return $this->query->select($dsl)->whereParentId($parentId)->all(); - } - - public function getIdsInDir(string $dirId):array - { - $dirData = $this->query->select(['id', 'matherial_path'])->whereId($dirId)->one(); - $pathIds = ($dirData['matherial_path']) ? explode('|', $dirData['matherial_path']) : []; - $pathIds[] = $dirId; - $matherialPath = join('|', $pathIds); - $dirs = $this->query->select(['id'])->whereInPath($matherialPath)->all(); - $ids = array_map(function($dir){ - return $dir['id']; - }, $dirs); - return array_values($ids); - } - -} \ No newline at end of file diff --git a/src/Lib/CategoriesTree/Interfaces/Application/IDataBuilder.php b/src/Lib/CategoriesTree/Interfaces/Application/IDataBuilder.php deleted file mode 100755 index 1b85081..0000000 --- a/src/Lib/CategoriesTree/Interfaces/Application/IDataBuilder.php +++ /dev/null @@ -1,10 +0,0 @@ - false, 'primary_key' => ['id']], $this->adapter); - $table ->addColumn('id', 'string') - ->addColumn('matherial_path', 'string') - ->addColumn('parent_id', 'string') - ->addColumn('name', 'string') - ->create(); - } - - public function down(array $settings): void - { - $table = new Table($settings[ILibFactory::TABLE_NAME], ['id' => false, 'primary_key' => ['id']], $this->adapter); - $table->drop()->save(); - } -} diff --git a/src/Modules/JsonObjects/Application/DataBuilder.php b/src/Modules/JsonObjects/Application/DataBuilder.php index 65c0212..d10b2b8 100755 --- a/src/Modules/JsonObjects/Application/DataBuilder.php +++ b/src/Modules/JsonObjects/Application/DataBuilder.php @@ -3,23 +3,24 @@ namespace Src\Modules\JsonObjects\Application; use Src\Modules\JsonObjects\Interfaces\Application\IDataBuilder; -use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage as IDirStorage; +use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage; -class DataBuilder implements IDataBuilder { +class DataBuilder implements IDataBuilder +{ - protected IDirStorage $dirStorage; + protected IDirsStorage $dirStorage; - public function setDirStorage(IDirStorage $dirStorage):void + public function setDirStorage(IDirsStorage $dirStorage): void { $this->dirStorage = $dirStorage; } - public function build(array $data):array + public function build(array $data): array { $dirData = []; - if(key_exists('dir-id', $data) && $data['dir-id']){ + if (key_exists('dir-id', $data) && $data['dir-id']) { $dirData = $this->dirStorage->getById($data['dir-id']); - if(!$dirData){ + if (!$dirData) { $dirData = ['id' => '']; } $data['dir'] = [ @@ -29,4 +30,19 @@ class DataBuilder implements IDataBuilder { return $data; } -} \ No newline at end of file + public function buildDirData(array $requestData): array + { + $dsl = [ + 'id', + 'matherial_path', + 'path' => ['id'] + ]; + $parentData = $this->dirStorage->getById($requestData['parent-dir'], $dsl); + if ($parentData) { + $requestData['parent'] = [ + $parentData['id'] => $parentData, + ]; + } + return $requestData; + } +} diff --git a/src/Modules/JsonObjects/Application/Domain.php b/src/Modules/JsonObjects/Application/Domain.php index f91303d..49629af 100755 --- a/src/Modules/JsonObjects/Application/Domain.php +++ b/src/Modules/JsonObjects/Application/Domain.php @@ -11,11 +11,13 @@ use Src\Modules\JsonObjects\Interfaces\Dto\Item\IResourceItem; use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemPersistLayer; use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage; use Src\Modules\JsonObjects\Interfaces\Application\IDataBuilder; -use Src\Lib\CategoriesTree\Interfaces\Application\IValidator as IDirValidator; -use Src\Lib\CategoriesTree\Interfaces\Application\IDomain as IDirDomain; -use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage as IDirStorage; +use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage; +use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsPersistLayer; +use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IResource as IDirResource; +use Illuminate\Support\Facades\Log; -class Domain implements IDomain { +class Domain implements IDomain +{ use TraitDomain; @@ -31,103 +33,98 @@ class Domain implements IDomain { protected IDataBuilder $dataBuilder; - protected IDirValidator $dirValidator; + protected IDirsStorage $dirsStorage; - protected IDirDomain $dirDomain; + protected IDirsPersistLayer $dirsPersistLayer; - protected IDirStorage $dirStorage; + protected IDirResource $dirResource; - public function setValidator(IValidator $validator):void + public function setValidator(IValidator $validator): void { $this->validator = $validator; } - public function setDtoFactory(IDtoFactory $factory):void + public function setDtoFactory(IDtoFactory $factory): void { $this->dtoFactory = $factory; } - public function setPersistLayer(IItemPersistLayer $layer):void + public function setPersistLayer(IItemPersistLayer $layer): void { $this->persistLayer = $layer; } - public function setStorage(IItemStorage $storage):void + public function setStorage(IItemStorage $storage): void { $this->storage = $storage; } - public function setDataBuilder(IDataBuilder $dataBuilder):void + public function setDataBuilder(IDataBuilder $dataBuilder): void { $this->dataBuilder = $dataBuilder; } - public function setDirValidator(IDirValidator $validator):void + public function setDirStorage(IDirsStorage $storage): void { - $this->dirValidator = $validator; + $this->dirsStorage = $storage; } - public function setDirDomain(IDirDomain $domain):void + public function setDirsPersistLayer(IDirsPersistLayer $layer): void { - $this->dirDomain = $domain; + $this->dirsPersistLayer = $layer; } - public function setDirStorage(IDirStorage $storage):void - { - $this->dirStorage = $storage; - } - - public function createObject(array $data):bool + public function createObject(array $data): bool { $this->item = $this->dtoFactory->getItemFactory()->createResource(); - if($this->validator->createObject($data)){ + if ($this->validator->createObject($data)) { $cleanData = $this->validator->getCleanData(); $fullData = $this->dataBuilder->build($cleanData); $item = $this->dtoFactory->getItemFactory()->createPersist(); $item->load($fullData); $this->item->load($item->getAttributes()); - if($this->item->validate()){ + if ($this->item->validate()) { $this->persistLayer->create($item); $this->item->getObject()->onSave(); return true; } $this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE; return false; - }else{ + } else { $this->errors = $this->validator->getErrors(); $this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE; return false; } } - public function editObject(array $data):bool + public function editObject(array $data): bool { $this->item = $this->dtoFactory->getItemFactory()->createResource(); - if($this->validator->editObject($data)){ + if ($this->validator->editObject($data)) { $cleanData = $this->validator->getCleanData(); $itemData = $this->storage->getById($cleanData['id']); $item = $this->dtoFactory->getItemFactory()->createPersist(); $item->load($itemData); $item->update($cleanData); $this->item->load($item->getAttributes()); - if($this->item->validate()){ + if ($this->item->validate()) { $this->persistLayer->update($item); $this->item->getObject()->onSave(); return true; } $this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE; return false; - }else{ + } else { $this->errors = $this->validator->getErrors(); $this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE; return false; } } - public function renameObject(array $data):bool + public function renameObject(array $data): bool { $this->item = $this->dtoFactory->getItemFactory()->createResource(); - if($this->validator->renameObject($data)){ + if ($this->validator->renameObject($data)) { $cleanData = $this->validator->getCleanData(); $itemData = $this->storage->getById($cleanData['id']); $item = $this->dtoFactory->getItemFactory()->createPersist(); @@ -136,49 +133,125 @@ class Domain implements IDomain { $this->persistLayer->update($item); $this->item->load($item->getAttributes()); return true; - }else{ + } else { $this->errors = $this->validator->getErrors(); $this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE; return false; } } - public function deleteObject(array $data):bool + public function deleteObject(array $data): bool { - if($this->validator->deleteObject($data)){ + if ($this->validator->deleteObject($data)) { $cleanData = $this->validator->getCleanData(); $itemData = $this->storage->getById($cleanData['id']); - if(!$itemData['disabled']){ + if (!$itemData['disabled']) { $this->persistLayer->delete($cleanData['id']); return true; } return false; - }else{ + } else { $this->errors = $this->validator->getErrors(); $this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE; return false; } } - public function deleteDir(array $data):bool + public function deleteDir(array $data): bool { - if($this->dirValidator->deleteDir($data)){ - $cleanData = $this->dirValidator->getCleanData(); - $dirIds = $this->dirStorage->getIdsInDir($cleanData['id']); + if ($this->validator->deleteDir($data)) { + $cleanData = $this->validator->getCleanData(); + $dirIds = $this->dirsStorage->getIdsInDir($cleanData['id']); $dirIds[] = $cleanData['id']; $this->persistLayer->deleteInDirs($dirIds); - $this->dirDomain->deleteDir($data); + $this->_deleteDir($data); return true; - }else{ - $this->errors = $this->dirValidator->getErrors(); + } else { + $this->errors = $this->validator->getErrors(); $this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE; return false; } } - public function getItem():IResourceItem + public function createDir(array $data): bool + { + $this->dirResource = $this->dtoFactory->getDirFactory()->createResource(); + if ($this->validator->createDir($data)) { + try { + $cleanData = $this->validator->getCleanData(); + $dirData = $this->dataBuilder->buildDirData($cleanData); + $dirPersist = $this->dtoFactory->getDirFactory()->createPersist(); + $dirPersist->load($dirData); + $this->dirsPersistLayer->newDir($dirPersist); + $this->dirResource->load($dirPersist->getAttributes()); + return true; + } catch (\Throwable $e) { + Log::error($e); + return false; + } + } else { + $this->errors = $this->validator->getErrors(); + $this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE; + return false; + } + } + + public function renameDir(array $data): bool + { + $this->dirResource = $this->dtoFactory->getDirFactory()->createResource(); + if ($this->validator->renameDir($data)) { + try { + $cleanData = $this->validator->getCleanData(); + $dirData = $this->getDirData($cleanData['id']); + $dirPersist = $this->dtoFactory->getDirFactory()->createPersist(); + $dirPersist->load($dirData); + $dirPersist->update($cleanData); + $this->dirsPersistLayer->updateDir($dirPersist); + $this->dirResource->load($dirPersist->getAttributes()); + return true; + } catch (\Throwable $e) { + Log::error($e); + return false; + } + } else { + $this->errors = $this->validator->getErrors(); + $this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE; + return false; + } + } + + private function _deleteDir(array $data): bool + { + if ($this->validator->deleteDir($data)) { + try { + $cleanData = $this->validator->getCleanData(); + $dirsIds = $this->dirsStorage->getIdsInDir($cleanData['id']); + $dirsIds[] = $cleanData['id']; + $this->dirsPersistLayer->deleteDirs($dirsIds); + return true; + } catch (\Throwable $e) { + Log::error($e); + return false; + } + } else { + $this->errors = $this->validator->getErrors(); + $this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE; + return false; + } + } + + public function getDir(): IDirResource + { + return $this->dirResource; + } + + protected function getDirData(string $dirId, array $dsl = []) + { + return $this->dirsStorage->getById($dirId, $dsl); + } + + public function getItem(): IResourceItem { return $this->item; } - -} \ No newline at end of file +} diff --git a/src/Modules/JsonObjects/Application/Factory.php b/src/Modules/JsonObjects/Application/Factory.php index 5da2a9d..2e8635d 100755 --- a/src/Modules/JsonObjects/Application/Factory.php +++ b/src/Modules/JsonObjects/Application/Factory.php @@ -8,7 +8,8 @@ use Src\Modules\JsonObjects\Interfaces\Application\IValidator; use Src\Modules\JsonObjects\Interfaces\Application\IDomain; use Src\Modules\JsonObjects\Interfaces\Application\IDataBuilder; -class Factory implements IFactory { +class Factory implements IFactory +{ protected IModuleFactory $moduleFactory; @@ -31,15 +32,15 @@ class Factory implements IFactory { protected function createInstance($instance) { - if(gettype($instance) == 'string'){ + if (gettype($instance) == 'string') { return new $instance; } - if(gettype($instance) == 'object'){ + if (gettype($instance) == 'object') { return $instance; } } - public function setModuleFactory(IModuleFactory $factorory):void + public function setModuleFactory(IModuleFactory $factorory): void { $this->moduleFactory = $factorory; } @@ -57,14 +58,14 @@ class Factory implements IFactory { protected function creteDataBuilder(): DataBuilder { $dataBuilder = $this->createInstance($this->conf['dataBuilder']); - $storage = $this->moduleFactory->getDirsTreeFactory()->getInfrastructureFactory()->getStorage(); + $storage = $this->moduleFactory->getInfrastructureFactory()->getDirsStorage(); $dataBuilder->setDirStorage($storage); return $dataBuilder; } public function getDomain(): Domain { - if($this->domain === null){ + if ($this->domain === null) { $this->domain = $this->createInstance($this->conf['domain']); $validator = $this->createValidator(); $this->domain->setValidator($validator); @@ -76,22 +77,19 @@ class Factory implements IFactory { $this->domain->setStorage($storage); $dataBuilder = $this->creteDataBuilder(); $this->domain->setDataBuilder($dataBuilder); - $dirValidator = $this->moduleFactory->getDirsTreeFactory()->getApplicationFactory()->createValidator(); - $this->domain->setDirValidator($dirValidator); - $dirDomain = $this->moduleFactory->getDirsTreeFactory()->getApplicationFactory()->getDomain(); - $this->domain->setDirDomain($dirDomain); - $dirStorage = $this->moduleFactory->getDirsTreeFactory()->getInfrastructureFactory()->getStorage(); + $dirStorage = $this->moduleFactory->getInfrastructureFactory()->getDirsStorage(); $this->domain->setDirStorage($dirStorage); + $dirsPersistLayer = $this->moduleFactory->getInfrastructureFactory()->getDirsPersistLayer(); + $this->domain->setDirsPersistLayer($dirsPersistLayer); } return $this->domain; } public function getFilesBrowser(): FilesBrowser { - if($this->filesBrowser === null){ + if ($this->filesBrowser === null) { $this->filesBrowser = $this->createInstance($this->conf['filesBrowser']); } return $this->filesBrowser; } - -} \ No newline at end of file +} diff --git a/src/Modules/JsonObjects/Application/Validator.php b/src/Modules/JsonObjects/Application/Validator.php index 6cca6b8..103a143 100755 --- a/src/Modules/JsonObjects/Application/Validator.php +++ b/src/Modules/JsonObjects/Application/Validator.php @@ -5,13 +5,14 @@ namespace Src\Modules\JsonObjects\Application; use Src\Common\Application\TraitValidator; use Src\Modules\JsonObjects\Interfaces\Application\IValidator; -class Validator implements IValidator { +class Validator implements IValidator +{ use TraitValidator { getCleanData as baseCleanData; } - public function createObject(array $data):bool + public function createObject(array $data): bool { $rules = [ 'dir-id' => [ @@ -27,13 +28,11 @@ class Validator implements IValidator { 'max:32', ], ]; - $messages = [ - - ]; + $messages = []; return $this->validate($data, $rules, $messages); } - public function editObject(array $data):bool + public function editObject(array $data): bool { $rules = [ 'id' => [ @@ -49,13 +48,11 @@ class Validator implements IValidator { 'array', ] ]; - $messages = [ - - ]; + $messages = []; return $this->validate($data, $rules, $messages); } - public function renameObject(array $data):bool + public function renameObject(array $data): bool { $rules = [ 'id' => [ @@ -67,13 +64,11 @@ class Validator implements IValidator { 'max:32', ], ]; - $messages = [ - - ]; + $messages = []; return $this->validate($data, $rules, $messages); } - public function deleteObject(array $data):bool + public function deleteObject(array $data): bool { $rules = [ 'id' => [ @@ -81,8 +76,59 @@ class Validator implements IValidator { 'max:32', ], ]; - $messages = [ + $messages = []; + return $this->validate($data, $rules, $messages); + } + public function createDir(array $data): bool + { + $rules = [ + 'parent-dir' => [ + 'max:36', + 'nullable', + ], + 'name' => [ + 'max:36', + 'required', + ], + ]; + $messages = [ + 'max' => 'Слишком длинная строка', + 'required' => 'Обязательное поле', + ]; + return $this->validate($data, $rules, $messages); + } + + public function renameDir(array $data): bool + { + $rules = [ + 'id' => [ + 'max:36', + 'nullable', + ], + 'name' => [ + 'max:36', + 'required', + ], + ]; + $messages = [ + 'max' => 'Слишком длинная строка', + 'required' => 'Обязательное поле', + ]; + return $this->validate($data, $rules, $messages); + } + + public function deleteDir(array $data): bool + { + $rules = [ + 'id' => [ + 'max:36', + 'nullable', + ], + ]; + $messages = [ + 'max' => 'Слишком длинная строка', + 'required' => 'Обязательное поле', ]; return $this->validate($data, $rules, $messages); } @@ -90,10 +136,9 @@ class Validator implements IValidator { public function getCleanData() { $cleanData = $this->baseCleanData(); - if(key_exists('object', $cleanData)){ + if (key_exists('object', $cleanData)) { $cleanData['object'] = json_encode($cleanData['object']); } return $cleanData; } - -} \ No newline at end of file +} diff --git a/src/Lib/CategoriesTree/Dto/CategoryTrait.php b/src/Modules/JsonObjects/Dto/Dir/CategoryTrait.php similarity index 87% rename from src/Lib/CategoriesTree/Dto/CategoryTrait.php rename to src/Modules/JsonObjects/Dto/Dir/CategoryTrait.php index dd2b2ac..ab727cc 100755 --- a/src/Lib/CategoriesTree/Dto/CategoryTrait.php +++ b/src/Modules/JsonObjects/Dto/Dir/CategoryTrait.php @@ -1,8 +1,8 @@ loadPath($data['path']); } if (key_exists('parent', $data)) { - $parentData = array_pop($data['parent']); + $parentData = array_pop($data['parent']) ?? []; $this->loadParent($parentData); } } diff --git a/src/Modules/JsonObjects/Dto/Dir/Factory.php b/src/Modules/JsonObjects/Dto/Dir/Factory.php new file mode 100755 index 0000000..f4f6f28 --- /dev/null +++ b/src/Modules/JsonObjects/Dto/Dir/Factory.php @@ -0,0 +1,47 @@ +conf[IPersist::class] = [ + 'class' => Persist::class, + ]; + $this->conf[IResource::class] = [ + 'class' => Resource::class, + ]; + array_replace($this->conf, $conf); + } + + public function setDtoFactory(IDtoFactory $factory): void + { + $this->dtoFactory = $factory; + } + + public function createPersist(): IPersist + { + $persist = new $this->conf[IPersist::class]['class']; + $persist->setDtoFactory($this->dtoFactory); + $persist->init(); + return $persist; + } + + public function createResource(): IResource + { + $resource = new $this->conf[IResource::class]['class']; + $resource->setDtoFactory($this->dtoFactory); + return $resource; + } +} diff --git a/src/Lib/CategoriesTree/Dto/Persist.php b/src/Modules/JsonObjects/Dto/Dir/Persist.php similarity index 81% rename from src/Lib/CategoriesTree/Dto/Persist.php rename to src/Modules/JsonObjects/Dto/Dir/Persist.php index 6cfc915..57c1efe 100755 --- a/src/Lib/CategoriesTree/Dto/Persist.php +++ b/src/Modules/JsonObjects/Dto/Dir/Persist.php @@ -1,10 +1,10 @@ path = []; foreach ($data as $itemData) { - $pathItem = $this->dtoFactory->createPersist(); + $pathItem = $this->dtoFactory->getDirFactory()->createPersist(); $pathItem->load($itemData); $this->path[] = $pathItem; } @@ -48,7 +48,7 @@ class Persist implements IPersist public function loadParent(array $data) { - $this->parent = $this->dtoFactory->createPersist(); + $this->parent = $this->dtoFactory->getDirFactory()->createPersist(); $this->parent->load($data); } diff --git a/src/Lib/CategoriesTree/Dto/Resource.php b/src/Modules/JsonObjects/Dto/Dir/Resource.php similarity index 80% rename from src/Lib/CategoriesTree/Dto/Resource.php rename to src/Modules/JsonObjects/Dto/Dir/Resource.php index a4ca0c0..dce998d 100755 --- a/src/Lib/CategoriesTree/Dto/Resource.php +++ b/src/Modules/JsonObjects/Dto/Dir/Resource.php @@ -1,10 +1,10 @@ path = []; foreach ($data as $item) { - $pathItem = $this->dtoFactory->createResource(); + $pathItem = $this->dtoFactory->getDirFactory()->createResource(); $pathItem->load($item); $this->path[] = $pathItem; } @@ -58,7 +58,10 @@ class Resource implements IResource public function loadParent(array $data) { - $this->parent = $this->dtoFactory->createResource(); + if (!$data) { + return; + } + $this->parent = $this->dtoFactory->getDirFactory()->createResource(); $this->parent->load($data); } diff --git a/src/Modules/JsonObjects/Dto/Factory.php b/src/Modules/JsonObjects/Dto/Factory.php index 0ff550a..bc4eae6 100755 --- a/src/Modules/JsonObjects/Dto/Factory.php +++ b/src/Modules/JsonObjects/Dto/Factory.php @@ -6,13 +6,18 @@ use Src\Modules\JsonObjects\Interfaces\Dto\IFactory; use Src\Modules\JsonObjects\Interfaces\IFactory as IModulesFactory; use Src\Modules\JsonObjects\Interfaces\Dto\Item\IFactory as IItemFactory; use Src\Modules\JsonObjects\Dto\Item\Factory as ItemFactory; +use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IFactory as IDirFactory; +use Src\Modules\JsonObjects\Dto\Dir\Factory as DirFactory; -class Factory implements IFactory { +class Factory implements IFactory +{ protected IModulesFactory $modulesFactory; protected ?IItemFactory $itemFactory = null; + protected ?IDirFactory $dirFactory = null; + protected array $conf; public function init(array $conf = []): void @@ -21,6 +26,9 @@ class Factory implements IFactory { 'item' => [ 'factory' => ItemFactory::class, ], + 'dir' => [ + 'factory' => DirFactory::class, + ], ]; $this->conf = array_replace_recursive($this->conf, $conf); } @@ -30,14 +38,14 @@ class Factory implements IFactory { $this->modulesFactory = $factory; } - public function getModulesFactory():IModulesFactory + public function getModulesFactory(): IModulesFactory { return $this->modulesFactory; } - public function getItemFactory():ItemFactory + public function getItemFactory(): ItemFactory { - if($this->itemFactory === null){ + if ($this->itemFactory === null) { $this->itemFactory = new $this->conf['item']['factory']; $this->itemFactory->init($this->conf['item']); $this->itemFactory->setDtoFactory($this); @@ -45,4 +53,13 @@ class Factory implements IFactory { return $this->itemFactory; } -} \ No newline at end of file + public function getDirFactory(): DirFactory + { + if ($this->dirFactory === null) { + $this->dirFactory = new $this->conf['dir']['factory']; + $this->dirFactory->init($this->conf['dir']); + $this->dirFactory->setDtoFactory($this); + } + return $this->dirFactory; + } +} diff --git a/src/Modules/JsonObjects/Dto/Item/Factory.php b/src/Modules/JsonObjects/Dto/Item/Factory.php index 2bdae3f..0ab7f59 100755 --- a/src/Modules/JsonObjects/Dto/Item/Factory.php +++ b/src/Modules/JsonObjects/Dto/Item/Factory.php @@ -6,7 +6,8 @@ use Src\Modules\JsonObjects\Interfaces\IFactory as IModuleFactory; use Src\Modules\JsonObjects\Interfaces\Dto\Item\IFactory; use Src\Modules\JsonObjects\Interfaces\Dto\IFactory as IDtoFactory; -class Factory implements IFactory { +class Factory implements IFactory +{ protected ?IDtoFactory $dtoFactory = null; @@ -21,31 +22,30 @@ class Factory implements IFactory { $this->conf = array_replace_recursive($this->conf, $conf); } - public function setDtoFactory(IDtoFactory $factory):void + public function setDtoFactory(IDtoFactory $factory): void { $this->dtoFactory = $factory; } - public function createPersist(string $type = ''):PersistItem + public function createPersist(string $type = ''): PersistItem { $persist = new $this->conf['persistItem']; $objFactory = $this->dtoFactory->getModulesFactory()->getSetting(IModuleFactory::OBJECTS_FACTORY); $persist->setObjectsFactory($objFactory); - if($type){ + if ($type) { $obj = $objFactory->createObjectField($type); $persist->setObject($obj); } return $persist; } - public function createResource():ResourceItem + public function createResource(): ResourceItem { $resource = new $this->conf['resourceItem']; - $dirResource = $this->dtoFactory->getModulesFactory()->getDirsTreeFactory()->getDtoFactory()->createResource(); + $dirResource = $this->dtoFactory->getModulesFactory()->getDtoFactory()->getDirFactory()->createResource(); $resource->setDir($dirResource); $objFactory = $this->dtoFactory->getModulesFactory()->getSetting(IModuleFactory::OBJECTS_FACTORY); $resource->setObjectsFactory($objFactory); return $resource; } - -} \ No newline at end of file +} diff --git a/src/Modules/JsonObjects/Dto/Item/ResourceItem.php b/src/Modules/JsonObjects/Dto/Item/ResourceItem.php index 56570d3..6bb92b2 100755 --- a/src/Modules/JsonObjects/Dto/Item/ResourceItem.php +++ b/src/Modules/JsonObjects/Dto/Item/ResourceItem.php @@ -3,14 +3,15 @@ namespace Src\Modules\JsonObjects\Dto\Item; use Src\Modules\JsonObjects\Interfaces\Dto\Item\IResourceItem; -use Src\Lib\CategoriesTree\Interfaces\Dto\IResource as IDirResource; +use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IResource as IDirResource; use Src\Common\Dto\Object\AbstractComposite; -class ResourceItem extends AbstractItem implements IResourceItem { +class ResourceItem extends AbstractItem implements IResourceItem +{ protected IDirResource $dir; - public function setDir(IDirResource $dir):void + public function setDir(IDirResource $dir): void { $this->dir = $dir; } @@ -19,51 +20,50 @@ class ResourceItem extends AbstractItem implements IResourceItem { { $this->dir->load($dirData); } - - public function toArray(array $fields = []):array + + public function toArray(array $fields = []): array { $result = []; - if(!$fields){ + if (!$fields) { $fields = ['id', 'key', 'name', 'description', 'object']; } - foreach($fields as $key=>$field){ - if($field == 'id'){ + foreach ($fields as $key => $field) { + if ($field == 'id') { $result['id'] = $this->id; } - if($field == 'key'){ + if ($field == 'key') { $result['key'] = $this->key; } - if($field == 'name'){ + if ($field == 'name') { $result['name'] = $this->name; } - if($field == 'description'){ + if ($field == 'description') { $result['description'] = $this->description; } - if($field == 'object'){ + if ($field == 'object') { $result['object'] = $this->object->getJson(); } } return $result; } - public function getDir():IDirResource + public function getDir(): IDirResource { return $this->dir; } - public function isDisabled():bool + public function isDisabled(): bool { return (bool) $this->disabled; } - public function getObject():AbstractComposite + public function getObject(): AbstractComposite { return $this->object; } - public function getName():string + public function getName(): string { return $this->name; } - -} \ No newline at end of file +} diff --git a/src/Modules/JsonObjects/Factory.php b/src/Modules/JsonObjects/Factory.php index 1edb7c1..9f4a0e9 100755 --- a/src/Modules/JsonObjects/Factory.php +++ b/src/Modules/JsonObjects/Factory.php @@ -4,7 +4,7 @@ namespace Src\Modules\JsonObjects; use Src\Modules\JsonObjects\Interfaces\IFactory; use Src\Modules\JsonObjects\Interfaces\IModulesProvider; -use Src\Lib\CategoriesTree\Interfaces\IFactory as IDirsTreeFactory; +// use Src\Lib\CategoriesTree\Interfaces\IFactory as IDirsTreeFactory; use Src\Sidebar\Interfaces\IFactory as ISidebarFactory; use Src\Common\Interfaces\IFactory as ICommonFactory; use Src\Modules\JsonObjects\Interfaces\Dto\IFactory as IDtoFactory; @@ -17,14 +17,15 @@ use Src\Modules\JsonObjects\Interfaces\Application\IFactory as IApplicationFacto use Src\Modules\JsonObjects\Application\Factory as ApplicationFactory; use Src\Common\Dto\Object\Factory as ObjectsFactory; -class Factory implements IFactory { +class Factory implements IFactory +{ - protected IDirsTreeFactory $dirsTreeFactory; + // protected IDirsTreeFactory $dirsTreeFactory; protected ISidebarFactory $sidebarFactory; protected ICommonFactory $commonFactory; - + protected ?IDtoFactory $dtoFactory = null; protected ?IPagesFactory $pagesFactory = null; @@ -37,7 +38,7 @@ class Factory implements IFactory { protected array $conf; - + public function init(array $conf = []): void { $this->conf = [ @@ -63,31 +64,31 @@ class Factory implements IFactory { $this->commonFactory = $provider->getCommonFactory(); } - public function getSidebarFactory():ISidebarFactory + public function getSidebarFactory(): ISidebarFactory { return $this->sidebarFactory; } - public function getCommonFactory():ICommonFactory + public function getCommonFactory(): ICommonFactory { return $this->commonFactory; } - public function setDirsTreeFactory(IDirsTreeFactory $factory) - { - $this->dirsTreeFactory = $factory; - $this->dirsTreeFactory->setSetting(IDirsTreeFactory::TABLE_NAME, $this->settings[self::DIRS_TABLE]); - } + // public function setDirsTreeFactory(IDirsTreeFactory $factory) + // { + // $this->dirsTreeFactory = $factory; + // $this->dirsTreeFactory->setSetting(IDirsTreeFactory::TABLE_NAME, $this->settings[self::DIRS_TABLE]); + // } public function setObjectsFactory(ObjectsFactory $factory): void { $this->settings[self::OBJECTS_FACTORY] = $factory; } - public function getDirsTreeFactory():IDirsTreeFactory - { - return $this->dirsTreeFactory; - } + // public function getDirsTreeFactory():IDirsTreeFactory + // { + // return $this->dirsTreeFactory; + // } public function loadSettings(array $settings) { @@ -104,9 +105,9 @@ class Factory implements IFactory { return $this->settings; } - public function getDtoFactory():DtoFactory + public function getDtoFactory(): DtoFactory { - if($this->dtoFactory === null){ + if ($this->dtoFactory === null) { $this->dtoFactory = new $this->conf['dto']['factory']; $this->dtoFactory->setModulesFactory($this); $this->dtoFactory->init($this->conf['dto']); @@ -114,9 +115,9 @@ class Factory implements IFactory { return $this->dtoFactory; } - public function getPagesFactory():PagesFactory + public function getPagesFactory(): PagesFactory { - if($this->pagesFactory === null){ + if ($this->pagesFactory === null) { $this->pagesFactory = new $this->conf['pages']['factory']; $this->pagesFactory->setModuleFactory($this); $this->pagesFactory->init($this->conf['pages']); @@ -124,9 +125,9 @@ class Factory implements IFactory { return $this->pagesFactory; } - public function getInfrastructureFactory():InfrastructureFactory + public function getInfrastructureFactory(): InfrastructureFactory { - if($this->infrastructureFactory === null){ + if ($this->infrastructureFactory === null) { $this->infrastructureFactory = new $this->conf['infrastructure']['factory']; $this->infrastructureFactory->setModuleFactory($this); $this->infrastructureFactory->init($this->conf['infrastructure']); @@ -134,14 +135,13 @@ class Factory implements IFactory { return $this->infrastructureFactory; } - public function getApplicationFactory():ApplicationFactory + public function getApplicationFactory(): ApplicationFactory { - if($this->applicationFactory === null){ + if ($this->applicationFactory === null) { $this->applicationFactory = new $this->conf['application']['factory']; $this->applicationFactory->setModuleFactory($this); $this->applicationFactory->init($this->conf['application']); } return $this->applicationFactory; } - -} \ No newline at end of file +} diff --git a/src/Lib/CategoriesTree/Infrastructure/PersistLayer.php b/src/Modules/JsonObjects/Infrastructure/DirsPersistLayer.php similarity index 62% rename from src/Lib/CategoriesTree/Infrastructure/PersistLayer.php rename to src/Modules/JsonObjects/Infrastructure/DirsPersistLayer.php index f73679d..ff4f6b9 100755 --- a/src/Lib/CategoriesTree/Infrastructure/PersistLayer.php +++ b/src/Modules/JsonObjects/Infrastructure/DirsPersistLayer.php @@ -1,12 +1,13 @@ tableName = $tableName; } - public function newDir(IPersist $dto):bool + public function newDir(IPersist $dto): bool { $attrs = $dto->getInsertAttributes(); $qb = DB::table($this->tableName); return $qb->insert($attrs); } - public function updateDir(IPersist $dto):int + public function updateDir(IPersist $dto): int { $attrs = $dto->getUpdatedAttrs(); - if($attrs){ + if ($attrs) { $qb = DB::table($this->tableName); return $qb->where($this->tableName . '.id', '=', $dto->getId())->update($attrs); } return 0; } - public function deleteDirs(array $ids):int + public function deleteDirs(array $ids): int { $qb = DB::table($this->tableName); return $qb->whereIn($this->tableName . '.id', $ids)->delete(); } - -} \ No newline at end of file +} diff --git a/src/Modules/JsonObjects/Infrastructure/DirsQuery.php b/src/Modules/JsonObjects/Infrastructure/DirsQuery.php new file mode 100755 index 0000000..f737149 --- /dev/null +++ b/src/Modules/JsonObjects/Infrastructure/DirsQuery.php @@ -0,0 +1,106 @@ +tableName = $tableName; + } + + protected function reset() + { + $this->queryBuilder = DB::table($this->tableName); + } + + // protected function getSelectSection(array $fields, array $allowFields, string $table, string $prefix = ''): array + // { + // $segments = $this->baseGetSelectSection($fields, $allowFields, $table, $prefix); + // $result = []; + // foreach ($segments as $field => $alias) { + // $result[] = $field . ' AS ' . $alias; + // } + // return $result; + // } + + public function select(array $fields) + { + $this->reset(); + $selectSection = $this->_getSelectSection($fields, ['id', 'matherial_path', 'parent_id', 'name'], $this->tableName); + $this->queryBuilder->select($selectSection); + return $this; + } + + public function whereId($id) + { + $this->queryBuilder->where($this->tableName . '.id', '=', $id); + return $this; + } + + public function whereIdIn(array $ids) + { + $this->queryBuilder->whereIn($this->tableName . '.id', $ids); + return $this; + } + + public function whereParentId($parentId) + { + $this->queryBuilder->where($this->tableName . '.parent_id', '=', $parentId); + return $this; + } + + public function whereInPath(string $matherialPath) + { + $this->queryBuilder->where($this->tableName . '.matherial_path', 'like', $matherialPath . '%'); + return $this; + } + + // public function withParent(array $fields) + // { + // $this->joinParend(); + // $selectSection = $this->getSelectSection($fields, ['id', 'matherial_path', 'parent_id', 'name'], $this->tableName, 'parent_'); + // $this->queryBuilder->addSelect($selectSection); + // return $this; + // } + + // protected function joinParend() + // { + // if (!$this->isParentJoined) { + // $first = $this->tableName . '.id'; + // $two = $this->tableName . '.parent_id'; + // $this->queryBuilder->leftJoin($this->tableName . ' AS parent', $first, '=', $two); + // $this->isParentJoined = true; + // } + // } + + public function all(): array + { + $result = []; + foreach ($this->queryBuilder->get()->all() as $row) { + $result[$row->id] = $row; + } + return json_decode(json_encode($result), true); + } + + public function one(): array + { + $result = $this->queryBuilder->first() ?? []; + $result = json_decode(json_encode($result), true); + return $result; + } +} diff --git a/src/Modules/JsonObjects/Infrastructure/DirsStorage.php b/src/Modules/JsonObjects/Infrastructure/DirsStorage.php new file mode 100755 index 0000000..2409e83 --- /dev/null +++ b/src/Modules/JsonObjects/Infrastructure/DirsStorage.php @@ -0,0 +1,64 @@ +query = $query; + } + + public function setParentQuery(IDirsQuery $query) + { + $this->parentQuery = $query; + } + + public function getById($id, array $dsl = []): array + { + $this->query->select($dsl)->whereId($id); + $data = $this->query->one(); + if (!$data) { + return []; + } + if (key_exists('parent', $dsl)) { + $parentData = $this->parentQuery->select($dsl['parent'])->whereId($data['parent_id'])->all(); + $data['parent'] = $parentData; + } + if (key_exists('path', $dsl) && isset($data['matherial_path'])) { + $ids = explode('|', $data['matherial_path']); + $path = $this->query->select($dsl['path'])->whereIdIn($ids)->all(); + $data['path'] = $path; + } + return $data; + } + + public function getByParentId($parentId, array $dsl = []): array + { + return $this->query->select($dsl)->whereParentId($parentId)->all(); + } + + public function getIdsInDir(string $dirId): array + { + $dirData = $this->query->select(['id', 'matherial_path'])->whereId($dirId)->one(); + $pathIds = ($dirData['matherial_path']) ? explode('|', $dirData['matherial_path']) : []; + $pathIds[] = $dirId; + $matherialPath = join('|', $pathIds); + $dirs = $this->query->select(['id'])->whereInPath($matherialPath)->all(); + $ids = array_map(function ($dir) { + return $dir['id']; + }, $dirs); + return array_values($ids); + } +} diff --git a/src/Modules/JsonObjects/Infrastructure/Factory.php b/src/Modules/JsonObjects/Infrastructure/Factory.php index 268f4ac..9e5481f 100755 --- a/src/Modules/JsonObjects/Infrastructure/Factory.php +++ b/src/Modules/JsonObjects/Infrastructure/Factory.php @@ -4,13 +4,17 @@ namespace Src\Modules\JsonObjects\Infrastructure; use Src\Modules\JsonObjects\Interfaces\Infrastructure\IFactory; use Src\Modules\JsonObjects\Interfaces\IFactory as IModuleFactory; -use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemQuery; use Src\Modules\JsonObjects\Infrastructure\ItemQuery; use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage; use Src\Modules\JsonObjects\Infrastructure\ItemStorage; use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemPersistLayer; use Src\Modules\JsonObjects\Infrastructure\ItemPersistLayer; -use Src\Modules\JsonObjects\Interfaces\Infrastructure\IMigrations; +use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage; +use Src\Modules\JsonObjects\Infrastructure\DirsStorage; +use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsQuery; +use Src\Modules\JsonObjects\Infrastructure\DirsQuery; +use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsPersistLayer; +use Src\Modules\JsonObjects\Infrastructure\DirsPersistLayer; class Factory implements IFactory { @@ -21,7 +25,9 @@ class Factory implements IFactory protected ?IItemPersistLayer $persistLayer = null; - protected ?IMigrations $migration = null; + protected ?IDirsStorage $dirsStorage = null; + + protected ?IDirsPersistLayer $dirsPersistLayer = null; protected array $conf; @@ -31,6 +37,9 @@ class Factory implements IFactory 'itemQuery' => ItemQuery::class, 'itemStorage' => ItemStorage::class, 'itemPersistLayer' => ItemPersistLayer::class, + 'dirsStorage' => DirsStorage::class, + 'dirsQuery' => DirsQuery::class, + 'dirPersistLayer' => DirsPersistLayer::class, ]; $this->conf = array_replace_recursive($this->conf, $conf); } @@ -54,8 +63,8 @@ class Factory implements IFactory $this->storage = new $this->conf['itemStorage']; $query = $this->createQuery(); $this->storage->setObjectsQuery($query); - $dirStorage = $this->moduleFactory->getDirsTreeFactory()->getInfrastructureFactory()->getStorage(); - $this->storage->setDirStorage($dirStorage); + $dirsStorage = $this->getDirsStorage(); + $this->storage->setDirStorage($dirsStorage); } return $this->storage; } @@ -69,4 +78,34 @@ class Factory implements IFactory } return $this->persistLayer; } + + public function createDirsQuery(): IDirsQuery + { + $query = new $this->conf['dirsQuery']; + $tableName = $this->moduleFactory->getSetting(IModuleFactory::DIRS_TABLE); + $query->setTableName($tableName); + return $query; + } + + public function getDirsStorage(): IDirsStorage + { + if ($this->dirsStorage === null) { + $this->dirsStorage = new $this->conf['dirsStorage']; + $query = $this->createDirsQuery(); + $this->dirsStorage->setQuery($query); + $query = $this->createDirsQuery(); + $this->dirsStorage->setParentQuery($query); + } + return $this->dirsStorage; + } + + public function getDirsPersistLayer(): IDirsPersistLayer + { + if ($this->dirsPersistLayer === null) { + $this->dirsPersistLayer = new $this->conf['dirPersistLayer']; + $tableName = $this->moduleFactory->getSetting(IModuleFactory::DIRS_TABLE); + $this->dirsPersistLayer->setTableName($tableName); + } + return $this->dirsPersistLayer; + } } diff --git a/src/Modules/JsonObjects/Infrastructure/ItemQuery.php b/src/Modules/JsonObjects/Infrastructure/ItemQuery.php index 877e94d..b13bd9c 100755 --- a/src/Modules/JsonObjects/Infrastructure/ItemQuery.php +++ b/src/Modules/JsonObjects/Infrastructure/ItemQuery.php @@ -6,9 +6,9 @@ use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemQuery; use Illuminate\Support\Facades\DB; use Illuminate\Database\Query\Builder; use Src\Common\Infrastructure\TraitSqlQuery; -use hrustbb2\arrayproc\ArrayProcessor; -class ItemQuery implements IItemQuery { +class ItemQuery implements IItemQuery +{ use TraitSqlQuery { TraitSqlQuery::getSelectSection as baseGetSelectSection; @@ -18,29 +18,16 @@ class ItemQuery implements IItemQuery { protected Builder $queryBuilder; - protected array $arrayProcConf = []; - public function setTableName(string $tableName) { $this->tableName = $tableName; } - protected function getSelectSection(array $fields, array $allowFields, string $table, string $prefix = ''): array - { - $segments = $this->baseGetSelectSection($fields, $allowFields, $table, $prefix); - $result = []; - foreach($segments as $field=>$alias){ - $result[] = $field . ' AS ' . $alias; - } - return $result; - } - public function select(array $fields = []) { $this->queryBuilder = DB::table($this->tableName); - $select = $this->getSelectSection($fields, ['id', 'dir_id', 'key', 'name', 'description', 'object', 'disabled'], $this->tableName, 'object_'); + $select = $this->_getSelectSection($fields, ['id', 'dir_id', 'key', 'name', 'description', 'object', 'disabled'], $this->tableName); $this->queryBuilder->select($select); - $this->arrayProcConf = ['prefix' => 'object_']; return $this; } @@ -89,20 +76,17 @@ class ItemQuery implements IItemQuery { public function all(): array { - $arrayProc = new ArrayProcessor(); - // DB::enableQueryLog(); - $data = $this->queryBuilder->get()->toArray(); - // $log = DB::getQueryLog(); - // dd($log); - return $arrayProc->process($this->arrayProcConf, $data)->resultArray(); + $result = []; + foreach ($this->queryBuilder->get()->all() as $row) { + $result[$row->id] = $row; + } + return json_decode(json_encode($result), true); } public function one(): array { - $arrayProc = new ArrayProcessor(); - $data = $this->queryBuilder->get()->toArray(); - $d = $arrayProc->process($this->arrayProcConf, $data)->resultArray(); - return array_pop($d) ?? []; + $result = $this->queryBuilder->first() ?? []; + $result = json_decode(json_encode($result), true); + return $result; } - -} \ No newline at end of file +} diff --git a/src/Modules/JsonObjects/Infrastructure/ItemStorage.php b/src/Modules/JsonObjects/Infrastructure/ItemStorage.php index 7bd6284..2648bc4 100755 --- a/src/Modules/JsonObjects/Infrastructure/ItemStorage.php +++ b/src/Modules/JsonObjects/Infrastructure/ItemStorage.php @@ -4,36 +4,37 @@ namespace Src\Modules\JsonObjects\Infrastructure; use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage; use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemQuery; -use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage as IDirStorage; +use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage; use Src\Common\Infrastructure\TraitStorage; -class ItemStorage implements IItemStorage { +class ItemStorage implements IItemStorage +{ use TraitStorage; protected IItemQuery $objectsQuery; - protected IDirStorage $dirStorage; + protected IDirsStorage $dirsStorage; public function setObjectsQuery(IItemQuery $query) { $this->objectsQuery = $query; } - public function setDirStorage(IDirStorage $storage):void + public function setDirStorage(IDirsStorage $storage): void { - $this->dirStorage = $storage; + $this->dirsStorage = $storage; } - public function getById(string $itemId, array $dsl = []):array + public function getById(string $itemId, array $dsl = []): array { $itemData = $this->objectsQuery->select($dsl)->whereId($itemId)->one(); - if(empty($itemData)){ + if (empty($itemData)) { return []; } - if(key_exists('dir', $dsl)){ + if (key_exists('dir', $dsl)) { $dirId = $itemData['dir_id']; - $dirData = $this->dirStorage->getById($dirId, $dsl['dir']); + $dirData = $this->dirsStorage->getById($dirId, $dsl['dir']); $itemData['dir'] = [ $dirId => $dirData, ]; @@ -41,26 +42,25 @@ class ItemStorage implements IItemStorage { return $itemData; } - public function getByIds(array $ids, array $dsl = []):array + public function getByIds(array $ids, array $dsl = []): array { $itemsData = $this->objectsQuery->select($dsl)->whereIdIn($ids)->all(); return $itemsData; - } + } - public function getByType(string $type, int $limit, int $offset, array $dsl = []):array + public function getByType(string $type, int $limit, int $offset, array $dsl = []): array { $itemsData = $this->objectsQuery->select($dsl)->limit($limit, $offset)->whereType($type)->all(); return $itemsData; } - public function getByKey(string $key, array $dsl = []):array + public function getByKey(string $key, array $dsl = []): array { return $this->objectsQuery->select($dsl)->whereKey($key)->one(); } - public function getByDirId(string $dirId, array $dsl = []):array + public function getByDirId(string $dirId, array $dsl = []): array { return $this->objectsQuery->select($dsl)->whereDirId($dirId)->all(); } - -} \ No newline at end of file +} diff --git a/src/Modules/JsonObjects/Interfaces/Application/IDataBuilder.php b/src/Modules/JsonObjects/Interfaces/Application/IDataBuilder.php index 082ecc8..3ba6cbe 100755 --- a/src/Modules/JsonObjects/Interfaces/Application/IDataBuilder.php +++ b/src/Modules/JsonObjects/Interfaces/Application/IDataBuilder.php @@ -2,9 +2,11 @@ namespace Src\Modules\JsonObjects\Interfaces\Application; -use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage as IDirStorage; +use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage; -interface IDataBuilder { - public function setDirStorage(IDirStorage $dirStorage):void; - public function build(array $data):array; -} \ No newline at end of file +interface IDataBuilder +{ + public function setDirStorage(IDirsStorage $dirStorage): void; + public function build(array $data): array; + public function buildDirData(array $requestData): array; +} diff --git a/src/Modules/JsonObjects/Interfaces/Application/IDomain.php b/src/Modules/JsonObjects/Interfaces/Application/IDomain.php index b315912..52faf42 100755 --- a/src/Modules/JsonObjects/Interfaces/Application/IDomain.php +++ b/src/Modules/JsonObjects/Interfaces/Application/IDomain.php @@ -9,23 +9,26 @@ use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemPersistLayer; use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage; use Src\Modules\JsonObjects\Interfaces\Dto\Item\IResourceItem; use Src\Modules\JsonObjects\Interfaces\Application\IDataBuilder; -use Src\Lib\CategoriesTree\Interfaces\Application\IValidator as IDirValidator; -use Src\Lib\CategoriesTree\Interfaces\Application\IDomain as IDirDomain; -use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage as IDirStorage; +use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage; +use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsPersistLayer; +use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IResource as IDirResource; -interface IDomain extends IBaseDomain { - public function setValidator(IValidator $validator):void; - public function setDtoFactory(IDtoFactory $factory):void; - public function setPersistLayer(IItemPersistLayer $layer):void; - public function setStorage(IItemStorage $storage):void; - public function setDataBuilder(IDataBuilder $dataBuilder):void; - public function setDirValidator(IDirValidator $validator):void; - public function setDirDomain(IDirDomain $domain):void; - public function setDirStorage(IDirStorage $storage):void; - public function createObject(array $data):bool; - public function editObject(array $data):bool; - public function renameObject(array $data):bool; - public function deleteObject(array $data):bool; - public function deleteDir(array $data):bool; - public function getItem():IResourceItem; -} \ No newline at end of file +interface IDomain extends IBaseDomain +{ + public function setValidator(IValidator $validator): void; + public function setDtoFactory(IDtoFactory $factory): void; + public function setPersistLayer(IItemPersistLayer $layer): void; + public function setStorage(IItemStorage $storage): void; + public function setDataBuilder(IDataBuilder $dataBuilder): void; + public function setDirStorage(IDirsStorage $storage): void; + public function setDirsPersistLayer(IDirsPersistLayer $layer): void; + public function createObject(array $data): bool; + public function editObject(array $data): bool; + public function renameObject(array $data): bool; + public function deleteObject(array $data): bool; + public function deleteDir(array $data): bool; + public function getItem(): IResourceItem; + public function createDir(array $data): bool; + public function renameDir(array $data): bool; + public function getDir(): IDirResource; +} diff --git a/src/Modules/JsonObjects/Interfaces/Application/IValidator.php b/src/Modules/JsonObjects/Interfaces/Application/IValidator.php index 895899e..58a554f 100755 --- a/src/Modules/JsonObjects/Interfaces/Application/IValidator.php +++ b/src/Modules/JsonObjects/Interfaces/Application/IValidator.php @@ -4,9 +4,13 @@ namespace Src\Modules\JsonObjects\Interfaces\Application; use Src\Common\Interfaces\Application\IBaseValidator; -interface IValidator extends IBaseValidator { - public function createObject(array $data):bool; - public function editObject(array $data):bool; - public function renameObject(array $data):bool; - public function deleteObject(array $data):bool; -} \ No newline at end of file +interface IValidator extends IBaseValidator +{ + public function createObject(array $data): bool; + public function editObject(array $data): bool; + public function renameObject(array $data): bool; + public function deleteObject(array $data): bool; + public function createDir(array $data): bool; + public function renameDir(array $data): bool; + public function deleteDir(array $data): bool; +} diff --git a/src/Lib/CategoriesTree/Interfaces/Dto/IAbstractCategory.php b/src/Modules/JsonObjects/Interfaces/Dto/Dir/IAbstractCategory.php similarity index 70% rename from src/Lib/CategoriesTree/Interfaces/Dto/IAbstractCategory.php rename to src/Modules/JsonObjects/Interfaces/Dto/Dir/IAbstractCategory.php index 3075ff3..b1d2d79 100755 --- a/src/Lib/CategoriesTree/Interfaces/Dto/IAbstractCategory.php +++ b/src/Modules/JsonObjects/Interfaces/Dto/Dir/IAbstractCategory.php @@ -1,11 +1,12 @@ factory->getDirsTreeFactory()->getApplicationFactory()->getDomain(); + $domain = $this->factory->getApplicationFactory()->getDomain(); $data = $request->all(); $resp = [ 'success' => $domain->createDir($data), @@ -45,7 +46,7 @@ class DirController extends Controller { public function renameDir(Request $request) { - $domain = $this->factory->getDirsTreeFactory()->getApplicationFactory()->getDomain(); + $domain = $this->factory->getApplicationFactory()->getDomain(); $data = $request->all(); $resp = [ 'success' => $domain->renameDir($data), @@ -65,5 +66,4 @@ class DirController extends Controller { ]; return response()->json($resp, $domain->getResponseCode()); } - -} \ No newline at end of file +} diff --git a/src/Modules/JsonObjects/Pages/Dir.php b/src/Modules/JsonObjects/Pages/Dir.php index 554b175..6ca40de 100755 --- a/src/Modules/JsonObjects/Pages/Dir.php +++ b/src/Modules/JsonObjects/Pages/Dir.php @@ -4,9 +4,9 @@ namespace Src\Modules\JsonObjects\Pages; use Src\Common\Pages\Page; use Src\Modules\JsonObjects\Interfaces\Pages\IDir; -use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage as IDirsStorage; -use Src\Lib\CategoriesTree\Interfaces\Dto\IFactory as IDirsDtoFactory; -use Src\Lib\CategoriesTree\Interfaces\Dto\IResource as IDirResource; +use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage; +use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IFactory as IDirsDtoFactory; +use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IResource as IDirResource; use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage; use Src\Modules\JsonObjects\Interfaces\Dto\Item\IFactory as IItemDtoFactory; use Src\Modules\JsonObjects\Interfaces\Dto\Item\IResourceItem; @@ -144,6 +144,10 @@ class Dir extends Page implements IDir 'href' => route('admin.jsonObjects.dir', ['dir-id' => $this->currentDir->getParent()->getId()], false), ]; } + $bc[] = [ + 'title' => $this->currentDir->getName(), + 'href' => route('admin.jsonObjects.dir', ['dir-id' => $this->currentDir->getId()], false), + ]; return $bc; } diff --git a/src/Modules/JsonObjects/Pages/Factory.php b/src/Modules/JsonObjects/Pages/Factory.php index 1f19577..76ac159 100755 --- a/src/Modules/JsonObjects/Pages/Factory.php +++ b/src/Modules/JsonObjects/Pages/Factory.php @@ -33,9 +33,9 @@ class Factory implements IFactory $page = new $this->conf['dir']; $sidebarMenu = $this->moduleFactory->getSidebarFactory()->getMenu(); $page->setSidebar($sidebarMenu); - $dirsStorage = $this->moduleFactory->getDirsTreeFactory()->getInfrastructureFactory()->getStorage(); + $dirsStorage = $this->moduleFactory->getInfrastructureFactory()->getDirsStorage(); $page->setDirsStorage($dirsStorage); - $dirsDtoFactory = $this->moduleFactory->getDirsTreeFactory()->getDtoFactory(); + $dirsDtoFactory = $this->moduleFactory->getDtoFactory()->getDirFactory(); $page->setDirsDtoFactory($dirsDtoFactory); $itemStorage = $this->moduleFactory->getInfrastructureFactory()->getStorage(); $page->setItemStorage($itemStorage); diff --git a/src/Modules/JsonObjects/Pages/Item.php b/src/Modules/JsonObjects/Pages/Item.php index 011719f..ff9f410 100755 --- a/src/Modules/JsonObjects/Pages/Item.php +++ b/src/Modules/JsonObjects/Pages/Item.php @@ -118,6 +118,10 @@ class Item extends Page implements IItem 'href' => route('admin.jsonObjects.dir', ['dir-id' => $this->item->getDir()->getParent()->getId()], false), ]; } + $bc[] = [ + 'title' => $this->item->getDir()->getName(), + 'href' => route('admin.jsonObjects.dir', ['dir-id' => $this->item->getDir()->getId()], false), + ]; $bc[] = [ 'title' => $this->item->getName(), 'href' => route('admin.jsonObjects.editItem', ['item-id' => $this->item->getId()], false), diff --git a/src/ModulesProvider.php b/src/ModulesProvider.php index 0d12010..0d2eaa1 100755 --- a/src/ModulesProvider.php +++ b/src/ModulesProvider.php @@ -18,8 +18,8 @@ use Src\Modules\JsonObjects\Interfaces\IModulesProvider as IJSONProvider; use Src\Modules\JsonObjects\Interfaces\IFactory as IJSONFactory; use Src\Modules\JsonObjects\Factory as JSONFactory; -use Src\Lib\CategoriesTree\Interfaces\IFactory as IDirTreeFactory; -use Src\Lib\CategoriesTree\Factory as DirTreeFactory; +// use Src\Lib\CategoriesTree\Interfaces\IFactory as IDirTreeFactory; +// use Src\Lib\CategoriesTree\Factory as DirTreeFactory; use Src\Common\Interfaces\Dto\Object\IFactory as IObjFactory; @@ -45,17 +45,17 @@ class ModulesProvider implements ICommonProvider, ISidebarProvider, IJSONProvide 'common' => [ 'factory' => CommonFactory::class, ], - 'jsonObjectsDirs' => [ - 'factory' => DirTreeFactory::class, - 'settings' => [ - IDirTreeFactory::DB_CHARSET => 'utf8', - IDirTreeFactory::DB_HOST => env('DB_HOST'), - IDirTreeFactory::DB_NAME => env('DB_DATABASE'), - IDirTreeFactory::DB_PASS => env('DB_PASSWORD'), - IDirTreeFactory::DB_USER => env('DB_USERNAME'), - // IDirTreeFactory::TABLE_NAME => $dirsTable, - ], - ], + // 'jsonObjectsDirs' => [ + // 'factory' => DirTreeFactory::class, + // 'settings' => [ + // IDirTreeFactory::DB_CHARSET => 'utf8', + // IDirTreeFactory::DB_HOST => env('DB_HOST'), + // IDirTreeFactory::DB_NAME => env('DB_DATABASE'), + // IDirTreeFactory::DB_PASS => env('DB_PASSWORD'), + // IDirTreeFactory::DB_USER => env('DB_USERNAME'), + // // IDirTreeFactory::TABLE_NAME => $dirsTable, + // ], + // ], 'jsonObjects' => [ 'factory' => JSONFactory::class, 'settings' => [ @@ -108,14 +108,14 @@ class ModulesProvider implements ICommonProvider, ISidebarProvider, IJSONProvide return $this->commonFactory; } - protected function createDirTreeFactory(): DirTreeFactory - { - $factory = $this->createInstance($this->conf['jsonObjectsDirs']['factory']); - $factory->loadSettings($this->conf['jsonObjectsDirs']['settings']); - $factory->init(); - $factory->setCommonFactory($this->getCommonFactory()); - return $factory; - } + // protected function createDirTreeFactory(): DirTreeFactory + // { + // $factory = $this->createInstance($this->conf['jsonObjectsDirs']['factory']); + // $factory->loadSettings($this->conf['jsonObjectsDirs']['settings']); + // $factory->init(); + // $factory->setCommonFactory($this->getCommonFactory()); + // return $factory; + // } public function getJsonObjectsFactory(): JSONFactory { @@ -123,8 +123,8 @@ class ModulesProvider implements ICommonProvider, ISidebarProvider, IJSONProvide $this->jsonFactory = $this->createInstance($this->conf['jsonObjects']['factory']); $this->jsonFactory->init(); $this->jsonFactory->loadSettings($this->conf['jsonObjects']['settings']); - $dirTreeFactory = $this->createDirTreeFactory(); - $this->jsonFactory->setDirsTreeFactory($dirTreeFactory); + // $dirTreeFactory = $this->createDirTreeFactory(); + // $this->jsonFactory->setDirsTreeFactory($dirTreeFactory); $this->jsonFactory->injectModules($this); } return $this->jsonFactory; diff --git a/storage/uploads/.gitignore b/storage/uploads/.gitignore new file mode 100755 index 0000000..9edb6ed --- /dev/null +++ b/storage/uploads/.gitignore @@ -0,0 +1,4 @@ +* +!_thumb/ +!files-browser +!.gitignore diff --git a/storage/uploads/0009e677-adfa-11ed-bb3c-6431504e7ac2.jpeg b/storage/uploads/0009e677-adfa-11ed-bb3c-6431504e7ac2.jpeg deleted file mode 100644 index 4510ad7..0000000 Binary files a/storage/uploads/0009e677-adfa-11ed-bb3c-6431504e7ac2.jpeg and /dev/null differ diff --git a/storage/uploads/Снимок экрана_2025-07-01_15-19-20.png b/storage/uploads/Снимок экрана_2025-07-01_15-19-20.png deleted file mode 100644 index 9bd177b..0000000 Binary files a/storage/uploads/Снимок экрана_2025-07-01_15-19-20.png and /dev/null differ