Esempio n. 1
0
 /**
  * @param User         $user
  * @param Organization $organization
  * @param array        $folderTypes
  * @param bool         $isSeen
  * @return array
  */
 public function getEmailUserList(User $user, Organization $organization, array $folderTypes = [], $isSeen = null)
 {
     $qb = $this->createQueryBuilder('eu');
     $qb->join('eu.folders', 'f')->join('f.origin', 'o')->andWhere($qb->expr()->eq('eu.owner', $user->getId()))->andWhere($qb->expr()->eq('eu.organization', $organization->getId()))->andWhere($qb->expr()->eq('o.isActive', ':active'))->setParameter('active', true);
     if ($folderTypes) {
         $qb->andWhere($qb->expr()->in('f.type', $folderTypes));
     }
     if ($isSeen !== null) {
         $qb->andWhere($qb->expr()->eq('eu.seen', ':seen'))->setParameter('seen', (bool) $isSeen);
     }
     return $qb->getQuery()->getResult();
 }
 /**
  * Get user topic
  *
  * @param User|int $user
  * @param Organization $organization
  * @return string
  */
 public static function getUserTopic($user, Organization $organization)
 {
     $userId = $user instanceof User ? $user->getId() : $user;
     return sprintf(self::TOPIC, $userId, $organization->getId());
 }
Esempio n. 3
0
 /**
  * Add user limitation
  *
  * @param DatagridConfiguration $config
  * @param string                $accessLevel
  * @param User                  $user
  * @param Organization          $organization
  *
  * @throws \Exception
  */
 protected function applyACL(DatagridConfiguration $config, $accessLevel, User $user, Organization $organization)
 {
     $where = $config->offsetGetByPath('[source][query][where][and]', []);
     /** todo: refactor this check usages */
     if ($accessLevel == AccessLevel::BASIC_LEVEL) {
         $where = array_merge($where, ['u.id = ' . $user->getId()]);
     } elseif ($accessLevel == AccessLevel::GLOBAL_LEVEL) {
         $leftJoins = $config->offsetGetByPath('[source][query][join][inner]', []);
         $leftJoins[] = ['join' => 'u.organizations', 'alias' => 'org'];
         $config->offsetSetByPath('[source][query][join][inner]', $leftJoins);
         $where = array_merge($where, ['org.id in (' . $organization->getId() . ')']);
     } elseif ($accessLevel !== AccessLevel::SYSTEM_LEVEL) {
         $resultBuIds = [];
         if ($accessLevel == AccessLevel::LOCAL_LEVEL) {
             $resultBuIds = $this->treeProvider->getTree()->getUserBusinessUnitIds($user->getId(), $organization->getId());
         } elseif ($accessLevel == AccessLevel::DEEP_LEVEL) {
             $resultBuIds = $this->treeProvider->getTree()->getUserSubordinateBusinessUnitIds($user->getId(), $organization->getId());
         }
         $leftJoins = $config->offsetGetByPath('[source][query][join][inner]', []);
         $leftJoins[] = ['join' => 'u.businessUnits', 'alias' => 'bu'];
         $config->offsetSetByPath('[source][query][join][inner]', $leftJoins);
         $where = array_merge($where, ['bu.id in (' . implode(', ', $resultBuIds) . ')']);
     }
     if (count($where)) {
         $config->offsetSetByPath('[source][query][where][and]', $where);
     }
 }
Esempio n. 4
0
 /**
  * @param Organization $organization
  *
  * @return null|BusinessUnit
  */
 protected function getCurrentBusinessUnit(Organization $organization)
 {
     $user = $this->getCurrentUser();
     if (!$user) {
         return null;
     }
     $businessUnits = $user->getBusinessUnits()->filter(function (BusinessUnit $businessUnit) use($organization) {
         return $businessUnit->getOrganization()->getId() === $organization->getId();
     });
     if (!$this->isAssignGranted) {
         return $businessUnits->first();
     }
     // if assign is granted then only allowed business units can be used
     $allowedBusinessUnits = $this->businessUnitManager->getBusinessUnitIds();
     /** @var BusinessUnit $businessUnit */
     foreach ($businessUnits as $businessUnit) {
         if (in_array($businessUnit->getId(), $allowedBusinessUnits)) {
             return $businessUnit;
         }
     }
     return null;
 }
Esempio n. 5
0
 public function testId()
 {
     $this->assertNull($this->organization->getId());
 }
