protected function getChemin($data = null) { if (is_null($data)) { $a = $this->findParentActivites(); } else { $ta = new Activites(); $a = $ta->findOne($data['activite']); } $d = $a->getDossierPhoto(); return $d . '/' . ($data ? $data['slug'] : $this->slug); }
function fetch($annee = NULL) { $ta = new Activites(); $as = $ta->findByAnnee($annee); $activite = null; if ($as->count() == 1) { $activite = $as->current(); $this->controller->_helper->Album->setBranche($activite); } $m = new Wtk_Form_Model('editer'); $i = $m->addString('titre', 'Titre', $this->photo->titre); $m->addConstraintRequired($i); $enum = array(); foreach ($as as $a) { if ($this->controller->assert(null, $a, 'editer-photo')) { $enum[$a->id] = $a->getIntituleComplet(); } } if ($enum) { $m->addEnum('activite', "Activité", $this->photo->activite, $enum); } $m->addFile('photo', "Photo"); $m->addBool('promouvoir', "Promouvoir en page d'accueil", $this->photo->promotion); $m->addNewSubmission('enregistrer', "Enregistrer"); if ($m->validate()) { $t = $this->photo->getTable(); $db = $t->getAdapter(); $db->beginTransaction(); try { $i = $m->getInstance('photo'); if ($i->isUploaded()) { $tmp = $i->getTempFilename(); $this->photo->storeFile($tmp); } try { $this->photo->activite = $m->activite; } catch (Exception $e) { } $this->photo->titre = $m->titre; $this->photo->slug = $t->createSlug($m->titre, $this->photo->slug); $this->photo->promotion = (int) $m->promouvoir; $this->photo->save(); $this->controller->_helper->Flash->info("Photo éditée"); $this->controller->logger->info("Photo éditée", $this->controller->_helper->Url('voir', null, null, array('photo' => $this->photo->slug))); $db->commit(); } catch (Exception $e) { $db->rollBack(); throw $e; } $this->controller->redirectSimple('voir', null, null, array('photo' => $this->photo->slug)); } return array('unite' => $this->unite, 'annee' => $annee, 'form_model' => $m, 'activite' => $activite, 'photo' => $this->photo); }
function direct($throw = true) { $slug = $this->getRequest()->getParam('album'); $t = new Activites(); try { $activite = $t->findBySlug($slug); $this->getRequest()->setParam('annee', $activite->getAnnee()); } catch (Strass_Db_Table_NotFound $e) { if ($throw) { throw new Strass_Controller_Action_Exception_NotFound("Album " . $slug . " inexistant"); } else { return null; } } $this->setBranche($activite); return $activite; }
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; } } }
function findLastDate($annee) { $t = new Activites(); $db = $t->getAdapter(); $s = $t->select()->from('activite', array('activite.fin'))->join('participation', 'participation.activite = activite.id' . ' AND ' . $db->quoteInto('participation.unite = ?', $this->id), array())->order('activite.fin DESC')->limit(1); if ($annee) { $s->where('? < activite.fin', Strass_Controller_Action_Helper_Annee::dateDebut($annee))->where('activite.fin < ?', strftime('%Y-%m-%d', strtotime(Strass_Controller_Action_Helper_Annee::dateFin($annee) . ' -5 weeks'))); } return $s->query()->fetchColumn(); }
function getActivites($futures = TRUE, $count = null) { $db = $this->getTable()->getAdapter(); // récupérer toutes les unités concernées. // récupérer les activités des ces unités. $select = $db->select()->from('activites')->distinct()->join('participe', $db->quoteInto('participe.activite = activites.id AND participe.unite IN (?)', new Zend_Db_Expr($db->select()->from('unites', 'id')->join('appartient', $db->quoteInto('appartient.unite = unites.id' . ' AND ' . 'appartient.individu = ?', $this->id), array())->__toString())), array())->order('debut'); if (!is_null($futures)) { $select->where('debut ' . ($futures ? '>' : '<') . ' STRFTIME("%Y-%m-%d %H:%M", "NOW")'); } if (!is_null($count)) { $select->limit($count); } $activites = new Activites(); return $activites->fetchAll($select); }
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)); }