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

Source for file class.workshop_com.php

Documentation is available at class.workshop_com.php

  1. <?php
  2. /**
  3.  * @package linea21.modules
  4.  * @subpackage workshop
  5.  * @see workshop
  6.  * @author linea21 <info@linea21.com>
  7.  * @version $id SVN
  8.  * @access public
  9.  * @license http://opensource.org/licenses/gpl-3.0.html
  10.  *  Workgroup Forum Management
  11.  */
  12.  
  13. class workshop_com {
  14.   /* @param
  15.    * */
  16.  
  17.   var $TDB_COM = T_WORK_COM; // nom de la table.
  18.   var $ID;
  19.   var $SUBJECT;
  20.   var $BODY;
  21.   var $PARENT;
  22.   var $USER_ID;
  23.   var $WORKSHOP_ID;
  24.   var $DATE_CREA;
  25.   var $LAST_MODIFY;
  26.   var $STATUT;
  27.   protected $dispatcher = null;
  28.  
  29.   public function __construct()
  30.   {
  31.     $this->dispatcher = $GLOBALS['dispatcher'];
  32.   }
  33.  
  34.   public function __call($method, $arguments)
  35.   {
  36.     $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'workshop_com.extensible_function', array(
  37.       'method'    => $method,
  38.       'arguments' => $arguments
  39.     )));
  40.     if (!$event->isProcessed())
  41.     {
  42.       throw new Exception(sprintf('Call to undefined method %s::%s.', get_class($this), $method));
  43.     }
  44.  
  45.     return $event->getReturnValue();
  46.   }
  47.  
  48.   /**
  49.    * workshop_com::CheckDataIntegrity()
  50.    * Vérification intégrité des données
  51.    *
  52.    * @access public
  53.    * @param array $table contient les composants d'une discussion
  54.    * @return boolean true
  55.    *  si verifié, sinon string 'message d'erreur'
  56.    */
  57.   function CheckDataIntegrity($table, $sql_object)
  58.   {
  59.     if (strlen($table[0]) < 3) return _t('workshop','com_no_subject');
  60.     if (strlen($table[1]) < 10) return _t('workshop','com_no_body');
  61.     return true;
  62.   }
  63.  
  64.   /**
  65.    * workshop_com::AddCom()
  66.    * Ajout d'une nouvelle discussion
  67.    *
  68.    * @access public
  69.    * @param array $table_com : contient les composants d'une discussion
  70.    * @param object $sql_object 
  71.    * @return integer $last_id
  72.    */
  73.   function AddCom($table_com, $sql_object)
  74.   {
  75.     $table_com=$sql_object->DBescape($table_com);
  76.  
  77.     $this->SUBJECT = strip_input(trim($table_com[0]));
  78.     $this->BODY = strip_input(trim($table_com[1]), '<a><img><sup><sub><span><br>');
  79.     $this->BODY = str_replace('<br>', '<br />', $this->BODY); // necessary for nicEdit
  80.     
  81.     if ($table_com[2] != '') {
  82.       $this->PARENT_ID = $table_com[2];
  83.     } else $this->PARENT_ID = 0;
  84.     $this->USER_ID = $table_com[3];
  85.     $this->WORKSHOP_ID = $table_com[4];
  86.     $this->STATUT = "P";
  87.  
  88.     if ($this->PARENT_ID == 0) {
  89.       $requete = "INSERT INTO " . $this->TDB_COM . " (workcom_subject, workcom_body, workcom_parent, workcom_user_id, workcom_workshop_id, workcom_statut, workcom_date_crea, workcom_last_modify ) " . "VALUES('" . $this->SUBJECT . "', '" . $this->BODY . "', " . $this->PARENT_ID . ", " . $this->USER_ID . ", " . $this->WORKSHOP_ID . ", '" . $this->STATUT . "', NOW(), NOW());";
  90.       $last_id = $sql_object->DBInsert ($requete, 1);
  91.     } else {
  92.       $requete_root = "UPDATE  " . $this->TDB_COM . " SET workcom_last_modify=NOW() WHERE workcom_id=" . $this->PARENT_ID . ";";
  93.       $result_root = $sql_object->DBQuery($requete_root);
  94.       $requete = "INSERT INTO " . $this->TDB_COM . " (workcom_subject, workcom_body, workcom_parent, workcom_user_id, workcom_workshop_id, workcom_statut, workcom_date_crea, workcom_last_modify ) " . "VALUES('" . $this->SUBJECT . "', '" . $this->BODY . "', " . $this->PARENT_ID . ", " . $this->USER_ID . ", " . $this->WORKSHOP_ID . ", '" . $this->STATUT . "', NOW(), NOW());";
  95.       $last_id = $sql_object->DBInsert ($requete, 1);
  96.     }
  97.     return $last_id;
  98.   }
  99.  
  100.   /**
  101.    * workshop_com::DeleteCom()
  102.    * suppression d'un message
  103.    *
  104.    * @access public
  105.    * @param int $com_id identifiant du message
  106.    * @param int $parent_id identifiant du parent
  107.    * @param object $sql_object 
  108.    * @return bool $result
  109.    */
  110.   function DeleteCom($ID, $com_id, $parent_id, $sql_object)
  111.   {
  112.     if (is_numeric($ID)) {
  113.       $this->ID = $ID;
  114.     } else return false;
  115.  
  116.     if ($parent_id == 0) {
  117.       $requete_son = "SELECT workcom_id FROM " . $this->TDB_COM . " WHERE workcom_statut <> 'E' AND workcom_parent=$com_id  AND workcom_workshop_id=$ID";
  118.       echo $requete_son;
  119.       $result_son = $sql_object->DBSelect($requete_son);
  120.  
  121.       if ($result_son <> 0) {
  122.         $requete = "UPDATE " . $this->TDB_COM . " SET workcom_statut='E' WHERE workcom_id=$com_id;";
  123.         $result = $sql_object->DBQuery ($requete);
  124.         for($i = 0; $i < count($result_son); $i++) {
  125.           $requete_son_e = "UPDATE " . $this->TDB_COM . " SET workcom_statut='E' WHERE workcom_id=" . $result_son[$i]['workcom_id'] . ";";
  126.           $result_son_e = $sql_object->DBQuery ($requete_son_e);
  127.         }
  128.         return $result;
  129.       } else {
  130.         $requete = "UPDATE " . $this->TDB_COM . " SET workcom_statut='E' WHERE workcom_id=$com_id;";
  131.         $result = $sql_object->DBQuery ($requete);
  132.         return $result;
  133.       }
  134.     } else {
  135.       $requete = "UPDATE " . $this->TDB_COM . " SET workcom_statut='E' WHERE workcom_id=$com_id;";
  136.       $result = $sql_object->DBQuery ($requete);
  137.       return $result;
  138.     }
  139.   }
  140.  
  141.   /**
  142.    * workshop_com::LockCom()
  143.    * vérouillage d'un message
  144.    *
  145.    * @access public
  146.    * @param int $ID identifiant du workshop
  147.    * @param int $com_id identifiant du message
  148.    * @param int $parent_id identifiant du message parent
  149.    * @param int $lock 
  150.    * @param object $sql_object 
  151.    * @return bool $result
  152.    */
  153.   function LockCom($ID, $com_id, $parent_id, $lock, $sql_object)
  154.   {
  155.     if ($lock == 0) $statut = 'C';
  156.     else $statut = 'P';
  157.  
  158.     if (is_numeric($ID)) {
  159.       $this->ID = $ID;
  160.     } else return false;
  161.  
  162.     if ($parent_id == 0) {
  163.       $requete_son = "SELECT workcom_id FROM " . $this->TDB_COM . " WHERE workcom_statut <> 'E' AND workcom_parent=$com_id  AND workcom_workshop_id=$ID";
  164.       $result_son = $sql_object->DBSelect($requete_son);
  165.  
  166.       if ($result_son <> 0) {
  167.         $requete = "UPDATE " . $this->TDB_COM . " SET workcom_statut='" . $statut . "' WHERE workcom_id=$com_id;";
  168.         $result = $sql_object->DBQuery ($requete);
  169.         for($i = 0; $i < count($result_son); $i++) {
  170.           $requete_son_e = "UPDATE " . $this->TDB_COM . " SET workcom_statut='" . $statut . "' WHERE workcom_id=" . $result_son[$i]['workcom_id'] . ";";
  171.           $result_son_e = $sql_object->DBQuery ($requete_son_e);
  172.         }
  173.         return $result;
  174.       } else {
  175.         $requete = "UPDATE " . $this->TDB_COM . " SET workcom_statut='" . $statut . "' WHERE workcom_id=$com_id;";
  176.         $result = $sql_object->DBQuery ($requete);
  177.         return $result;
  178.       }
  179.     } else {
  180.       $requete = "UPDATE " . $this->TDB_COM . " SET workcom_statut='" . $statut . "' WHERE workcom_id=$com_id;";
  181.       $result = $sql_object->DBQuery ($requete);
  182.       return $result;
  183.     }
  184.   }
  185.  
  186.   /**
  187.    * workshop_com::ModifyCom()
  188.    * modification d'un message
  189.    *
  190.    * @access public
  191.    * @param int $ID identifiant du message
  192.    * @param array $table_com contient les composants d'un message
  193.    * @param object $sql_object 
  194.    * @return bool $result
  195.    */
  196.   function ModifyCom($ID, $table_com, $sql_object)
  197.   {
  198.     $table_com=$sql_object->DBescape($table_com);
  199.  
  200.     if ($table_com[0] != '') {
  201.       $this->SUBJECT = strip_input(trim($table_com[0]));
  202.     }
  203.     if ($table_com[1] != '') {
  204.       $this->BODY = strip_input(trim($table_com[1]), '<a><img><sup><sub><span>');
  205.       $this->BODY = str_replace('<br>', '<br />', $this->BODY); // necessary for nicEdit
  206.     }
  207.  
  208.     $requete = "UPDATE  " . $this->TDB_COM . " SET workcom_subject='" . $this->SUBJECT . "', workcom_body='" . $this->BODY . "' , workcom_last_modify=NOW() WHERE workcom_id=" . $ID . ";";
  209.     $result = $sql_object->DBQuery($requete);
  210.     return $result;
  211.   }
  212.  
  213.   /**
  214.    * workshop_com::ModifyComUser()
  215.    * modification d'un message utilisateur authentifié
  216.    *
  217.    * @access public
  218.    * @param int $ID identifiant du message
  219.    * @param array $table_com contient les composants d'un message
  220.    * @param int $user_id identifiant de l'utilisateur
  221.    * @param object $sql_object 
  222.    * @return bool $result
  223.    */
  224.   function ModifyComUser($ID, $table_com, $user_id, $sql_object)
  225.   {
  226.     $table_com=$sql_object->DBescape($table_com);
  227.  
  228.     if ($table_com[0] != '') {
  229.       $this->SUBJECT = strip_input(trim($table_com[0]));
  230.     }
  231.     if ($table_com[1] != '') {
  232.       $this->BODY = strip_input(trim($table_com[1]), '<a><img><sup><sub><span>');
  233.       $this->BODY = str_replace('<br>', '<br />', $this->BODY); // necessary for nicEdit
  234.     }
  235.     $result_user = $this->_CheckUser($sql_object, $ID);
  236.     if ($result_user <> $user_id) {
  237.       $result = _t('workshop','not_author');
  238.     } else {
  239.       $requete = "UPDATE  " . $this->TDB_COM . " SET workcom_subject='" . $this->SUBJECT . "', workcom_body='" . $this->BODY . "' , workcom_last_modify=NOW() WHERE workcom_id=" . $ID . ";";
  240.       $result = $sql_object->DBQuery($requete);
  241.     }
  242.     return $result;
  243.   }
  244.  
  245.   /**
  246.    * workshop_com::_CheckUser()
  247.    * obtention de l'id d'un auteur de message
  248.    *
  249.    * @param object $sql_object 
  250.    * @param integer $mes_id 
  251.    * @return id_utilisateur $result[0]['workcom_user_id']
  252.    */
  253.   function _CheckUser($sql_object, $mes_id = -1)
  254.   {
  255.     if ($mes_id <> -1) {
  256.       $requete = "SELECT  workcom_user_id FROM " . $this->TDB_COM . " WHERE workcom_id=" . $mes_id . ";";
  257.     }
  258.     $result = $sql_object->DBSelect($requete);
  259.     return $result[0]['workcom_user_id'];
  260.   }
  261. }
  262.  
  263. ?>

Documentation generated on Thu, 03 May 2012 15:03:25 +0200 by phpDocumentor 1.4.1