コード例 #1
0
 protected function connectCalendars()
 {
     // first user is admin, often
     /** @var \Oro\Bundle\UserBundle\Entity\User $admin */
     $admin = $this->user->find(1);
     /** @var Calendar $calendarAdmin */
     $calendarAdmin = $this->calendar->findDefaultCalendar($admin->getId(), $admin->getOrganization()->getId());
     /** @var \Oro\Bundle\UserBundle\Entity\User $sale */
     $sale = $this->user->findOneBy(['username' => 'sale']);
     /** @var Calendar $calendarSale */
     $calendarSale = $this->calendar->findDefaultCalendar($sale->getId(), $sale->getOrganization()->getId());
     /** @var \Oro\Bundle\UserBundle\Entity\User $market */
     $market = $this->user->findOneBy(['username' => 'marketing']);
     /** @var Calendar $calendarMarket */
     $calendarMarket = $this->calendar->findDefaultCalendar($market->getId(), $market->getOrganization()->getId());
     /** @var User[] $users */
     $users = $this->getRandomUsers();
     foreach ($users as $user) {
         if (in_array($user->getId(), [$admin->getId(), $sale->getId(), $market->getId()])) {
             //to prevent self assignment
             continue;
         }
         /** @var Calendar $calendar */
         $calendar = $this->calendar->findDefaultCalendar($user->getId(), $user->getOrganization()->getId());
         if (mt_rand(0, 1)) {
             $calendarProperty = new CalendarProperty();
             $calendarProperty->setTargetCalendar($calendarAdmin)->setCalendarAlias('user')->setCalendar($calendar->getId());
             $this->em->persist($calendarProperty);
         }
         if (mt_rand(0, 1)) {
             $calendarProperty = new CalendarProperty();
             $calendarProperty->setTargetCalendar($calendarSale)->setCalendarAlias('user')->setCalendar($calendar->getId());
             $this->em->persist($calendarProperty);
         }
         if (mt_rand(0, 1)) {
             $calendarProperty = new CalendarProperty();
             $calendarProperty->setTargetCalendar($calendarMarket)->setCalendarAlias('user')->setCalendar($calendar->getId());
             $this->em->persist($calendarProperty);
         }
         $this->em->persist($calendar);
     }
     $this->em->flush();
 }
コード例 #2
0
 protected function connectCalendars()
 {
     /** @var \Oro\Bundle\UserBundle\Entity\User[] $users */
     $users = $this->user->findAll();
     // first user is admin, often
     /** @var \Oro\Bundle\UserBundle\Entity\User $admin */
     $admin = $this->user->find(1);
     /** @var Calendar $calendarAdmin */
     $calendarAdmin = $this->calendar->findDefaultCalendar($admin->getId(), $admin->getOrganization()->getId());
     /** @var \Oro\Bundle\UserBundle\Entity\User $sale */
     $sale = $this->user->findOneBy(['username' => 'sale']);
     /** @var Calendar $calendarSale */
     $calendarSale = $this->calendar->findDefaultCalendar($sale->getId(), $sale->getOrganization()->getId());
     /** @var \Oro\Bundle\UserBundle\Entity\User $market */
     $market = $this->user->findOneBy(['username' => 'marketing']);
     /** @var Calendar $calendarMarket */
     $calendarMarket = $this->calendar->findDefaultCalendar($market->getId(), $market->getOrganization()->getId());
     $i = 0;
     while ($i <= 5) {
         //get random user
         $userId = mt_rand(2, count($users) - 1);
         $user = $users[$userId];
         unset($users[$userId]);
         $users = array_values($users);
         if (in_array($user->getId(), [$admin->getId(), $sale->getId(), $market->getId()])) {
             //to prevent self assignment
             continue;
         }
         /** @var Calendar $calendar */
         $calendar = $this->calendar->findDefaultCalendar($user->getId(), $user->getOrganization()->getId());
         if (mt_rand(0, 1)) {
             $calendarProperty = new CalendarProperty();
             $calendarProperty->setTargetCalendar($calendarAdmin)->setCalendarAlias('user')->setCalendar($calendar->getId());
             $this->persist($this->container->get('doctrine.orm.entity_manager'), $calendarProperty);
         }
         if (mt_rand(0, 1)) {
             $calendarProperty = new CalendarProperty();
             $calendarProperty->setTargetCalendar($calendarSale)->setCalendarAlias('user')->setCalendar($calendar->getId());
             $this->persist($this->container->get('doctrine.orm.entity_manager'), $calendarProperty);
         }
         if (mt_rand(0, 1)) {
             $calendarProperty = new CalendarProperty();
             $calendarProperty->setTargetCalendar($calendarMarket)->setCalendarAlias('user')->setCalendar($calendar->getId());
             $this->persist($this->container->get('doctrine.orm.entity_manager'), $calendarProperty);
         }
         $this->persist($this->container->get('doctrine.orm.entity_manager'), $calendar);
         $i++;
     }
     $this->flush($this->container->get('doctrine.orm.entity_manager'));
 }
コード例 #3
0
ファイル: EntityListener.php プロジェクト: Maksold/platform
 /**
  * @param PostFlushEventArgs $event
  */
 public function postFlush(PostFlushEventArgs $event)
 {
     if (!empty($this->insertedCalendars)) {
         $em = $event->getEntityManager();
         foreach ($this->insertedCalendars as $calendar) {
             // connect the calendar to itself
             $calendarProperty = new CalendarProperty();
             $calendarProperty->setTargetCalendar($calendar)->setCalendarAlias(Calendar::CALENDAR_ALIAS)->setCalendar($calendar->getId());
             $em->persist($calendarProperty);
         }
         $this->insertedCalendars = [];
         $em->flush();
     }
 }