public function up(EventEmitterInterface $globalEmitter)
 {
     $eq = $this->eq;
     $profileService = $this->profileService;
     $themeService = $this->themeService;
     $themeService->getEventEmitter()->on(ThemeService::EVENT_DELETE, function (Theme $theme) use($eq, $profileService) {
         array_reduce($eq->getProfilesByThemeId($theme->getId()), function (ProfileExpertInEQ $eq) use($profileService) {
             $profile = $profileService->getProfileById($eq->getProfileId());
             $profile->setExpertInIds(array_filter($profile->getExpertInIds(), function ($input) use($eq) {
                 return (int) $input !== (int) $eq->getThemeId();
             }));
             $this->profileRepository->saveProfile($profile);
         });
         $eq->deleteEQOfTheme($theme->getId());
     });
     $profileService->getEventEmitter()->on(ProfileService::EVENT_PROFILE_CREATED, function (Profile $profile) use($eq) {
         $eq->sync($profile->getId(), $profile->getExpertInIds());
     });
     $profileService->getEventEmitter()->on(ProfileService::EVENT_PROFILE_UPDATED, function (Profile $profile) use($eq) {
         $eq->sync($profile->getId(), $profile->getExpertInIds());
     });
     $profileService->getEventEmitter()->on(ProfileService::EVENT_PROFILE_DELETE, function (Profile $profile) use($eq) {
         $eq->deleteEQOfProfile($profile->getId());
     });
 }
Example #2
0
 public function unlinkCollection(int $profileId, int $collectionId) : ImmutableCollectionTree
 {
     $profile = $this->getProfileById($profileId);
     $collections = $profile->getCollections()->createMutableInstance();
     if ($collections->hasCollection($collectionId)) {
         $collections->detachChild($collectionId);
     }
     $profile->replaceCollections($collections->createImmutableInstance());
     $this->profileRepository->saveProfile($profile);
     $this->getEventEmitter()->emit(self::EVENT_PROFILE_UPDATED, [$profile]);
     return $profile->getCollections();
 }
Example #3
0
 public function switchToProfile(Account $account, int $switchToProfileId) : Account
 {
     if (!$account->getProfiles()->filter(function (Profile $profile) use($switchToProfileId) {
         return $profile->getId() === $switchToProfileId;
     })->count()) {
         throw new AccountNotContainsProfileException(sprintf('Profile (ID: %s) is not exists', $switchToProfileId));
     }
     $account->getProfiles()->map(function (Profile $profile) use($switchToProfileId, &$found) {
         $profile->getId() === $switchToProfileId ? $profile->setAsCurrent() : $profile->unsetAsCurrent();
     });
     $this->accountRepository->saveAccount($account);
     array_map(function (Profile $profile) {
         $this->profileRepository->saveProfile($profile);
     }, $account->getProfiles()->toArray());
     return $account;
 }