function fetch($annee = NULL) { if (!$this->activite) { return array('activites' => $this->unite->findActivites($annee)); } else { $this->controller->assert(null, $this->activite, 'envoyer-photo', "Vous n'avez pas le droit d'envoyer de photo de " . $this->activite->getIntituleComplet() . "."); } $m = new Wtk_Form_Model('envoyer'); $i = $m->addString('titre', 'Titre'); $m->addConstraintRequired($i); $m->addFile('photo', "Photo"); $m->addString('commentaire', 'Votre commentaire'); $m->addBool('envoyer', "J'ai d'autres photos à envoyer", true); $m->addNewSubmission('envoyer', "Envoyer"); $t = new Photos(); if ($m->validate()) { $p = new Photo(); $p->titre = $m->titre; $p->slug = $t->createSlug(wtk_strtoid($m->titre)); $p->activite = $this->activite->id; $action = $m->envoyer ? 'envoyer' : 'consulter'; $c = new Commentaire(); $c->auteur = Zend_Registry::get('individu')->id; $c->message = $m->commentaire; $db = $t->getAdapter(); $db->beginTransaction(); try { $c->save(); $p->commentaires = $c->id; $p->save(); $i = $m->getInstance('photo'); if ($i->isUploaded()) { $tmp = $i->getTempFilename(); $p->storeFile($tmp); } $url = $this->controller->_helper->Url('voir', 'photos', null, array('photo' => $p->slug), true); $this->controller->logger->info("Photo envoyée", $url); foreach ($this->activite->findUnitesParticipantesExplicites() as $u) { $ident = new Identification(); $ident->photo = $p->id; $ident->unite = $u->id; $ident->save(); $this->controller->logger->info("Unité identifiée sur une photo", $url); } $db->commit(); } catch (Exception $e) { $db->rollBack(); throw $e; } $this->controller->_helper->Flash->info("Photo envoyée"); $this->controller->redirectSimple($action, null, null, array('album' => $this->activite->slug)); } $photos = $this->activite->findPhotos($t->select()->order('date')); return array('unite' => $this->unite, 'annee' => $annee, 'model' => $m, 'activite' => $this->activite, 'photos' => $photos); }
function consulterAction() { $this->view->activite = $a = $this->_helper->Album(); $this->metas(array('DC.Title' => $a->getIntitule(), 'DC.Subject' => 'photos')); $photos = new Photos(); $s = $photos->select()->order('date'); $this->view->photos = $a->findPhotos($s); $this->connexes->append("Chaîne", array('controller' => 'activites', 'action' => 'consulter', 'activite' => $a->slug, 'album' => null)); $this->actions->append("Éditer la chaîne", array('controller' => 'activites', 'action' => 'editer', 'activite' => $a->slug, 'album' => null)); $this->actions->append("Envoyer une photo", array('action' => 'envoyer'), array(null, $a, 'envoyer-photo')); }
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(); }
function findPhotosAleatoires($annee = null) { // Une photos aléatoire d'une activité où l'unité à participé $t = new Photos(); $db = $t->getAdapter(); $s = $t->select()->setIntegrityCheck(false)->distinct()->from('photo'); /* Rechercher les albums ou l'unité a participé */ $s->join('participation', 'participation.activite = photo.activite' . ' AND ' . $db->quoteInto("participation.unite = ?", $this->id), array()); /* Rechercher si l'unité est identifiée sur la photo */ $s->joinLeft(array('identification' => 'photo_identification'), $db->quoteInto('identification.photo = photo.id' . ' AND ' . 'identification.unite = ?', $this->id), array()); /* Préfére les photos où l'unité est identifiée explicitement. */ $s->order('identification.unite DESC'); /* Préfère les photo comm. */ $s->order('photo.promotion DESC'); /* Mélanger les photos comm. et identifie */ $s->order('RANDOM()'); if ($annee) { $s->where("strftime('%Y', activite.debut, '-8 months') = ?", strval($annee)); } $s->limit(6); // paramétrable ? return $t->fetchAll($s); }
function findPhoto() { $t = new Photos(); $s = $t->select()->setIntegrityCheck(false)->from('photo')->where('photo.commentaires = ?', $this->parent); return $t->fetchOne($s); }