public function createCommunity(CreateCommunityParameters $parameters) : Community
 {
     $owner = $this->currentAccountService->getCurrentAccount();
     $entity = new Community($owner, $parameters->getTitle(), $parameters->getDescription(), $parameters->hasThemeId() ? $this->themeRepository->getThemeById($parameters->getThemeId()) : null);
     $this->communityRepository->createCommunity($entity);
     $strategy = new CommunityImageStrategy($entity, $this->imageFileSystem, $this->wwwImageDir);
     $this->avatarService->generateImage($strategy);
     $this->backdropService->backdropPreset($entity, $this->backdropPresetFactory, $this->backdropPresetFactory->getListIds()[array_rand($this->backdropPresetFactory->getListIds())]);
     $this->communityRepository->saveCommunity($entity);
     $this->getEventEmitter()->emit(self::EVENT_COMMUNITY_CREATED, [$entity]);
     return $entity;
 }
 public function createCollection(CreateCollectionParameters $parameters, bool $disableAccess = false)
 {
     $collection = new Collection($parameters->getOwnerSID());
     if (!$disableAccess) {
         $this->getEventEmitter()->emit(self::EVENT_COLLECTION_ACCESS, [$collection]);
     }
     $collection->setTitle($parameters->getTitle())->setDescription($parameters->getDescription())->setThemeIds($parameters->getThemeIds());
     $this->collectionRepository->createCollection($collection);
     $this->avatarService->generateImage(new CollectionImageStrategy($collection, $this->images, $this->wwwImagesDir));
     $this->backdropService->backdropPreset($collection, $this->presetFactory, $this->presetFactory->getListIds()[array_rand($this->presetFactory->getListIds())]);
     $this->collectionRepository->saveCollection($collection);
     $this->getEventEmitter()->emit(self::EVENT_COLLECTION_CREATED, [$collection]);
     return $collection;
 }
Exemple #3
0
 public function createProfileForAccount(Account $account) : Profile
 {
     if ($account->getProfiles()->count() >= self::MAX_PROFILES_PER_ACCOUNT) {
         throw new MaxProfilesReachedException(sprintf('You can only have %d profiles per account', self::MAX_PROFILES_PER_ACCOUNT));
     }
     $account->getProfiles()->add($profile = new Profile($account));
     $this->profileRepository->createProfile($profile);
     $this->accountService->switchToProfile($account, $profile->getId());
     $this->generateProfileImage($profile->getId());
     $this->backdropService->backdropPreset($profile, $this->backdropPresetFactory, $this->backdropPresetFactory->getListIds()[array_rand($this->backdropPresetFactory->getListIds())]);
     $this->getEventEmitter()->emit(self::EVENT_PROFILE_CREATED, [$profile]);
     return $profile;
 }