Esempio n. 6
0
 /**
  * Add ACL Check condition to the Query Builder
  *
  * @param QueryBuilder $queryBuilder
  * @param string       $accessLevel
  * @param User         $user
  * @param Organization $organization
  */
 protected function addAcl(QueryBuilder $queryBuilder, $accessLevel, User $user, Organization $organization)
 {
     if ($accessLevel == AccessLevel::BASIC_LEVEL) {
         $queryBuilder->andWhere($queryBuilder->expr()->in('users.id', [$user->getId()]));
     } elseif ($accessLevel == AccessLevel::GLOBAL_LEVEL) {
         $queryBuilder->join('users.organizations', 'org')->andWhere($queryBuilder->expr()->in('org.id', [$organization->getId()]));
     } elseif ($accessLevel !== AccessLevel::SYSTEM_LEVEL) {
         if ($accessLevel == AccessLevel::LOCAL_LEVEL) {
             $resultBuIds = $this->treeProvider->getTree()->getUserBusinessUnitIds($user->getId(), $organization->getId());
         } elseif ($accessLevel == AccessLevel::DEEP_LEVEL) {
             $resultBuIds = $this->treeProvider->getTree()->getUserSubordinateBusinessUnitIds($user->getId(), $organization->getId());
         }
         $queryBuilder->join('users.businessUnits', 'bu')->andWhere($queryBuilder->expr()->in('bu.id', $resultBuIds));
     }
 }
 /**
  * Get user topic
  *
  * @param User $user
  * @param Organization $organization
  * @return string
  */
 public static function getUserTopic(User $user, Organization $organization)
 {
     return sprintf(self::TOPIC, $user->getId(), $organization->getId());
 }
Esempio n. 8
0
 protected function loadCalendars()
 {
     $days = $this->getDatePeriod();
     $events = [];
     foreach ($days as $day) {
         /** @var \DateTime $day */
         if (!$this->isWeekend($day)) {
             //work day
             $event = new CalendarEvent();
             $event->setTitle('Work Reminder');
             $day->setTime(8, 0, 0);
             $event->setStart(clone $day);
             $day->setTime(18, 0, 0);
             $event->setEnd(clone $day);
             $event->setAllDay(true);
             $events['workday'][] = $event;
             //call
             $event = new CalendarEvent();
             $event->setTitle('Client Call');
             $day->setTime(11, 0, 0);
             $event->setStart(clone $day);
             $day->setTime(12, 0, 0);
             $event->setEnd(clone $day);
             $event->setAllDay(false);
             $events['call'][] = $event;
             //meeting
             $event = new CalendarEvent();
             $event->setTitle('Meeting');
             $day->setTime(16, 0, 0);
             $event->setStart(clone $day);
             $day->setTime(18, 0, 0);
             $event->setEnd(clone $day);
             $event->setAllDay(false);
             $events['meeting'][] = $event;
             //lunch
             $event = new CalendarEvent();
             $event->setTitle('Lunch');
             $day->setTime(12, 0, 0);
             $event->setStart(clone $day);
             $day->setTime(12, 30, 0);
             $event->setEnd(clone $day);
             $event->setAllDay(false);
             $events['lunch'][] = $event;
             //business trip
             $event = new CalendarEvent();
             $event->setTitle('Business trip');
             $day->setTime(0, 0, 0);
             $event->setStart(clone $day);
             $day->setTime(0, 0, 0);
             $day->add(\DateInterval::createFromDateString('+3 days'));
             $event->setEnd(clone $day);
             $event->setAllDay(true);
             $events['b_trip'][] = $event;
         } else {
             $event = new CalendarEvent();
             $event->setTitle('Weekend');
             $day->setTime(8, 0, 0);
             $event->setStart(clone $day);
             $day->setTime(18, 0, 0);
             $event->setEnd(clone $day);
             $event->setAllDay(true);
             $events['weekend'][] = $event;
         }
     }
     foreach ($this->users as $user) {
         //get default calendar, each user has default calendar after creation
         $calendar = $this->calendar->findDefaultCalendar($user->getId(), $this->organization->getId());
         $this->setSecurityContext($calendar->getOwner());
         foreach ($events as $typeEvents) {
             if (mt_rand(0, 1)) {
                 foreach ($typeEvents as $typeEvent) {
                     $calendar->addEvent(clone $typeEvent);
                 }
             }
         }
         $this->em->persist($calendar);
     }
     $this->em->flush();
     $this->em->clear('Oro\\Bundle\\CalendarBundle\\Entity\\CalendarEvent');
     $this->em->clear('Oro\\Bundle\\CalendarBundle\\Entity\\Calendar');
 }
Esempio n. 9
0
 /**
  * @param EntityManager $em
  * @param User          $user
  * @param Organization  $organization
  *
  * @return bool
  */
 protected function isCalendarExists(EntityManager $em, User $user, Organization $organization)
 {
     $calendarRepository = $em->getRepository('OroCalendarBundle:Calendar');
     return (bool) $calendarRepository->findDefaultCalendar($user->getId(), $organization->getId());
 }