示例#1
0
 /**
  * Sauvegarde ou met a jour la guilde passée.
  * @param \Commun\Model\Guildes $oGuilde
  * @return \Commun\Model\Guildes
  */
 public function saveOrUpdateGuilde($oGuilde)
 {
     $oGuilde->setNom(strtolower($oGuilde->getNom()));
     try {
         $oTabGuilde = $this->selectBy(array("idGuildes" => $oGuilde->getIdGuildes()));
         if (!$oTabGuilde) {
             $oTabGuilde = $this->selectBy(array("nom" => $oGuilde->getNom(), "serveur" => $oGuilde->getServeur(), "idFaction" => $oGuilde->getIdFaction()));
         }
     } catch (\Exception $exc) {
         throw new DatabaseException(1000, 4, $this->_getServiceLocator(), $oGuilde->getArrayCopy(), $exc);
     }
     // si n'existe pas on insert
     if (!$oTabGuilde) {
         try {
             $this->insert($oGuilde);
             $oGuilde->setIdGuildes($this->lastInsertValue);
         } catch (\Exception $exc) {
             throw new DatabaseException(1000, 2, $this->_getServiceLocator(), $oGuilde->getArrayCopy(), $exc);
         }
     } else {
         try {
             // sinon on update
             $oGuilde->setIdGuildes($oTabGuilde->getIdGuildes());
             $this->update($oGuilde);
         } catch (\Exception $exc) {
             throw new DatabaseException(1000, 1, $this->_getServiceLocator(), $oGuilde->getArrayCopy(), $exc);
         }
     }
     return $oGuilde;
 }