entityManager = $entityManager; $this->container =$container; // $this->userBoxManager = $container->get('net15.user.box.manager'); } /** * @param TrashBox $element * @return TrashBox|null */ public function quickUpdate(TrashBox $element): ?TrashBox { if (!$this->entityManager->contains($element)) { try { $this->entityManager->persist($element); } catch (ORMException $e) { return null; } } try { $this->entityManager->flush(); } catch (OptimisticLockException $e) { return null; } catch (ORMException $e) { return null; } return $element; } public function getByUser(CustomUserInterface $user){ $trashBox = $this->entityManager->getRepository(TrashBox::class)->findOneBy(['user'=>$user]); if($trashBox === null){ $name = $user->getId().'-trash-box'; $userBox = $this->container->get('net15.user.box.manager')->getByUser($user); // $userBox = $this->userBoxManager->getByUser($user); $trashBox = $this->create($name, $user, $userBox); } return $trashBox; } public function create(string $name, CustomUserInterface $user, FolderItemInterface $userBox){ if (!$user instanceof CustomUserInterface || !$userBox instanceof FolderItemInterface) return null; $trashBox = new TrashBox(); $trashBox->setDefault($name, $user, $userBox); if (!$this->quickUpdate($trashBox)) return null; return $trashBox; } /* * directories is children */ public function addDirectories(FolderItemInterface $folder){ } public function update(FolderItemInterface $folder){ } public function remove(FolderItemInterface $folder){ } }