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.     if ($type == 'LINK'{
  90.       if (strlen($table[0]2return _t('resources','no_url');
  91.       if (!$this->IsValidProtocol($table[0])) return _t('resources','invalid_protocol');
  92.       if(CHECK_LINK==true{
  93.         if (!$this->CheckOnlineFile($table[0])) return _t('resources','server_noresponse');
  94.       }
  95.     }
  96.     if ($type == 'BIBLIO'{
  97.       if (strlen($table[0]3return _t('resources','biblio_no_author');
  98.       if (strlen($table[1]3return _t('resources','biblio_no_title');
  99.     }
  100.     if ($type == 'MULTI'{
  101.       if (strlen($table[0]3return _t('resources','multi_no_name');
  102.       if (strlen($table[1]5return _t('resources','multi_no_description');
  103.       if (strlen($table[2]2return _t('resources','no_url');
  104.       if ($table[4== 'OUT' && !$this->IsValidProtocol($table[2])) return _t('resources','invalid_protocol');
  105.       if ($table[4== 'IN'$table[2SITE_ROOT_URL $table[2];
  106.       if(CHECK_LINK==true{
  107.         if (!$this->CheckOnlineFile($table[2])) return _t('resources','server_noresponse');
  108.       }
  109.     }
  110.  
  111.     return true;
  112.   }
  113.  
  114.   /**
  115.    * resources::CheckOnlineFile()
  116.    * vérifie l'existence d'un fichier en ligne
  117.    *
  118.    * @access public
  119.    * @param  $path 
  120.    * @return boolean 
  121.    */
  122.   function CheckOnlineFile($path)
  123.   {
  124.     $file_pt @fopen($path'r');
  125.     if (!$file_ptreturn false;
  126.     else {
  127.       fclose($file_pt);
  128.       return true;
  129.     }
  130.   }
  131.  
  132.   /**
  133.    * resources::IsValidProtocol()
  134.    * vérifie si une url donnée a un protocole reconnu par un client web standard
  135.    *
  136.    * @access public
  137.    * @param array $url : chemin absolu
  138.    * @return boolean 
  139.    */
  140.   function IsValidProtocol($url)
  141.   {
  142.     if (substr($url07!= 'http://' && substr($url08!= 'https://' && substr($url06!= 'ftp://' && substr($url07!= 'ftps://'return false;
  143.     else return true;
  144.   }
  145.  
  146.   /**
  147.    * resources::_wichType()
  148.    * détermine les tables de la bdd en action
  149.    *
  150.    * @access private
  151.    * @param string $type : type de la ressource Workshop ou publication
  152.    * @param string $resources : type de la ressource
  153.    * @return void 
  154.    */
  155.   function _wichType($type$resources)
  156.   {
  157.     switch ($type{
  158.       case 'WORKSHOP':
  159.         $this->ACTIVE_TYPE = 'W';
  160.         break;
  161.       case 'PUBLICATION':
  162.         $this->ACTIVE_TYPE = 'P';
  163.         break;
  164.       default:
  165.         return "error";
  166.     }
  167.  
  168.     switch ($resources{
  169.       case 'BIBLIO':
  170.         $this->TDB_LIAISON = J_BIBLIO;
  171.         $this->ACTIVE_TABLE = T_BIBLIO_RES;
  172.         break;
  173.       case 'LINK':
  174.         $this->TDB_LIAISON = J_LINK;
  175.         $this->ACTIVE_TABLE = T_LINK_RES;
  176.         break;
  177.       case 'MULTI':
  178.         $this->TDB_LIAISON = J_MULTI;
  179.         $this->ACTIVE_TABLE = T_MULTI_RES;
  180.         break;
  181.       default:
  182.         return "error";
  183.     }
  184.   }
  185.  
  186.  
  187.   /**
  188.    * resources::AddBiblioRes()
  189.    * Ajout d'une nouvelle ressource bibliographique
  190.    *
  191.    * @access public
  192.    * @param array $res_table tableau contenant les infos resources
  193.    * @param int $ID identifiant du père (rattachement)
  194.    * @param string $type 'PUBLICATION' ou 'WORKSHOP'
  195.    * @param object $sql_object 
  196.    * @return integer $last_id
  197.    */
  198.   function AddBiblioRes($ID$res_table$type$sql_object)
  199.   {
  200.     $res_table=$sql_object->DBescape($res_table);
  201.     if ($this->_wichType($type'BIBLIO'== "error"exit();
  202.     $this->B_AUTHOR = strip_input($res_table[0]);
  203.     $this->B_TITLE = strip_input($res_table[1]);
  204.     $this->B_SUBTITLE = strip_input($res_table[2]);
  205.     $this->B_EDITOR = strip_input($res_table[3]);
  206.     $this->B_DATE = strip_input($res_table[4]);
  207.     $this->B_RANGE = $res_table[5];
  208.     $this->B_VALIDITY = 'Y';
  209.     $requete "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 . "');";
  210.     $last_id $sql_object->DBInsert ($requete1);
  211.     if (is_numeric($last_id)) {
  212.       $requete "INSERT INTO " $this->TDB_LIAISON . " VALUES(" $ID "," $last_id ", '" $this->ACTIVE_TYPE . "');";
  213.       $result $sql_object->DBInsert ($requete);
  214.     }
  215.     return $result;
  216.   }
  217.  
  218.   /**
  219.    * resources::ModifyBiblioRes()
  220.    * modification d'une ressource bibliographique
  221.    *
  222.    * @access public
  223.    * @param int $ID identifiant de la ressource
  224.    * @param object $sql_object 
  225.    * @param array $res_table tableau contenant les infos resources
  226.    * @return bool $result
  227.    */
  228.   function ModifyBiblioRes($ID$res_table$sql_object)
  229.   {
  230.     $res_table=$sql_object->DBescape($res_table);
  231.     $this->B_ID = $ID;
  232.     $this->B_AUTHOR = strip_input($res_table[0]);
  233.     $this->B_TITLE = strip_input($res_table[1]);
  234.     $this->B_SUBTITLE = strip_input($res_table[2]);
  235.     $this->B_EDITOR = strip_input($res_table[3]);
  236.     $this->B_DATE = strip_input($res_table[4]);
  237.     $requete "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 . "';";
  238.     $result $sql_object->DBQuery($requete);
  239.     return $result;
  240.   }
  241.  
  242.   /**
  243.    * resources::DeleteBiblioRes()
  244.    * suppression d'une ressource bibliographique
  245.    *
  246.    * @access public
  247.    * @param int $ID identifiant de la ressource a supprimer
  248.    * @param object $sql_object 
  249.    * @return bool $result
  250.    */
  251.   function DeleteBiblioRes($ID$sql_object)
  252.   {
  253.     if (is_numeric($ID)) {
  254.       $this->B_ID = $ID;
  255.     }
  256.     $requete "UPDATE  " $this->TDB_BIBLIO . " SET bibliores_validity='N' WHERE bibliores_id=" $this->B_ID . ";";
  257.     $result $sql_object->DBQuery($requete);
  258.     return $result;
  259.   }
  260.  
  261.   /**
  262.    * resources::AddLinkRes()
  263.    * Ajout d'une ressource de type lien
  264.    *
  265.    * @access public
  266.    * @param int $ID identifiant du père (rattachement)
  267.    * @param array $res_table tableau contenant les infos ressources
  268.    * @param string $type 'PUBLICATION' ou 'WORKSHOP'
  269.    * @param object $sql_object 
  270.    * @return integer $last_id
  271.    */
  272.   function AddLinkRes($ID$res_table$type$sql_object)
  273.   {
  274.     $res_table=$sql_object->DBescape($res_table);
  275.  
  276.     $notvalidlink _t('resources','invalid_link');
  277.     if ($this->_wichType($type'LINK'== "error"exit;
  278.     $this->L_TEXT = strip_input($res_table[0]);
  279.     if ($res_table[1== ''{
  280.       $this->L_MASK = $this->L_TEXT;
  281.     else {
  282.       $this->L_MASK = strip_input($res_table[1]);
  283.     }
  284.     if (is_numeric($res_table[2])) {
  285.       $this->L_RANGE = $res_table[2];
  286.     }
  287.     $this->L_VALIDITY = 'Y';
  288.     $requete "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 . "');";
  289.     $last_id $sql_object->DBInsert ($requete1);
  290.     if (is_numeric($last_id)) {
  291.       $requete "INSERT INTO " $this->TDB_LIAISON . " VALUES(" $ID "," $last_id ", '" $this->ACTIVE_TYPE . "');";
  292.       $result $sql_object->DBInsert ($requete);
  293.     }
  294.     return $result;
  295.   }
  296.  
  297.   /**
  298.    * resources::ModifyLinkRes()
  299.    * modification d'une ressource de type lien
  300.    *
  301.    * @access public
  302.    * @param int $ID identifiant de la ressource
  303.    * @param array $res_table tableau contenant les infos ressources
  304.    * @param object $sql_object 
  305.    * @return bool $result
  306.    */
  307.   function ModifyLinkRes($ID$res_table$sql_object)
  308.   {
  309.     $res_table=$sql_object->DBescape($res_table);
  310.  
  311.     $this->L_ID = $ID;
  312.     $this->L_TEXT = strip_input($res_table[0]);
  313.     if ($res_table[1== ''{
  314.       $this->L_MASK = $this->L_TEXT;
  315.     else {
  316.       $this->L_MASK = strip_input($res_table[1]);
  317.     }
  318.     $requete "UPDATE " $this->TDB_LINK . " SET linkres_text='" $this->L_TEXT . "' , linkres_mask='" $this->L_MASK . "' WHERE linkres_id='" $this->L_ID . "';";
  319.     echo $requete;
  320.     $result $sql_object->DBQuery($requete);
  321.     return $result;
  322.   }
  323.  
  324.   /**
  325.    * resources::DeleteLinkRes()
  326.    * suppression d'une ressource de type lien
  327.    *
  328.    * @access public
  329.    * @param int $ID identifiant de la ressource a supprimer
  330.    * @param object $sql_object 
  331.    * @return bool $result
  332.    */
  333.   function DeleteLinkRes($ID$sql_object)
  334.   {
  335.     if (is_numeric($ID)) {
  336.       $this->B_ID = $ID;
  337.     }
  338.     $requete "UPDATE  " $this->TDB_LINK . " SET linkres_validity='N' WHERE linkres_id=" $this->B_ID . ";";
  339.     $result $sql_object->DBQuery($requete);
  340.     return $result;
  341.   }
  342.  
  343.   /**
  344.    * resources::AddMultiRes()
  345.    * Ajout d'une ressource de type multimedia
  346.    *
  347.    * @access public
  348.    * @param int $ID identifiant du père (rattachement)
  349.    * @param array $res_table tableau contenant les infos ressources
  350.    * @param string $type 'PUBLICATION' ou 'WORKSHOP'
  351.    * @param object $sql_object 
  352.    * @return integer $last_id
  353.    */
  354.   function AddMultiRes($ID$res_table$type$sql_object)
  355.   {
  356.     $res_table=$sql_object->DBescape($res_table);
  357.  
  358.     if ($this->_wichType($type'MULTI'== "error"exit;
  359.     $this->M_NAME = strip_input($res_table[0]);
  360.  
  361.     $this->M_DESC = strip_input($res_table[1]);
  362.     $this->M_URI = strip_input($res_table[2]);
  363.     $this->M_RANGE = $res_table[3];
  364.     $this->M_VALIDITY = 'Y';
  365.     $requete "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 . "');";
  366.     $last_id $sql_object->DBInsert ($requete1);
  367.     if (is_numeric($last_id)) {
  368.       $requete "INSERT INTO " $this->TDB_LIAISON . " VALUES(" $ID "," $last_id ", '" $this->ACTIVE_TYPE . "');";
  369.       $result $sql_object->DBInsert ($requete);
  370.     }
  371.     return $result;
  372.   }
  373.  
  374.   /**
  375.    * resources::ModifyMultiRes()
  376.    * modification d'une ressource de type multimedia
  377.    *
  378.    * @access public
  379.    * @param int $ID identifiant de la ressource
  380.    * @param array $res_table tableau contenant les infos ressources
  381.    * @param object $sql_object 
  382.    * @return bool $result
  383.    */
  384.   function ModifyMultiRes($ID$res_table$sql_object)
  385.   {
  386.     $res_table=$sql_object->DBescape($res_table);
  387.  
  388.     $this->M_ID = $ID;
  389.     $this->M_NAME = strip_input($res_table[0]);
  390.     $this->M_DESC = strip_input($res_table[1]);
  391.     $this->M_URI = strip_input($res_table[2]);
  392.     $requete "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 . "';";
  393.     $result $sql_object->DBQuery($requete);
  394.  
  395.     return $result;
  396.   }
  397.  
  398.   /**
  399.    * resources::DeleteMultiRes()
  400.    * suppression d'une ressource multimedia
  401.    *
  402.    * @access public
  403.    * @param int $ID identifiant de la ressource a supprimer
  404.    * @param object $sql_object 
  405.    * @return bool $result
  406.    */
  407.   function DeleteMultiRes($ID$sql_object)
  408.   {
  409.     if (is_numeric($ID)) {
  410.       $this->M_ID = $ID;
  411.     }
  412.     $requete "UPDATE  " $this->TDB_MULTI . " SET multires_validity='N' WHERE multires_id=" $this->M_ID . ";";
  413.     $result $sql_object->DBQuery($requete);
  414.     return $result;
  415.   }
  416. }
  417.  
  418. ?>

Documentation generated on Fri, 01 Apr 2011 09:29:14 +0200 by phpDocumentor 1.4.1