예제 #1
0
 /**
  * {@inheritDoc}
  */
 public function doLoad(ObjectManager $manager)
 {
     // Test for required user/status references first
     if (!$this->hasReference('admin') || !$this->hasReference('created')) {
         throw new \RuntimeException('Travel request fixtures require user/status bundle fixtures.');
     }
     $aclManager = $this->container->get('opit.security.acl.manager');
     // First travel request
     $admin = $this->getReference('admin');
     $departureDate = new \DateTime('next monday');
     $arrivalDate = clone $departureDate;
     $arrivalDate->add(new \DateInterval('P3D'));
     $travelRequest1 = new TravelRequest();
     $travelRequest1->setUser($admin);
     $travelRequest1->setGeneralManager($this->getReference('generalManager'));
     $travelRequest1->setDepartureDate($departureDate);
     $travelRequest1->setArrivalDate($arrivalDate);
     $travelRequest1->setCustomerRelated(1);
     $travelRequest1->setTripPurpose('Conference');
     // Add Destinations
     if ($this->hasReference('currency-huf') && $this->hasReference('transportation-type-airplane')) {
         $destination1 = new TRDestination();
         $destination1->setTransportationType($this->getReference('transportation-type-airplane'));
         $destination1->setName('Vienna');
         $destination1->setCost('57000');
         $destination1->setCurrency($this->getReference('currency-huf'));
         $travelRequest1->addDestination($destination1);
     }
     if ($this->hasReference('currency-eur') && $this->hasReference('transportation-type-bus')) {
         $destination2 = new TRDestination();
         $destination2->setTransportationType($this->getReference('transportation-type-bus'));
         $destination2->setName('Hotel Stefanie');
         $destination2->setCost('8.50');
         $destination2->setCurrency($this->getReference('currency-eur'));
         $travelRequest1->addDestination($destination2);
     }
     // Add accomodation
     if ($this->hasReference('currency-eur')) {
         $accomodation1 = new TRAccomodation();
         $accomodation1->setHotelName('Hotel Stefanie');
         $accomodation1->setCity('Vienna');
         $accomodation1->setNumberOfNights(2);
         $accomodation1->setCost('187');
         $accomodation1->setCurrency($this->getReference('currency-eur'));
         $travelRequest1->addAccomodation($accomodation1);
     }
     // Create status comment
     $comment1 = new CommentTRStatus();
     $comment1->setContent('Generated by the system.');
     // Add travel request states
     $travelRequest1Status = new StatesTravelRequests($this->getReference('created'));
     $travelRequest1Status->setComment($comment1);
     $travelRequest1->addState($travelRequest1Status);
     $manager->persist($travelRequest1);
     // Second travel request
     $user = $this->getReference('user');
     $departureDate2 = new \DateTime('next month tuesday');
     $arrivalDate2 = clone $departureDate2;
     $arrivalDate2->add(new \DateInterval('P1W'));
     $travelRequest2 = new TravelRequest();
     $travelRequest2->setUser($user);
     $travelRequest2->setGeneralManager($this->getReference('generalManager'));
     $travelRequest2->setDepartureDate($departureDate2);
     $travelRequest2->setArrivalDate($arrivalDate2);
     $travelRequest2->setCustomerRelated(0);
     $travelRequest2->setCustomerName('IBM');
     $travelRequest2->setTripPurpose('Business meeting');
     // Add Destinations
     if ($this->hasReference('currency-huf') && $this->hasReference('transportation-type-airplane')) {
         $destination3 = new TRDestination();
         $destination3->setTransportationType($this->getReference('transportation-type-airplane'));
         $destination3->setName('UK');
         $destination3->setCost('112500');
         $destination3->setCurrency($this->getReference('currency-huf'));
         $travelRequest2->addDestination($destination3);
     }
     if ($this->hasReference('currency-gbp') && $this->hasReference('transportation-type-taxi')) {
         $destination4 = new TRDestination();
         $destination4->setTransportationType($this->getReference('transportation-type-taxi'));
         $destination4->setName('Westpoint Hotel');
         $destination4->setCost('35');
         $destination4->setCurrency($this->getReference('currency-gbp'));
         $travelRequest2->addDestination($destination4);
         $destination5 = new TRDestination();
         $destination5->setTransportationType($this->getReference('transportation-type-bus'));
         $destination5->setName('London weekly pass');
         $destination5->setCost('16.50');
         $destination5->setCurrency($this->getReference('currency-gbp'));
         $travelRequest2->addDestination($destination5);
     }
     // Add accomodation
     if ($this->hasReference('currency-gbp')) {
         $accomodation2 = new TRAccomodation();
         $accomodation2->setHotelName('Westpoint Hotel');
         $accomodation2->setCity('London');
         $accomodation2->setNumberOfNights(7);
         $accomodation2->setCost('753');
         $accomodation2->setCurrency($this->getReference('currency-gbp'));
         $travelRequest2->addAccomodation($accomodation2);
     }
     // Fake the state times
     $createdDateTime = new \DateTime();
     $createdDateTime->sub(new \DateInterval('PT1H'));
     $forApprovalDateTime = clone $createdDateTime;
     $forApprovalDateTime->add(new \DateInterval('PT10M'));
     // Add travel request states (scope user)
     $travelRequest2Status = new StatesTravelRequests($this->getReference('created'));
     $travelRequest2Status->setCreatedUser($user);
     $travelRequest2Status->setCreated($createdDateTime);
     $travelRequest2->addState($travelRequest2Status);
     $travelRequest3Status = new StatesTravelRequests($this->getReference('forApproval'));
     $travelRequest3Status->setCreatedUser($user);
     $travelRequest3Status->setCreated($forApprovalDateTime);
     $travelRequest2->addState($travelRequest3Status);
     $travelRequest4Status = new StatesTravelRequests($this->getReference('approved'));
     $travelRequest4Status->setCreatedUser($this->getReference('generalManager'));
     $travelRequest2->addState($travelRequest4Status);
     $manager->persist($travelRequest2);
     $manager->flush();
     // Grant owner access
     $aclManager->grant($travelRequest1, $admin);
     $aclManager->grant($travelRequest2, $user);
     $this->addReference('travel-request-approved', $travelRequest2);
     $this->addReference('travel-request-status-approved', $travelRequest4Status);
 }
예제 #2
0
 /**
  * Add destinations
  *
  * @param \Opit\OpitHrm\TravelBundle\Entity\TRDestination $destinations
  * @return TravelRequest
  */
 public function addDestination(\Opit\OpitHrm\TravelBundle\Entity\TRDestination $destinations)
 {
     $this->destinations[] = $destinations;
     $destinations->setTravelRequest($this);
     // synchronously updating inverse side
     return $this;
 }