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

Documentation generated on Thu, 20 Mar 2014 16:46:15 +0100 by phpDocumentor 1.4.1