id = uniqid(); } public function setDtoFactory(IDtoFactory $factory) { $this->dtoFactory = $factory; } public function loadPath(array $data) { $this->path = []; foreach ($data as $itemData) { $pathItem = $this->dtoFactory->getDirFactory()->createPersist(); $pathItem->load($itemData); $this->path[] = $pathItem; } } public function getPath(): array { return $this->path; } public function loadParent(array $data) { $this->parent = $this->dtoFactory->getDirFactory()->createPersist(); $this->parent->load($data); } public function update(array $data): void { if (isset($data['name']) && $data['name'] != $this->name) { $this->name = $data['name']; $this->updatedAttrs['name'] = $data['name']; } } public function getInsertAttributes(): array { $parentId = ($this->parent) ? $this->parent->getId() : ''; $attrs = [ 'id' => $this->id, 'parent_id' => $parentId, 'name' => $this->name, ]; $parentPath = ($this->parent) ? $this->parent->getPath() : []; $pathIds = array_map(function (IAbstractCategory $item) { return $item->getId(); }, $parentPath); $pathIds[] = $parentId; $attrs['matherial_path'] = join('|', $pathIds); return $attrs; } public function getUpdatedAttrs(): array { return $this->updatedAttrs; } }