Пример #1
0
 /**
  * Update the user's camp
  * 
  * @param \Xali\Bundle\UserBundle\Entity\User $volunteer
  * @param \Xali\Bundle\CampBundle\Entity\Camp $camp
  * @param \Xali\Bundle\OrganisationBundle\Entity\Organisation
  * @return integer -1 if parameters type are invalids, 0 if request failed
  * and 1 if it works, and 2 if volunteerd doesn't belong to this 
  * organisation
  */
 public function updateCamp($volunteer, $camp)
 {
     $return = 0;
     //If parameters are invalids (usually $volunteer)
     if ($volunteer instanceof User && $camp instanceof Camp) {
         //If user belong to an other organisation
         $volunteerOrganisation = $volunteer->getCamp() == null ? null : $volunteer->getCamp()->getOrganisation();
         if ($volunteerOrganisation != null && $camp->getOrganisation()->getId() != $volunteerOrganisation->getId()) {
             return 2;
         }
         $queryBuilder = $this->createQueryBuilder('u');
         $q = $queryBuilder->update('XaliUserBundle:User', 'u')->set('u.camp', ':camp')->setParameter('camp', $camp)->where('u.id = :user_id')->setParameter('user_id', $volunteer->getId())->getQuery();
         $return = $q->execute();
     } else {
         $return = -1;
     }
     return $return;
 }
Пример #2
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $countries = array('south africa', 'algeria', 'angola', 'bénin');
     $citiesSouthAfrica = array('tshwane', 'ethekwini', 'ekurhuleni', 'newcastle', 'matjhabeng');
     $citiesAlgeria = array('oran', 'constantine', 'annaba', 'blida', 'batna');
     $citiesAngola = array('luanda', 'huambo', 'lobito', 'benguela', 'lucapa');
     $citiesBenin = array('cotonou', 'abomey-calavi', 'parakou', 'djougou', 'bohicon');
     $cities = array($citiesSouthAfrica, $citiesAlgeria, $citiesAngola, $citiesBenin);
     $dateOfCreation = new \DateTime();
     $organisations = $manager->getRepository('XaliOrganisationBundle:Organisation')->findAll();
     $camps = array();
     //Create camps
     for ($i = 0; $i < 1500; $i++) {
         $camp = new Camp();
         $idCountry = rand(0, count($countries) - 1);
         //Set city etc using arrays above
         $camp->setCountry($countries[$idCountry]);
         //Set city using the number of city in country $idCountry
         $camp->setCity($cities[$idCountry][rand(0, count($cities[$idCountry]) - 1)]);
         $camp->setName($i);
         $camp->setOrganisation($organisations[(int) ($i / 15)]);
         $camp->setDateOfCreation($dateOfCreation);
         $camps[] = $camp;
         $manager->persist($camp);
     }
     //Assign users to camps
     $users = $manager->getRepository('XaliUserBundle:User')->findAll();
     $usersNumber = count($users);
     $organisations = $manager->getRepository('XaliOrganisationBundle:Organisation')->findAll();
     $organisationsNumber = count($organisations);
     for ($i = 0; $i < $usersNumber; $i++) {
         //Firsts users has organisations managers
         if ($i < $organisationsNumber) {
             $index = $i * 15 > 0 ? $i * 15 - 1 : 0;
             $users[$i]->setCamp($camps[$index]);
         } else {
             //Each 15 times, the user has no camp
             if ($i % 15 != 0) {
                 $users[$i]->setCamp($camps[rand(0, count($camps) - 1)]);
             } else {
                 $users[$i]->setCamp(null);
             }
         }
         $manager->persist($users[$i]);
     }
     $manager->flush();
 }
Пример #3
0
 /**
  * Check if the user has rights to add a survivor in a camp
  * 
  * @param Xali\Bundle\UserBundle\Entity\User $user
  * @param Xali\Bundle\CampBundle\Entity\Camp $camp
  * @return boolean
  */
 public function userBelongsToCamp($user, $camp)
 {
     //If $user is not a valid User or $camp is not a valid Camp
     if (!$user instanceof User || !$camp instanceof Camp) {
         return false;
     }
     //If user belong to a camp  and he try to add a survivor in its camp
     return $user->getCamp() != null && $user->getCamp()->getId() == $camp->getId();
 }
Пример #4
0
 /**
  * Check if the survivor belong to the camp
  * Note: check survivor validity (for update for example check if the
  * given id is different to 0) above in controller
  * 
  * @param \Xali\Bundle\SurvivorBundle\Entity\Survivor $survivor
  * @param \Xali\Bundle\CampBundle\Entity\Camp $camp
  * @return boolean
  */
 public function survivorBelongsToCamp($survivor, $camp)
 {
     //If survivor or camp is invalid
     if (!$survivor instanceof Survivor || !$camp instanceof Camp) {
         return false;
     }
     /*
      * If survivor has a camp and survivor belong to $camp
      */
     return $survivor->getCamp() != null && $survivor->getCamp()->getId() == $camp->getId();
 }