public function executeGMissatges(sfWebRequest $request) { $this->setLayout('gestio'); $this->IDS = $this->getUser()->getSessionPar('idS'); $this->IDU = $this->getUser()->getSessionPar('idU'); //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 = $this->getUser()->ParReqSesForm($request, 'accio', ""); $this->MODE = array(); if ($request->isMethod('POST') || $request->isMethod('GET')) { $accio = $request->getParameter('accio'); if ($request->hasParameter('BCERCA')) { $this->accio = 'C'; } if ($request->hasParameter('BNOU')) { $this->accio = 'N'; } if ($request->hasParameter('BSAVE')) { $this->accio = 'S'; } if ($request->hasParameter('BDELETE')) { $this->accio = 'D'; } } $this->getUser()->setSessionPar('accio', $this->accio); 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'] = true; $this->FMissatge = MissatgesPeer::inicialitza(0, $this->IDU, $this->IDS); $this->getUser()->setSessionPar('IDM', 0); $this->IDU = $this->getUser()->getSessionPar('idU'); break; case 'E': $this->MODE['EDICIO'] = true; $IDM = $request->getParameter('IDM'); $this->getUser()->setSessionPar('IDM', $IDM); $this->FMissatge = MissatgesPeer::inicialitza($IDM, $this->IDU, $this->IDS); $this->IDU = $this->getUser()->getSessionPar('idU'); break; case 'S': $IDM = $this->getUser()->getSessionPar('IDM'); $this->FMissatge = MissatgesPeer::inicialitza($IDM, $this->IDU, $this->IDS); $this->FMissatge->bind($request->getParameter('missatges')); if ($this->FMissatge->isValid()) { $this->FMissatge->save(); $this->getUser()->addLogAction($accio, 'gMisatges', $this->FMissatge->getObject()); //Si el missatge és global, enviarem un mail a tothom. if ($this->FMissatge->getObject()->getIsglobal()) { $ADMIN = OptionsPeer::getString('MAIL_ADMIN', $this->IDS); //Carreguem el correu de l'administrador $OM = $this->FMissatge->getObject(); //Carreguem el missatge que hem entrat $MAILS = UsuarisPeer::getAdminMails(); //Carreguem els mails dels administradors $BODY = OptionsPeer::getString('BODY_MAIL_MISSATGE_GLOBAL', $this->IDS); $BODY = str_replace('{NOM}', $OM->getUsuaris()->getNomComplet(), $BODY); $BODY = str_replace('{SITE}', $OM->getSiteNom(), $BODY); $BODY = str_replace('{ENLLAC}', $this->getController()->genUrl('gestio/gMissatges?accio=E&IDM=' . $OM->getMissatgeid(), true), $BODY); $SUBJECT = 'Hospici : Nou missatge global'; self::sendMail($ADMIN, $MAILS, $SUBJECT, $BODY); //Enviem el missatge. } $this->redirect('gestio/gMissatges?accio=I'); } $this->MODE['EDICIO'] = true; break; case 'D': $this->IDM = $this->getUser()->getSessionPar('IDM'); $M = MissatgesPeer::retrieveByPK($this->IDM); if ($M instanceof Missatges) { $M->setActiu(false); $M->save(); $this->getUser()->addLogAction($accio, 'gMisatges', $M); } $this->redirect('gestio/gMissatges?accio=I'); 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; } }
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; } }
/** * Carrega els missatges que han de ser publicats avui i tamb� aquells que tenen respostes associades. * @return array(idM => array( 'OM' => Missatges , 'RESPOSTES' = array( Respostes ) ) ) )) * */ static function getMissatgesAvui($idS = 1) { $RET = array(); $C = new Criteria(); $C = self::getCriteriaActiu($C, $idS); $avui = date('Y-m-d', time()); $C->add(self::PUBLICACIO, $avui); $C->addDescendingOrderByColumn(self::PUBLICACIO); $C->addDescendingOrderByColumn(self::MISSATGEID); foreach (MissatgesPeer::doSelect($C) as $OM) { $RET[$OM->getMissatgeid()]['OM'] = $OM; $RET[$OM->getMissatgeid()]['RESPOSTES'] = array(); } foreach (RespostesPeer::getRespostesAvui($idS) as $OR) { //Si la resposta és d'un missatge que avui ja s'ensenya... la guardem. if (isset($RET[$OR->getIdpare()])) { $RET[$OR->getIdpare()]['RESPOSTES'][] = $OR; //Si la resposta és d'un missatge antic, el carreguem i mostrem } else { $OM = MissatgesPeer::retrieveByPK($OR->getIdpare()); if ($OM instanceof Missatges) { $RET[$OM->getMissatgeid()]['OM'] = $OM; $RET[$OM->getMissatgeid()]['RESPOSTES'][] = $OR; } } } return $RET; }