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

Source for file class.workshop.php

Documentation is available at class.workshop.php

  1. <?php
  2. /**
  3.  * @package linea21.modules
  4.  * @subpackage workshop
  5.  * @author linea21 <info@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  *  Work group Management
  10.  */
  11.  
  12. class workshop {
  13.   /* @param
  14.    * */
  15.   var $TDB_WORKSHOP = T_WORK// nom de la table.
  16.   var $ID;
  17.   var $DENOMINATION;
  18.   var $RESUME;
  19.   var $THEME;
  20.   var $COMMENT;
  21.   var $LEVEL;
  22.   var $DATE_CREA;
  23.   var $LAST_MODIFY;
  24.   var $STATUT;
  25.   protected $dispatcher = null;
  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'workshop.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.    * workshop::CheckDataIntegrity()
  48.    * Vérification intégrité des données
  49.    *
  50.    * @access public
  51.    * @param array $table contient les composants d'un groupe de travail
  52.    * @return boolean true
  53.    *  si verifié, sinon string 'message d'erreur'
  54.    */
  55.   function CheckDataIntegrity($table$sql_object)
  56.   {
  57.       // Filter data event + return value
  58.       $r $this->dispatcher->filter(new sfEvent($this'workshop.before_datacheck'array('data' => $table))$table);
  59.       $table $r->getReturnValue();
  60.       
  61.     if (strlen($table[0]3return _t('workshop','no_title');
  62.     if (strlen($table[1]3return _t('workshop','no_resume');
  63.     if ($table[2== -1return _t('workshop','no_theme');
  64.  
  65.     if (substr($table[6]-1== ','{
  66.       $table[6substr($table[6]0-1);
  67.     }
  68.     $table_organizer @explode(','$table[6]);
  69.     for ($i 0;$i count($table_organizer);$i++{
  70.       $table_organizer[$itrim($table_organizer[$i]);
  71.       if (strlen(trim($table_organizer[$i])) 2$return _t('workshop','no_author');
  72.       $result $this->_CheckUserValidity($table_organizer[$i]$sql_object);
  73.       if (!is_numeric($result)) $return _t('workshop','author_not_valid'" : " $table_organizer[$i];
  74.       else $return $result;
  75.       $result_admin $this->_CheckAdmin($sql_object-1$table_organizer[$i]);
  76.       if ($result_admin == false$return _t('workshop','author_not_admin'" : " $table_organizer[$i];
  77.       if (!is_numeric($return)) return $return;
  78.     }
  79.     
  80.     // Notify the beginning of the current method
  81.     $this->dispatcher->notify(new sfEvent($this'workshop.after_datacheck'array('data' => $table)));
  82.     
  83.     return $return;
  84.   }
  85.  
  86.   /**
  87.    * workshop::_CheckAdmin()
  88.    * Vérification droits d'utilisation avancé Admin ou Animateur
  89.    *
  90.    * @access private
  91.    * @param object $sql_object 
  92.    * @return integer $user_id (option)
  93.    * @param string $user_login (option)
  94.    * @return integer id de l'utilisateur si verifié, sinon false
  95.    */
  96.   function _CheckAdmin($sql_object$user_id = -1$user_login = -1)
  97.   {
  98.       // Notify the beginning of the current method
  99.       $this->dispatcher->notify(new sfEvent($this'workshop.is_admin'array('user_id' => $user_id'user_login' => $user_login)));
  100.       
  101.     if ($user_id <> -1{
  102.       $q "SELECT rights_workshop, U.user_id FROM " T_USER " AS U LEFT OUTER JOIN " T_RIGHT " AS R on U.user_rights=R.rights_id  WHERE user_id='" $user_id "' AND user_validity='Y';";
  103.     }
  104.     if ($user_login <> -1{
  105.       $q "SELECT rights_workshop, U.user_id FROM " T_USER " AS U LEFT OUTER JOIN " T_RIGHT " AS R on U.user_rights=R.rights_id  WHERE lower(user_login)= '" strtolower($user_login"' AND user_validity='Y';";
  106.     }
  107.     $result $sql_object->DBSelect($q);
  108.     if ($result[0]['rights_workshop'== 'A' || $result[0]['rights_workshop'== 'O'return $result[0]['user_id'];
  109.     else return false;
  110.   }
  111.  
  112.   /**
  113.    * workshop::_CheckUserValidity()
  114.    * Vérification validité de l'utilisateur
  115.    *
  116.    * @access private
  117.    * @param string $login 
  118.    * @param object $sql_object 
  119.    * @return integer si $login existe
  120.    *  sinon renvoie false
  121.    */
  122.   function _CheckUserValidity($login$sql_object)
  123.   {
  124.       // Notify the beginning of the current method
  125.       $this->dispatcher->notify(new sfEvent($this'workshop.is_user_valid'array('login' => $login)));
  126.       
  127.     $q "SELECT user_id FROM " T_USER " WHERE lower(user_login)= '" strtolower($login"' AND user_validity='Y';";
  128.     $result $sql_object->DBSelect($q);
  129.     if ($result == 0return false;
  130.     if (count($result1exit();
  131.     else return (int)$result[0]['user_id'];
  132.   }
  133.  
  134.   /**
  135.    * workshop::CheckUsersIntegrity()
  136.    * Vérification pour ajout d'utilisateurs
  137.    *
  138.    * @access public
  139.    * @param string $logins 
  140.    * @param integer $id 
  141.    * @param object $sql_object 
  142.    * @param string $statut 
  143.    * @return string $result
  144.    */
  145.   function CheckUsersIntegrity($logins$id$sql_object$statut)
  146.   {
  147.       // Notify the beginning of the current method
  148.       $this->dispatcher->notify(new sfEvent($this'workshop.check_users_integrity'array('logins' => $logins'workshop_id' => $id'statut' => $statut)));
  149.  
  150.     if (strlen(trim($logins)) 2return _t('workshop','no_author');
  151.  
  152.     if (substr($logins-1== ','{
  153.       $logins substr($logins0-1);
  154.     }
  155.     $users @explode(','$logins);
  156.  
  157.     foreach ($users as $user{
  158.       $user trim($user);
  159.       // check if user exists
  160.       $result $this->_CheckUserValidity($user$sql_object);
  161.       if ($result== falsereturn _t('workshop','author_not_valid'" : " $user;
  162.       // check if user has rights enough
  163.       if ($statut == 'O'{
  164.         $result $this->_CheckAdmin($sql_object-1$user);
  165.         if ($result == falsereturn _t('workshop','author_not_admin'" : " $user;
  166.       }
  167.       // check if user is already member of the workgroup
  168.       $q "SELECT user_id FROM " T_USER " WHERE lower(user_login)= '" strtolower($user"' AND user_validity='Y';";
  169.       $data $sql_object->DBSelect($q);
  170.  
  171.       $q "SELECT COUNT(jwu_id) AS nb FROM " J_WORK_USERS " WHERE jwu_user_id=" $data[0]['user_id'" AND jwu_workshop_id=" $id ";";
  172.       $data $sql_object->DBSelect($q'OBJECT');
  173.       if ($data[0]->nb != 0return _t('workshop','yet_author'" : " $user;
  174.     }
  175.  
  176.     return true;
  177.   }
  178.  
  179.   /**
  180.    * workshop::AddWorkshop()
  181.    * Ajout d'un groupe de travail
  182.    *
  183.    * @access public
  184.    * @param array $table_workshop contient les composants d'un workshop
  185.    * @param object $sql_object 
  186.    * @return integer $last_id
  187.    */
  188.   function AddWorkshop($table_workshop$sql_object)
  189.   {
  190.       // Filter data event + return value
  191.       $r $this->dispatcher->filter(new sfEvent($this'workshop.before_add'array('data' => $table_workshop))$table_workshop);
  192.       $table_workshop $r->getReturnValue();
  193.       
  194.     $table_workshop=$sql_object->DBescape($table_workshop);
  195.  
  196.     if($table_workshop[4== -1$table_workshop[4]=0;
  197.  
  198.     $this->DENOMINATION = strip_input(trim($table_workshop[0]));
  199.     $this->RESUME = strip_input(trim($table_workshop[1])true);
  200.     $this->THEME = $table_workshop[2];
  201.     $this->COMMENT = strip_input(trim($table_workshop[3])true);
  202.     $this->LEVEL = $table_workshop[4];
  203.     $this->STATUT = $table_workshop[5];
  204.  
  205.     $q "INSERT INTO " $this->TDB_WORKSHOP . " (workshop_denomination, workshop_resume, workshop_theme, workshop_comment, workshop_level, workshop_statut, workshop_date_crea) VALUES('" $this->DENOMINATION . "', '" $this->RESUME . "', " $this->THEME . ", '" $this->COMMENT . "', " $this->LEVEL . ", '" $this->STATUT . "', NOW());";
  206.     $last_id $sql_object->DBInsert ($q1);
  207.     
  208.     // Notify the end of the current method
  209.     $this->dispatcher->notify(new sfEvent($this'workshop.after_add'array('data' => $table_workshop'id' => $last_id)));
  210.     
  211.     return $last_id;
  212.   }
  213.  
  214.   /**
  215.    * workshop::ModifyWorkshop()
  216.    * modification d'un workshop
  217.    *
  218.    * @access public
  219.    * @param int $ID identifiant d'un workshop
  220.    * @param array $table_workshop contient les composants d'un workshop
  221.    * @param object $sql_object 
  222.    * @return bool $result
  223.    */
  224.   function ModifyWorkshop($ID$table_workshop$sql_object)
  225.   {
  226.       // Filter data event + return value
  227.       $r $this->dispatcher->filter(new sfEvent($this'workshop.before_modify'array('data' => $table_workshop'id' => $ID))$table_workshop);
  228.       $table_workshop $r->getReturnValue();
  229.       
  230.     $table_workshop=$sql_object->DBescape($table_workshop);
  231.  
  232.     if($table_workshop[4== -1$table_workshop[4]=0;
  233.  
  234.     if (is_numeric($ID)) {
  235.       $this->ID = $ID;
  236.     }
  237.  
  238.     $this->DENOMINATION = strip_input(trim($table_workshop[0]));
  239.     $this->RESUME = strip_input(trim($table_workshop[1])true);
  240.     $this->THEME = $table_workshop[2];
  241.     $this->COMMENT = strip_input(trim($table_workshop[3])true);
  242.     $this->LEVEL = $table_workshop[4];
  243.  
  244.     $q "UPDATE  " $this->TDB_WORKSHOP . " set workshop_denomination='" $this->DENOMINATION . "', workshop_resume='" $this->RESUME . "' , workshop_theme=" $this->THEME . ", workshop_level=" $this->LEVEL . ", workshop_comment='" $this->COMMENT . "' WHERE workshop_id=" $this->ID . ";";
  245.     $result $sql_object->DBQuery($q);
  246.     
  247.     // Notify the end of the current method
  248.     $this->dispatcher->notify(new sfEvent($this'workshop.after_modify'array('data' => $table_workshop'id' => $this->ID)));
  249.     
  250.     return $result;
  251.   }
  252.   
  253.   
  254.   /**
  255.    * Workshop::changeRanges()
  256.    * changes Workshop range
  257.    *
  258.    * @access public
  259.    * @param array : Id (key) and ranges (value)
  260.    * @param object $sql_object 
  261.    * @return bool $result
  262.    */
  263.  
  264.   function changeRanges($array$sql_object)
  265.   {
  266.  
  267.     foreach ($array as $key => $value{
  268.       $query "UPDATE " $this->TDB_WORKSHOP . " set workshop_range='".$value."' WHERE workshop_id='" $key "';";
  269.       $result $sql_object->DBQuery($query);
  270.     }
  271.  
  272.     // Notify the beginning of the current method
  273.     $this->dispatcher->notify(new sfEvent($this'workshop.change_ranges'array('data' => $array)));
  274.     
  275.     return $result;
  276.   }
  277.  
  278.   /**
  279.    * modification du statut d'un workshop
  280.    *
  281.    * @access public
  282.    * @param int $id identifiant du workshop
  283.    * @param string $state (facultatif) 'P' Public/'D' Draft/'AA' AdminArchive/'PA' PublicArchive/'E' Erase
  284.    * @param object $sql_object 
  285.    * @return bool $result
  286.    */
  287.  
  288.   function StateWorkshop($ID$state$sql_object)
  289.   {
  290.       // Notify the end of the current method
  291.       $this->dispatcher->notify(new sfEvent($this'workshop.change_state'array('id' => $ID'state' => $state)));
  292.       
  293.     if (is_numeric($ID)) {
  294.       $this->ID = $ID;
  295.     }
  296.     if ($state != ''{
  297.       strtoupper($state);
  298.       switch ($state{
  299.         case 'P':
  300.           $this->STATUT = $state;
  301.           break;
  302.         case 'D':
  303.           $this->STATUT = $state;
  304.           break;
  305.         case 'AA':
  306.           $this->STATUT = $state;
  307.           break;
  308.         case 'PA':
  309.           $this->STATUT = $state;
  310.           break;
  311.         case 'E':
  312.           $this->STATUT = $state;
  313.           break;
  314.         default:
  315.           $this->STATUT = 'D';
  316.           break;
  317.       }
  318.     else $this->STATUT = 'D';
  319.     $q "UPDATE  " $this->TDB_WORKSHOP . " set workshop_statut='" $this->STATUT . "' WHERE workshop_id=" $this->ID . ";";
  320.     $result $sql_object->DBQuery($q);
  321.     return $result;
  322.   }
  323.  
  324.   /**
  325.    * suppression d'un workshop
  326.    *
  327.    * @access public
  328.    * @param int $id identifiant du workshop a supprimer
  329.    * @param object $sql_object 
  330.    * @return bool $result
  331.    */
  332.  
  333.   function DeleteWorkshop($ID$sql_object)
  334.   {
  335.       // Notify the beginning of the current method
  336.       $this->dispatcher->notify(new sfEvent($this'workshop.delete'array('id' => $ID)));
  337.       
  338.     if (is_numeric($ID)) {
  339.       $this->ID = $ID;
  340.     }
  341.     $result $this->StateWorkshop($this->ID'E'$sql_object);
  342.  
  343.     return $result;
  344.   }
  345.  
  346.   /**
  347.    * workshop::AddUserWorkshop()
  348.    * Ajout d'un ou plusieurs utilisateurs au workshop
  349.    *
  350.    * @access public
  351.    * @param int $work_id identifiant du workshop
  352.    * @param string $user_login login(s) utilisateur(s)
  353.    * @param array $user_right droit confié a l'utilisateur sur le workshop
  354.    * @param object $sql_object 
  355.    * @return integer $last_id
  356.    */
  357.   function AddUserWorkshop($work_id$user_login$user_right $sql_object)
  358.   {
  359.       // Notify the beginning of the current method
  360.       $this->dispatcher->notify(new sfEvent($this'workshop.add_user'array('id' => $work_id'user_login' => $user_login'user_right' => $user_right)));
  361.       
  362.     if (is_numeric($work_id)) {
  363.       $this->ID = $work_id;
  364.     else return false;
  365.     if (substr($user_login-1== ','{
  366.       $user_login substr($user_login0-1);
  367.     }
  368.     $user_login @explode(','$user_login);
  369.     for ($i 0;$i count($user_login);$i++{
  370.       $q "SELECT user_id FROM " T_USER " WHERE lower(user_login) = '" strtolower($user_login[$i]"' AND user_validity='Y';";
  371.       $data $sql_object->DBSelect($q);
  372.       $user_id $data[0]['user_id'];
  373.       $q "INSERT INTO " J_WORK_USERS " (jwu_workshop_id, jwu_user_id, jwu_user_right) VALUES(" $this->ID . ", " $user_id ",'" $user_right "');";
  374.       $last_id $sql_object->DBInsert ($q1);
  375.     }
  376.  
  377.     return $last_id;
  378.   }
  379.  
  380.   /**
  381.    * workshop::DeleteUserWorkshop()
  382.    * suppression d'un utilisateur au workshop
  383.    *
  384.    * @access public
  385.    * @param int $user_id identifiant du workshop
  386.    * @param string $work_id login de l'utilisateur
  387.    * @param object $sql_object 
  388.    * @return bool $result
  389.    */
  390.   function DeleteUserWorkshop($user_id$work_id$sql_object)
  391.   {
  392.       // Notify the beginning of the current method
  393.       $this->dispatcher->notify(new sfEvent($this'workshop.delete_user'array('id' => $work_id'user_id' => $user_id)));
  394.        
  395.     if (is_numeric($work_id&& is_numeric($user_id)) {
  396.       $q "DELETE FROM " J_WORK_USERS " WHERE jwu_workshop_id=" $work_id " AND jwu_user_id=" $user_id ";";
  397.       $result $sql_object->DBQuery($q);
  398.       return $result;
  399.     else return false;
  400.   }
  401.   
  402.   /**
  403.    * workshop::acceptUser()
  404.    * acceptation d'un utilisateur au workshop
  405.    *
  406.    * @access public
  407.    * @param int $work_id identifiant du workshop
  408.    * @param string $user_id 
  409.    * @param object $sql_object 
  410.    * @return bool $result
  411.    */
  412.   function acceptUser($work_id$user_id$sql_object)
  413.   {
  414.       // Notify the beginning of the current method
  415.       $this->dispatcher->notify(new sfEvent($this'workshop.accept_user'array('id' => $work_id'user_id' => $user_id)));
  416.        
  417.       if (is_numeric($work_id)) {
  418.  
  419.           $q "UPDATE " J_WORK_USERS " SET jwu_user_right='U' WHERE jwu_user_id=" $user_id " AND jwu_workshop_id=" $work_id " ;";
  420.           $result $sql_object->DBQuery($q);
  421.           
  422.           return $result;
  423.       else return false;
  424.   }
  425.  
  426.   /**
  427.    * workshop::ModifyUserWorkshop()
  428.    * NOT USED
  429.    * modification d'un utilisateur au workshop
  430.    *
  431.    * @access public
  432.    * @param int $work_id identifiant du workshop
  433.    * @param string $user_login login de l'utilisateur
  434.    * @param object $sql_object 
  435.    * @return bool $result
  436.    */
  437.   function ModifyUserWorkshop($work_id$user_login$sql_object)
  438.   {
  439.       // Notify the beginning of the current method
  440.       $this->dispatcher->notify(new sfEvent($this'workshop.modify_user'array('id' => $work_id'user_login' => $user_login)));
  441.       
  442.     if (is_numeric($work_id)) {
  443.       $user_id $this->_CheckUserValidity($user_login$sql_object);
  444.       $q "UPDATE " J_WORK_USERS " SET jwu_user_id=" $user_id " WHERE jwu_user_right='O'  AND jwu_workshop_id=" $work_id " ;";
  445.       $result $sql_object->DBQuery($q);
  446.       return $result;
  447.     else return false;
  448.   }
  449.  
  450.   /**
  451.    * workshop::ModifyOrganizerWorkshop()
  452.    * modification des organisateurs d'un workshop
  453.    *
  454.    * @access public
  455.    * @param int $work_id identifiant du workshop
  456.    * @param string $table_login string des organisateurs séparés par ','
  457.    * @param object $sql_object 
  458.    * @return int $last_id
  459.    */
  460.   function ModifyOrganizerWorkshop($work_id$table_login$sql_object)
  461.   {
  462.       // Notify the beginning of the current method
  463.       $this->dispatcher->notify(new sfEvent($this'workshop.modify_organizer'array('id' => $work_id'logins' => $table_login)));
  464.       
  465.     if (substr($table_login-1== ','{
  466.       $table_login substr($table_login0-1);
  467.     }
  468.     $table_login @explode(','$table_login);
  469.     $q "DELETE FROM " J_WORK_USERS " WHERE jwu_workshop_id=" $work_id " AND jwu_user_right='O';";
  470.     $result $sql_object->DBQuery($q);
  471.     for ($i 0;$i count($table_login);$i++{
  472.       $user_id $this->_CheckUserValidity(trim($table_login[$i])$sql_object);
  473.       $q2 "DELETE FROM " J_WORK_USERS " WHERE jwu_workshop_id=" $work_id " AND jwu_user_id=" $user_id ";";
  474.       $result2 $sql_object->DBQuery($q2);
  475.       $q3 "INSERT INTO " J_WORK_USERS " (jwu_workshop_id, jwu_user_id, jwu_user_right) VALUES(" $work_id ", " $user_id ",'O');";
  476.       $last_id $sql_object->DBInsert ($q31);
  477.     }
  478.     return $last_id;
  479.   }
  480.  
  481. }
  482.  
  483. ?>

Documentation generated on Mon, 08 Apr 2013 18:13:23 +0200 by phpDocumentor 1.4.1