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

Source for file class.publication.php

Documentation is available at class.publication.php

  1. <?php
  2. /**
  3.  * @package linea21.modules
  4.  * @subpackage publication
  5.  * @author linea21 <info@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  *  Publication Management
  10.  */
  11.  
  12. class publication {
  13.   /* @param
  14.    * */
  15.   var $TDB_PUBLI = T_PUBLI; // nom de la table.
  16.   var $ID;
  17.   var $TITLE;
  18.   var $RESUME;
  19.   var $THEME;
  20.   var $SCALE;
  21.   var $LEVEL;
  22.   var $POSTED_BY;
  23.   var $PUBLISHED_DATE;
  24.   var $COMMENT;
  25.   var $DATE_CREA;
  26.   var $LAST_MODIFY;
  27.   var $STATUT;
  28.   protected $dispatcher = null;
  29.  
  30.   public function __construct()
  31.   {
  32.     $this->dispatcher = $GLOBALS['dispatcher'];
  33.   }
  34.  
  35.   public function __call($method, $arguments)
  36.   {
  37.     $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'publication.extensible_function', array(
  38.       'method'    => $method,
  39.       'arguments' => $arguments
  40.     )));
  41.     if (!$event->isProcessed())
  42.     {
  43.       throw new Exception(sprintf('Call to undefined method %s::%s.', get_class($this), $method));
  44.     }
  45.  
  46.     return $event->getReturnValue();
  47.   }
  48.  
  49.   /**
  50.    * publication::CheckDataIntegrity()
  51.    * Vérification intégrité des données
  52.    *
  53.    * @access public
  54.    * @param array $table : contient les composants d'une publication
  55.    * @return boolean true
  56.    *  si verifié, sinon string 'message d'erreur'
  57.    */
  58.   function CheckDataIntegrity($table, $sql_object)
  59.   {
  60.       // Filter data event + return value
  61.       $r = $this->dispatcher->filter(new sfEvent($this, 'publication.before_datacheck', array('data' => $table)), $table);
  62.       $table = $r->getReturnValue();
  63.       
  64.     if (strlen($table[0]) < 3) return _t('publication','no_title');
  65.     if (strlen($table[1]) < 3) return _t('publication','no_resume');
  66.     if ($table[2] == -1) return _t('publication','no_theme');
  67.     if ($table[3] == -1) return _t('publication','no_scale');
  68.     if (strlen(trim($table[5])) < 2) return _t('publication','no_author');
  69.     $result = $this->_CheckUserValidity($table[5], $sql_object);
  70.     if (!is_numeric($result['user_id'])) return _t('publication','author_not_valid');
  71.     if ($result['publi_right'] == 'U') return _t('publication','author_not_rights');
  72.     
  73.     // Notify the beginning of the current method
  74.     $this->dispatcher->notify(new sfEvent($this, 'publication.after_datacheck', array('data' => $table)));
  75.     
  76.     return $result;
  77.     
  78.   }
  79.  
  80.   /**
  81.    * publication::_CheckUserValidity()
  82.    * Vérification validité de l'utilisateur
  83.    *
  84.    * @access private
  85.    * @param string $login 
  86.    * @param object $sql_object 
  87.    * @return array contenant $user_id et droit si login associé à la publication
  88.    *  sinon renvoie false
  89.    */
  90.   function _CheckUserValidity($login, $sql_object)
  91.   {
  92.       // Notify the beginning of the current method
  93.       $this->dispatcher->notify(new sfEvent($this, 'publication.check_user', array('login' => $login)));
  94.       
  95.     $user = array('user_id' => '', 'publi_right' => '');
  96.  
  97.     $q = "SELECT user_id, rights_publication FROM " . T_USER . " LEFT OUTER JOIN " . T_RIGHT . " ON user_rights=rights_id WHERE user_login= '" . $login . "' AND user_validity='Y';";
  98.     $result = $sql_object->DBSelect($q);
  99.  
  100.     if ($result == 0) return false;
  101.     if (count($result) > 1) exit();
  102.     else {
  103.       $user['user_id'] = $result[0]['user_id'];
  104.       $user['publi_right'] = $result[0]['rights_publication'];
  105.     }
  106.     
  107.     return $user;
  108.   }
  109.  
  110.   /**
  111.    * publication::AddPublication()
  112.    * Ajout d'une nouvelle publication/dossier
  113.    *
  114.    * @access public
  115.    * @param array $table_publi contient les composants d'une publication
  116.    * @param object $sql_object 
  117.    * @return integer $last_id
  118.    */
  119.   function AddPublication($table_publi, $sql_object)
  120.   {
  121.       // Filter data event + return value
  122.       $r = $this->dispatcher->filter(new sfEvent($this, 'publication.before_add', array('data' => $table_publi)), $table_publi);
  123.       $table_publi = $r->getReturnValue();
  124.       
  125.     $table_publi=$sql_object->DBescape($table_publi);
  126.  
  127.     if($table_publi[4] == -1) $table_publi[4]=0;
  128.  
  129.     $this->TITLE = strip_input(trim($table_publi[0]), true);
  130.     $this->RESUME = strip_input(trim($table_publi[1]), true);
  131.     $this->THEME = $table_publi[2];
  132.     $this->SCALE = $table_publi[3];
  133.     $this->LEVEL = $table_publi[4];
  134.     $this->POSTED_BY = $table_publi[5];
  135.     $this->COMMENT = strip_input(trim($table_publi[6], true));
  136.  
  137.     if ($table_publi[7] != '') {
  138.       $this->STATUT = strtoupper($table_publi[7]);
  139.     }
  140.     if ($this->STATUT == 'P') {
  141.       $this->PUBLISHED_DATE = "NOW()";
  142.     } else {
  143.       $this->PUBLISHED_DATE = "'0001-01-01'";
  144.     }
  145.     $q = "INSERT INTO " . $this->TDB_PUBLI . " (publi_title, publi_resume, publi_theme, publi_scale, publi_level, publi_posted_by, publi_published_date, publi_comment, publi_statut, publi_date_crea) VALUES('" . $this->TITLE . "', '" . $this->RESUME . "', " . $this->THEME . ", " . $this->SCALE . ", " . $this->LEVEL . ", " . $this->POSTED_BY . ", " . $this->PUBLISHED_DATE . ", '" . $this->COMMENT . "', '" . $this->STATUT . "', NOW());";
  146.     $last_id = $sql_object->DBInsert ($q, 1);
  147.     
  148.     // Notify the end of the current method
  149.     $this->dispatcher->notify(new sfEvent($this, 'publication.after_add', array('data' => $table_publi, 'id' => $last_id)));
  150.     
  151.     return $last_id;
  152.   }
  153.  
  154.   /**
  155.    * publication::ModifyPublication()
  156.    * modification d'une publication
  157.    *
  158.    * @access public
  159.    * @param int $ID identifiant de la publication
  160.    * @param array $table_publi contient les composants d'une publication
  161.    * @param object $sql_object 
  162.    * @return bool $result
  163.    */
  164.   function ModifyPublication($ID, $table_publi, $sql_object)
  165.   {
  166.  
  167.       // Filter data event + return value
  168.       $r = $this->dispatcher->filter(new sfEvent($this, 'publication.before_modify', array('data' => $table_publi, 'id' => $ID)), $table_publi);
  169.       $table_publi = $r->getReturnValue();
  170.       
  171.     $table_publi=$sql_object->DBescape($table_publi);
  172.  
  173.     if($table_publi[4] == -1) $table_publi[4]=0;
  174.      
  175.     if (is_numeric($ID)) {
  176.       $this->ID = $ID;
  177.     } else exit;
  178.     $this->TITLE = strip_input(trim($table_publi[0]), true);
  179.     $this->RESUME = strip_input(trim($table_publi[1]), true);
  180.     $this->THEME = $table_publi[2];
  181.     $this->SCALE = $table_publi[3];
  182.     $this->LEVEL = $table_publi[4];
  183.     $this->POSTED_BY = $table_publi[5];
  184.     $this->COMMENT = strip_input(trim($table_publi[6], true));
  185.     $this->STATUT = $table_publi[7];
  186.  
  187.     $mask = $this->_HavePublishedDate($table_publi[8]);
  188.  
  189.     $q = "UPDATE  " . $this->TDB_PUBLI . " set publi_title='" . $this->TITLE . "', publi_resume='" . $this->RESUME . "' , publi_theme='" . $this->THEME . "', publi_scale='" . $this->SCALE . "', publi_level='" . $this->LEVEL . "', publi_comment='" . $this->COMMENT . "', publi_posted_by='" . $this->POSTED_BY . "', publi_last_modify=NOW(), publi_statut='" . $this->STATUT . "'" . $mask . " WHERE publi_id='" . $this->ID . "';";
  190.     $result = $sql_object->DBQuery($q);
  191.     
  192.     // Notify the end of the current method
  193.     $this->dispatcher->notify(new sfEvent($this, 'publication.after_modify', array('data' => $table_publi, 'id' => $this->ID)));
  194.     
  195.     return $result;
  196.   }
  197.   
  198.   
  199.   /**
  200.    * publication::changeRanges()
  201.    * changes Workshop range
  202.    *
  203.    * @access public
  204.    * @param array : Id (key) and ranges (value)
  205.    * @param object $sql_object 
  206.    * @return bool $result
  207.    */
  208.  
  209.   function changeRanges($array, $sql_object)
  210.   {
  211.  
  212.     foreach ($array as $key => $value) {
  213.       $query = "UPDATE " . $this->TDB_PUBLI . " set publi_range='".$value."' WHERE publi_id='" . $key . "';";
  214.       $result = $sql_object->DBQuery($query);
  215.     }
  216.     
  217.     // Notify the beginning of the current method
  218.     $this->dispatcher->notify(new sfEvent($this, 'publication.change_ranges', array('data' => $array)));
  219.  
  220.     return $result;
  221.   }
  222.  
  223.   /**
  224.    * publication::_HavePublishedDate()
  225.    * Détermine la date de publication a inserer dans la bdd
  226.    *
  227.    * @access private
  228.    * @param string $current_status : statut actuel de la publication
  229.    * @return string $sql_mask
  230.    */
  231.   function _HavePublishedDate($current_status)
  232.   {
  233.     switch ($this->STATUT) {
  234.       case 'P':
  235.         if ($current_status == 'D') $sql_mask = ", publi_published_date= NOW()";
  236.         else $sql_mask = '';
  237.         break;
  238.       case 'D':
  239.         $sql_mask = ", publi_published_date= '0001-01-01'";
  240.         break;
  241.       default:
  242.         $sql_mask = '';
  243.     }
  244.     return $sql_mask;
  245.   }
  246.  
  247.   /**
  248.    * publication::DeletePublication()
  249.    * suppression d'une publication
  250.    *
  251.    * @access public
  252.    * @param int $ID identifiant de la publication a supprimer
  253.    * @param object $sql_object 
  254.    * @return bool $result
  255.    */
  256.   function DeletePublication($ID, $sql_object)
  257.   {
  258.       // Notify the beginning of the current method
  259.       $this->dispatcher->notify(new sfEvent($this, 'publication.delete', array('id' => $ID)));
  260.       
  261.     $this->ID = $ID;
  262.     $q = "UPDATE  " . $this->TDB_PUBLI . " set publi_statut='E', publi_last_modify=NOW() WHERE publi_id=" . $this->ID . ";";
  263.     $result = $sql_object->DBQuery($q);
  264.  
  265.     return $result;
  266.   }
  267. }
  268.  
  269. ?>

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