linea21-modules
[ class tree: linea21-modules ] [ index: linea21-modules ] [ all elements ]

Source for file class.news.php

Documentation is available at class.news.php

  1. <?php
  2. /**
  3.  * @package linea21.modules
  4.  * @subpackage news
  5.  * @author linea21 <info@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  *  News Management
  10.  */
  11.  
  12. class news {
  13.   /* @param
  14.    * */
  15.   public $TDB_NEWS = T_NEWS// nom de la table.
  16.   public $NB_TEMPLATE = 3// nombre de templates associés a la classe
  17.   public $URI_INPUT = "news/input/"// dossier racine de stockage des photos
  18.   public $URI_OUTPUT = "news/output/"// dossier racine de diffusion des archives
  19.   public $UPLOAD_MAX_MO = UPLOAD_MAX_MO// taille maximale d'upload des photos en octets
  20.   public $MAX_PHOTO_MAX_WIDTH = MAX_PHOTO_MAX_WIDTH;
  21.   public $MAX_PHOTO_MIN_WIDTH = MAX_PHOTO_MIN_WIDTH;
  22.   public $ID;
  23.   public $TITLE;
  24.   public $HEADER;
  25.   public $BODY;
  26.   public $THEME;
  27.   public $SCALE;
  28.   public $LEVEL;
  29.   public $TEMPLATE;
  30.   public $PHOTO_URI;
  31.   public $RANGE;
  32.   public $POSTED_BY;
  33.   public $POST_DATE;
  34.   public $PUBLISHED_DATE;
  35.   public $PEREMPT_DATE;
  36.   public $IS_NATIONAL;
  37.   public $STATUT;
  38.   protected $dispatcher = null;
  39.  
  40.  
  41.   public function __construct()
  42.   {
  43.     $this->dispatcher = $GLOBALS['dispatcher'];
  44.   }
  45.  
  46.   public function __call($method$arguments)
  47.   {
  48.     $event $this->dispatcher->notifyUntil(new sfEvent($this'news.extensible_function'array(
  49.       'method'    => $method,
  50.       'arguments' => $arguments
  51.     )));
  52.     if (!$event->isProcessed())
  53.     {
  54.       throw new Exception(sprintf('Call to undefined method %s::%s.'get_class($this)$method));
  55.     }
  56.  
  57.     return $event->getReturnValue();
  58.   }
  59.  
  60.  
  61.   /**
  62.    * news::_getDate()
  63.    * date courante et ajout
  64.    *
  65.    * @access private
  66.    * @param int $m chiffre des mois
  67.    * @param int $d chiffre des jours
  68.    * @param int $y chiffre des années
  69.    * @return string $format_date
  70.    * @return 
  71.    */
  72.   private function _getDate($m 0$d 0$y 0)
  73.   {
  74.     $format_date mktime(date("H")date("i")date("s")date("m"$mdate("d"date("Y")-1);
  75.     $format_date strftime('%Y-%m-%d %H:%M:%S'$format_date);
  76.  
  77.     return $format_date;
  78.   }
  79.  
  80.   /**
  81.    * news::GetTemplateName()
  82.    * Obtention de la dénomination du template
  83.    *
  84.    * @param integer $num 
  85.    * @return string $return
  86.    */
  87.   public function GetTemplateName($num)
  88.   {
  89.     if ($num == 1$return _t('news','template_1');
  90.     if ($num == 2$return _t('news','template_2');
  91.     if ($num == 3$return _t('news','template_3');
  92.     if ($num == 4$return _t('news','template_4');
  93.  
  94.     return $return;
  95.   }
  96.  
  97.   /**
  98.    * news::CheckDataIntegrity()
  99.    * Vérification intégrité des données
  100.    *
  101.    * @access public
  102.    * @param array $table : contient les composants Nécessaires d'une news
  103.    * @return boolean true
  104.    *  si verifié, sinon string 'message d'erreur'
  105.    */
  106.  
  107.   public function CheckDataIntegrity($table)
  108.   {
  109.     $event new sfEvent($this'news.before_data_check');
  110.     $this->dispatcher->filter($event$table);
  111.  
  112.     $table $event->getReturnValue();
  113.  
  114.  
  115.     if (strlen($table[0]3return _t('news','no_title');
  116.     if (strlen($table[1]3return _t('news','no_header');
  117.     if (strlen($table[2]3return _t('news','no_body');
  118.     if ($table[3<= || !is_numeric($table[3])) return _t('news','no_theme');
  119.     if ($table[4<= || !is_numeric($table[4])) return _t('news','no_scale');
  120.     if ($table[6<= || !is_numeric($table[6])) return _t('news','no_template');
  121.  
  122.     $event new sfEvent($this'news.after_data_check'array('data' => $table));
  123.     $this->dispatcher->notify($event);
  124.  
  125.     return true;
  126.   }
  127.  
  128.   /**
  129.    * news::AddNews()
  130.    * Ajout d'une news
  131.    *
  132.    * @access public
  133.    * @param array $table_news : contient les composants d'une news
  134.    * @param object $sql_object 
  135.    * @return integer $last_id
  136.    */
  137.   public function AddNews($table_news$sql_object)
  138.   {
  139.     $table_news=$sql_object->DBescape($table_news);
  140.  
  141.     if ($table_news[0!= ''{
  142.       $this->TITLE = strip_input(trim($table_news[0])true);
  143.     }
  144.     if ($table_news[1!= ''{
  145.       $this->HEADER = strip_input(trim($table_news[1])true);
  146.     }
  147.     if ($table_news[2!= ''{
  148.       $this->BODY = strip_input(trim($table_news[2])true);
  149.     }
  150.     if (is_numeric($table_news[3])) {
  151.       $this->THEME = $table_news[3];
  152.     }
  153.     if (is_numeric($table_news[4])) {
  154.       $this->SCALE = $table_news[4];
  155.     }
  156.     if (is_numeric($table_news[5])) {
  157.       if($table_news[5== -1$table_news[5]=0;
  158.       $this->LEVEL = $table_news[5];
  159.     }
  160.     if (is_numeric($table_news[6])) {
  161.       $this->TEMPLATE = $table_news[6];
  162.     }
  163.     if ($table_news[7!= ''{
  164.       $this->PHOTO_URI = $table_news[7];
  165.     }
  166.     if (is_numeric($table_news[8])) {
  167.       $this->RANGE = $table_news[8];
  168.     }
  169.     if (is_numeric($table_news[9])) {
  170.       $this->POSTED_BY = $table_news[9];
  171.     }
  172.     if ($table_news[11!= ''{
  173.       $this->IS_NATIONAL = strtoupper($table_news[11]);
  174.     }
  175.     if ($table_news[12!= ''{
  176.       $this->STATUT = strtoupper($table_news[12]);
  177.     }
  178.     if ($this->STATUT == 'P'{
  179.       $this->PUBLISHED_DATE = $this->_getDate();
  180.       if ($table_news[10!= ''{
  181.         $this->PEREMPT_DATE = $table_news[10];
  182.       else {
  183.         $this->PEREMPT_DATE = '0001-01-01';
  184.       }
  185.     else {
  186.       $this->PUBLISHED_DATE = '0001-01-01';
  187.       $this->PEREMPT_DATE = '0001-01-01';
  188.     }
  189.     $requete "INSERT INTO " $this->TDB_NEWS . " (news_title, news_header, news_body, news_theme, news_scale, " "news_level, news_template, news_photo_uri, news_range, news_posted_by, news_published_date, " "news_perempt_date, news_is_national, news_statut, news_date_crea) " "VALUES('" $this->TITLE . "', '" $this->HEADER . "', '" $this->BODY . "', " $this->THEME . ", " $this->SCALE . ", " $this->LEVEL . ", " $this->TEMPLATE . ", '" $this->PHOTO_URI . "', " $this->RANGE . ", " $this->POSTED_BY . ", '" $this->PUBLISHED_DATE . "' , '" $this->PEREMPT_DATE . "', '" $this->IS_NATIONAL . "', '" $this->STATUT . "', now());";
  190.  
  191.     $last_id $sql_object->DBInsert ($requete1);
  192.     return $last_id;
  193.   }
  194.  
  195.   /**
  196.    * news::DeleteNews()
  197.    * suppression d'une news
  198.    *
  199.    * @access public
  200.    * @param int $ID : identifiant de la news
  201.    * @param object $sql_object 
  202.    * @return bool $result
  203.    */
  204.  
  205.   public function DeleteNews($ID$sql_object)
  206.   {
  207.     $this->ID = $ID;
  208.     $requete "UPDATE  " $this->TDB_NEWS . " set news_statut='E', news_last_modify=NOW() WHERE news_id='" $this->ID . "';";
  209.     $result $sql_object->DBQuery($requete);
  210.     return $result;
  211.   }
  212.  
  213.   /**
  214.    * news::ModifyNews()
  215.    * modification d'une news
  216.    *
  217.    * @access public
  218.    * @param integer $ID : identifiant de la news
  219.    * @param object $sql_object 
  220.    * @param array $table_news : contient les composants d'une news
  221.    * @return boolean $result
  222.    */
  223.   public function ModifyNews($ID$table_news$sql_object)
  224.   {
  225.  
  226.     $table_news=$sql_object->DBescape($table_news);
  227.     if (is_numeric($ID)) {
  228.       $this->ID = $ID;
  229.     }
  230.     if ($table_news[0!= ''{
  231.       $this->TITLE = strip_input(trim($table_news[0])true);
  232.     }
  233.     if ($table_news[1!= ''{
  234.       $this->HEADER = strip_input(trim($table_news[1])true);
  235.     }
  236.     if ($table_news[2!= ''{
  237.       $this->BODY = strip_input(trim($table_news[2])true);
  238.     }
  239.     if (is_numeric($table_news[3])) {
  240.       $this->THEME = $table_news[3];
  241.     }
  242.     if (is_numeric($table_news[4])) {
  243.       $this->SCALE = $table_news[4];
  244.     }
  245.     if (is_numeric($table_news[5])) {
  246.       if($table_news[5== -1$table_news[5]=0;
  247.       $this->LEVEL = $table_news[5];
  248.     }
  249.     if (is_numeric($table_news[6])) {
  250.       $this->TEMPLATE = $table_news[6];
  251.     }
  252.     if ($table_news[7!= ''{
  253.       $this->PHOTO_URI = $table_news[7];
  254.     }
  255.     if ($table_news[8!= ''{
  256.       $this->STATUT = $table_news[8];
  257.     }
  258.  
  259.     $mask $this->_HavePublishedDate($table_news[9]);
  260.  
  261.     $requete "UPDATE  " $this->TDB_NEWS . " set news_title='" $this->TITLE . "', news_header='" $this->HEADER . "', news_body='" $this->BODY . "' , news_theme='" $this->THEME . "', news_scale='" $this->SCALE . "', news_level='" $this->LEVEL . "', news_template='" $this->TEMPLATE . "', news_photo_uri='" $this->PHOTO_URI . "', news_statut='" $this->STATUT . "', news_last_modify=NOW() " $mask " WHERE news_id='" $this->ID . "';";
  262.     $result $sql_object->DBQuery($requete);
  263.     return $result;
  264.   }
  265.  
  266.   /**
  267.    * news::_HavePublishedDate()
  268.    * Détermine la date de publication a inserer dans la bdd
  269.    *
  270.    * @access private
  271.    * @param string $current_status : statut actuel de l'actualité
  272.    * @return string $sql_mask
  273.    */
  274.   private function _HavePublishedDate($current_status)
  275.   {
  276.     switch ($this->STATUT{
  277.       case 'P':
  278.         if ($current_status == 'D'$sql_mask ", news_published_date= NOW()";
  279.         else $sql_mask '';
  280.         break;
  281.       case 'D':
  282.         $sql_mask ", news_published_date= '0001-01-01'";
  283.         break;
  284.       default:
  285.         $sql_mask '';
  286.     }
  287.     return $sql_mask;
  288.   }
  289. }
  290.  
  291. ?>

Documentation generated on Fri, 01 Apr 2011 09:28:48 +0200 by phpDocumentor 1.4.1