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

Source for file News.php

Documentation is available at News.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.  * Interfaccia per la gestione delle notizie del sito.
  27.  *
  28.  * @package  MCMS
  29.  * @version  2
  30.  * @author   Silvio Moioli <silvio at moioli dot net>
  31.  *
  32.  */
  33.  
  34. /** Carica la classe base di MCMS per l'interfacciamento al Database */
  35. require_once $_SERVER["DOCUMENT_ROOT"]."/admin/lib/model/Engine.php";
  36. /**
  37.  * Carica la classe per le pagine (Page)
  38.  */
  39. require_once $_SERVER["DOCUMENT_ROOT"]."/admin/lib/model/Page.php";
  40.  
  41. /**
  42.  * Interfaccia per la gestione delle notizie del sito.
  43.  *
  44.  * Permette di utilizzare il database in modo trasparente: creare oggetti
  45.  * di questa classe e operare sugli attributi tramite gli appositi metodi
  46.  * modificherà automaticamente il database sottostante.
  47.  * 
  48.  * @package  MCMS
  49.  * @version  2
  50.  * @author   Silvio Moioli <silvio at moioli dot net>
  51.  *
  52.  */
  53. class News extends Page
  54. {
  55.     //Attributi ereditati: $ID e $engine
  56.  
  57.     //Costruttori   
  58.         /**
  59.      * Costruttore di lettura
  60.      *
  61.      * Costruttore "di lettura" (costruisce una notizia da un record del
  62.      * database già esistente).
  63.      * Nota: non può essere creata una nuova notizia da qui, ma solo dal Factory
  64.      * Method nella classe Site.
  65.      * Per i costruttori "di scrittura", quindi, vedere la classe Site
  66.      * nel file Site.php.
  67.      *
  68.      * @param int $ID l'ID del database sottostante
  69.      * @param Engine $engine un motore per interagire con il database
  70.      *  sottostante
  71.      * @return mixed la notizia se la costruzione è andata a buon fine, altrimenti
  72.      *  un PEAR_Error
  73.      * @see Engine
  74.      */
  75.     function News($ID$engine)
  76.     {
  77.         $this->Page($ID$engine);
  78.     }
  79.     
  80.     //Metodi
  81.         /**
  82.      * Getter per il campo Fonte dalla tabella Notizia.
  83.      * 
  84.      * Ritorna una stringa con l'URL della principale fonte da cui è tratta
  85.      * questa notizia. Permette di utilizzare il fontebase in modo
  86.      * trasparente (è come se si usassero normali attributi di una classe).
  87.      *
  88.      * @return mixed una stringa con l'URL se l'operazione è andata a buon fine,
  89.      *  NULL se la notizia non ha fonte (interna al sito), altrimenti
  90.      *  un DB_ERROR in caso di errore
  91.      */
  92.      function getSource()
  93.      {
  94.         $thisEngine $this->getEngine();
  95.         $thisDB $thisEngine->getDB();
  96.         $thisID $thisDB->escapeSimple($this->getID());
  97.         $res $thisDB->getOne("SELECT `url fonte notizia` FROM `notizie`".
  98.                                "WHERE `id pagina` = '$thisIDLIMIT 1;");
  99.         
  100.         #$thisDB->disconnect();
  101.         return $res;
  102.      }
  103.     
  104.     /**
  105.      * Setter per il campo Fonte dalla tabella Notizia.
  106.      * 
  107.      * Cambia l'oggetto corrispondente alla fonte di ultima modifica di
  108.      * questa notizia. Permette di utilizzare il fontebase in modo
  109.      * trasparente (è come se si usassero normali attributi di una classe).
  110.      *
  111.      * @param string $source l'URL della fonte primaria di questa notizia o
  112.      *  NULL.
  113.      * @return mixed true se l'operazione è andata a buon fine, altrimenti
  114.      *  un DB_ERROR
  115.      */
  116.      function setSource($source)
  117.      {
  118.         $thisEngine $this->getEngine();
  119.         $thisDB $thisEngine->getDB();
  120.         $thisID $thisDB->escapeSimple($this->getID());
  121.         $source $thisDB->escapeSimple($thisDB->escapeSimple($source));
  122.         $thisDB->query("UPDATE `notizieSET `url fonte notizia`='$source'".
  123.                        "WHERE `id pagina` = '$thisID';");
  124.         
  125.         #$thisDB->disconnect();
  126.         return true;
  127.      }
  128.      
  129.     /**
  130.      * Getter per gli articoli correlati a questa notizia.
  131.      * 
  132.      * Ritorna un array contenente gli articoli correlati a questa notizia.
  133.      *
  134.      * @return mixed un array di Article se l'operazione è andata a
  135.      *  buon fine o un DB_ERROR in caso di errore
  136.      * @see Article
  137.      */
  138.      function getCorrelatedArticles()
  139.      {
  140.         $thisEngine $this->getEngine();
  141.         $thisDB $thisEngine->getDB();
  142.         $newsID $thisDB->escapeSimple($this->getID());
  143.         
  144.         $sql "SELECT `id articolo` FROM `articoli correlati notizia` WHERE".
  145.                "`id notizia` ='$newsID';";
  146.         $articleIDs $thisDB->getCol($sql);
  147.  
  148.         #$thisDB->disconnect();
  149.                 
  150.         //Creo l'array degli oggetti a partire dagli IDs
  151.         $articles array();
  152.         foreach ($articleIDs as $i{
  153.             $articles[new Article($i$thisEngine);
  154.         }
  155.  
  156.         return $articles;
  157.      }
  158.      
  159.     /**
  160.      * Ritorna il numero degli articoli correlati a questa notizia.
  161.      * 
  162.      *
  163.      * @return mixed un int se l'operazione è andata a
  164.      *  buon fine o un DB_ERROR in caso di errore
  165.      * @see Article
  166.      */
  167.      function getCorrelatedArticlesCount()
  168.      {
  169.         $thisEngine $this->getEngine();
  170.         $thisDB $thisEngine->getDB();
  171.         $newsID $thisDB->escapeSimple($this->getID());
  172.         
  173.         $sql "SELECT COUNT(`id articolo`) FROM `articoli correlati notizia` WHERE".
  174.                "`id notizia` ='$newsID';";
  175.         $result $thisDB->getCol($sql);
  176.  
  177.         #$thisDB->disconnect();
  178.         return $result;
  179.      }
  180.      
  181.     /**
  182.      * Setter per gli articoli correlati a questa notizia.
  183.      * 
  184.      * Cambia gli articoli correlati a questa notizia con un insieme di altri.
  185.      *
  186.      * @param array $articles i nuovi articoli correlati
  187.      * @return mixed true se l'operazione è andata a buon fine o un DB_ERROR
  188.      *  in caso di errore
  189.      * @see Article
  190.      */
  191.      function setCorrelatedArticles($articles)
  192.      {
  193.          $this->dropCorrelatedArticles();
  194.          foreach ($articles as $i){
  195.              $this->addCorrelatedArticle($i);
  196.          }
  197.          
  198.          return true;
  199.      }
  200.     
  201.     /**
  202.      * Aggiunge un nuovo articolo correlato.
  203.      * 
  204.      * L'articolo specificato viene catalogato come correlato a questa notizia.
  205.      *
  206.      * @param Article $article l'articolo da aggiungere
  207.      * @return mixed true se l'operazione è andata a buon fine o un
  208.      *  DB_ERROR in caso di errore
  209.      * @see Article
  210.      */
  211.      function addCorrelatedArticle($article)
  212.      {
  213.         $thisEngine $this->getEngine();
  214.         $thisDB $thisEngine->getDB();
  215.         $articleID $thisDB->escapeSimple($article->getID());
  216.         $pageID $thisDB->escapeSimple($this->getID());
  217.         $sql "INSERT INTO `articoli correlati notizia` (`id notizia`,".
  218.                "`id articolo` ) VALUES ( '$pageID', '$articleID' );";
  219.         $thisDB->query($sql);
  220.         
  221.  
  222.         #$thisDB->disconnect();
  223.         return true;
  224.      }
  225.      
  226.     /**
  227.      * Rimuove un articolo correlato.
  228.      * 
  229.      * Rimuove la correlazione fra questa notizia e l'articolo passato.
  230.      *
  231.      * @param Article $article l'articolo da rimuovere
  232.      * @return mixed true se l'operazione è andata a buon fine o un
  233.      *  DB_ERROR in caso di errore
  234.      * @see Article
  235.      */
  236.      function dropCorrelatedArticle($article)
  237.      {
  238.         $thisEngine $this->getEngine();
  239.         $thisDB $thisEngine->getDB();
  240.         $articleID $thisDB->escapeSimple($article->getID());
  241.         $pageID $thisDB->escapeSimple($this->getID());
  242.  
  243.         $sql "DELETE FROM `articoli correlati notizia` WHERE".
  244.                "(`id notizia`='$pageIDAND `id articolo`='$articleID');";
  245.         $thisDB->query($sql);
  246.  
  247.         #$thisDB->disconnect();
  248.         return true;
  249.      }
  250.      
  251.     /**
  252.      * Rimuove tutti gli articoli correlati.
  253.      * 
  254.      * Rimuove tutti gli articoli correlati a questa notizia.
  255.      *
  256.      * @return mixed true se l'operazione è andata a buon fine o un
  257.      *  DB_ERROR in caso di errore
  258.      * @see Article
  259.      */
  260.      function dropCorrelatedArticles()
  261.      {
  262.         $thisEngine $this->getEngine();
  263.         $thisDB $thisEngine->getDB();
  264.         $newsID $thisDB->escapeSimple($this->getID());
  265.         
  266.         $sql "DELETE FROM `articoli correlati notizia` WHERE".
  267.                "`id notizia`='$newsID'";
  268.         $thisDB->query($sql);
  269.  
  270.         #$thisDB->disconnect();
  271.         return true;
  272.      }
  273. }
  274. ?>

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