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

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