function validerAction() { $this->metas(array('DC.Title' => "Valider une inscription")); $this->branche->append("Inscriptions", array('action' => 'inscriptions', 'adelec' => null)); $t = new Inscriptions(); $this->assert(null, $t, 'valider', "Vous n'avez pas le droit de valider les inscriptions en attente."); $adelec = $this->_getParam('adelec'); if ($adelec) { try { $ins = $t->findByEMail($adelec); } catch (Strass_Db_Table_NotFound $e) { $this->view->model = null; return; } } else { if (!($ins = $t->fetchAll()->current())) { $this->view->model = null; return; } } $this->view->individu = $ind = $ins->findIndividus(); $this->view->inscription = $ins; $this->branche->append($ins->getFullname()); $this->view->model = $m = new Wtk_Form_Model('valider'); $i = $m->addString('prenom', 'Prénom', $ins->prenom); $i->setReadonly((bool) $ind); $m->addConstraintRequired($i); $i = $m->addString('nom', 'Nom', $ins->nom); $i->setReadonly((bool) $ind); $m->addConstraintRequired($i); if ($ind) { $enum = array($ind->id => "Oui, rattacher à " . $ind->getFullname(), '$$nouveau$$' => "Non, c'est un homonyme, créer une nouvelle fiche"); $m->addEnum('fiche', null, $ind->id, $enum); } $m->addString('message', "Message à " . $ins->getFullname()); $m->addNewSubmission('accepter', 'Accepter'); $m->addNewSubmission('refuser', 'Spam !'); if ($s = $m->validate()) { $tu = new Users(); $ti = new Individus(); $db = $ti->getAdapter(); if ($s->id == 'accepter') { $creer = !$ind || $m->get('fiche') == '$$nouveau$$'; if ($creer) { $ind = new Individu(); $ind->slug = $ti->createSlug(wtk_strtoid($ins->getFullname())); $ind->prenom = $m->prenom; $ind->nom = $m->nom; $ind->sexe = $ins->sexe; $ind->naissance = $ins->naissance; $ind->adelec = $ins->adelec; } $db->beginTransaction(); try { if ($creer) { $ind->save(); } $user = $ind->findUser(); if (!$user->isMember()) { $user = new User(); } $user->individu = $ind->id; $user->username = $ins->adelec; $user->password = $ins->password; $user->save(); $mail = new Strass_Mail_InscriptionValide($user, $m->get('message')); $mail->send(); $this->logger->info("Inscription acceptée", $this->_helper->Url('fiche', 'individus', null, array('individu' => $ind->slug)), (string) $ind); $ins->delete(); $db->commit(); } catch (Exception $e) { $db->rollBack(); throw $e; } $this->_helper->Flash->info("Inscription acceptée"); } else { $db->beginTransaction(); try { $this->logger->warn("Inscription de {$ins->adelec} refusée", $this->_helper->Url('inscriptions', 'membres', null, null, true)); $mail = new Strass_Mail_InscriptionRefus($ins, $m->get('message')); $mail->send(); $ins->delete(); $db->commit(); } catch (Exception $e) { $db->rollBack(); throw $e; } $this->_helper->Flash->info("Inscription refusée"); } if ($this->_getParam('adelec')) { $this->redirectSimple('inscriptions', 'membres', null, null, true); } else { $this->redirectSimple('valider'); } } }
function findCandidats($annee) { $t = new Individus(); $db = $t->getAdapter(); $s = $t->select()->setIntegrityCheck(false)->distinct()->from('individu')->join('unite_type', $db->quoteInto("unite_type.id = ?\n", intval($this->type)), array())->joinLeft('appartenance', $db->quoteInto('appartenance.individu = individu.id AND appartenance.unite = ?', $this->id) . ' AND ' . '(' . ('appartenance.fin IS NULL AND ' . $db->quoteInto("appartenance.debut < ?", Strass_Controller_Action_Helper_Annee::dateFin($annee))) . ')', array())->where('appartenance.id IS NULL')->where("unite_type.sexe IN ('m', individu.sexe)\n")->where("individu.naissance\n")->where("unite_type.age_min <= ? - individu.naissance - 1\n", $annee . '-8-01')->where("? - individu.naissance - 1 <= unite_type.age_max\n", $annee . '-8-01')->order('individu.nom', 'individu.prenom'); return $t->fetchAll($s); }