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; } }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = RespostesPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setIdresposta($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setIdpare($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setIdusuari($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setTipus($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setData($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setText($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setIdsite($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setActiu($arr[$keys[7]]); } }
public function getRespostesCount() { return RespostesPeer::getRespostesCount($this->getMissatgeid()); }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(RespostesPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(RespostesPeer::DATABASE_NAME); $criteria->add(RespostesPeer::IDRESPOSTA, $pks, Criteria::IN); $objs = RespostesPeer::doSelect($criteria, $con); } return $objs; }
<br /><br /> <div class="TITOL">Respostes</div> <!-- Aquí hi ha el formulari que s'obre quan es carrega un missatge a través d'AJAX --> <div id="FORMULARI_RESPOSTA"> <form id="FORM_RESPOSTA"> <?php echo textarea_tag('RESPOSTA', "Escriu aquí la resposta i prem intro per guardar...", array('style' => 'width:500px;')); ?> </form> <br /><br /> </div> <?php foreach (RespostesPeer::getRespostes($OM->getMissatgeid()) as $OR) { $OU = UsuarisPeer::retrieveByPK($OR->getIdusuari()); if ($OU instanceof Usuaris) { ?> <div style=""> <div style="float: left; margin-right:10px;"> <div style="font-size: 10px;"><i><?php echo $OU->getNomComplet(); ?> </i></div> <div style="font-size: 8px; color:gray;"><?php echo $OR->getData('d/m/Y H:i'); ?> </div> </div> <div style="float: left;"><?php
/** * 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; }