Пример #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
 /**
  * Update an organisation
  * 
  * @param \Xali\Bundle\UserBundle\Entity\User $manager the manager we want
  * to assign
  * @param \Xali\Bundle\OrganisationBundle\Entity\Organisation $organisation
  * the organisation to update
  * @return string
  */
 public function updateOrganisation($manager, $organisation)
 {
     if (!empty($manager) && $manager instanceof User) {
         $result = null;
         $managerOrganisation = $manager->getCamp() == null ? null : $manager->getCamp()->getOrganisation();
         //user belong to an other organisation
         if ($managerOrganisation != null && $managerOrganisation->getId() != $organisation->getId()) {
             return "form.error.belong_other_org";
         }
         $sql = "UPDATE organisation\n                    SET manager_id = ?, name = ?, dateofcreation = ?\n                    WHERE organisation.id = ?\n                    ";
         try {
             $stmt = $this->_em->getConnection()->prepare($sql);
             $stmt->execute(array($manager->getId(), $organisation->getName(), $organisation->getDateOfCreation()->format('Y-m-d'), $organisation->getId()));
         } catch (UniqueConstraintViolationException $e) {
             $result = "form.error.violation_key";
         } catch (\Exception $e) {
             $result = "form.error.other_error";
         }
     } else {
         //Manager's email adress is invalid
         $result = "form.error.invalid_email";
     }
     return $result;
 }
Пример #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();
 }