em = $em; $this->process = $process; $this->storage = $storage; $this->smanager = $smanager; $this->boxSettingName = 'NET15.TICKETBUNDLE.MAIN.BOX'; $this->fileManagerMainService = $fileManagerMainService; $this->fileManagerPermission = $fileManagerPermission; $this->groupManagerService = $groupManagerService; } public function getBox(){ $box = $this->smanager->get($this->boxSettingName,null,false,"ticketBundle"); if(is_null($box)){ //todo create box and store $systemBox = $this->fileManagerMainService->getSystemBox(); if(!$systemBox instanceof FolderItem) return null; //create folder & group //create folder $f = new FolderItem(); $f->setParent($systemBox); $f->setName('ticketbox'); $r = $this->fileManagerMainService->updateFolder($f); if(!$r) return null;//if we cant create folder $g = new UserGroup(); $g->setDefault('ticketbox'); $r = $this->groupManagerService->registerGroup($g); if(!$r) return null; $folderPermission = new FolderGroupPermission(); $folderPermission->setDefault($g,$f,FilePermission::OWNER); //register access permission for the group $r = $this->fileManagerPermission->updateFolderGroupPermission($folderPermission); if(!$r) return null; $this->smanager->update($this->boxSettingName,$f->getGuid(), "ticketBundle"); return $f; } return $this->fileManagerMainService->getFolderItemFromGuid($box); } /** * @param TicketItemInterface $ticket * @return bool */ public function createTicketFolder(TicketItemInterface $ticket){ $ticketName = 'ticket-'.$ticket->getId(); $systemBox = $this->getBox(); if(!$systemBox instanceof FolderItem) return false; //create folder & group //create folder $f = new FolderItem(); $f->setParent($systemBox); $f->setName($ticketName); $r = $this->fileManagerMainService->updateFolder($f); if(!$r) return false;//if we cant create folder $g = new UserGroup(); $g->setDefault($ticketName); $r = $this->groupManagerService->registerGroup($g); if(!$r) return false; $folderPermission = new FolderGroupPermission(); $folderPermission->setDefault($g,$f,FilePermission::OWNER); //register access permission for the group $r = $this->fileManagerPermission->updateFolderGroupPermission($folderPermission); if(!$r) return false; if(!$this->fileManagerMainService->updateFolder($f)) return false; $ticket->setRootFolder($f) ->setGroup($g); return true; } }