Example #1
0
 function inscriptionAction()
 {
     $this->metas(array('DC.Title' => "Fiche d'inscription"));
     $this->branche->append();
     $m = new Wtk_Form_Model('inscription');
     // FICHE INDIVIDU
     $g = $m->addGroup('fiche');
     $i = $g->addString('prenom', "Prénom");
     $m->addConstraintRequired($i);
     $i = $g->addString('nom', "Nom");
     $m->addConstraintRequired($i);
     $t = new Unites();
     $sexes = $t->findSexesAccueillis();
     if (in_array('m', $sexes) || count($sexes) > 1) {
         $enum = array('h' => 'Masculin', 'f' => 'Féminin');
         $i = $g->addEnum('sexe', 'Sexe', null, $enum);
         $m->addConstraintRequired($i);
     } else {
         $i = $g->addString('sexe', 'Sexe', $sexes[0])->setReadonly(true);
     }
     $i = $g->addDate('naissance', "Date de naissance", 0);
     $m->addConstraintRequired($i);
     // COMPTE
     $g = $m->addGroup('compte');
     $i = $g->addEMail('adelec', "Adresse électronique");
     $t = new Inscriptions();
     $m->addConstraintForbid($i, $t->findAllEMails(), "Cette adresse électronique est déjà utilisée");
     $i0 = $g->addString('motdepasse', "Mot de passe");
     $m->addConstraintLength($i0, 6);
     $i1 = $g->addString('confirmer', "Confirmer");
     $m->addConstraintEqual($i1, $i0);
     $i = $g->addString('presentation', "Présentation");
     $m->addConstraintRequired($i);
     $this->view->model = $pm = new Wtk_Pages_Model_Form($m);
     if ($pm->validate()) {
         $data = $m->get('fiche');
         $data['adelec'] = strtolower($m->get('compte/adelec'));
         $data['password'] = Users::hashPassword($m->get('compte/adelec'), $m->get('compte/motdepasse'));
         $data['presentation'] = $m->compte->presentation;
         $db = $t->getAdapter();
         $db->beginTransaction();
         try {
             $k = $t->insert($data);
             $i = $t->findOne($k);
             $this->logger->info("Nouvelle inscription", $this->_helper->Url('valider', 'membres', null, array('adelec' => $i->adelec)));
             $this->_helper->Flash->info("Inscription en modération");
             $mail = new Strass_Mail_Inscription($i);
             try {
                 $mail->send();
             } catch (Zend_Mail_Transport_Exception $e) {
                 $this->logger->error("Échec de l'envoi de mail aux admins", null, $e);
             }
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         $this->redirectSimple('index', 'unites', null, array(), true);
     }
 }
Example #2
0
 function direct($throw = true)
 {
     $slug = $this->getRequest()->getParam('unite');
     $t = new Unites();
     try {
         if ($slug) {
             $unite = $t->findBySlug($slug);
         } else {
             $unite = $t->findRacine();
         }
     } catch (Strass_Db_Table_NotFound $e) {
         if ($throw) {
             if ($slug) {
                 throw new Strass_Controller_Action_Exception_NotFound("Unité " . $slug . " inconnue");
             } else {
                 $url = $this->_actionController->_helper->Url('fonder', 'unites', null, null, true);
                 $aide = "Vous devez [" . $url . " enregistrer une unité] pour commencer.";
                 throw new Strass_Controller_Action_Exception_Notice("Pas d'unité !", 404, $aide);
             }
         } else {
             return null;
         }
     }
     $this->liensConnexes($unite);
     $page = Zend_Registry::get('page');
     $fn = $unite->getFullname();
     if (!$page->metas->get('DC.Title')) {
         $page->metas->set('DC.Title', $fn);
     }
     $page->metas->set('DC.Creator', $fn);
     return $unite;
 }
Example #3
0
 public function initAcl()
 {
     $cache = Zend_Registry::get('cache');
     if (($acl = $cache->load('strass_acl')) === false) {
         $acl = new Strass_Acl();
         Zend_Registry::set('acl', $acl);
         if ($acl->hasRole('nobody')) {
             return;
         }
         $acl->add(new Zend_Acl_Resource('visiteur'));
         $acl->add(new Zend_Acl_Resource('membres'));
         $acl->add(new Zend_Acl_Resource('inscriptions'));
         $acl->add(new Zend_Acl_Resource('site'));
         $acl->addRole(new Zend_Acl_Role('nobody'));
         // groupes virtuels
         $acl->addRole(new Zend_Acl_Role('admins'));
         $acl->addRole(new Zend_Acl_Role('sachem'));
         $acl->addRole(new Zend_Acl_Role('membres'));
         $t = new Unites();
         $racines = $t->findRacines();
         foreach ($racines as $u) {
             $u->initAclRoles($acl);
         }
         $acl->allow('admins');
         $acl->allow('sachem', null, 'totem');
         $acl->allow('membres', 'membres', 'voir');
         $cache->save($acl, 'strass_acl');
     } else {
         Zend_Registry::set('acl', $acl, array(), null);
     }
     return $acl;
 }
Example #4
0
 function _preRender($controller)
 {
     $config = Zend_Registry::get('config');
     $page = Zend_Registry::get('page');
     /* création du document, widget racine */
     $request = $controller->getRequest();
     $cn = strtolower($request->getControllerName());
     $an = strtolower($request->getActionName());
     $mn = strtolower($request->getModuleName());
     $association = $config->get('system/association');
     $view = $controller->view;
     $document = new Wtk_Document($page->metas);
     $document->sitemap = '/sitemap';
     $document->addFlags($mn, $cn, $an);
     $style = $config->get('system/style', 'joubert');
     try {
         $document->setStyle(Wtk_Document_Style::factory($style));
     } catch (Wtk_Document_Style_NotFound $e) {
         error_log("Style " . $style . " inconnu.");
     }
     $document->addStyleComponents('layout', 'common', $cn, $mn, $association);
     if ($view->unite) {
         $unite = $view->unite;
     } else {
         try {
             $t = new Unites();
             $unite = $t->findRacine();
         } catch (Exception $e) {
             $unite = null;
         }
     }
     if ($unite) {
         $document->addFlags($unite->slug, $unite->findParentTypesUnite()->slug);
     }
     $document->addFlags(Strass::onDevelopment() ? 'development' : 'production');
     $document->addFlags($association);
     $document->header->addFlags($association);
     $document->footer->addSection('wrapper');
     $link = new Wtk_Link('/', $page->metas->site);
     $document->header->setTitle($link);
     foreach ($page->formats as $format) {
         if ($format->suffix != $this->suffix) {
             $document->addAlternative($controller->view->url(array('format' => $format->suffix)), $format->title, $format->mimeType);
         }
     }
     $view->page = $page;
     $view->document = $document;
 }
Example #5
0
 public function initView($view)
 {
     foreach (self::$menu as $item) {
         $acl = array_key_exists('acl', $item) ? $item['acl'] : array();
         $this->append($item['metas'], $item['url'], $acl, true);
     }
     $t = new Unites();
     $racines = $t->findRacines();
     foreach ($racines as $i => $u) {
         if (!$i) {
             continue;
         }
         // On saute l'unité racine par défaut
         $this->append($u->getFullName(), array('unite' => $u->slug), array(), true);
     }
     parent::initView($view);
     $view->parent = $view->document->footer->current();
 }
Example #6
0
 function initPage()
 {
     /* On préserve la page entre les appels à init, cela permet de
        préserver les liens, branches, etc. en cas d'erreur. */
     try {
         return Zend_Registry::get('page');
     } catch (Exception $e) {
         $config = Zend_Registry::get('config');
         $t = new Unites();
         $racine = $t->findRacines()->current();
         /* instanciation de la page courante */
         $metas = $config->metas;
         $site = Strass::getSiteTitle();
         $page = new Strass_Page(new Wtk_Metas(array('DC.Title' => $metas->title, 'DC.Title.alternative' => $metas->title, 'DC.Subject' => $metas->subject, 'DC.Language' => $metas->language, 'DC.Creator' => $metas->author, 'DC.Date.created' => $metas->creation, 'DC.Date.available' => strftime('%Y-%m-%d'), 'organization' => $metas->organization, 'site' => $site)));
         Zend_Registry::set('page', $page);
         $this->branche = $page->addon(new Strass_Addon_Branche());
         $this->connexes = $page->addon(new Strass_Addon_Liens('connexes', 'Pages connexes'));
         $page->addon(new Strass_Addon_Formats());
         $label = 'Administrer';
         if ($this->assert(null, 'site', 'admin')) {
             $label = new Wtk_Link($this->_helper->Url('index', 'admin', null, null, true), $label);
         }
         $this->actions = $page->addon(new Strass_Addon_Liens('admin', $label));
         $page->addon(new Strass_Addon_Console($this->_helper->Auth));
         $page->addon(new Strass_Addon_Citation());
         $page->addon(new Strass_Addon_Menu());
         if ($config->system->short_title) {
             $this->branche->append($config->system->short_title, array(), array(), true);
         }
         if ($this->_afficherMenuUniteRacine && $racine) {
             $this->_helper->Unite->liensConnexes($racine, $action = 'index', $controller = 'unites');
         }
         if (!$this instanceof Strass_Controller_ErrorController && $this->_titreBranche) {
             $this->branche->append($this->_titreBranche, array('controller' => strtolower($this->_request->getControllerName())), array(), true);
         }
         return $page;
     }
 }
Example #7
0
 function indexAction()
 {
     $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
     $viewRenderer->setView($this->initView());
     $pages = array(array('uri' => '/'), array('controller' => 'liens'), array('controller' => 'citation'));
     /* Les unités */
     $t = new Unites();
     foreach ($t->findRacines() as $u) {
         $spages = array();
         foreach ($u->findSousUnites(true, true) as $su) {
             array_push($spages, array('controller' => 'unites', 'action' => 'index', 'params' => array('unite' => $su->slug)));
             array_push($spages, array('controller' => 'documents', 'action' => 'index', 'params' => array('unite' => $su->slug)));
             array_push($spages, array('controller' => 'unites', 'action' => 'archives', 'params' => array('unite' => $su->slug)));
         }
         array_push($pages, array('controller' => 'unites', 'action' => 'index', 'params' => array('unite' => $u->slug), 'pages' => $spages));
         array_push($pages, array('controller' => 'unites', 'action' => 'archives', 'params' => array('unite' => $u->slug)));
         array_push($pages, array('controller' => 'documents', 'action' => 'index', 'params' => array('unite' => $u->slug)));
     }
     /* Journaux */
     $t = new Journaux();
     foreach ($t->fetchAll() as $j) {
         $articles = array();
         foreach ($j->findArticles('article.public IS NOT NULL OR article.public != 0') as $a) {
             array_push($articles, array('controller' => 'journaux', 'action' => 'consulter', 'params' => array('article' => $a->slug)));
         }
         array_push($pages, array('controller' => 'journaux', 'action' => 'lire', 'params' => array('journal' => $j->slug), 'pages' => $articles));
     }
     /* Photos promues */
     $t = new Photos();
     $s = $t->select()->where('promotion > 0');
     foreach ($t->fetchAll($s) as $p) {
         array_push($pages, array('controller' => 'photos', 'action' => 'voir', 'params' => array('photo' => $p->slug)));
     }
     $this->view->nav = new Zend_Navigation($pages);
     $this->getResponse()->setheader('Content-Type', 'text/xml');
     $this->render();
 }
Example #8
0
 function editerAction()
 {
     $this->view->activite = $a = $this->_helper->Activite();
     $this->assert(null, $a, 'editer', "Vous n'avez pas le droit d'éditer cettes activités");
     $this->metas(array('DC.Title' => 'Éditer ' . $a->getIntitule()));
     $this->view->model = $m = new Wtk_Form_Model('activite');
     $t = new Unites();
     $explicites = $a->findUnitesParticipantesExplicites();
     $enum = array();
     foreach ($t->fetchAll() as $unite) {
         if ($this->assert(null, $unite, 'prevoir')) {
             $enum[$unite->id] = $unite->getFullname();
         }
     }
     $values = array();
     foreach ($explicites as $unite) {
         $values[] = $unite->id;
     }
     $i = $m->addEnum('unites', 'Unités participantes', $values, $enum, true);
     // multiple
     $m->addConstraintRequired($i);
     $m->addString('intitule', 'Intitulé explicite', $a->intitule);
     $m->addString('lieu', 'Lieu', $a->lieu);
     $m->addDate('debut', 'Début', $a->debut, '%Y-%m-%d %H:%M');
     $m->addDate('fin', 'Fin', $a->fin, '%Y-%m-%d %H:%M');
     $m->addString('description', 'Description', $a->description);
     $enum = array(null => 'Nouveau document');
     foreach ($explicites->rewind()->current()->findDocuments() as $doc) {
         $enum[$doc->id] = $doc->titre;
     }
     $t = $m->addTable('documents', "Pièces-jointes", array('document' => array('Enum', "Document", $enum), 'fichier' => array('File', "Fichier"), 'titre' => array('String', "Titre"), 'origin' => array('Integer')), false);
     foreach ($a->findPiecesJointes() as $pj) {
         $doc = $pj->findParentDocuments();
         $titre = $doc->countLiaisons() > 1 ? null : $doc->titre;
         $t->addRow($pj->document, null, $titre, $pj->id);
     }
     $t->addRow();
     $m->addNewSubmission('enregistrer', 'Enregistrer');
     if ($m->validate()) {
         $t = new Activites();
         $tu = new Unites();
         $tpj = new PiecesJointes();
         $td = new Documents();
         $unites = call_user_func_array(array($tu, 'find'), (array) $m->unites);
         $db = $a->getTable()->getAdapter();
         $db->beginTransaction();
         try {
             $champs = array('debut', 'fin', 'lieu', 'description');
             foreach ($champs as $champ) {
                 $a->{$champ} = $m->{$champ};
             }
             $a->updateUnites($unites);
             $a->intitule = $m->intitule;
             $a->slug = $t->createSlug($a->getIntituleComplet(), $a->slug);
             $a->save();
             $old = $a->findPiecesJointes();
             $new = array();
             /* création et mise à jour de pièce jointe */
             foreach ($m->getInstance('documents') as $row) {
                 $d = null;
                 if ($row->document) {
                     $d = $td->findOne($row->document);
                 }
                 if ($row->origin) {
                     $pj = $tpj->findOne($row->origin);
                     if (!$d) {
                         $d = $pj->findParentDocuments();
                     }
                 } else {
                     $pj = new PieceJointe();
                     $pj->activite = $a->id;
                     if (!$d) {
                         $d = new Document();
                     }
                 }
                 /* On ne met à jour que les pièces jointes exclusives */
                 if (!$row->document) {
                     /* requérir un titre pour les documents exclusifs */
                     $if = $row->getChild('fichier');
                     if (!$row->titre && ($if->isUploaded() || $row->origin)) {
                         throw new Wtk_Form_Model_Exception("Titre obligatoire", $row->getChild('titre'));
                     }
                     $d->slug = $d->getTable()->createSlug($row->titre);
                     $d->titre = $row->titre;
                     if ($if->isUploaded()) {
                         $d->suffixe = end(explode('.', $row->fichier['name']));
                         $d->storeFile($if->getTempFilename());
                     } elseif (!$row->origin) {
                         continue;
                     }
                     /* ligne vide */
                     $d->save();
                 }
                 $pj->document = $d->id;
                 $pj->save();
                 $new[] = $pj->id;
             }
             // Nettoyage des documents supprimés
             foreach ($old as $opj) {
                 if (in_array($opj->id, $new)) {
                     continue;
                 }
                 $opj->delete();
             }
             $this->logger->info("Activité mise-à-jour", $this->_helper->Url('consulter', null, null, array('activite' => $a->slug)));
             $db->commit();
             $this->redirectSimple('consulter', null, null, array('activite' => $a->slug));
         } catch (Wtk_Form_Model_Exception $e) {
             $db->rollBack();
             $m->errors[] = $e;
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
     }
 }
Example #9
0
 function findUnitesParticipantesExplicites()
 {
     $t = new Unites();
     $s = $t->select()->setIntegrityCheck(false)->distinct()->from('unite')->joinLeft('participation', 'participation.unite = unite.id', array())->joinLeft(array('mere' => 'unite'), 'mere.id = unite.parent', array())->joinLeft(array('part_mere' => 'participation'), 'part_mere.unite = mere.id AND ' . 'part_mere.activite = participation.activite', array())->where('participation.activite = ?', $this->id)->where('part_mere.id IS NULL');
     return $t->fetchAll($s);
 }
Example #10
0
 function findUnite()
 {
     $t = new Unites();
     $s = $t->select()->setIntegrityCheck(false)->from('unite')->join('unite_document', 'unite_document.unite = unite.id', array())->where('unite_document.document = ?', $this->id);
     return $t->fetchOne($s);
 }
Example #11
0
 function unitesAction()
 {
     $this->metas(array('DC.Title' => 'Les unités'));
     $this->branche->append();
     $this->actions->append("Fonder", array('action' => 'fonder', 'controller' => 'unites'));
     $t = new Unites();
     $this->view->unites = $m = new Wtk_Table_Model_Tree('nom', 'accueil', 'statut', 'chef', 'fiche-chef', 'inscrits', 'url-supprimer', 'flags');
     $unites = $t->fetchAll();
     $pathes = array();
     foreach ($unites as $unite) {
         if ($unite->parent) {
             $parent = $unite->findParentUnites();
             $ppath = $pathes[$parent->slug];
         } else {
             $ppath = array();
         }
         $apps = $unite->findAppartenances(null);
         $inscrits = $apps->count();
         $chef = $unite->findChef(null);
         $level = $inscrits == 0 || !$chef ? 'warn' : null;
         $path = $m->append($ppath, $unite->getFullname(), $this->_helper->Url('index', 'unites', null, array('unite' => $unite->slug)), $unite->isFermee() ? 'fermée' : 'ouverte', $chef ? $chef->getFullname() : 'Inconnu', $chef ? $this->_helper->Url('fiche', 'individus', null, array('individu' => $chef->slug)) : null, "{$inscrits} inscrits", $this->_helper->Url('supprimer', 'unites', null, array('unite' => $unite->slug)), array($unite->isFermee() ? 'fermee' : 'ouverte', $unite->findParentTypesUnite()->slug, $level));
         $pathes[$unite->slug] = $path;
     }
 }
Example #12
0
 static function getSiteTitle()
 {
     $config = Zend_Registry::get('config');
     $t = new Unites();
     if (@$config->metas->title) {
         return $config->metas->title;
     } else {
         try {
             $racine = $t->findRacine();
             return $racine->getName();
         } catch (Exception $e) {
             return null;
         }
     }
 }
Example #13
0
 function fonderAction()
 {
     $this->view->parente = $unite = $this->_helper->Unite(false);
     $this->assert(null, $unite, 'fonder', "Pas le droit de fonder une sous-unité !");
     /* on crée une sous unité si le parent est explicitement désignée */
     $this->view->sousunite = $sousunite = $this->_getParam('unite');
     $ttu = new TypesUnite();
     // sous types possibles
     if ($this->view->sousunite) {
         $soustypes = $unite->getSousTypes();
     } else {
         $soustypes = $ttu->fetchAll($ttu->select()->where('virtuelle = 0'));
     }
     $st = $soustypes->count() > 1 ? 'sous-unité' : $soustypes->rewind()->current();
     if ($sousunite) {
         $this->metas(array('DC.Title' => 'Fonder une ' . $st . ' de ' . $unite->getFullname()));
     } else {
         $this->metas(array('DC.Title' => 'Fonder une unité'));
     }
     $m = new Wtk_Form_Model('fonder');
     /* Parente */
     $i = $m->addEnum('parente', 'Unité parente');
     if ($sousunite) {
         $i->set($unite->id);
     } else {
         $t = new Unites();
         $i->addItem(null, 'Orpheline');
         foreach ($t->findSuperUnites() as $u) {
             $i->addItem($u->id, $u->getFullname());
         }
     }
     /* Types */
     $ens = array();
     $enum = array();
     foreach ($soustypes as $type) {
         $en = $type->extra;
         if ($en) {
             array_push($ens, $en);
         }
         $label = $type->nom;
         /* en cas de nom doublon (ex: équipe, sizaine), inclure le nom du type parent */
         $homonymes = $ttu->countRows($ttu->select()->where('nom = ?', $type->nom)) > 1;
         if (!$unite && $homonymes) {
             $label .= ' (' . $type->findParentTypesUnite()->nom . ')';
         }
         $enum[$type->id] = $label;
     }
     $ens = array_unique($ens);
     $types = $enum;
     $m->addEnum('type', 'Type', key($enum), $enum);
     if (key($enum) == 'sizloup') {
         // préselectionner les couleurs des loups.
         $couleurs = array('Noir', 'Gris', 'Brun', 'Blanc', 'Fauve', 'Tacheté');
         $enum = array();
         foreach ($couleurs as $couleur) {
             // ne pas permettre de recréer une sizaine.
             $ex = $unite->findUnites("unites.nom = '" . $couleur . "'")->current();
             if (!$ex) {
                 $enum[wtk_strtoid($couleur)] = $couleur;
             }
         }
         $m->addEnum('nom', 'Nom', null, $enum);
     } else {
         $m->addString('nom', "Nom");
     }
     $m->addString('extra', current($ens));
     $m->addNewSubmission('fonder', 'Fonder');
     if ($m->validate()) {
         $t = new Unites();
         $db = $t->getAdapter();
         $db->beginTransaction();
         try {
             $u = new Unite();
             $u->slug = $t->createSlug(wtk_strtoid($types[$m->type] . '-' . $m->nom));
             $u->nom = $m->nom;
             $u->type = $m->type;
             $u->extra = $m->extra;
             $u->parent = $m->parente ? $m->parente : null;
             $u->save();
             $this->logger->info("Fondation de " . $u->getFullname(), $this->_helper->Url('index', 'unites', null, array('unite' => $u->slug), true));
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         $this->redirectSimple('index', 'unites', null, array('unite' => $u->slug), true);
     }
     $this->view->model = $m;
 }
Example #14
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));
         }
     }
 }
