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

Source for file class.page.php

Documentation is available at class.page.php

  1. <?php
  2. /**
  3.  * @package linea21.modules
  4.  * @subpackage page
  5.  * @author Simon Georget <simon@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  *  Page Management
  10.  */
  11.  
  12. class page {
  13.   /* @param
  14.    * */
  15.   public $TDB_PAGE = T_PAGE// nom de la table.
  16.   public $ID;
  17.   public $TITLE;
  18.   public $HEADER;
  19.   public $BODY;
  20.   public $POSTED_BY;
  21.   public $POST_DATE;
  22.   public $PUBLISHED_DATE;
  23.   public $STATUS;
  24.   protected $dispatcher = null;
  25.  
  26.  
  27.   public function __construct()
  28.   {
  29.     $this->dispatcher = $GLOBALS['dispatcher'];
  30.   }
  31.  
  32.   public function __call($method$arguments)
  33.   {
  34.     $event $this->dispatcher->notifyUntil(new sfEvent($this'page.extensible_function'array(
  35.       'method'    => $method,
  36.       'arguments' => $arguments
  37.     )));
  38.     if (!$event->isProcessed())
  39.     {
  40.       throw new Exception(sprintf('Call to undefined method %s::%s.'get_class($this)$method));
  41.     }
  42.  
  43.     return $event->getReturnValue();
  44.   }
  45.  
  46.  
  47.   /**
  48.    * _getDate()
  49.    * date courante et ajout
  50.    *
  51.    * @access private
  52.    * @param int $m chiffre des mois
  53.    * @param int $d chiffre des jours
  54.    * @param int $y chiffre des années
  55.    * @return string $format_date
  56.    * @return 
  57.    */
  58.   private function _getDate($m 0$d 0$y 0)
  59.   {
  60.     $format_date mktime(date("H")date("i")date("s")date("m"$mdate("d"date("Y")-1);
  61.     $format_date strftime('%Y-%m-%d %H:%M:%S'$format_date);
  62.  
  63.     return $format_date;
  64.   }
  65.  
  66.  
  67.   /**
  68.    * checkDataIntegrity()
  69.    * Vérification intégrité des données
  70.    *
  71.    * @access public
  72.    * @param array $array : contient les composants nécessaires d'une page
  73.    * @return boolean true
  74.    *  si verifié, sinon string 'message d'erreur'
  75.    */
  76.  
  77.   public function checkDataIntegrity($array)
  78.   {
  79.       
  80.       // Filter data event + return value
  81.       $r $this->dispatcher->filter(new sfEvent($this'page.before_datacheck'array('data' => $array))$array);
  82.       $array $r->getReturnValue();
  83.  
  84.     if (strlen($array[0]3return _t('page','no_title');
  85.     if (strlen($array[1]3return _t('page','no_header');
  86.     if (strlen($array[2]3return _t('page','no_body');
  87.  
  88.     // Notify the beginning of the current method
  89.       $this->dispatcher->notify(new sfEvent($this'page.after_datacheck'array('data' => $array)));
  90.  
  91.     return true;
  92.   }
  93.  
  94.   /**
  95.    * addPage()
  96.    * Ajout d'une page
  97.    *
  98.    * @access public
  99.    * @param array $array : contient les composants d'une page
  100.    * @param object $sql_object 
  101.    * @return integer $last_id
  102.    */
  103.   public function addPage($array$sql_object)
  104.   {
  105.       
  106.       // Filter data event + return value
  107.       $r $this->dispatcher->filter(new sfEvent($this'page.before_add'array('data' => $array))$array);
  108.       $array $r->getReturnValue();
  109.       
  110.     $array=$sql_object->DBescape($array);
  111.  
  112.     if ($array[0!= ''{
  113.       $this->TITLE = strip_input(trim($array[0])true);
  114.     }
  115.     if ($array[1!= ''{
  116.       $this->HEADER = strip_input(trim($array[1])true);
  117.     }
  118.     if ($array[2!= ''{
  119.       $this->BODY = strip_input(trim($array[2])true);
  120.     }
  121.     if (is_numeric($array[3])) {
  122.       $this->POSTED_BY = $array[3];
  123.     }
  124.     if ($array[4!= ''{
  125.       $this->STATUS = strtoupper($array[4]);
  126.     }
  127.     if ($this->STATUS == 'P'{
  128.       $this->PUBLISHED_DATE = $this->_getDate();
  129.     else {
  130.       $this->PUBLISHED_DATE = '0001-01-01';
  131.     }
  132.     $q "INSERT INTO " $this->TDB_PAGE . " (page_title, page_header, page_body, page_posted_by, page_published_date, page_status, page_date_crea) " "VALUES('" $this->TITLE . "', '" $this->HEADER . "', '" $this->BODY . "', " $this->POSTED_BY . ", '" $this->PUBLISHED_DATE . "', '" $this->STATUS . "', now());";
  133.  
  134.     $last_id $sql_object->DBInsert ($q1);
  135.     
  136.     // Notify the end of the current method
  137.     $this->dispatcher->notify(new sfEvent($this'page.after_add'array('data' => $array'id' => $last_id)));
  138.     
  139.     return $last_id;
  140.   }
  141.  
  142.   /**
  143.    * deletePage()
  144.    * suppression d'une page
  145.    *
  146.    * @access public
  147.    * @param int $ID : identifiant de la page
  148.    * @param object $sql_object 
  149.    * @return bool $result
  150.    */
  151.  
  152.   public function deletePage($ID$sql_object)
  153.   {
  154.       // Notify the beginning of the current method
  155.       $this->dispatcher->notify(new sfEvent($this'page.delete'array('id' => $ID)));
  156.       
  157.     $this->ID = $ID;
  158.     $q "UPDATE  " $this->TDB_PAGE . " set page_status='E', page_last_modify=NOW() WHERE page_id='" $this->ID . "';";
  159.     $result $sql_object->DBQuery($q);
  160.     return $result;
  161.   }
  162.  
  163.   /**
  164.    * modifyPage()
  165.    * modification d'une page
  166.    *
  167.    * @access public
  168.    * @param integer $ID : identifiant de la page
  169.    * @param object $sql_object 
  170.    * @param array $array : contient les composants d'une page
  171.    * @return boolean $result
  172.    */
  173.   public function modifyPage($ID$array$sql_object)
  174.   {
  175.  
  176.       // Filter data event + return value
  177.       $r $this->dispatcher->filter(new sfEvent($this'page.before_modify'array('data' => $array'id' => $ID))$array);
  178.       $array $r->getReturnValue();
  179.       
  180.     $array=$sql_object->DBescape($array);
  181.     if (is_numeric($ID)) {
  182.       $this->ID = $ID;
  183.     }
  184.     if ($array[0!= ''{
  185.       $this->TITLE = strip_input(trim($array[0])true);
  186.     }
  187.     if ($array[1!= ''{
  188.       $this->HEADER = strip_input(trim($array[1])true);
  189.     }
  190.     if ($array[2!= ''{
  191.       $this->BODY = strip_input(trim($array[2])true);
  192.     }
  193.     if (is_numeric($array[3])) {
  194.       $this->POSTED_BY = $array[3];
  195.     }
  196.     if ($array[4!= ''{
  197.       $this->STATUS = $array[4];
  198.     }
  199.  
  200.     $mask $this->_HavePublishedDate($array[5]);
  201.  
  202.     $q "UPDATE  " $this->TDB_PAGE . " set page_title='" $this->TITLE . "', page_header='" $this->HEADER . "', page_body='" $this->BODY . "' , page_posted_by=" $this->POSTED_BY . ", page_status ='" $this->STATUS . "', page_last_modify=NOW() " $mask " WHERE page_id='" $this->ID . "';";
  203.     $result $sql_object->DBQuery($q);
  204.     
  205.     // Notify the end of the current method
  206.     $this->dispatcher->notify(new sfEvent($this'page.after_modify'array('data' => $array'id' => $this->ID)));
  207.     
  208.     return $result;
  209.   }
  210.   
  211.  
  212.   /**
  213.    * _havePublishedDate()
  214.    * Détermine la date de publication a inserer dans la bdd
  215.    *
  216.    * @access private
  217.    * @param string $current_status : statut actuel de l'actualité
  218.    * @return string $sql_mask
  219.    */
  220.   private function _havePublishedDate($current_status)
  221.   {
  222.     switch ($this->STATUS{
  223.       case 'P':
  224.         if ($current_status == 'D'$sql_mask ", page_published_date= NOW()";
  225.         else $sql_mask '';
  226.         break;
  227.       case 'D':
  228.         $sql_mask ", page_published_date= '0001-01-01'";
  229.         break;
  230.       default:
  231.         $sql_mask '';
  232.     }
  233.     return $sql_mask;
  234.   }
  235. }
  236.  
  237. ?>

Documentation generated on Mon, 08 Apr 2013 18:12:32 +0200 by phpDocumentor 1.4.1