コード例 #1
0
 static function update($DADES_NOVES, $idA, $idS = 1)
 {
     $MERGE = array();
     //Carreguem totes les dades de l'agenda
     $FOA = AgendatelefonicaPeer::initialize($idA, $idS);
     $DADES_REALS = $FOA->getObject()->getAgendatelefonicadadess();
     //Primer esborrem tots els que tenim entrats i guardem les seves dades
     foreach ($DADES_REALS as $K => $V) {
         $V->setActiu(false);
         $V->save();
         $MERGE[$V->getAgendatelefonicadadesid()] = $V;
     }
     foreach ($DADES_NOVES as $K => $V) {
         //Si tenim un id > 0 llavors és update.
         if ($V['id'] > 0) {
             $MERGE[$V['id']]->setDada($V['Dada']);
             $MERGE[$V['id']]->setNotes($V['Notes']);
             $MERGE[$V['id']]->setTipus($V['Select']);
             $MERGE[$V['id']]->setActiu(true);
             $MERGE[$V['id']]->save();
             //Altrament el donem d'alta
         } else {
             $DR = new Agendatelefonicadades();
             $DR->setAgendatelefonicaAgendatelefonicaid($idA);
             $DR->setTipus($V['Select']);
             $DR->setDada($V['Dada']);
             $DR->setNotes($V['Notes']);
             $DR->setSiteId($idS);
             $DR->save();
         }
     }
 }
コード例 #2
0
 public function executeGAgenda($request)
 {
     $this->setLayout('gestio');
     $this->IDS = $this->getUser()->getSessionPar('idS');
     //Netegem cerca
     if ($request->getParameter('accio') == 'C') {
         $this->CERCA = $this->getUser()->setSessionPar('cerca', array('text' => ''));
     }
     //Inicialitzem les variables
     $this->CERCA = $this->getUser()->ParReqSesForm($request, 'cerca', array('text' => ""));
     $this->accio = $request->getParameter('accio', 'C');
     $this->MODE = "";
     $this->P = $request->getParameter('P', 1);
     //Tractem el formulari de cerca
     $this->FCerca = new CercaForm();
     $this->FCerca->bind($this->CERCA);
     //Definim l'acció segons el botó premut
     if ($this->getRequest()->hasParameter('BNOU')) {
         $this->accio = 'N';
     }
     if ($this->getRequest()->hasParameter('BSAVE')) {
         $this->accio = 'S';
     }
     if ($this->getRequest()->hasParameter('BDELETE')) {
         $this->accio = 'D';
     }
     if ($this->getRequest()->hasParameter('BCERCA')) {
         $this->accio = 'L';
     }
     $this->getUser()->setSessionPar('accio', $this->accio);
     switch ($this->accio) {
         case 'C':
             $this->getUser()->addLogAction('inside', 'gAgenda');
             $this->AGENDES = AgendatelefonicadadesPeer::doSearch($this->CERCA['text'], $this->IDS, $this->P);
             break;
         case 'N':
             $this->MODE = 'NOU';
             $this->FAgenda = AgendatelefonicaPeer::initialize(0, $this->IDS);
             break;
         case 'E':
             $this->MODE = 'EDICIO';
             $AID = $request->getParameter('AID');
             $this->FAgenda = AgendatelefonicaPeer::initialize($AID, $this->IDS);
             $OAT = $this->FAgenda->getObject();
             $this->DADES = $OAT->getAgendatelefonicadadesActiu();
             break;
         case 'S':
             $RA = $request->getParameter('agendatelefonica');
             $AID = $RA['AgendaTelefonicaID'];
             $this->FAgenda = AgendatelefonicaPeer::initialize($AID, $this->IDS);
             $this->FAgenda->bind($RA);
             if ($this->FAgenda->isValid()) {
                 $this->FAgenda->save();
                 $this->getUser()->addLogAction($this->accio, 'gAgenda', $this->FAgenda->getObject());
                 myUser::addLogTimeline('alta', 'agenda', $this->getUser()->getSessionPar('idU'), $this->IDS, $this->FAgenda->getObject()->getAgendatelefonicaId());
                 $this->AID = $this->FAgenda->getObject()->getAgendatelefonicaid();
                 AgendatelefonicadadesPeer::update($request->getParameter('Dades'), $this->AID, $this->IDS);
                 //Actualitzem també les dades relacionades
                 $this->MISSATGE = "El registre s'ha modificat correctament.";
                 $this->redirect('gestio/gAgenda?accio=L');
             } else {
                 $this->DADES = $this->FAgenda->getObject()->getAgendatelefonicadadess();
                 $this->MODE = 'EDICIO';
             }
             break;
         case 'D':
             $RA = $request->getParameter('agendatelefonica');
             $this->AID = $RA['AgendaTelefonicaID'];
             $this->FAgenda = AgendatelefonicaPeer::initialize($this->AID, $this->IDS);
             if (!$this->FAgenda->isNew()) {
                 $this->FAgenda->getObject()->setInactiu();
                 $this->getUser()->addLogAction($this->accio, 'gAgenda', $this->FAgenda->getObject());
                 myUser::addLogTimeline('baixa', 'agenda', $this->getUser()->getSessionPar('idU'), $this->IDS, $this->FAgenda->getObject()->getAgendatelefonicaId());
             }
             break;
         default:
             $this->AGENDES = AgendatelefonicadadesPeer::doSearch($this->CERCA['text'], $this->IDS, $this->P);
             break;
     }
     if (!empty($this->CERCA)) {
         $this->AGENDES = AgendatelefonicadadesPeer::doSearch($this->CERCA['text'], $this->IDS, $this->P);
     } else {
         $this->AGENDES = array();
     }
 }