예제 #1
0
 function direct()
 {
     $id = $this->getRequest()->getParam('inscription');
     $t = new Appartenances();
     try {
         $app = $t->findOne($id);
     } catch (Strass_Db_Table_NotFound $e) {
         throw new Strass_Controller_Action_Exception_NotFound("Inscription #" . $id . " inconnue.");
     }
     $this->setBranche($app);
     return $app;
 }
예제 #2
0
파일: Unites.php 프로젝트: bersace/strass
 function findFuturPredecesseurs($role, $titre)
 {
     $t = new Appartenances();
     $db = $t->getAdapter();
     $s = $t->select()->setIntegrityCheck(false)->distinct()->where('appartenance.unite = ?', $this->id)->where('appartenance.role = ?', $role->id)->where('appartenance.fin IS NULL')->where('appartenance.titre = ?', $titre);
     return $t->fetchAll($s);
 }
예제 #3
0
 function validate($annee, $pm, $data)
 {
     extract($data);
     $m = $pm->data;
     $u = $this->unite;
     $a = $annee;
     $t = new Appartenances();
     $tr = new Roles();
     $ti = new Individus();
     $db = $t->getAdapter();
     $db->beginTransaction();
     $tu = $u->findParentTypesUnite();
     try {
         if ($m->get('inscription/individu') == '$$nouveau$$') {
             $i = new Individu();
             $i->prenom = $m->get('fiche/prenom');
             $i->nom = $m->get('fiche/nom');
             $i->sexe = $m->get('fiche/sexe');
             $i->naissance = $a - $tu->age_min . '-01-01';
             $i->portable = $m->get('fiche/portable');
             $i->adelec = $m->get('fiche/adelec');
             $i->slug = $i->getTable()->createSlug(wtk_strtoid($i->getFullname(false, false)));
             $i->save();
         } else {
             $i = $ti->findOne($m->get('inscription/individu'));
             $app_active = $i->findInscriptionsActives()->current();
             if ($app_active) {
                 if ($m->get('cloture/clore')) {
                     $app_active->fin = $m->get('cloture/fin');
                     $app_active->save();
                 }
             }
         }
         if ($m->get('succession/succeder')) {
             $role = $m->get('inscription/role');
             list($role, $titre) = explode('__', $role);
             $r = $tr->findOne($role);
             $apps = $u->findFuturPredecesseurs($r, $titre);
             $app_predecesseur = $apps->current();
             if ($apps->count()) {
                 $app_predecesseur = $apps->current();
                 $app_predecesseur->fin = $m->get('succession/date');
                 $app_predecesseur->save();
             }
         }
         $app = new Appartient();
         $app->unite = $u->id;
         $app->individu = $i->id;
         $app->debut = $m->get('inscription/debut');
         list($role, $titre) = explode('__', $m->get('inscription/role'));
         $app->role = intval($role);
         $app->titre = $titre;
         if ($m->get('inscription/clore')) {
             $app->fin = $m->get('inscription/fin');
         }
         $app->save();
         $message = $i->getFullname(false, false) . " inscrit.";
         $this->controller->logger->info($message);
         $this->controller->_helper->Flash->info($message);
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         throw $e;
     }
     if ($m->get('inscription/continuer')) {
         $this->controller->redirectSimple();
     } else {
         $this->controller->redirectSimple('effectifs');
     }
 }
예제 #4
0
 function findInscriptionSuivante($annee)
 {
     $t = new Appartenances();
     $db = $t->getAdapter();
     $s = $t->select()->setIntegrityCheck(false)->from('appartenance')->where('appartenance.individu = ?', $this->id)->where('appartenance.debut >= ?', Strass_Controller_Action_Helper_Annee::dateDebut($annee))->order('appartenance.debut')->limit(1);
     return $t->fetchAll($s)->current();
 }
예제 #5
0
 function adminAction()
 {
     $this->view->individu = $individu = $this->_helper->Individu();
     $this->assert(null, $individu, 'admin', "Vous n'avez pas le droit d'administrer " . "l'inscription de cet individu.");
     $this->metas(array('DC.Title' => 'Administrer ' . $individu->getFullname()));
     $this->actions->append("Éditer la fiche", array('controller' => 'individus', 'action' => 'editer'), array(null, $individu));
     $as = $individu->findAppartenances(null, 'debut DESC');
     if (!$as->count()) {
         $this->view->apps = null;
     } else {
         $this->view->apps = $m = new Wtk_Form_Model('apps');
         $tu = new Unites();
         $us = $tu->fetchAll(null);
         $eu = array();
         foreach ($us as $u) {
             $eu[$u->id] = mb_substr($u->getFullName(), 0, 32);
         }
         $tr = new Roles();
         $rs = $tr->fetchAll(null, 'ordre');
         $er = array();
         foreach ($rs as $r) {
             $er[$r->id] = substr($r->slug, 0, 7);
         }
         $i = $m->addTable('appartenances', "Appartenances", array('unite' => array('Enum', 'Unité', $eu), 'role' => array('Enum', 'Role', $er), 'titre' => array('String', 'Titre'), 'debut' => array('Date', 'Début'), 'clore' => array('Bool', 'Clore', false), 'fin' => array('Date', 'Fin')));
         foreach ($as as $a) {
             $i->addRow($a->unite, $a->role, $a->titre, $a->debut, (bool) $a->fin, $a->fin);
         }
         $m->addNewSubmission('enregistrer', 'Enregistrer');
         if ($m->validate()) {
             $t = new Appartenances();
             $db = $t->getAdapter();
             $db->beginTransaction();
             try {
                 foreach ($as as $a) {
                     $a->delete();
                 }
                 foreach ($i as $row) {
                     $data = array('individu' => $individu->id, 'unite' => $row->unite, 'role' => $row->role, 'titre' => $row->titre, 'debut' => $row->debut);
                     if ($row->clore) {
                         $data['fin'] = $row->fin;
                     } else {
                         $data['fin'] = null;
                     }
                     $t->insert($data);
                 }
                 $this->logger->info("Inscription éditée", $this->_helper->Url('fiche', 'individus', null, array('individu' => $individu->slug), true));
                 $db->commit();
             } catch (Exception $e) {
                 $db->rollBack();
                 throw $e;
             }
             $this->redirectSimple('fiche', 'individus', null, array('individu' => $individu->slug));
         }
     }
 }