/**
  * {@inheritdoc}
  */
 public function reverseTransform($value)
 {
     if (!$value) {
         return [];
     }
     /** @var CalendarRepository $calendarRepository */
     $calendarRepository = $this->registry->getRepository('OroCalendarBundle:Calendar');
     $organizationId = $this->securityFacade->getOrganizationId();
     if (!$organizationId) {
         throw new TransformationFailedException('Can\'t get current organization');
     }
     $events = new ArrayCollection();
     /** @var User $user */
     $userIds = [];
     foreach ($value as $user) {
         $userIds[] = $user->getId();
     }
     $calendars = $calendarRepository->findDefaultCalendars($userIds, $organizationId);
     foreach ($calendars as $calendar) {
         $event = new CalendarEvent();
         $event->setCalendar($calendar);
         $events->add($event);
     }
     return $events;
 }
Esempio n. 2
0
 /**
  * Add Organization limitation for search data
  *
  * @param BeforeSearchEvent $event
  */
 public function beforeSearchEvent(BeforeSearchEvent $event)
 {
     $query = $event->getQuery();
     $organizationId = $this->securityFacade->getOrganizationId();
     if ($organizationId) {
         $query->andWhere('organization', 'in', [$organizationId, self::EMPTY_ORGANIZATION_ID], 'integer');
     }
     $event->setQuery($query);
 }
Esempio n. 3
0
 /**
  * @param FormEvent $event
  */
 public function onPreSetData(FormEvent $event)
 {
     $form = $event->getForm();
     $data = $event->getData();
     if ($data) {
         if ($data->getId()) {
             $form->remove('businessUnit');
             $form->add('businessUnit', 'oro_business_unit_tree_select', ['label' => 'oro.organization.businessunit.parent.label', 'empty_value' => 'oro.business_unit.form.none_business_user', 'property_path' => 'owner', 'required' => false, 'choices' => $this->getBusinessUnitChoices($this->businessUnitManager->getBusinessUnitsTree(null, $this->securityFacade->getOrganizationId())), 'forbidden_business_unit_ids' => $this->businessUnitManager->getChildBusinessUnitIds($data->getId(), $this->securityFacade->getOrganizationId())]);
         }
     }
 }
Esempio n. 4
0
 /**
  * Gets a list of user's calendars for which it is granted to add events
  *
  * @return array of [id, name]
  */
 public function getUserCalendars()
 {
     /** @var CalendarRepository $repo */
     $repo = $this->doctrineHelper->getEntityRepository('OroCalendarBundle:Calendar');
     $calendars = $repo->getUserCalendarsQueryBuilder($this->securityFacade->getOrganizationId(), $this->securityFacade->getLoggedUserId())->select('c.id, c.name')->getQuery()->getArrayResult();
     foreach ($calendars as &$calendar) {
         if (empty($calendar['name'])) {
             $calendar['name'] = $this->entityNameResolver->getName($this->securityFacade->getLoggedUser());
         }
     }
     return $calendars;
 }
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $buTree = $this->buManager->getBusinessUnitRepo()->getOrganizationBusinessUnitsTree($this->securityFacade->getOrganizationId());
     $view->vars['organization_tree_ids'] = $buTree;
     /** @var PersistentCollection $businessUnitData */
     $businessUnitData = $view->vars['data']->getBusinessUnits();
     if ($businessUnitData) {
         $businessUnitData = $businessUnitData->map(function ($item) {
             return $item->getId();
         })->getValues();
     }
     $view->vars['selected_organizations'] = [$this->securityFacade->getOrganizationId()];
     $view->vars['selected_business_units'] = $businessUnitData;
 }
 /**
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datagrid = $event->getDatagrid();
     $datasource = $datagrid->getDatasource();
     if ($datasource instanceof OrmDatasource) {
         $isPublicGranted = $this->calendarConfig->isPublicCalendarEnabled();
         $isSystemGranted = $this->calendarConfig->isSystemCalendarEnabled() && $this->securityFacade->isGranted('oro_system_calendar_view');
         if ($isPublicGranted && $isSystemGranted) {
             $datasource->getQueryBuilder()->andWhere('(sc.public = :public OR sc.organization = :organizationId)')->setParameter('public', true)->setParameter('organizationId', $this->securityFacade->getOrganizationId());
         } elseif ($isPublicGranted) {
             $datasource->getQueryBuilder()->andWhere('sc.public = :public')->setParameter('public', true);
         } elseif ($isSystemGranted) {
             $datasource->getQueryBuilder()->andWhere('sc.organization = :organizationId')->setParameter('organizationId', $this->securityFacade->getOrganizationId());
         } else {
             // it is denied to view both public and system calendars
             $datasource->getQueryBuilder()->andWhere('1 = 0');
         }
     }
 }
Esempio n. 7
0
 /**
  * @return int|null
  */
 protected function getOrganizationContextId()
 {
     return $this->securityFacade->getOrganizationId();
 }
 /**
  * Returns query builder that uses to build query for search bu id or by search string.
  * Result data limit by users that was have access to the current organization and excluding current user.
  *
  * @return QueryBuilder
  */
 protected function getBasicQueryBuilder()
 {
     $queryBuilder = $this->entityRepository->createQueryBuilder('u');
     $queryBuilder->join('u.organizations', 'org')->andWhere('org.id = :org')->andWhere('u.id != :currentUser')->setParameter('org', $this->securityFacade->getOrganizationId())->setParameter('currentUser', $this->securityFacade->getLoggedUserId());
     return $queryBuilder;
 }