예제 #1
0
파일: Photos.php 프로젝트: bersace/strass
 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);
 }
예제 #2
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;
         }
     }
 }
예제 #3
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));
     }
 }
예제 #4
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);
 }
예제 #5
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);
 }
예제 #6
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;
     }
 }
예제 #7
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));
         }
     }
 }
예제 #8
0
파일: Prevoir.php 프로젝트: bersace/strass
 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));
 }