MCMS
[ class tree: MCMS ] [ index: MCMS ] [ all elements ]

Source for file Committer.php

Documentation is available at Committer.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | MCMS: a PHP Content Management System for creating accessible sites. |
  5. // | Copyright (C) 2005  Silvio Moioli                                    |
  6. // |                                                                      |
  7. // | This program is free software; you can redistribute it and/or modify |
  8. // | it under the terms of the GNU General Public License as published by |
  9. // | the Free Software Foundation; either version 2 of the License, or    |
  10. // | (at your option) any later version.                                  |
  11. // |                                                                      |
  12. // | This program is distributed in the hope that it will be useful,      |
  13. // | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
  14. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
  15. // | GNU General Public License for more details.                         |
  16. // |                                                                      |
  17. // | You should have received a copy of the GNU General Public License    |
  18. // | along with this program; if not, write to the Free Software          |
  19. // | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 |
  20. // +----------------------------------------------------------------------+
  21. // | Authors: Silvio Moioli <silvio at moioli dot net> www.moioli.net     |
  22. // +----------------------------------------------------------------------+
  23. //
  24. //$Id:
  25.  
  26. /** Carica la classe base di MCMS per l'interfacciamento al Database */
  27. require_once $_SERVER["DOCUMENT_ROOT"]."/admin/lib/model/Engine.php";
  28. /** Carica la classe del compilatore di interfacce XHTML */
  29. require_once $_SERVER["DOCUMENT_ROOT"]."/admin/lib/view/Compiler.php";
  30. /** Carica il gestore dei permessi degli utenti in MCMS */
  31. require_once $_SERVER["DOCUMENT_ROOT"]."/admin/lib/controller/AuthManager.php";
  32.  
  33. /**
  34.  * Aggiorna View e Model a fronte di determinati comandi.
  35.  * 
  36.  * @package  MCMS
  37.  * @version  2
  38.  * @author   Silvio Moioli <silvio at moioli dot net>
  39.  *
  40.  */
  41. class Committer extends PEAR
  42. {
  43.     /** @var Engine l'oggetto per la comunicazione al Database */
  44.     var $engine = null;
  45.     /** @var Compiler l'oggetto per il salvataggio dei file dei siti */
  46.     var $compiler = null;
  47.     /** @var AuthManager il gestore dei permessi degli utenti in MCMS */
  48.     var $authManager = null;
  49.     
  50.     /**
  51.      * Costruttore standard.
  52.      *
  53.      * @param Engine $engine l'oggetto per la comunicazione al DB in uso
  54.      */
  55.     function Committer($engine$authManager)
  56.     {
  57.         $this->engine = $engine;
  58.         $this->compiler = new Compiler();
  59.         $this->authManager = $authManager;
  60.     }
  61.     
  62.     /**
  63.      * Aggiunge un articolo al sito specificato.
  64.      *
  65.      * @param Site $site il sito a cui agguingere l'articolo
  66.      * @param Author $author l'autore dell'articolo
  67.      * @param string $contents i contenuti XHTML dell'articolo
  68.      * @param string $title il titolo dell'articolo
  69.      * @param string $keywords le parole-chiave dell'articolo
  70.      * @param Category $category la categoria a cui l'articolo appartiene
  71.      * @param string $description una breve descrizione dell'articolo
  72.      * @param array $articles gli articoli ad esso correlati
  73.      * @return l'articolo aggiunto o un PEAR_ERROR
  74.      */
  75.     function addArticle($site$author$contents$title$keywords
  76.         $category$description$articles)
  77.     {
  78.         $article $site->addArticle($author$contents$title,
  79.         $keywords$category$description$articles);
  80.  
  81.         $this->compiler->save(new UserArticle($site$article));
  82.         foreach ($articles as $i){
  83.             $this->compiler->save(new UserArticle($site$i));
  84.         }
  85.         $this->compiler->save(new UserCategory($site$category));
  86.         $this->compiler->saveComponents($site);
  87.         
  88.         return $article;
  89.     }
  90.     
  91.     /**
  92.      * Modifica un articolo.
  93.      *
  94.      * @param Site $site il sito a cui l'articolo appartiene
  95.      * @param Article $article l'articolo da modificare
  96.      * @param string $contents i contenuti XHTML dell'articolo
  97.      * @param string $title il titolo dell'articolo
  98.      * @param string $keywords le parole-chiave dell'articolo
  99.      * @param Category $category la categoria a cui l'articolo appartiene
  100.      * @param string $description una breve descrizione dell'articolo
  101.      * @param array $articles gli articoli ad esso correlati
  102.      * @return l'articolo modificato o un PEAR_ERROR
  103.      */
  104.     function editArticle($site$article$contents$title$keywords,
  105.         $category$description$articles)
  106.     {
  107.         $result true;
  108.         $result $result and $article->setContents($contents);
  109.         $result $result and $article->setTitle($title);
  110.         $result $result and $article->setKeywords($keywords);
  111.         $oldCategory $article->getCategory();
  112.         $result $result and $article->setCategory($category);
  113.         $result $result and $article->setDescription($description);
  114.         $oldCorrelatedArticles $article->getCorrelatedArticles();
  115.         $result $result and $article->setCorrelatedArticles($articles);
  116.  
  117.         $this->compiler->save(new UserArticle($site$article));
  118.         foreach (array_merge($articles,$oldCorrelatedArticlesas $i){
  119.             $this->compiler->save(new UserArticle($site$i));
  120.         }
  121.         $this->compiler->save(new UserCategory($site$oldCategory));
  122.         if($oldCategory->getID(!= $category->getID()){
  123.             $this->compiler->save(new UserCategory($site$category));
  124.         }
  125.         $this->compiler->saveComponents($site);
  126.         
  127.         return $result;
  128.     }
  129.  
  130.     /**
  131.      * Rimuove un articolo.
  132.      *
  133.      * @param Site $site il sito a cui l'articolo appartiene
  134.      * @param Article $article l'articolo da cancellare
  135.      * @return true o un PEAR_ERROR
  136.      */
  137.     function dropArticle($site$article)
  138.     {
  139.         $this->compiler->remove(new UserArticle($site$article));
  140.         
  141.         $oldCorrelatedArticles $article->getCorrelatedArticles();
  142.         $oldCategory $article->getCategory();
  143.         $result $site->dropArticle($article);
  144.  
  145.         foreach ($oldCorrelatedArticles as $i){
  146.             $this->compiler->save(new UserArticle($site$i));
  147.         }
  148.         $this->compiler->save(new UserCategory($site$oldCategory));
  149.         $this->compiler->saveComponents($site);
  150.         
  151.         return $result;
  152.     }
  153.     
  154.     /**
  155.      * Aggiunge un autore.
  156.      *
  157.      * @param string $name il nome del nuovo autore
  158.      * @param string $surname il cognome del nuovo autore
  159.      * @param string $nick il nickname del nuovo autore
  160.      * @param string $email l'indirizzo email del nuovo autore
  161.      * @param string $password la password per MCMS del nuovo autore
  162.      * @return il nuovo autore aggiunto o un PEAR_ERROR
  163.      */
  164.     function addAuthor($name$surname$nick$email$password)
  165.     {
  166.         $author $this->engine->addAuthor($name$surname$nick$email);
  167.         $this->authManager->addUser($author$password);
  168.         
  169.         return $author;
  170.     }
  171.     
  172.     /**
  173.      * Modifica i dati di un autore.
  174.      *
  175.      * @param Author $author l'autore da modificare
  176.      * @param string $name il nome dell'autore
  177.      * @param string $surname il cognome dell'autore
  178.      * @param string $nick il nickname dell'autore
  179.      * @param string $email l'indirizzo email dell'autore
  180.      * @return l'autore modificato o un PEAR_ERROR
  181.      */
  182.     function editAuthor($author$name$surname$nick$email)
  183.     {
  184.         $result true;
  185.         $result $result and $author->setName($name);
  186.         $result $result and $author->setSurname($surname);
  187.         $result $result and $author->setNick($nick);
  188.         $result $result and $author->setEmail($email);
  189.  
  190.         $sites $this->engine->getSites();
  191.         foreach ($sites as $i){
  192.             $this->compiler->saveAll($i);
  193.         }
  194.         
  195.         return $result;        
  196.     }
  197.     
  198.     /**
  199.      * Cancella un autore
  200.      *
  201.      * @param Author $author l'autore da cancellare
  202.      * @return true o un PEAR_ERROR
  203.      */
  204.     function dropAuthor($author){
  205.         $result $this->engine->dropAuthor($author);
  206.         $this->authManager->removeUser($author);
  207.        
  208.         return $result;
  209.     }
  210.     
  211.     /**
  212.      * Aggiunge una notizia al sito specificato.
  213.      *
  214.      * @param Site $site il sito a cui aggiungere la notizia
  215.      * @param Author $author l'autore della notizia
  216.      * @param string $contents i contenuti XHTML della notizia
  217.      * @param string $title il titolo della notizia
  218.      * @param string $keywords le parole-chiave della notizia
  219.      * @param string $source la fonte originale della notizia
  220.      * @param array $articles gli articoli ad essa correlati
  221.      * @return la notizia aggiunta o un PEAR_ERROR
  222.      */
  223.     function addNews($site$author$contents$title$keywords$source,
  224.         $articles)
  225.     {
  226.         $news $site->addNews($author$contents$title$keywords,
  227.             $source$articles);
  228.                   
  229.         $this->compiler->save(new UserHomepage($site));
  230.         $this->compiler->save(new UserNews($site));
  231.         $this->compiler->saveComponents($site);
  232.         
  233.         return $news;
  234.     }
  235.     
  236.     /**
  237.      * Modifica una notizia.
  238.      *
  239.      * @param Site $site il sito a cui la notizia appartiene
  240.      * @param News $news la notizia da modificare
  241.      * @param Author $author l'autore della notizia
  242.      * @param string $contents i contenuti XHTML della notizia
  243.      * @param string $title il titolo della notizia
  244.      * @param string $keywords le parole-chiave della notizia
  245.      * @param string $source la fonte originale della notizia
  246.      * @param array $articles gli articoli ad essa correlati
  247.      * @return la notizia modificata o un PEAR_ERROR
  248.      */
  249.     function editNews($site$news$contents$title$keywords,
  250.         $source$articles)
  251.     {
  252.         $result true;
  253.         $result $result and $news->setContents($contents);
  254.         $result $result and $news->setTitle($title);
  255.         $result $result and $news->setKeywords($keywords);
  256.         $result $result and $news->setSource($source);
  257.         $result $result and $news->setCorrelatedArticles($articles);
  258.     
  259.         $this->compiler->save(new UserHomepage($site));
  260.         $this->compiler->save(new UserNews($site));
  261.         $this->compiler->saveComponents($site);
  262.         
  263.         return $result;
  264.     }
  265.  
  266.     /**
  267.      * Cancella una notizia.
  268.      *
  269.      * @param Site $site il sito a cui la notizia appartiene
  270.      * @param News $news la notizia da cancellare
  271.      * @return true o un PEAR_ERROR
  272.      */
  273.     function dropNews($site$news)
  274.     {
  275.         $result $site->dropNews($news);
  276.         
  277.         $this->compiler->save(new UserHomepage($site));
  278.         $this->compiler->save(new UserNews($site));
  279.         $this->compiler->saveComponents($site);
  280.         
  281.         return $result;
  282.     }
  283.     
  284.     /**
  285.      * Aggiunge una sezione al sito specificato.
  286.      *
  287.      * @param Site $site il sito a cui aggiungere la sezione
  288.      * @param string $name il nome della sezione
  289.      * @param string $description una breve descrizione della sezione
  290.      * @return la sezione aggiunta o un PEAR_ERROR
  291.      */
  292.     function addCategory($site$name$description)
  293.     {
  294.         $category $site->addCategory($name$description);
  295.         
  296.         $this->compiler->save(new UserHomepage($site));
  297.         $this->compiler->saveComponents($site);
  298.         $this->compiler->save(new UserCategory($site$category));
  299.         
  300.         return $category;
  301.     }
  302.     
  303.     /**
  304.      * Modifica una sezione del sito specificato.
  305.      *
  306.      * @param Site $site il sito a cui aggiungere la sezione
  307.      * @param Category $category la sezione da modificare
  308.      * @param string $name il nome della sezione
  309.      * @param string $description una breve descrizione della sezione
  310.      * @return la sezione aggiunta o un PEAR_ERROR
  311.      */
  312.     function editCategory($site$category$name$description)
  313.     {
  314.         $result true;
  315.         $result $result and $category->setName($name);
  316.         $result $result and $category->setDescription($description);
  317.         
  318.         $this->compiler->save(new UserHomepage($site));
  319.         $this->compiler->save(new UserCategory($site$category));
  320.         
  321.         $articles $category->getArticles();
  322.         foreach ($articles as $i){
  323.            $this->compiler->save(new UserArticle($site$i));
  324.         }
  325.  
  326.         $this->compiler->saveComponents($site);
  327.  
  328.         return $result;
  329.     }
  330.     
  331.     /**
  332.      * Cancella una sezione del sito.
  333.      *
  334.      * @param Site $site il sito a cui la sezione appartiene
  335.      * @param Category $category la sezione da cancellare
  336.      * @return true o un PEAR_ERROR
  337.      */
  338.     function dropCategory($site$category)
  339.     {
  340.         $result false;
  341.         //Deve restare sempre almeno una categoria
  342.         if ($site->getCategoriesCount()>1{
  343.             $result $site->dropCategory($category);
  344.             $this->compiler->remove(new UserCategory($site$category));
  345.         }
  346.         
  347.         $this->compiler->save(new UserHomepage($site));
  348.         
  349.         return $result;
  350.     }
  351.     
  352.     /**
  353.      * Aggiunge un nuovo sito.
  354.      *
  355.      * @param Author $author l'autore (fondatore) del sito
  356.      * @param string $name il nome del nuovo sito
  357.      * @param string $slogan il motto del sito
  358.      * @param string $keywords le parole-chiave del sito
  359.      * @return il nuovo sito o un PEAR_ERROR
  360.      */
  361.     function addSite($author$name$slogan$keywords)
  362.     {
  363.         $site $this->engine->addSite($name$slogan$author$keywords);
  364.         
  365.         $this->compiler->saveAll($site);
  366.         
  367.         return $site;
  368.     }
  369.     
  370.     /**
  371.      * Cancella un sito.
  372.      *
  373.      * @param Site $site il sito da cancellare
  374.      * @return true o un PEAR_ERROR
  375.      */
  376.     function dropSite($site)
  377.     
  378.         $this->compiler->removeAll($site);
  379.         
  380.         return $this->engine->dropSite($site);
  381.     }
  382.     
  383.     /**
  384.      * Modifica i componenti opzionali attivati su un sito.
  385.      *
  386.      * @param Site $site il sito da modificare
  387.      * @param array $components i componenti da attivare
  388.      * @return il sito modificato o un PEAR_ERROR
  389.      */
  390.     function editComponents($site$components)
  391.     {
  392.         $result $site->changeComponents($components);
  393.         
  394.         $this->compiler->saveAll($site);
  395.         
  396.         return $result;
  397.     }
  398.     
  399.     /**
  400.      * Modifica la pagina iniziale di un sito.
  401.      *
  402.      * @param Site $site il sito da modificare
  403.      * @param string $contents i contenuti XHTML della pagina
  404.      * @param string $slogan il motto del sito
  405.      * @param string $keywords le parole-chiave del sito
  406.      * @return la pagina modificata o un PEAR_ERROR
  407.      */
  408.     function editHomepage($site$contents$slogan$keywords)
  409.     {
  410.         $result true;
  411.         $homepage $site->getHomepage();
  412.         $result $result and $homepage->setContents($contents);
  413.         $result $result and $homepage->setSlogan($slogan);
  414.         $result $result and $homepage->setKeywords($keywords);
  415.         
  416.         $this->compiler->save(new UserHomepage($site));
  417.         
  418.         return $result;
  419.     }
  420. }
  421.  
  422. ?>

Documentation generated on Wed, 26 Jul 2006 21:44:51 +0200 by phpDocumentor 1.3.0RC6