Example #15
0
 function fetch($annee = NULL)
 {
     $u = $this->unite;
     $a = $annee;
     $m = new Wtk_Form_Model('prevoir');
     $t = new Unites();
     $enum = array();
     foreach ($t->fetchAll() as $unite) {
         if ($this->controller->assert(null, $unite, 'prevoir')) {
             $enum[$unite->id] = $unite->getFullname();
         }
     }
     if (!$enum) {
         throw new Strass_Controller_Action_Exception_Notice("Vous ne pouvez pas enregistrer une activité");
     }
     $i = $m->addEnum('unites', 'Unités participantes', $u->id, $enum, true);
     // multiple
     $m->addConstraintRequired($i);
     $annee = $this->controller->_helper->Annee(false);
     /* On cherche la date probable de l'activité qu'on veut prévoir. Soit
      * aucune activité n'est prévue cette année, alors on propose une date
      * près de la rentrée. Soit le calendrier est déjà remplis, alors on
      * propose comme date 4 semaines après la dernière activité
      * prévue. Comme ça on enchaîne l'enregistrement des activités. */
     $repere = $u->findLastDate($annee);
     if (!$repere) {
         $repere = Strass_Controller_Action_Helper_Annee::dateDebut($annee);
     } else {
         $debut = strftime('%Y-%m-%d', strtotime($repere . ' next saturday +4 weeks'));
         $fin = strftime('%Y-%m-%d', strtotime($repere . ' next sunday +4 weeks'));
     }
     $m->addDate('debut', 'Début', $debut . ' 14:30', '%Y-%m-%d %H:%M');
     $m->addDate('fin', 'Fin', $fin . '17:00', '%Y-%m-%d %H:%M');
     $m->addString('intitule', 'Intitulé explicite', "");
     $m->addBool('prevoir', "J'ai d'autres activités à prévoir", true);
     $m->addNewSubmission('ajouter', 'Ajouter');
     $m->addConstraintRequired($m->getInstance('unites'));
     if ($m->validate()) {
         $t = new Activites();
         $tu = new Unites();
         $td = new Documents();
         $a = new Activite();
         $a->debut = $m->debut;
         $a->fin = $m->fin;
         $unites = call_user_func(array($tu, 'find'), (array) $m->unites);
         // génération de l'intitulé
         $type = $unites->current()->findParentTypesUnite();
         $a->intitule = $m->intitule;
         $intitule = $type->getIntituleCompletActivite($a);
         $a->slug = $slug = $t->createSlug($intitule);
         $db = $t->getAdapter();
         $db->beginTransaction();
         try {
             $a->save();
             $a->updateUnites($unites);
             $this->controller->_helper->Flash->info("Activité enregistrée");
             $this->controller->logger->info("Nouvelle activite", $this->controller->_helper->Url('consulter', null, null, array('activite' => $a->slug)));
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         if ($m->get('prevoir')) {
             $this->controller->redirectSimple('prevoir');
         } else {
             $this->controller->redirectSimple('consulter', null, null, array('activite' => $slug));
         }
     }
     return array('model' => $m, 'calendrier' => $u->findActivites($this->current));
 }
Example #16
0
 function envoyerAction()
 {
     $this->view->doc = $d = $this->_helper->Document(false);
     if ($d) {
         $this->metas(array('DC.Title' => 'Éditer'));
         $this->view->unite = $unite = $d->findUnite();
     } else {
         $this->view->unite = $unite = $this->_helper->Unite(false);
         $this->branche->append('Documents', array('action' => 'index'));
         $this->metas(array('DC.Title' => 'Envoyer un document', 'DC.Title.alternative' => 'Envoyer'));
         $this->branche->append();
     }
     $t = new Unites();
     $unites = $t->fetchAll();
     $envoyables = array();
     foreach ($unites as $u) {
         if ($this->assert(null, $u, 'envoyer-document')) {
             $envoyables[$u->id] = $u->getFullName();
         }
     }
     if (!count($envoyables)) {
         throw new Strass_Controller_Action_Exception_Forbidden("Vous n'avez le droit d'envoyer de document pour aucune unité");
     }
     $this->view->model = $m = new Wtk_Form_Model('envoyer');
     $m->addNewSubmission('envoyer', "Envoyer");
     $m->addEnum('unite', "Unité", $unite->id, $envoyables);
     $i = $m->addString('titre', "Titre", $d ? $d->titre : null);
     $m->addConstraintRequired($i);
     $m->addString('auteur', "Auteur", $d ? $d->auteur : null);
     $m->addDate('date', "Date", $d ? $d->date : strftime('%F %T'));
     $m->addString('description', "Description", $d ? $d->description : null);
     $i = $m->addInstance('File', 'fichier', "Fichier");
     if (!$d) {
         $m->addConstraintRequired($i);
     }
     if ($m->validate()) {
         $t = new Documents();
         $db = $t->getAdapter();
         $db->beginTransaction();
         try {
             if ($d) {
                 $message = "Document modifié";
                 $du = $d->findDocsUnite()->current();
             } else {
                 if (!$d) {
                     $message = "Document envoyé";
                     $d = new Document();
                     $du = new DocUnite();
                 }
             }
             $d->slug = $t->createSlug(wtk_strtoid($m->titre), $d->slug);
             $d->titre = $m->titre;
             $d->auteur = $m->auteur;
             $d->date = $m->date;
             $d->description = $m->description;
             if ($i->isUploaded()) {
                 $d->suffixe = strtolower(end(explode('.', $m->fichier['name'])));
                 $d->save();
                 $d->storeFile($i->getTempFilename());
             } else {
                 $d->save();
             }
             $du->document = $d->id;
             $du->unite = $m->unite;
             $du->save();
             $this->logger->info($message, $this->_helper->Url('index', null, null, array('unite' => $du->findParentUnites()->slug), true));
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         $this->redirectSimple('details', null, null, array('document' => $d->slug));
     }
 }
Example #17
0
 function findUnites($actif = TRUE)
 {
     $t = new Unites();
     $s = $t->select()->setIntegrityCheck(false)->distinct()->from('unite')->joinLeft(array('parent' => 'unite'), 'parent.id = unite.parent', array())->joinLeft(array('grandparent' => 'unite'), 'grandparent.id = parent.parent', array())->join('appartenance', 'appartenance.unite IN (unite.id, parent.id, grandparent.id)', array())->where('appartenance.individu = ?', $this->id);
     if ($actif === true) {
         $s->where('appartenance.fin IS NULL');
     } else {
         if ($actif === false) {
             $s->where('appartenance.fin IS NOT NULL');
         }
     }
     return $t->fetchAll($s);
 }
Example #18
0
 function findUnites()
 {
     $t = new Unites();
     $s = $t->select()->setIntegrityCheck(false)->from('unite')->join('participation', 'participation.unite = unite.id', array())->where('participation.activite = ?', $this->activite);
     return $t->fetchAll($s);
 }
Example #19
0
 function findUnite()
 {
     $t = new Unites();
     $s = $t->select()->setIntegrityCheck(false)->from('unite')->join('journal', 'journal.unite = unite.id', array())->where('journal.id = ?', $this->journal);
     return $t->fetchOne($s);
 }