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 $IS_HOMEPAGE;
  21.   public $POSTED_BY;
  22.   public $POST_DATE;
  23.   public $PUBLISHED_DATE;
  24.   public $STATUS;
  25.   protected $dispatcher = null;
  26.  
  27.  
  28.   public function __construct()
  29.   {
  30.     $this->dispatcher = $GLOBALS['dispatcher'];
  31.   }
  32.  
  33.   public function __call($method$arguments)
  34.   {
  35.     $event $this->dispatcher->notifyUntil(new sfEvent($this'page.extensible_function'array(
  36.       'method'    => $method,
  37.       'arguments' => $arguments
  38.     )));
  39.     if (!$event->isProcessed())
  40.     {
  41.       throw new Exception(sprintf('Call to undefined method %s::%s.'get_class($this)$method));
  42.     }
  43.  
  44.     return $event->getReturnValue();
  45.   }
  46.  
  47.  
  48.   /**
  49.    * _getDate()
  50.    * date courante et ajout
  51.    *
  52.    * @access private
  53.    * @param int $m chiffre des mois
  54.    * @param int $d chiffre des jours
  55.    * @param int $y chiffre des années
  56.    * @return string $format_date
  57.    * @return 
  58.    */
  59.   private function _getDate($m 0$d 0$y 0)
  60.   {
  61.     $format_date mktime(date("H")date("i")date("s")date("m"$mdate("d"date("Y")-1);
  62.     $format_date strftime('%Y-%m-%d %H:%M:%S'$format_date);
  63.  
  64.     return $format_date;
  65.   }
  66.  
  67.  
  68.   /**
  69.    * checkDataIntegrity()
  70.    * Vérification intégrité des données
  71.    *
  72.    * @access public
  73.    * @param array $array : contient les composants nécessaires d'une page
  74.    * @return boolean true
  75.    *  si verifié, sinon string 'message d'erreur'
  76.    */
  77.  
  78.   public function checkDataIntegrity($array)
  79.   {
  80.       
  81.       // Filter data event + return value
  82.       $r $this->dispatcher->filter(new sfEvent($this'page.before_datacheck'array('data' => $array))$array);
  83.       $array $r->getReturnValue();
  84.  
  85.     if (strlen($array[0]3return _t('page','no_title');
  86.     if (strlen($array[1]3return _t('page','no_header');
  87.     if (strlen($array[2]3return _t('page','no_body');
  88.  
  89.     // Notify the beginning of the current method
  90.       $this->dispatcher->notify(new sfEvent($this'page.after_datacheck'array('data' => $array)));
  91.  
  92.     return true;
  93.   }
  94.  
  95.   /**
  96.    * addPage()
  97.    * Ajout d'une page
  98.    *
  99.    * @access public
  100.    * @param array $array : contient les composants d'une page
  101.    * @param object $sql_object 
  102.    * @return integer $last_id
  103.    */
  104.   public function addPage($array$sql_object)
  105.   {
  106.       
  107.       // Filter data event + return value
  108.       $r $this->dispatcher->filter(new sfEvent($this'page.before_add'array('data' => $array))$array);
  109.       $array $r->getReturnValue();
  110.       
  111.     $array=$sql_object->DBescape($array);
  112.  
  113.     if ($array[0!= ''{
  114.       $this->TITLE = strip_input(trim($array[0])true);
  115.     }
  116.     if ($array[1!= ''{
  117.       $this->HEADER = strip_input(trim($array[1])true);
  118.     }
  119.     if ($array[2!= ''{
  120.       $this->BODY = strip_input(trim($array[2])true);
  121.     }
  122.     if (is_numeric($array[3])) {
  123.       $this->POSTED_BY = $array[3];
  124.     }
  125.     if ($array[4!= ''{
  126.       $this->STATUS = strtoupper($array[4]);
  127.     }
  128.     if ($array[5!= ''{
  129.         $this->IS_HOMEPAGE = $array[5];
  130.     }
  131.     if ($this->STATUS == 'P'{
  132.       $this->PUBLISHED_DATE = $this->_getDate();
  133.     else {
  134.       $this->PUBLISHED_DATE = '0001-01-01';
  135.     }
  136.     $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());";
  137.  
  138.     $last_id $sql_object->DBInsert ($q1);
  139.     
  140.     $this->ID = $last_id;
  141.     
  142.     $this->updateHomePage($sql_object);
  143.     
  144.     // Notify the end of the current method
  145.     $this->dispatcher->notify(new sfEvent($this'page.after_add'array('data' => $array'id' => $last_id)));
  146.     
  147.     return $last_id;
  148.   }
  149.   
  150.   /**
  151.    * updateHomePage()
  152.    * Met à jour la homepage
  153.    *
  154.    * @return boolean true
  155.    */
  156.   
  157.   public function updateHomePage($sql_object)
  158.   {
  159.        
  160.       // Filter data event + return value
  161.       $r $this->dispatcher->filter(new sfEvent($this'page.before_homepage_update'array('id' => $this->ID ))$array);
  162.       $array $r->getReturnValue();
  163.        
  164.        
  165.       if($this->IS_HOMEPAGE == false)  {
  166.  
  167.           // we update only the current record without modifying others
  168.           $q "UPDATE " $this->TDB_PAGE . " SET page_homepage = 'N' WHERE page_id = '" $this->ID . "' ";
  169.           $sql_object->DBQuery($q);
  170.  
  171.       }
  172.        
  173.       if($this->IS_HOMEPAGE == true)  {
  174.            
  175.           // first, we remove the current homepage
  176.           $q "UPDATE " $this->TDB_PAGE . " SET page_homepage = 'N'";
  177.           $r $sql_object->DBQuery($q);
  178.  
  179.           // and we set the new homepage with given ID
  180.           if($r{
  181.               $q "UPDATE " $this->TDB_PAGE . " SET page_homepage = 'Y' WHERE page_id = '" $this->ID . "' ";
  182.               $sql_object->DBQuery($q);
  183.           }
  184.       }
  185.  
  186.       // Notify the beginning of the current method
  187.       $this->dispatcher->notify(new sfEvent($this'page.after_homepage_update'array('id' => $this->ID )));
  188.  
  189.       return true;
  190.   }
  191.   
  192.  
  193.   /**
  194.    * deletePage()
  195.    * suppression d'une page
  196.    *
  197.    * @access public
  198.    * @param int $ID : identifiant de la page
  199.    * @param object $sql_object 
  200.    * @return bool $result
  201.    */
  202.  
  203.   public function deletePage($ID$sql_object)
  204.   {
  205.       // Notify the beginning of the current method
  206.       $this->dispatcher->notify(new sfEvent($this'page.delete'array('id' => $ID)));
  207.       
  208.     $this->ID = $ID;
  209.     $q "UPDATE  " $this->TDB_PAGE . " set page_status='E', page_last_modify=NOW() WHERE page_id='" $this->ID . "';";
  210.     $result $sql_object->DBQuery($q);
  211.     return $result;
  212.   }
  213.  
  214.   /**
  215.    * modifyPage()
  216.    * modification d'une page
  217.    *
  218.    * @access public
  219.    * @param integer $ID : identifiant de la page
  220.    * @param object $sql_object 
  221.    * @param array $array : contient les composants d'une page
  222.    * @return boolean $result
  223.    */
  224.   public function modifyPage($ID$array$sql_object)
  225.   {
  226.  
  227.       // Filter data event + return value
  228.       $r $this->dispatcher->filter(new sfEvent($this'page.before_modify'array('data' => $array'id' => $ID))$array);
  229.       $array $r->getReturnValue();
  230.       
  231.     $array=$sql_object->DBescape($array);
  232.     if (is_numeric($ID)) {
  233.       $this->ID = $ID;
  234.     }
  235.     if ($array[0!= ''{
  236.       $this->TITLE = strip_input(trim($array[0])true);
  237.     }
  238.     if ($array[1!= ''{
  239.       $this->HEADER = strip_input(trim($array[1])true);
  240.     }
  241.     if ($array[2!= ''{
  242.       $this->BODY = strip_input(trim($array[2])true);
  243.     }
  244.     if (is_numeric($array[3])) {
  245.       $this->POSTED_BY = $array[3];
  246.     }
  247.     if ($array[4!= ''{
  248.       $this->STATUS = $array[4];
  249.     }
  250.  
  251.     $mask $this->_HavePublishedDate($array[5]);
  252.     
  253.     if ($array[6!= ''{
  254.         $this->IS_HOMEPAGE = $array[6];
  255.     }
  256.  
  257.     $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 . "';";
  258.     $result $sql_object->DBQuery($q);
  259.     
  260.     // we update the homepage
  261.     $this->updateHomePage($sql_object);
  262.     
  263.     // Notify the end of the current method
  264.     $this->dispatcher->notify(new sfEvent($this'page.after_modify'array('data' => $array'id' => $this->ID)));
  265.     
  266.     return $result;
  267.   }
  268.   
  269.   
  270.   /**
  271.    * homepage_exists()
  272.    * check if homepage exists
  273.    *
  274.    * @access public
  275.    * @return bool 
  276.    */
  277.   
  278.   public function homepage_exists()
  279.   {
  280.       global $sql_object;
  281.       
  282.       // Notify the beginning of the current method
  283.       $this->dispatcher->notify(new sfEvent($this'page.homepage_exists'));
  284.        
  285.  
  286.       $q "SELECT * FROM  " $this->TDB_PAGE . " WHERE page_homepage = 'Y' AND page_status='P';";
  287.       $r $sql_object->DBSelect($q);
  288.  
  289.       if(isset($r[0])) 
  290.           return true;
  291.       else {
  292.           return false;
  293.       }
  294.       
  295.   }
  296.   
  297.   /**
  298.    * get_homepage_id()
  299.    * return homepage_id
  300.    *
  301.    * @access public
  302.    * @return int $ID : identifiant de la page
  303.    */
  304.   
  305.   public function get_homepage_id()
  306.   {
  307.       global $sql_object;
  308.   
  309.       $q "SELECT * FROM  " $this->TDB_PAGE . " WHERE page_homepage = 'Y' AND page_status='P';";
  310.       $r $sql_object->DBSelect($q);
  311.       
  312.       if(isset($r[0])) return $r[0]['page_id'];
  313.  
  314.       return false;      
  315.   }
  316.   
  317.  
  318.   /**
  319.    * _havePublishedDate()
  320.    * Détermine la date de publication a inserer dans la bdd
  321.    *
  322.    * @access private
  323.    * @param string $current_status : statut actuel de l'actualité
  324.    * @return string $sql_mask
  325.    */
  326.   private function _havePublishedDate($current_status)
  327.   {
  328.     switch ($this->STATUS{
  329.       case 'P':
  330.         if ($current_status == 'D'$sql_mask ", page_published_date= NOW()";
  331.         else $sql_mask '';
  332.         break;
  333.       case 'D':
  334.         $sql_mask ", page_published_date= '0001-01-01'";
  335.         break;
  336.       default:
  337.         $sql_mask '';
  338.     }
  339.     return $sql_mask;
  340.   }
  341. }
  342.  
  343. ?>

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