Example #1
0
 function fonderAction()
 {
     $this->view->unite = $u = $this->_helper->Unite();
     $this->metas(array('DC.Title' => "Fonder le journal de " . $u->getFullName(), 'DC.Subject' => 'journaux,journal,gazette,blog'));
     $tu = $u->findParentTypesUnite();
     if ($tu->isTerminale() && $tu->age_min && $tu->age_min < 12) {
         throw new Strass_Controller_Action_Exception("Impossible de créer un journal d'unité " . "pour " . $u->getFullName());
     }
     $this->assert(null, $u, 'fonder-journal', "Vous n'avez pas le droit de fonder le journal de cette unité");
     $this->view->model = $m = new Wtk_Form_Model('fonder-journal');
     $i = $m->addString('nom', "Nom");
     $m->addConstraintRequired($i);
     $m->addNewSubmission('fonder', "Fonder");
     if ($m->validate()) {
         $t = new Journaux();
         $db = $t->getAdapter();
         $db->beginTransaction();
         try {
             $data = array('nom' => $m->get('nom'), 'slug' => $t->createSlug(wtk_strtoid($m->get('nom'))), 'unite' => $u->id);
             $k = $t->insert($data);
             $j = $t->findOne($k);
             $this->logger->info("Nouveau journal d'unité", $this->_helper->Url('index', 'journaux', array('journal' => $j->slug)));
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         $this->redirectSimple('index', 'journaux', null, array('journal' => $j->slug));
     }
 }
Example #2
0
 function direct($throw = true)
 {
     $slug = $this->getRequest()->getParam('journal');
     $t = new Journaux();
     try {
         $journal = $t->findBySlug($slug);
     } catch (Strass_Db_Table_NotFound $e) {
         if ($throw) {
             throw new Strass_Controller_Action_Exception_NotFound("Journal " . $slug . " inexistant.");
         } else {
             return null;
         }
     }
     $this->setBranche($journal);
     $this->_actionController->metas(array('DC.Title' => $journal->nom, 'DC.Subject' => 'journaux,journal,gazette,blog'));
     return $journal;
 }
Example #3
0
 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();
 }
Example #4
0
    function online($db)
    {
        $db->exec(<<<'EOS'
--
CREATE TABLE `journal` (
	id		INTEGER		PRIMARY KEY,
	slug		CHAR(128)	NOT NULL UNIQUE,
	-- Un seul blog par unité autorisé
	unite		INTEGER		UNIQUE REFERENCES unite(id),
	nom		CHAR(128)
);

INSERT INTO journal
(slug, unite, nom)
SELECT journaux.id, unite.id, journaux.nom
FROM journaux
JOIN unite ON unite.slug = journaux.unite;

DROP TABLE journaux;

CREATE VIEW vjournaux AS
SELECT journal.id, journal.slug, unite.slug, journal.nom
FROM journal
JOIN unite ON unite.id = journal.unite;


CREATE TABLE `article` (
	id		INTEGER		PRIMARY KEY,
	slug		CHAR(256)	NOT NULL UNIQUE,
	journal		INTEGER		REFERENCES journal(id),
	titre		CHAR(256),
	boulet		TEXT,
	article		TEXT,
	public		INT(1)		DEFAULT 0,
	commentaires	INTEGER		UNIQUE NOT NULL REFERENCES commentaire(id)
);

INSERT INTO commentaire
(auteur, message, date)
SELECT auteur.id, articles.id, articles.date || ' ' || substr(articles.heure, 0, 6)
FROM articles
JOIN individu AS auteur ON auteur.slug = articles.auteur;

INSERT INTO `article`
(slug, journal, titre, boulet, article, public, commentaires)
SELECT articles.id, journal.id,
       articles.titre, articles.boulet, articles.article, articles.public,
       (SELECT id FROM commentaire WHERE message = articles.id)
FROM articles
JOIN journal ON journal.slug = articles.journal;

CREATE VIEW varticles AS
SELECT article.id,
       journal.slug AS journal,
       article.slug, auteur.slug AS auteur,
       article.titre, commentaire.date
FROM article
JOIN journal ON journal.id = article.journal
JOIN commentaire ON commentaire.id = article.commentaires
JOIN individu AS auteur ON auteur.id = commentaire.auteur
ORDER BY journal.id, commentaire.date;


CREATE TABLE `article_etiquette` (
	id		INTEGER		PRIMARY KEY,
	article		INTEGER		NOT NULL REFERENCES article(id),
	etiquette	CHAR(128)	NOT NULL,
	UNIQUE(article, etiquette)
);

INSERT INTO article_etiquette
(article, etiquette)
SELECT DISTINCT
       article.id, rubriques.nom
FROM rubriques
JOIN articles ON articles.rubrique = rubriques.id AND articles.journal = rubriques.journal
JOIN article ON article.slug = articles.id;

DROP TABLE articles;
DROP TABLE rubriques;

EOS
);
        /* Migration des rapports en articles de gazette d'unité */
        $gazettes = $db->query(<<<'EOS'
SELECT DISTINCT unite.* FROM unite
JOIN participe ON participe.unite = unite.slug AND participe.rapport <> ''
LEFT JOIN journal ON journal.unite = unite.id
WHERE journal.id IS NULL
EOS
);
        $t = new Journaux();
        foreach ($gazettes as $i => $row) {
            $nom = "Blog";
            $slug = $t->createSlug($nom);
            $unite = $row['id'];
            $db->query("INSERT INTO journal (slug, unite, nom) VALUES (?, ?, ?)", array($slug, (int) $unite, $nom));
        }
        $db->exec(<<<'EOS'
INSERT INTO commentaire
(auteur, date, message)
SELECT DISTINCT
       MIN(appartenance.individu) AS auteur,
       activite.fin AS date,
       'RAPPORT ### ' || unite.slug || activite.slug AS message
FROM participe
JOIN unite ON unite.slug = participe.unite
JOIN unite_type ON unite_type.id = unite.type
JOIN activite ON activite.slug = participe.activite
JOIN appartenance ON appartenance.unite = (CASE unite_type.virtuelle WHEN 1 THEN unite.parent ELSE unite.id END)
JOIN unite_role AS role ON role.id = appartenance.role
WHERE participe.boulet <> '' OR participe.rapport <> ''
      AND role.acl_role = 'chef'
     AND appartenance.debut <= activite.debut
     AND (activite.fin <= appartenance.fin OR appartenance.fin = '')
GROUP BY date, message;

EOS
);
        $db->exec(<<<'EOS'
INSERT INTO article
(slug, journal, titre, boulet, article, public, commentaires)
SELECT activite.slug,
       journal.id, activite.intitule, participe.boulet, participe.rapport, 1, commentaire.id
FROM participe
JOIN unite ON unite.slug = participe.unite
JOIN activite ON activite.slug = participe.activite
JOIN journal ON journal.unite = unite.id
JOIN commentaire ON commentaire.message = 'RAPPORT ### ' || unite.slug || activite.slug
WHERE participe.boulet <> '' OR participe.rapport <> '';

UPDATE commentaire SET message = NULL WHERE message LIKE 'RAPPORT ### %';

-- DROP TABLE participe;
EOS
);
    }