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

Source for file class.contents.php

Documentation is available at class.contents.php

  1. <?php
  2. /**
  3.  * @package linea21.modules
  4.  * @subpackage content
  5.  * @see workshop, publication
  6.  * @author linea21 <info@linea21.com>
  7.  * @version $id SVN
  8.  * @access public
  9.  * @license http://opensource.org/licenses/gpl-3.0.html
  10.  *  Content Management
  11.  */
  12.  
  13. class contents {
  14.   /* @param
  15.    * */
  16.   var $TDB_LIAISON = J_PARTS;
  17.   var $ACTIVE_TABLE;
  18.   var $ACTIVE_TYPE; // valeur 'P' || 'W'
  19.   var $WR_ID;
  20.   var $WR_TITLE;
  21.   var $WR_BODY;
  22.   var $WR_DATE_CREA;
  23.   var $WR_LAST_MODIFY;
  24.   var $WR_TABLE = T_WORK_REP_CONT;
  25.  
  26.   var $P_ID;
  27.   var $P_TITLE;
  28.   var $P_BODY;
  29.   var $P_DATE_CREA;
  30.   var $P_LAST_MODIFY;
  31.   var $P_TABLE = T_PUBLI_CONT;
  32.  
  33.   protected $dispatcher = null;
  34.  
  35.   public function __construct()
  36.   {
  37.     $this->dispatcher = $GLOBALS['dispatcher'];
  38.   }
  39.  
  40.   public function __call($method, $arguments)
  41.   {
  42.     $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'contents.extensible_function', array(
  43.       'method'    => $method,
  44.       'arguments' => $arguments
  45.     )));
  46.     if (!$event->isProcessed())
  47.     {
  48.       throw new Exception(sprintf('Call to undefined method %s::%s.', get_class($this), $method));
  49.     }
  50.  
  51.     return $event->getReturnValue();
  52.   }
  53.   /**
  54.    * contents::CheckDataIntegrity()
  55.    * vérifie l'integrité d'un partie avant Insertion
  56.    *
  57.    * @access public
  58.    * @param array $table contient les composants d'une partie
  59.    * @param string $type 'P', 'W'
  60.    * @return boolean true
  61.    *  si verifié, sinon string 'message d'erreur'
  62.    */
  63.   function CheckDataIntegrity($table, $type)
  64.   {
  65.       // Filter data event + return value
  66.       $r = $this->dispatcher->filter(new sfEvent($this, 'contents.before_datacheck', array('data' => $table)), $table);
  67.       $table = $r->getReturnValue();
  68.       
  69.     if (strlen($table[0]) < 2) return _t('contents','no_title');
  70.     if (strlen($table[1]) < 10) return _t('contents','no_body');
  71.     
  72.     // Notify the beginning of the current method
  73.     $this->dispatcher->notify(new sfEvent($this, 'contents.after_datacheck', array('data' => $table)));
  74.  
  75.     return true;
  76.   }
  77.  
  78.  
  79.   /**
  80.    * contents::_wichType()
  81.    * initialisation des tables SQL
  82.    *
  83.    * @access private
  84.    * @param string $type : type du CONTENU 'WORKSHOP' ou 'PUBLICATION'
  85.    * @return string -void
  86.    */
  87.   function _wichType($type)
  88.   {
  89.     switch ($type) {
  90.       case 'WORKSHOP':
  91.         $this->ACTIVE_TABLE = $this->WR_TABLE;
  92.         $this->ACTIVE_TYPE = 'W';
  93.         break;
  94.       case 'PUBLICATION':
  95.         $this->ACTIVE_TABLE = $this->P_TABLE;
  96.         $this->ACTIVE_TYPE = 'P';
  97.         break;
  98.       default:
  99.         return "error";
  100.     }
  101.   }
  102.  
  103.   /**
  104.    * contents::AddContents()
  105.    * ajout d'une partie de contenu
  106.    *
  107.    * @access public
  108.    * @param integer $ID identifiant du père (rattachement)
  109.    * @param array $contents_table tableau contenant les infos ressources
  110.    * @param string $type 'WORKSHOP' ou 'PUBLICATION'
  111.    * @param object $ 
  112.    * @return integer $last_id
  113.    */
  114.   function AddContents($ID, $contents_table, $type, $sql_object)
  115.   {
  116.       // Filter data event + return value
  117.       $r = $this->dispatcher->filter(new sfEvent($this, 'contents.before_add', array('data' => $contents_table, 'parentid' => $ID, 'type' => $type)), $contents_table);
  118.       $contents_table = $r->getReturnValue();
  119.       
  120.     $contents_table=$sql_object->DBescape($contents_table);
  121.     if ($this->_wichType($type) == "error") exit;
  122.     $q = "INSERT INTO " . $this->ACTIVE_TABLE ;
  123.     if ($type == "WORKSHOP") {
  124.       $this->WR_TITLE = strip_input($contents_table[0]);
  125.       $this->WR_BODY = strip_input($contents_table[1], true);
  126.       $q.= " (workrepcon_title, workrepcon_body, workrepcon_date_crea, workrepcon_last_modify, workrepcon_validity)";
  127.       $q .= " VALUES('" . $this->WR_TITLE . "', '" . $this->WR_BODY . "', NOW(),NOW(), 'Y');";
  128.     }
  129.     if ($type == "PUBLICATION") {
  130.       $this->P_TITLE = strip_input($contents_table[0]);
  131.       $this->P_BODY = strip_input($contents_table[1], true);
  132.       
  133.       $q.= " (publicon_title, publicon_body, publicon_date_crea, publicon_last_modify, publicon_validity)";
  134.       $q .= " VALUES('" . $this->P_TITLE . "', '" . $this->P_BODY . "', NOW(),NOW(), 'Y');";
  135.     }
  136.     $last_id = $sql_object->DBInsert ($q, 1);
  137.  
  138.     if (is_numeric($last_id)) {
  139.       $q = "INSERT INTO " . $this->TDB_LIAISON . " VALUES(" . $ID . "," . $last_id . ", '" . $this->ACTIVE_TYPE . "');";
  140.       $result = $sql_object->DBInsert ($q);
  141.     }
  142.     
  143.     // Notify the end of the current method
  144.     $this->dispatcher->notify(new sfEvent($this, 'contents.after_add', array('data' => $contents_table, 'id' => $last_id, 'parentid' => $ID, 'type' => $type)));
  145.     
  146.     return $result;
  147.   }
  148.  
  149.   /**
  150.    * contents::ModifyContents()
  151.    * modification d'une partie de contenu
  152.    *
  153.    * @access public
  154.    * @param integer $ID : identifiant de la partie à modifier
  155.    * @param array $contents_table : tableau contenant les infos ressources
  156.    * @param string $type 'WORKSHOP' ou 'PUBLICATION'
  157.    * @param object $sql_object 
  158.    * @return boolean $result
  159.    */
  160.   function ModifyContents($ID, $contents_table, $type, $sql_object)
  161.   {
  162.       // Filter data event + return value
  163.       $r = $this->dispatcher->filter(new sfEvent($this, 'contents.before_modify', array('data' => $contents_table, 'id' => $ID, 'type' => $type)), $contents_table);
  164.       $contents_table = $r->getReturnValue();
  165.       
  166.     $contents_table=$sql_object->DBescape($contents_table);
  167.     if ($this->_wichType($type) == "error") exit;
  168.     if (!is_numeric($ID)) return false;
  169.     if ($type == "WORKSHOP") $this->WR_ID = $ID;
  170.     if ($type == "PUBLICATION") $this->P_ID = $ID;
  171.  
  172.     $q = "UPDATE " . $this->ACTIVE_TABLE . " SET ";
  173.     if ($type == "WORKSHOP") {
  174.       $this->WR_TITLE = strip_input($contents_table[0]);
  175.       $this->WR_BODY = strip_input($contents_table[1], true);
  176.       $q .= "workrepcon_title='" . $this->WR_TITLE . "', workrepcon_body='" . $this->WR_BODY . "', workrepcon_last_modify=NOW() WHERE workrepcon_id='" . $this->WR_ID . "';";
  177.     }
  178.     if ($type == "PUBLICATION") {
  179.       $this->P_TITLE = strip_input($contents_table[0]);
  180.       $this->P_BODY = strip_input($contents_table[1], true);
  181.  
  182.       $q .= "publicon_title='" . $this->P_TITLE . "', publicon_body='" . $this->P_BODY . "', publicon_last_modify=NOW() WHERE publicon_id='" . $this->P_ID . "';";
  183.     }
  184.     $result = $sql_object->DBQuery($q);
  185.     
  186.     // Notify the end of the current method
  187.     $this->dispatcher->notify(new sfEvent($this, 'contents.after_modify', array('data' => $contents_table, 'id' => $this->ID, 'type' => $type)));
  188.  
  189.     return $result;
  190.   }
  191.  
  192.   /**
  193.    * contents::changeRanges()
  194.    * changes contents range
  195.    *
  196.    * @access public
  197.    * @param array : Id (key) and ranges (value)
  198.    * @param object $sql_object 
  199.    * @return bool $result
  200.    */
  201.  
  202.   function changeRanges($array, $sql_object, $element)
  203.   {
  204.  
  205.     switch ($element) {
  206.       case "publication":
  207.         $table = $this->P_TABLE;
  208.         $field_id = 'publicon_id';
  209.         $field_range = 'publicon_range';
  210.         break;
  211.       case "workshop":
  212.         $table = $this->WR_TABLE;
  213.         $field_id = 'workrepcon_id';
  214.         $field_range = 'workrepcon_range';
  215.         break;
  216.     }
  217.     foreach ($array as $key => $value) {
  218.       $query = "UPDATE " . $table . " set ".$field_range." ='".$value."' WHERE ".$field_id." ='" . $key . "';";
  219.       $result = $sql_object->DBQuery($query);
  220.     }
  221.     
  222.     // Notify the beginning of the current method
  223.     $this->dispatcher->notify(new sfEvent($this, 'contents.change_ranges', array('data' => $array)));
  224.  
  225.     return $result;
  226.   }
  227.  
  228.   /**
  229.    * contents::DeleteContents()
  230.    * suppression d'une partie
  231.    *
  232.    * @access public
  233.    * @param integer $ID : identifiant du contents a supprimer
  234.    * @param string $type :  'WORKSHOP' ou 'PUBLICATION'
  235.    * @param object $sql_object 
  236.    * @return boolean $result
  237.    */
  238.   function DeleteContents($ID, $type, $sql_object)
  239.   {
  240.       // Notify the end of the current method
  241.       $this->dispatcher->notify(new sfEvent($this, 'contents.delete', array('id' => $ID, 'type' => $type)));
  242.       
  243.     if (is_numeric($ID)) {
  244.       if ($type == "WORKSHOP") {
  245.         $champ1 = "workrepcon_id";
  246.         $champ2 = "jwp_contents_id";
  247.         $champ3 = "workrepcon_validity";
  248.         $champ4 = "workrepcon_last_modify";
  249.       }
  250.       if ($type == "PUBLICATION") {
  251.         $champ1 = "publicon_id";
  252.         $champ2 = "jpp_contents_id";
  253.         $champ3 = "publicon_validity";
  254.         $champ4 = "publicon_last_modify";
  255.       }
  256.     } else return false;
  257.     if ($this->_wichType($type) == "error") return false;
  258.     $q = "UPDATE " . $this->ACTIVE_TABLE . " SET " . $champ3 . "='N', ".$champ4."=NOW()  WHERE " . $champ1 . "='" . $ID . "';";
  259.     $result = $sql_object->DBQuery($q);
  260.  
  261.     return $result;
  262.   }
  263. }
  264.  
  265. ?>

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