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 identifierAction() { $this->metas(array('DC.Title' => "Identifier une unité", 'DC.Subject' => 'identifier,photos')); $this->view->photo = $p = $this->_helper->Photo(); $this->assert(null, $p); $this->actions->append("Éditer", array('action' => 'editer'), array(null, $p)); $this->view->model = $m = new Wtk_Form_Model('identifier'); $idents = $p->findIdentifications(); $values = array(); foreach ($idents as $ident) { $values[] = $ident->unite; } $a = $p->findParentActivites(); $unites = $a->findUnitesParticipantes(); $enum = array(); foreach ($unites as $unite) { $enum[$unite->id] = $unite->getFullname(); } $m->addEnum('unites', 'Unités', $values, $enum, true); // multiple $m->addNewSubmission('enregistrer', "Enregistrer"); if ($m->validate()) { $db = $p->getTable()->getAdapter(); $db->beginTransaction(); $new_idents = $m->get('unites'); try { foreach ($idents as $ident) { if (($k = array_search($ident->unite, $new_idents)) !== false) { unset($new_idents[$k]); continue; } $ident->delete(); $this->logger->warn("Identification retirée", $this->_helper->Url('voir', 'photos')); } foreach ($new_idents as $uid) { $ident = new Identification(); $ident->photo = $p->id; $ident->unite = $uid; $ident->save(); $this->logger->info("Unité identifiée sur une photo", $this->_helper->Url('voir', 'photos')); } $db->commit(); } catch (Exception $e) { $db->rollBack(); throw $e; } $this->_helper->Flash->info("Identifications mise-à-jour"); $this->redirectSimple('voir'); } }