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

Source for file class.resources.php

Documentation is available at class.resources.php

  1. <?php
  2. /**
  3.  * @package linea21.modules
  4.  * @subpackage resources
  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.  *  Resource Management
  11.  */
  12.  
  13. class resources {
  14.   /* @param
  15.    * */
  16.   var $TDB_LIAISON;
  17.   var $ACTIVE_TABLE;
  18.   var $ACTIVE_TYPE// valeur 'P' || 'W'
  19.  
  20.   var $B_ID;
  21.   var $B_AUTHOR;
  22.   var $B_TITLE;
  23.   var $B_SUBTITLE;
  24.   var $B_EDITOR;
  25.   var $B_DATE;
  26.   var $B_RANGE;
  27.   var $B_DATE_CREA;
  28.   var $B_LAST_MODIFY;
  29.   var $B_VALIDITY;
  30.   var $TDB_BIBLIO = T_BIBLIO_RES;
  31.  
  32.   var $L_ID;
  33.   var $L_TEXT;
  34.   var $L_MASK;
  35.   var $L_RANGE;
  36.   var $L_DATE_CREA;
  37.   var $L_LAST_MODIFY;
  38.   var $L_VALIDITY;
  39.   var $TDB_LINK = T_LINK_RES;
  40.  
  41.   var $M_ID;
  42.   var $M_NAME;
  43.   var $M_DESC;
  44.   var $M_URI;
  45.   var $M_RANGE;
  46.   var $M_DATE_CREA;
  47.   var $M_LAST_MODIFY;
  48.   var $M_VALIDITY;
  49.   var $TDB_MULTI = T_MULTI_RES;
  50.   var $M_MAX_PHOTO_MAX_WIDTH = 720;
  51.   var $M_MAX_PHOTO_MIN_WIDTH = 280;
  52.   var $M_UPLOAD_MAX_MO = 1024000// taille maximale d'upload des fichiers en octets
  53.   var $M_URI_INPUT = "multimedia/input/"// dossier racine de stockage des elements multimedias
  54.   var $M_URI_OUTPUT = "multimedia/output/"// dossier racine de diffusion des elements multimedias
  55.   protected $dispatcher = null;
  56.  
  57.   public function __construct()
  58.   {
  59.     $this->dispatcher = $GLOBALS['dispatcher'];
  60.   }
  61.  
  62.   public function __call($method$arguments)
  63.   {
  64.     $event $this->dispatcher->notifyUntil(new sfEvent($this'resources.extensible_function'array(
  65.       'method'    => $method,
  66.       'arguments' => $arguments
  67.     )));
  68.     if (!$event->isProcessed())
  69.     {
  70.       throw new Exception(sprintf('Call to undefined method %s::%s.'get_class($this)$method));
  71.     }
  72.  
  73.     return $event->getReturnValue();
  74.   }
  75.  
  76.  
  77.   /**
  78.    * resources::CheckDataIntegrity()
  79.    * vérifie l'integrité d'un ressource avant Insertion
  80.    *
  81.    * @access public
  82.    * @param array $table : contient les composants d'une ressource
  83.    * @param string $type : 'LINK', 'BIBLIO', 'MULTI'
  84.    * @return boolean true
  85.    *  si verifié, sinon string 'message d'erreur'
  86.    */
  87.   function CheckDataIntegrity($table$type)
  88.   {
  89.       // Filter data event + return value
  90.       $r $this->dispatcher->filter(new sfEvent($this'resources.before_datacheck'array('data' => $table'type' => $type))$table);
  91.       $table $r->getReturnValue();
  92.       
  93.     if ($type == 'LINK'{
  94.       if (strlen($table[0]2return _t('resources','no_url');
  95.       if (!$this->IsValidProtocol($table[0])) return _t('resources','invalid_protocol');
  96.       if(CHECK_LINK==true{
  97.         if (!$this->CheckOnlineFile($table[0])) return _t('resources','server_noresponse');
  98.       }
  99.     }
  100.     if ($type == 'BIBLIO'{
  101.       if (strlen($table[0]3return _t('resources','biblio_no_author');
  102.       if (strlen($table[1]3return _t('resources','biblio_no_title');
  103.     }
  104.     if ($type == 'MULTI'{
  105.       if (strlen($table[0]3return _t('resources','multi_no_name');
  106.       if (strlen($table[1]5return _t('resources','multi_no_description');
  107.       if (strlen($table[2]2return _t('resources','no_url');
  108.       if(CHECK_LINK==true{
  109.         if (!$this->IsValidProtocol($table[2])) return _t('resources','invalid_protocol');
  110.         if (!$this->CheckOnlineFile($table[2])) return _t('resources','server_noresponse');
  111.       }
  112.     }
  113.     
  114.     // Notify the beginning of the current method
  115.     $this->dispatcher->notify(new sfEvent($this'resources.after_datacheck'array('data' => $table'type' => $type)));
  116.  
  117.     return true;
  118.   }
  119.  
  120.   /**
  121.    * resources::CheckOnlineFile()
  122.    * vérifie l'existence d'un fichier en ligne
  123.    *
  124.    * @access public
  125.    * @param  $path 
  126.    * @return boolean 
  127.    */
  128.   function CheckOnlineFile($path)
  129.   {
  130.       // Notify the beginning of the current method
  131.       $this->dispatcher->notify(new sfEvent($this'resources.check_online_files'array('path' => $path)));
  132.       
  133.     $file_pt @fopen($path'r');
  134.     if (!$file_ptreturn false;
  135.     else {
  136.       fclose($file_pt);
  137.       return true;
  138.     }
  139.   }
  140.  
  141.   /**
  142.    * resources::IsValidProtocol()
  143.    * vérifie si une url donnée a un protocole reconnu par un client web standard
  144.    *
  145.    * @access public
  146.    * @param array $url : chemin absolu
  147.    * @return boolean 
  148.    */
  149.   function IsValidProtocol($url)
  150.   {
  151.       // Notify the beginning of the current method
  152.       $this->dispatcher->notify(new sfEvent($this'resources.is_valid_protocol'array('url' => $url)));
  153.       
  154.     if (substr($url07!= 'http://' && substr($url08!= 'https://' && substr($url06!= 'ftp://' && substr($url07!= 'ftps://'return false;
  155.     else return true;
  156.   }
  157.  
  158.   /**
  159.    * resources::_wichType()
  160.    * détermine les tables de la bdd en action
  161.    *
  162.    * @access private
  163.    * @param string $type : type de la ressource Workshop ou publication
  164.    * @param string $resources : type de la ressource
  165.    * @return void 
  166.    */
  167.   function _wichType($type$resources)
  168.   {
  169.     switch ($type{
  170.       case 'WORKSHOP':
  171.         $this->ACTIVE_TYPE = 'W';
  172.         break;
  173.       case 'PUBLICATION':
  174.         $this->ACTIVE_TYPE = 'P';
  175.         break;
  176.       default:
  177.         return "error";
  178.     }
  179.  
  180.     switch ($resources{
  181.       case 'BIBLIO':
  182.         $this->TDB_LIAISON = J_BIBLIO;
  183.         $this->ACTIVE_TABLE = T_BIBLIO_RES;
  184.         break;
  185.       case 'LINK':
  186.         $this->TDB_LIAISON = J_LINK;
  187.         $this->ACTIVE_TABLE = T_LINK_RES;
  188.         break;
  189.       case 'MULTI':
  190.         $this->TDB_LIAISON = J_MULTI;
  191.         $this->ACTIVE_TABLE = T_MULTI_RES;
  192.         break;
  193.       default:
  194.         return "error";
  195.     }
  196.   }
  197.  
  198.  
  199.   /**
  200.    * resources::AddBiblioRes()
  201.    * Ajout d'une nouvelle ressource bibliographique
  202.    *
  203.    * @access public
  204.    * @param array $res_table tableau contenant les infos resources
  205.    * @param int $ID identifiant du père (rattachement)
  206.    * @param string $type 'PUBLICATION' ou 'WORKSHOP'
  207.    * @param object $sql_object 
  208.    * @return integer $last_id
  209.    */
  210.   function AddBiblioRes($ID$res_table$type$sql_object)
  211.   {
  212.       // Filter data event + return value
  213.       $r $this->dispatcher->filter(new sfEvent($this'resources.before_add_biblio'array('data' => $res_table'parentid' => $ID'type' => $type))$res_table);
  214.       $res_table $r->getReturnValue();
  215.       
  216.     $res_table=$sql_object->DBescape($res_table);
  217.     if ($this->_wichType($type'BIBLIO'== "error"exit();
  218.     $this->B_AUTHOR = strip_input($res_table[0]);
  219.     $this->B_TITLE = strip_input($res_table[1]);
  220.     $this->B_SUBTITLE = strip_input($res_table[2]);
  221.     $this->B_EDITOR = strip_input($res_table[3]);
  222.     $this->B_DATE = strip_input($res_table[4]);
  223.     $this->B_RANGE = $res_table[5];
  224.     $this->B_VALIDITY = 'Y';
  225.     $q "INSERT INTO " $this->ACTIVE_TABLE . " (bibliores_author, bibliores_title, bibliores_sub_title, bibliores_editor, bibliores_date, bibliores_range, bibliores_date_crea, bibliores_validity) " "VALUES('" $this->B_AUTHOR . "', '" $this->B_TITLE . "', '" $this->B_SUBTITLE . "', '" $this->B_EDITOR . "', '" $this->B_DATE . "', " $this->B_RANGE . ", NOW(), '" $this->B_VALIDITY . "');";
  226.     $last_id $sql_object->DBInsert ($q1);
  227.     if (is_numeric($last_id)) {
  228.       $q "INSERT INTO " $this->TDB_LIAISON . " VALUES(" $ID "," $last_id ", '" $this->ACTIVE_TYPE . "');";
  229.       $result $sql_object->DBInsert ($q);
  230.     }
  231.     
  232.     // Notify the end of the current method
  233.     $this->dispatcher->notify(new sfEvent($this'resources.after_add_biblio'array('data' => $res_table'parentid' => $ID'type' => $type'id' => $last_id)));
  234.     
  235.     return $result;
  236.   }
  237.  
  238.   /**
  239.    * resources::ModifyBiblioRes()
  240.    * modification d'une ressource bibliographique
  241.    *
  242.    * @access public
  243.    * @param int $ID identifiant de la ressource
  244.    * @param object $sql_object 
  245.    * @param array $res_table tableau contenant les infos resources
  246.    * @return bool $result
  247.    */
  248.   function ModifyBiblioRes($ID$res_table$sql_object)
  249.   {
  250.       // Filter data event + return value
  251.       $r $this->dispatcher->filter(new sfEvent($this'resources.before_modify_biblio'array('data' => $res_table'id' => $ID))$res_table);
  252.       $res_table $r->getReturnValue();
  253.       
  254.     $res_table=$sql_object->DBescape($res_table);
  255.     $this->B_ID = $ID;
  256.     $this->B_AUTHOR = strip_input($res_table[0]);
  257.     $this->B_TITLE = strip_input($res_table[1]);
  258.     $this->B_SUBTITLE = strip_input($res_table[2]);
  259.     $this->B_EDITOR = strip_input($res_table[3]);
  260.     $this->B_DATE = strip_input($res_table[4]);
  261.     $q "UPDATE " $this->TDB_BIBLIO . " SET bibliores_author='" $this->B_AUTHOR . "' , bibliores_title='" $this->B_TITLE . "', bibliores_sub_title='" $this->B_SUBTITLE . "', bibliores_editor='" $this->B_EDITOR . "', bibliores_date='" $this->B_DATE . "' WHERE bibliores_id='" $this->B_ID . "';";
  262.     $result $sql_object->DBQuery($q);
  263.     
  264.     // Notify the end of the current method
  265.     $this->dispatcher->notify(new sfEvent($this'resources.after_modify_biblio'array('data' => $res_table'id' => $this->B_ID)));
  266.     
  267.     return $result;
  268.   }
  269.  
  270.   /**
  271.    * resources::DeleteBiblioRes()
  272.    * suppression d'une ressource bibliographique
  273.    *
  274.    * @access public
  275.    * @param int $ID identifiant de la ressource a supprimer
  276.    * @param object $sql_object 
  277.    * @return bool $result
  278.    */
  279.   function DeleteBiblioRes($ID$sql_object)
  280.   {
  281.       // Notify the beginning of the current method
  282.       $this->dispatcher->notify(new sfEvent($this'resources.delete_biblio'array('id' => $ID)));
  283.       
  284.     if (is_numeric($ID)) {
  285.       $this->B_ID = $ID;
  286.     }
  287.     $q "UPDATE  " $this->TDB_BIBLIO . " SET bibliores_validity='N' WHERE bibliores_id=" $this->B_ID . ";";
  288.     $result $sql_object->DBQuery($q);
  289.     return $result;
  290.   }
  291.  
  292.   /**
  293.    * resources::AddLinkRes()
  294.    * Ajout d'une ressource de type lien
  295.    *
  296.    * @access public
  297.    * @param int $ID identifiant du père (rattachement)
  298.    * @param array $res_table tableau contenant les infos ressources
  299.    * @param string $type 'PUBLICATION' ou 'WORKSHOP'
  300.    * @param object $sql_object 
  301.    * @return integer $last_id
  302.    */
  303.   function AddLinkRes($ID$res_table$type$sql_object)
  304.   {
  305.       // Filter data event + return value
  306.       $r $this->dispatcher->filter(new sfEvent($this'resources.before_add_link'array('data' => $res_table'parentid' => $ID'type' => $type))$res_table);
  307.       $res_table $r->getReturnValue();
  308.       
  309.     $res_table=$sql_object->DBescape($res_table);
  310.  
  311.     $notvalidlink _t('resources','invalid_link');
  312.     if ($this->_wichType($type'LINK'== "error"exit;
  313.     $this->L_TEXT = strip_input($res_table[0]);
  314.     if ($res_table[1== ''{
  315.       $this->L_MASK = $this->L_TEXT;
  316.     else {
  317.       $this->L_MASK = strip_input($res_table[1]);
  318.     }
  319.     if (is_numeric($res_table[2])) {
  320.       $this->L_RANGE = $res_table[2];
  321.     }
  322.     $this->L_VALIDITY = 'Y';
  323.     $q "INSERT INTO " $this->ACTIVE_TABLE . " (linkres_text, linkres_mask, linkres_range, linkres_date_crea, linkres_validity) VALUES('" $this->L_TEXT . "', '" $this->L_MASK . "', " $this->L_RANGE . ", NOW(), '" $this->L_VALIDITY . "');";
  324.     $last_id $sql_object->DBInsert ($q1);
  325.     if (is_numeric($last_id)) {
  326.       $q "INSERT INTO " $this->TDB_LIAISON . " VALUES(" $ID "," $last_id ", '" $this->ACTIVE_TYPE . "');";
  327.       $result $sql_object->DBInsert ($q);
  328.     }
  329.     
  330.     // Notify the end of the current method
  331.     $this->dispatcher->notify(new sfEvent($this'resources.after_add_link'array('data' => $res_table'parentid' => $ID'type' => $type'id' => $last_id)));
  332.     
  333.     return $result;
  334.   }
  335.  
  336.   /**
  337.    * resources::ModifyLinkRes()
  338.    * modification d'une ressource de type lien
  339.    *
  340.    * @access public
  341.    * @param int $ID identifiant de la ressource
  342.    * @param array $res_table tableau contenant les infos ressources
  343.    * @param object $sql_object 
  344.    * @return bool $result
  345.    */
  346.   function ModifyLinkRes($ID$res_table$sql_object)
  347.   {
  348.       // Filter data event + return value
  349.       $r $this->dispatcher->filter(new sfEvent($this'resources.before_modify_link'array('data' => $res_table'id' => $ID))$res_table);
  350.       $res_table $r->getReturnValue();
  351.       
  352.     $res_table=$sql_object->DBescape($res_table);
  353.  
  354.     $this->L_ID = $ID;
  355.     $this->L_TEXT = strip_input($res_table[0]);
  356.     if ($res_table[1== ''{
  357.       $this->L_MASK = $this->L_TEXT;
  358.     else {
  359.       $this->L_MASK = strip_input($res_table[1]);
  360.     }
  361.     $q "UPDATE " $this->TDB_LINK . " SET linkres_text='" $this->L_TEXT . "' , linkres_mask='" $this->L_MASK . "' WHERE linkres_id='" $this->L_ID . "';";
  362.  
  363.     $result $sql_object->DBQuery($q);
  364.     
  365.     // Notify the end of the current method
  366.     $this->dispatcher->notify(new sfEvent($this'resources.after_modify_link'array('data' => $res_table'id' => $this->L_ID)));
  367.     
  368.     return $result;
  369.   }
  370.  
  371.   /**
  372.    * resources::DeleteLinkRes()
  373.    * suppression d'une ressource de type lien
  374.    *
  375.    * @access public
  376.    * @param int $ID identifiant de la ressource a supprimer
  377.    * @param object $sql_object 
  378.    * @return bool $result
  379.    */
  380.   function DeleteLinkRes($ID$sql_object)
  381.   {
  382.       // Notify the beginning of the current method
  383.       $this->dispatcher->notify(new sfEvent($this'resources.delete_link'array('id' => $ID)));
  384.       
  385.     if (is_numeric($ID)) {
  386.       $this->B_ID = $ID;
  387.     }
  388.     $q "UPDATE  " $this->TDB_LINK . " SET linkres_validity='N' WHERE linkres_id=" $this->B_ID . ";";
  389.     $result $sql_object->DBQuery($q);
  390.     return $result;
  391.   }
  392.  
  393.   /**
  394.    * resources::AddMultiRes()
  395.    * Ajout d'une ressource de type multimedia
  396.    *
  397.    * @access public
  398.    * @param int $ID identifiant du père (rattachement)
  399.    * @param array $res_table tableau contenant les infos ressources
  400.    * @param string $type 'PUBLICATION' ou 'WORKSHOP'
  401.    * @param object $sql_object 
  402.    * @return integer $last_id
  403.    */
  404.   function AddMultiRes($ID$res_table$type$sql_object)
  405.   {
  406.       // Filter data event + return value
  407.       $r $this->dispatcher->filter(new sfEvent($this'resources.before_add_multi'array('data' => $res_table'parentid' => $ID'type' => $type))$res_table);
  408.       $res_table $r->getReturnValue();
  409.       
  410.     $res_table=$sql_object->DBescape($res_table);
  411.  
  412.     if ($this->_wichType($type'MULTI'== "error"exit;
  413.     $this->M_NAME = strip_input($res_table[0]);
  414.  
  415.     $this->M_DESC = strip_input($res_table[1]);
  416.     $this->M_URI = strip_input($res_table[2]);
  417.     $this->M_RANGE = $res_table[3];
  418.     $this->M_VALIDITY = 'Y';
  419.     $q "INSERT INTO " $this->ACTIVE_TABLE . " (multires_name, multires_description, multires_media_uri, multires_range, multires_date_crea, multires_validity) VALUES('" $this->M_NAME . "', '" $this->M_DESC . "', '" $this->M_URI . "', " $this->M_RANGE . ", NOW(), '" $this->M_VALIDITY . "');";
  420.     $last_id $sql_object->DBInsert ($q1);
  421.     if (is_numeric($last_id)) {
  422.       $q "INSERT INTO " $this->TDB_LIAISON . " VALUES(" $ID "," $last_id ", '" $this->ACTIVE_TYPE . "');";
  423.       $result $sql_object->DBInsert ($q);
  424.     }
  425.     
  426.     // Notify the end of the current method
  427.     $this->dispatcher->notify(new sfEvent($this'resources.after_add_multi'array('data' => $res_table'parentid' => $ID'type' => $type'id' => $last_id)));
  428.     
  429.     return $result;
  430.   }
  431.  
  432.   /**
  433.    * resources::ModifyMultiRes()
  434.    * modification d'une ressource de type multimedia
  435.    *
  436.    * @access public
  437.    * @param int $ID identifiant de la ressource
  438.    * @param array $res_table tableau contenant les infos ressources
  439.    * @param object $sql_object 
  440.    * @return bool $result
  441.    */
  442.   function ModifyMultiRes($ID$res_table$sql_object)
  443.   {
  444.       // Filter data event + return value
  445.       $r $this->dispatcher->filter(new sfEvent($this'resources.before_modify_multi'array('data' => $res_table'id' => $ID))$res_table);
  446.       $res_table $r->getReturnValue();
  447.       
  448.     $res_table=$sql_object->DBescape($res_table);
  449.  
  450.     $this->M_ID = $ID;
  451.     $this->M_NAME = strip_input($res_table[0]);
  452.     $this->M_DESC = strip_input($res_table[1]);
  453.     $this->M_URI = strip_input($res_table[2]);
  454.     $q "UPDATE " $this->TDB_MULTI . " SET multires_name='" $this->M_NAME . "' , multires_description='" $this->M_DESC . "' , multires_media_uri='" $this->M_URI . "' WHERE multires_id='" $this->M_ID . "';";
  455.     $result $sql_object->DBQuery($q);
  456.     
  457.     // Notify the end of the current method
  458.     $this->dispatcher->notify(new sfEvent($this'resources.after_modify_multi'array('data' => $res_table'id' => $this->M_ID)));
  459.  
  460.     return $result;
  461.   }
  462.  
  463.   /**
  464.    * resources::changeRanges()
  465.    * changes Resources range
  466.    *
  467.    * @access public
  468.    * @param array : Id (key) and ranges (value)
  469.    * @param object $sql_object 
  470.    * @return bool $result
  471.    */
  472.  
  473.   function changeRanges($array$sql_object$element)
  474.   {
  475.  
  476.     switch ($element{
  477.       case "link":
  478.         $table $this->TDB_LINK;
  479.         break;
  480.       case "biblio":
  481.         $table $this->TDB_BIBLIO;
  482.         break;
  483.       case "multi":
  484.         $table $this->TDB_MULTI;
  485.         break;
  486.     }
  487.     foreach ($array as $key => $value{
  488.       $query "UPDATE " $table " set ".$element."res_range ='".$value."' WHERE ".$element."res_id ='" $key "';";
  489.       $result $sql_object->DBQuery($query);
  490.     }
  491.     
  492.     // Notify the beginning of the current method
  493.     $this->dispatcher->notify(new sfEvent($this'resources.change_ranges'array('data' => $array'element' => $element)));
  494.  
  495.     return $result;
  496.   }
  497.  
  498.   /**
  499.    * resources::DeleteMultiRes()
  500.    * suppression d'une ressource multimedia
  501.    *
  502.    * @access public
  503.    * @param int $ID identifiant de la ressource a supprimer
  504.    * @param object $sql_object 
  505.    * @return bool $result
  506.    */
  507.   function DeleteMultiRes($ID$sql_object)
  508.   {
  509.       // Notify the beginning of the current method
  510.       $this->dispatcher->notify(new sfEvent($this'resources.delete_multi'array('id' => $ID)));
  511.       
  512.     if (is_numeric($ID)) {
  513.       $this->M_ID = $ID;
  514.     }
  515.     $q "UPDATE  " $this->TDB_MULTI . " SET multires_validity='N' WHERE multires_id=" $this->M_ID . ";";
  516.     $result $sql_object->DBQuery($q);
  517.     return $result;
  518.   }
  519. }
  520.  
  521. ?>

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