function calculerDates($annee) { $u = $this->unite; $a = $annee; $fin = strftime('%Y-%m-%d', strtotime(Strass_Controller_Action_Helper_Annee::dateFin($annee) . ' next saturday -4 weeks')); $calendrier = $u->findActivites($a); if ($calendrier->count()) { $debut = substr($calendrier->current()->debut, 0, 10); $min_fin = strftime('%Y-%m-%d', strtotime(Strass_Controller_Action_Helper_Annee::dateFin($annee) . ' next saturday -6 weeks')); $max_fin = strftime('%Y-%m-%d', strtotime(Strass_Controller_Action_Helper_Annee::dateFin($annee) . ' next saturday')); while ($calendrier->valid()) { $fin = substr($calendrier->current()->fin, 0, 10); $calendrier->next(); } if ($min_fin > $fin) { $fin = $min_fin; } if ($max_fin < $fin) { $fin = $max_fin; } } else { $debut = strftime('%Y-%m-%d', strtotime(Strass_Controller_Action_Helper_Annee::dateDebut($annee) . ' next saturday +4 weeks')); } return array($debut, $fin); }
function findByAnnee($annee) { $s = $this->select()->where("? < activite.debut", Strass_Controller_Action_Helper_Annee::dateDebut($annee))->where("activite.fin < ?", Strass_Controller_Action_Helper_Annee::dateFin($annee))->order('activite.debut'); return $this->fetchAll($s); }
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 findActivites($annee = null) { $t = new Activites(); $db = $t->getAdapter(); $s = $t->select()->setIntegrityCheck(false)->distinct()->from('activite')->join('participation', 'participation.activite = activite.id', array())->join('unite', 'unite.id = participation.unite', array())->join('appartenance', $db->quoteInto("appartenance.individu = ?", $this->id) . " AND " . "appartenance.unite = unite.id", array())->order('activite.debut DESC'); if ($annee) { $s->where("activite.debut >= ?", Strass_Controller_Action_Helper_Annee::dateDebut($annee)); $s->where("activite.fin <= ?", Strass_Controller_Action_Helper_Annee::dabteFin($annee)); } return $t->fetchAll($s); }
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)); }