/**
  * 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;
 }
 /**
  * Insert or update an organisation according to $organisation's id
  * 
  * @param Xali\Bundle\OrganisationBundle\Entity\Organisation $organisation
  * the organisation
  * @param Xali\Bundle\UserBundle\Entity\User $manager
  * the manager user want to assign
  * @return string error message if there is
  * @author Anthony Bocci Anthony Bocci <*****@*****.**>
  */
 public function insertOrUpdate($organisation, $manager)
 {
     $em = $this->getDoctrine()->getManager();
     $orgRepo = $em->getRepository('XaliOrganisationBundle:Organisation');
     //Insert
     if (empty($organisation->getId())) {
         return $orgRepo->insertOrganisation($manager, $organisation);
     } else {
         //Update
         return $orgRepo->updateOrganisation($manager, $organisation);
     }
 }