public function executeGMissatges(sfWebRequest $request)
 {
     $this->setLayout('gestio');
     $this->IDS = $this->getUser()->getSessionPar('idS');
     $this->IDU = $this->getUser()->getSessionPar('idU');
     $this->IDM = $request->getParameter('IDM');
     //Netegem cerca
     if ($request->getParameter('accio') == 'I') {
         $this->CERCA = $this->getUser()->setSessionPar('cerca', array('text' => ''));
         $this->PAGINA = $this->getUser()->setSessionPar('p', 1);
         $this->accio = $this->getUser()->setSessionPar('accio', "");
     }
     //Actualitzem el requadre de cerca
     $this->FCerca = new CercaForm();
     $this->FCerca->bind($request->getParameter('cerca'));
     $this->CERCA = $this->getUser()->ParReqSesForm($request, 'cerca', array('text' => ""));
     $this->PAGINA = $this->getUser()->ParReqSesForm($request, 'p', 1);
     $this->accio = $request->getParameter('accio', '');
     $this->MODE = array();
     if ($request->isMethod('POST') || $request->isMethod('GET')) {
         $accio = $request->getParameter('accio');
         if ($request->hasParameter('BNOU')) {
             $this->accio = 'N';
         }
         if ($request->hasParameter('BSAVE')) {
             $this->accio = 'S';
         }
         if ($request->hasParameter('BDELETE')) {
             $this->accio = 'D';
         }
     }
     switch ($this->accio) {
         //Entrem per primer cop a aquest apartat
         case 'I':
             $this->MISSATGES = MissatgesPeer::doSearch($this->CERCA['text'], $this->PAGINA, false, $this->IDS);
             $this->getUser()->addLogAction('inside', 'gMissatges');
             break;
         case 'N':
             $this->MODE = "NOU";
             $this->FMissatge = MissatgesPeer::inicialitza(0, $this->IDU, $this->IDS);
             $this->OM = $this->FMissatge->getObject();
             break;
             //Consultem un missatge.
         //Consultem un missatge.
         case 'C':
             $this->MODE = "CONSULTA";
             $this->OM = MissatgesPeer::retrieveByPK($this->IDM);
             $this->FMissatge = new MissatgesForm($this->OM);
             break;
         case 'AJAX_RESPOSTA_SAVE':
             $TEXT = $request->getParameter('FORMULARI');
             $OR = new Respostes();
             $OR->setIdpare($this->IDM);
             $OR->setIdusuari($this->IDU);
             $OR->setTipus(RespostesPeer::TIPUS_MISSATGE);
             $OR->setData(date('Y-m-d H:i', time()));
             $OR->setText($TEXT);
             $OR->setIdsite($this->IDS);
             $OR->setActiu(true);
             $OR->save();
             //Carreguem dades pel partial
             $OM = MissatgesPeer::retrieveByPK($this->IDM);
             $FMissatge = new MissatgesForm($OM);
             $MODE = 'CONSULTA';
             $IDU = $this->IDU;
             return $this->renderPartial('formMissatge', array('FMISSATGE' => $FMissatge, 'IDU' => $IDU, 'OM' => $OM, 'MODE' => $MODE));
             break;
         case 'AJAX_RESPOSTA_DELETE':
             $ERRORS = array();
             $ID = $request->getParameter('FORMULARI');
             $OR = RespostesPeer::retrieveByPK($ID);
             if ($OR instanceof Respostes) {
                 $OR->setActiu(false);
                 $OR->save();
             } else {
                 $ERRORS[] = "No s'ha trobat cap resposta amb aquest codi: {$ID}.";
             }
             //Carreguem dades pel partial
             $OM = MissatgesPeer::retrieveByPK($this->IDM);
             $FMissatge = new MissatgesForm($OM);
             $MODE = 'CONSULTA';
             $IDU = $this->IDU;
             return $this->renderPartial('formMissatge', array('ERRORS' => $ERRORS, 'FMISSATGE' => $FMissatge, 'IDU' => $IDU, 'OM' => $OM, 'MODE' => $MODE));
             break;
         case 'AJAX_MISSATGE_SAVE':
             parse_str($request->getParameter('FORMULARI'), $RP);
             $RP = $RP['missatges'];
             $this->FMissatge = MissatgesPeer::inicialitza($RP['MissatgeID'], $this->IDU, $this->IDS);
             $this->FMissatge->bind($RP);
             if ($this->FMissatge->isValid()) {
                 $this->FMissatge->save();
                 $OM = $this->FMissatge->getObject();
                 $OM->save();
                 $this->getUser()->addLogAction($accio, 'gMisatges', $OM);
                 myUser::addLogTimeline($this->FMissatge->isNew() ? 'alta' : 'modificació', 'taulell', $this->getUser()->getSessionPar('idU'), $this->IDS, $OM->getMissatgeid());
                 if ($OM->getIsglobal()) {
                     $OM->EnviaMissatgeGlobalHospici();
                 }
                 $MODE = 'CONSULTA';
             } else {
                 //Retornem els errors que apareguin.
                 $ERRORS[] = "Hi ha hagut algun error inesperat...";
                 $OM = MissatgesPeer::retrieveByPK($RP['MissatgeID']);
                 $MODE = 'NOU';
             }
             //Carreguem dades pel partial
             $FMissatge = MissatgesPeer::inicialitza($OM->getMissatgeid(), $this->IDU, $this->IDS);
             return $this->renderPartial('formMissatge', array('ERRORS' => $ERRORS, 'FMISSATGE' => $FMissatge, 'IDU' => $this->IDU, 'OM' => $OM, 'MODE' => $MODE));
             break;
         case 'AJAX_MISSATGE_DELETE':
             parse_str($request->getParameter('FORMULARI'), $RP);
             $RP = $RP['missatges'];
             $OM = MissatgesPeer::retrieveByPK($this->IDM);
             if ($OM instanceof Missatges) {
                 $OM->setActiu(false);
                 $OM->save();
                 $this->getUser()->addLogAction($accio, 'gMisatges', $OM);
                 myUser::addLogTimeline('baixa', 'taulell', $this->getUser()->getSessionPar('idU'), $this->IDS, $this->IDM);
             }
             return $this->renderText('');
             break;
         case 'SF':
             $this->MISSATGES = MissatgesPeer::doSearch($this->CERCA['text'], $this->PAGINA, true, $this->IDS);
             break;
         default:
             $this->MISSATGE = new Missatges();
             $this->getUser()->setSessionPar('IDM', 0);
             $this->MISSATGES = MissatgesPeer::doSearch($this->CERCA['text'], $this->PAGINA, false, $this->IDS);
             break;
     }
 }
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      Respostes $value A Respostes object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(Respostes $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getIdresposta();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }