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.         // Filter data event + return value
  60.         $r $this->dispatcher->filter(new sfEvent($this'workshopcom.before_datacheck'array('data' => $table))$table);
  61.         $table $r->getReturnValue();
  62.          
  63.         if (strlen($table[0]3return _t('workshop','com_no_subject');
  64.         if (strlen($table[1]10return _t('workshop','com_no_body');
  65.         
  66.         // we check if user id is numeric and belongs to the workgroup
  67.         // test to prevent SQL error if provided ID is wrong (can happen with TextBoxList js plugin
  68.         if(!is_numeric($table[3])) return _t('workshop','author_not_allowed');
  69.         $q "SELECT * FROM l21_j_work_users where jwu_user_id = ".$table[3]." AND jwu_workshop_id =".$table[4].";";
  70.         $r $sql_object->DBSelect($q);
  71.         if(!isset($r[0]['jwu_id'])) return _t('workshop','author_not_allowed');
  72.  
  73.         // Notify the beginning of the current method
  74.         $this->dispatcher->notify(new sfEvent($this'workshopcom.after_datacheck'array('data' => $table)));
  75.  
  76.         return true;
  77.     }
  78.  
  79.     /**
  80.      * workshop_com::AddCom()
  81.      * Ajout d'une nouvelle discussion
  82.      *
  83.      * @access public
  84.      * @param array $table_com : contient les composants d'une discussion
  85.      * @param object $sql_object 
  86.      * @return integer $last_id
  87.      */
  88.     function AddCom($table_com$sql_object)
  89.     {
  90.         // Filter data event + return value
  91.         $r $this->dispatcher->filter(new sfEvent($this'workshopcom.before_add'array('data' => $table_com))$table_com);
  92.         $table_com $r->getReturnValue();
  93.          
  94.         $table_com=$sql_object->DBescape($table_com);
  95.  
  96.         $this->SUBJECT = strip_input(trim($table_com[0]));
  97.         $this->BODY = strip_input(trim($table_com[1])'<a><img><sup><sub><span><br>');
  98.         $this->BODY = str_replace('<br>''<br />'$this->BODY)// necessary for nicEdit
  99.  
  100.         if ($table_com[2!= ''{
  101.             $this->PARENT_ID $table_com[2];
  102.         else $this->PARENT_ID 0;
  103.         $this->USER_ID = $table_com[3];
  104.         $this->WORKSHOP_ID = $table_com[4];
  105.         $this->STATUT = "P";
  106.  
  107.         if ($this->PARENT_ID == 0{
  108.             $q "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());";
  109.             $last_id $sql_object->DBInsert ($q1);
  110.         else {
  111.             $q_root "UPDATE  " $this->TDB_COM . " SET workcom_last_modify=NOW() WHERE workcom_id=" $this->PARENT_ID ";";
  112.             $result_root $sql_object->DBQuery($q_root);
  113.             $q "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());";
  114.             $last_id $sql_object->DBInsert ($q1);
  115.         }
  116.  
  117.         // Notify the end of the current method
  118.         $this->dispatcher->notify(new sfEvent($this'workshopcom.after_add'array('data' => $table_com'id' => $last_id)));
  119.  
  120.         return $last_id;
  121.     }
  122.     
  123.  
  124.     /**
  125.      * workshop_com::DeleteCom()
  126.      * suppression d'un message
  127.      *
  128.      * @access public
  129.      * @param int $com_id identifiant du message
  130.      * @param int $parent_id identifiant du parent
  131.      * @param object $sql_object 
  132.      * @return bool $result
  133.      */
  134.     function DeleteCom($ID$com_id$parent_id$sql_object)
  135.     {
  136.          
  137.         // Notify the beginning of the current method
  138.         $this->dispatcher->notify(new sfEvent($this'workshopcom.delete'array('id' => $ID'comid' => $com_id'parentid' => $parent_id)));
  139.          
  140.         if (is_numeric($ID)) {
  141.             $this->ID = $ID;
  142.         else return false;
  143.  
  144.         if ($parent_id == 0{
  145.             $q_son "SELECT workcom_id FROM " $this->TDB_COM . " WHERE workcom_statut <> 'E' AND workcom_parent=$com_id  AND workcom_workshop_id=$ID";
  146.  
  147.             $result_son $sql_object->DBSelect($q_son);
  148.  
  149.             if ($result_son <> 0{
  150.                 $q "UPDATE " $this->TDB_COM . " SET workcom_statut='E' WHERE workcom_id=$com_id;";
  151.                 $result $sql_object->DBQuery ($q);
  152.                 for($i 0$i count($result_son)$i++{
  153.                     $q_son_e "UPDATE " $this->TDB_COM . " SET workcom_statut='E' WHERE workcom_id=" $result_son[$i]['workcom_id'";";
  154.                     $result_son_e $sql_object->DBQuery ($q_son_e);
  155.                 }
  156.                 return $result;
  157.             else {
  158.                 $q "UPDATE " $this->TDB_COM . " SET workcom_statut='E' WHERE workcom_id=$com_id;";
  159.                 $result $sql_object->DBQuery ($q);
  160.                 return $result;
  161.             }
  162.         else {
  163.             $q "UPDATE " $this->TDB_COM . " SET workcom_statut='E' WHERE workcom_id=$com_id;";
  164.             $result $sql_object->DBQuery ($q);
  165.             return $result;
  166.         }
  167.     }
  168.  
  169.     /**
  170.      * workshop_com::LockCom()
  171.      * vérouillage d'un message
  172.      *
  173.      * @access public
  174.      * @param int $ID identifiant du workshop
  175.      * @param int $com_id identifiant du message
  176.      * @param int $parent_id identifiant du message parent
  177.      * @param int $lock 
  178.      * @param object $sql_object 
  179.      * @return bool $result
  180.      */
  181.     function LockCom($ID$com_id$parent_id$lock$sql_object)
  182.     {
  183.         // Notify the beginning of the current method
  184.         $this->dispatcher->notify(new sfEvent($this'workshopcom.lock'array('id' => $ID'comid' => $com_id'parentid' => $parent_id'lock' => $lock)));
  185.          
  186.         if ($lock == 0$statut 'C';
  187.         else $statut 'P';
  188.  
  189.         if (is_numeric($ID)) {
  190.             $this->ID = $ID;
  191.         else return false;
  192.  
  193.         if ($parent_id == 0{
  194.             $q_son "SELECT workcom_id FROM " $this->TDB_COM . " WHERE workcom_statut <> 'E' AND workcom_parent=$com_id  AND workcom_workshop_id=$ID";
  195.             $result_son $sql_object->DBSelect($q_son);
  196.  
  197.             if ($result_son <> 0{
  198.                 $q "UPDATE " $this->TDB_COM . " SET workcom_statut='" $statut "' WHERE workcom_id=$com_id;";
  199.                 $result $sql_object->DBQuery ($q);
  200.                 for($i 0$i count($result_son)$i++{
  201.                     $q_son_e "UPDATE " $this->TDB_COM . " SET workcom_statut='" $statut "' WHERE workcom_id=" $result_son[$i]['workcom_id'";";
  202.                     $result_son_e $sql_object->DBQuery ($q_son_e);
  203.                 }
  204.                 return $result;
  205.             else {
  206.                 $q "UPDATE " $this->TDB_COM . " SET workcom_statut='" $statut "' WHERE workcom_id=$com_id;";
  207.                 $result $sql_object->DBQuery ($q);
  208.                 return $result;
  209.             }
  210.         else {
  211.             $q "UPDATE " $this->TDB_COM . " SET workcom_statut='" $statut "' WHERE workcom_id=$com_id;";
  212.             $result $sql_object->DBQuery ($q);
  213.             return $result;
  214.         }
  215.     }
  216.  
  217.     /**
  218.      * workshop_com::ModifyCom()
  219.      * modification d'un message
  220.      *
  221.      * @access public
  222.      * @param int $ID identifiant du message
  223.      * @param array $table_com contient les composants d'un message
  224.      * @param object $sql_object 
  225.      * @return bool $result
  226.      */
  227.     function ModifyCom($ID$table_com$sql_object)
  228.     {
  229.         // Filter data event + return value
  230.         $r $this->dispatcher->filter(new sfEvent($this'workshopcom.before_modify'array('data' => $table_com'id' => $ID))$table_com);
  231.         $table_com $r->getReturnValue();
  232.          
  233.         $table_com=$sql_object->DBescape($table_com);
  234.  
  235.         if ($table_com[0!= ''{
  236.             $this->SUBJECT = strip_input(trim($table_com[0]));
  237.         }
  238.         if ($table_com[1!= ''{
  239.             $this->BODY = strip_input(trim($table_com[1])'<a><img><sup><sub><span>');
  240.             $this->BODY = str_replace('<br>''<br />'$this->BODY)// necessary for nicEdit
  241.         }
  242.         $this->USER_ID = $table_com[3];
  243.  
  244.         $q "UPDATE  " $this->TDB_COM . " SET workcom_subject='" $this->SUBJECT . "', workcom_body='" $this->BODY .  "', workcom_user_id=" $this->USER_ID . " , workcom_last_modify=NOW() WHERE workcom_id=" $ID ";";
  245.         $result $sql_object->DBQuery($q);
  246.  
  247.         // Notify the end of the current method
  248.         $this->dispatcher->notify(new sfEvent($this'workshopcom.after_modify'array('data' => $table_com'id' => $ID)));
  249.  
  250.         return $result;
  251.     }
  252.  
  253.     /**
  254.      * workshop_com::ModifyComUser()
  255.      * modification d'un message utilisateur authentifié
  256.      *
  257.      * @access public
  258.      * @param int $ID identifiant du message
  259.      * @param array $table_com contient les composants d'un message
  260.      * @param int $user_id identifiant de l'utilisateur
  261.      * @param object $sql_object 
  262.      * @return bool $result
  263.      */
  264.     function ModifyComUser($ID$table_com$user_id$sql_object$hasrights)
  265.     {
  266.         // Filter data event + return value
  267.         $r $this->dispatcher->filter(new sfEvent($this'workshopcom.before_modify_auth'array('data' => $table_com'id' => $ID'user_id' => $user_id))$table_com);
  268.         $table_com $r->getReturnValue();
  269.          
  270.         $table_com=$sql_object->DBescape($table_com);
  271.  
  272.         if ($table_com[0!= ''{
  273.             $this->SUBJECT = strip_input(trim($table_com[0]));
  274.         }
  275.         if ($table_com[1!= ''{
  276.             $this->BODY = strip_input(trim($table_com[1])'<a><img><sup><sub><span>');
  277.             $this->BODY = str_replace('<br>''<br />'$this->BODY)// necessary for nicEdit
  278.         }
  279.         $result_user $this->_getUserId($ID$sql_object);
  280.         if ($result_user != $user_id && $hasrights == false{
  281.             $result _t('workshop','not_author');
  282.         else {
  283.             $q "UPDATE  " $this->TDB_COM . " SET workcom_subject='" $this->SUBJECT . "', workcom_body='" $this->BODY . "' , workcom_last_modify=NOW() WHERE workcom_id=" $ID ";";
  284.             $result $sql_object->DBQuery($q);
  285.         }
  286.  
  287.         // Notify the end of the current method
  288.         $this->dispatcher->notify(new sfEvent($this'workshopcom.after_modify_auth'array('data' => $table_com'id' => $ID'user_id' => $user_id'is_admin' => $isadmin)));
  289.  
  290.         return $result;
  291.     }
  292.  
  293.     /**
  294.      * workshop_com::_getUserId()
  295.      * obtention de l'id d'un auteur de message
  296.      *
  297.      * @param object $sql_object 
  298.      * @param integer $mes_id 
  299.      * @return id_utilisateur $result[0]['workcom_user_id']
  300.      */
  301.     function _getUserId($mes_id$sql_object)
  302.     {
  303.         // Notify the end of the current method
  304.         $this->dispatcher->notify(new sfEvent($this'workshopcom.get_userid'array('id' => $mes_id)));
  305.          
  306.         $q "SELECT  workcom_user_id FROM " $this->TDB_COM . " WHERE workcom_id=" $mes_id ";";
  307.  
  308.         $result $sql_object->DBSelect($q);
  309.         return $result[0]['workcom_user_id'];
  310.     }
  311. }
  312.  
  313. ?>

Documentation generated on Thu, 20 Mar 2014 16:47:10 +0100 by phpDocumentor 1.4.1