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

Source for file class.project.php

Documentation is available at class.project.php

  1. <?php
  2. /**
  3.  * @package linea21.modules
  4.  * @subpackage project
  5.  * @author linea21 <info@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  *  Project Management
  10.  */
  11.  
  12. class project {
  13.   /* @param
  14.    * */
  15.   var $TDB_PROJECT = T_PROJECT// nom de la table.
  16.   var $ID;
  17.   var $PARENT_ID;
  18.   var $SCALE_ID;
  19.   var $PRIORITY_ID;
  20.   var $THEME_ID;
  21.   var $WORKSHOP_ID;
  22.   var $NAME;
  23.   var $DESCRIPTION;
  24.   var $BODY;
  25.   var $BEGIN_DATE;
  26.   var $ESTIMATED_DATE;
  27.   var $END_DATE;
  28.   var $COMPLETED;
  29.   var $SDI;
  30.   var $PUBLISHED_DATE;
  31.   var $POSTED_BY;
  32.   var $DATE_CREA;
  33.   var $STATUT;
  34.   var $LAST_MODIFY;
  35.   protected $dispatcher = null;
  36.  
  37.   public function __construct()
  38.   {
  39.     $this->dispatcher = $GLOBALS['dispatcher'];
  40.   }
  41.  
  42.   public function __call($method$arguments)
  43.   {
  44.     $event $this->dispatcher->notifyUntil(new sfEvent($this'project.extensible_function'array(
  45.       'method'    => $method,
  46.       'arguments' => $arguments
  47.     )));
  48.     if (!$event->isProcessed())
  49.     {
  50.       throw new Exception(sprintf('Call to undefined method %s::%s.'get_class($this)$method));
  51.     }
  52.  
  53.     return $event->getReturnValue();
  54.   }
  55.  
  56.   /**
  57.    * project::_getDate()
  58.    * date courante et ajout
  59.    *
  60.    * @access private
  61.    * @param int $m chiffre des mois
  62.    * @param int $d chiffre des jours
  63.    * @param int $y chiffre des années
  64.    * @return string $format_date
  65.    * @return 
  66.    */
  67.   function _getDate($m 0$d 0$y 0)
  68.   {
  69.     $format_date mktime(date("H")date("i")date("s")date("m"$mdate("d"date("Y")-1);
  70.     $format_date strftime('%Y-%m-%d %H:%M:%S'$format_date);
  71.  
  72.     return $format_date;
  73.   }
  74.  
  75.   /**
  76.    * project::CheckDataIntegrity()
  77.    * Vérification intégrité des données
  78.    *
  79.    * @access public
  80.    * @param array $table : contient les composants Nécessaires d'un projet
  81.    * @return boolean true
  82.    *  si verifié, sinon string 'message d'erreur'
  83.    */
  84.  
  85.   function CheckDataIntegrity($table)
  86.   {
  87.       // Filter data event + return value
  88.       $r $this->dispatcher->filter(new sfEvent($this'project.before_datacheck'array('data' => $table))$table);
  89.       $table $r->getReturnValue();
  90.       
  91.     if (strlen($table[0]3return _t('project','no_name');
  92.     if (strlen($table[1]3return _t('project','no_description');
  93.     if (strlen($table[2]3return _t('project','no_body');
  94.     if ($table[5<= || !is_numeric($table[5])) return _t('project','no_priority');
  95.     if ($table[4<= || !is_numeric($table[4])) return _t('project','no_scale');
  96.     if(!empty($table[6])) return checkdate_validity($table[6]_t('project','begin_date_err'));
  97.     if(!empty($table[7])) return checkdate_validity($table[7]_t('project','estimated_date_err'));
  98.     if(!empty($table[8])) return checkdate_validity($table[8]_t('project','end_date_err'));
  99.     if(!is_numeric($table[14]|| $table[14]>100 || $table[14]<return _t('project','progression_error');
  100.     
  101.     // Notify the beginning of the current method
  102.     $this->dispatcher->notify(new sfEvent($this'project.after_datacheck'array('data' => $table)));
  103.  
  104.     return true;
  105.   }
  106.  
  107.   /**
  108.    * project::AddProject()
  109.    * Ajout d'un projet
  110.    *
  111.    * @access public
  112.    * @param array $table_project : contient les composants d'un projet
  113.    * @param object $sql_object 
  114.    * @return integer $last_id
  115.    */
  116.   function AddProject($table_project$sql_object)
  117.   {
  118.       // Filter data event + return value
  119.       $r $this->dispatcher->filter(new sfEvent($this'project.before_add'array('data' => $table_project))$table_project);
  120.       $table_project $r->getReturnValue();
  121.       
  122.     $table_project=$sql_object->DBescape($table_project);
  123.  
  124.     if ($table_project[0!= ''{
  125.       $this->NAME = strip_input(trim($table_project[0])true);
  126.     }
  127.     if ($table_project[1!= ''{
  128.       $this->DESCRIPTION = strip_input(trim($table_project[1])true);
  129.     }
  130.     if ($table_project[2!= ''{
  131.       $this->BODY = strip_input(trim($table_project[2])true);
  132.     }
  133.     if (is_numeric($table_project[3]&& $table_project[3!= -1{
  134.       $this->PARENT_ID = $table_project[3];
  135.     else {
  136.       $this->PARENT_ID = 0;
  137.     }
  138.     if (is_numeric($table_project[4])) {
  139.       $this->SCALE_ID = $table_project[4];
  140.     }
  141.     if (is_numeric($table_project[5])) {
  142.       $this->PRIORITY_ID = $table_project[5];
  143.     }
  144.     if ($table_project[6!= ''{
  145.       $this->BEGIN_DATE = formatDate($table_project[6]true);
  146.     else {
  147.       $this->BEGIN_DATE = '0001-01-01';
  148.     }
  149.     if ($table_project[7!= ''{
  150.       $this->ESTIMATED_DATE = formatDate($table_project[7]true);
  151.     else {
  152.       $this->ESTIMATED_DATE = '0001-01-01';
  153.     }
  154.     if ($table_project[8!= ''{
  155.       $this->END_DATE = formatDate($table_project[8]true);
  156.     else {
  157.       $this->END_DATE = '0001-01-01';
  158.     }
  159.     if (is_numeric($table_project[9])) {
  160.       $this->POSTED_BY = $table_project[9];
  161.     }
  162.     if ($table_project[10!= ''{
  163.       $this->STATUT = strtoupper($table_project[10]);
  164.     }
  165.     if (is_numeric($table_project[11]&& $table_project[11!= -1{
  166.       $this->THEME_ID = $table_project[11];
  167.     else {
  168.       $this->THEME_ID = 0;
  169.     }
  170.     if (is_numeric($table_project[12]&& $table_project[12!= -1{
  171.       $this->WORKSHOP_ID = $table_project[12];
  172.     else {
  173.       $this->WORKSHOP_ID = 0;
  174.     }
  175.     $this->SDI = $table_project[13];
  176.     if ($this->STATUT == 'P'{
  177.       $this->PUBLISHED_DATE = $this->_getDate();
  178.     else {
  179.       $this->PUBLISHED_DATE = '0001-01-01';
  180.     }
  181.  
  182.      $this->COMPLETED = $table_project[14];
  183.  
  184.     $query "INSERT INTO " $this->TDB_PROJECT . " (project_name, project_description, project_body, ".
  185.     "project_parent_id, project_priority_id, project_scale_id, " .
  186.     "project_begin_date, project_estimated_date, project_end_date, ".
  187.     "project_completed, project_theme_id, project_workshop_id, ".
  188.     "project_posted_by, project_published_date, " .
  189.     "project_statut, project_date_crea) " .
  190.     "VALUES('" $this->NAME . "', '" $this->DESCRIPTION . "', '" $this->BODY .
  191.     "', " $this->PARENT_ID . ", " $this->PRIORITY_ID . ", " $this->SCALE_ID .
  192.     ", '" $this->BEGIN_DATE . "', '" $this->ESTIMATED_DATE . "', '" $this->END_DATE .
  193.     "', " $this->COMPLETED . ", " $this->THEME_ID . ", " $this->WORKSHOP_ID .
  194.     ", " $this->POSTED_BY . ", '" $this->PUBLISHED_DATE . "' , '" $this->STATUT .
  195.     "', now());";
  196.      
  197.     $this->ID = $sql_object->DBInsert ($query1);
  198.     $this->_addSDI($sql_object);
  199.     
  200.     // Notify the end of the current method
  201.     $this->dispatcher->notify(new sfEvent($this'project.after_add'array('data' => $table_project'id' => $this->ID)));
  202.  
  203.     return $this->ID;
  204.   }
  205.  
  206.   /**
  207.    * project::DeleteProject()
  208.    * suppression d'un projet
  209.    *
  210.    * @access public
  211.    * @param int $ID : identifiant du projet
  212.    * @param object $sql_object 
  213.    * @return bool $result
  214.    */
  215.  
  216.   function DeleteProject($ID$sql_object)
  217.   {
  218.       // Notify the end of the current method
  219.       $this->dispatcher->notify(new sfEvent($this'project.delete'array('id' => $ID)));
  220.       
  221.     $this->ID = $ID;
  222.  
  223.     $query "UPDATE " $this->TDB_PROJECT . " set project_statut='E', project_last_modify=NOW() WHERE project_id='" $this->ID . "';";
  224.     $result $sql_object->DBQuery($query);
  225.     if($result{
  226.       $query "DELETE FROM " J_PROJECT_SDI " WHERE jps_project_id='".$this->ID."';";
  227.       $res $sql_object->DBQuery($query);
  228.     }
  229.     if($result{
  230.       $query "UPDATE " $this->TDB_PROJECT . " set project_parent_id=0 WHERE project_parent_id='" $this->ID . "';";
  231.       $result $sql_object->DBQuery($query);
  232.     }
  233.     return $result;
  234.   }
  235.  
  236.   /**
  237.    * project::ModifyProject()
  238.    * modification d'un projet
  239.    *
  240.    * @access public
  241.    * @param integer $ID : identifiant du projet
  242.    * @param object $sql_object 
  243.    * @param array $table_project : contient les composants d'un projet
  244.    * @return boolean $result
  245.    */
  246.   function ModifyProject($ID$table_project$sql_object)
  247.   {
  248.  
  249.       // Filter data event + return value
  250.       $r $this->dispatcher->filter(new sfEvent($this'project.before_modify'array('data' => $table_project'id' => $ID))$table_project);
  251.       $table_project $r->getReturnValue();
  252.       
  253.     $table_project=$sql_object->DBescape($table_project);
  254.  
  255.     if (is_numeric($ID)) {
  256.       $this->ID = $ID;
  257.     }
  258.  
  259.     if ($table_project[0!= ''{
  260.       $this->NAME = strip_input(trim($table_project[0])true);
  261.     }
  262.     if ($table_project[1!= ''{
  263.       $this->DESCRIPTION = strip_input(trim($table_project[1])true);
  264.     }
  265.     if ($table_project[2!= ''{
  266.       $this->BODY = strip_input(trim($table_project[2])true);
  267.     }
  268.     if (is_numeric($table_project[3]&& $table_project[3!= -1{
  269.       $this->PARENT_ID = $table_project[3];
  270.     else {
  271.       $this->PARENT_ID = 0;
  272.     }
  273.     if (is_numeric($table_project[4])) {
  274.       $this->SCALE_ID = $table_project[4];
  275.     }
  276.     if (is_numeric($table_project[5])) {
  277.       $this->PRIORITY_ID = $table_project[5];
  278.     }
  279.     if ($table_project[6!= ''{
  280.       $this->BEGIN_DATE = formatDate($table_project[6]true);
  281.     else {
  282.       $this->BEGIN_DATE = '0001-01-01';
  283.     }
  284.     if ($table_project[7!= ''{
  285.       $this->ESTIMATED_DATE = formatDate($table_project[7]true);
  286.     else {
  287.       $this->ESTIMATED_DATE = '0001-01-01';
  288.     }
  289.     if ($table_project[8!= ''{
  290.       $this->END_DATE = formatDate($table_project[8]true);
  291.     else {
  292.       $this->END_DATE = '0001-01-01';
  293.     }
  294.     if ($table_project[9!= ''{
  295.       $this->STATUT = strtoupper($table_project[9]);
  296.     }
  297.     if (is_numeric($table_project[11]&& $table_project[11!= -1{
  298.       $this->THEME_ID = $table_project[11];
  299.     else {
  300.       $this->THEME_ID = 0;
  301.     }
  302.     if (is_numeric($table_project[12]&& $table_project[12!= -1{
  303.       $this->WORKSHOP_ID = $table_project[12];
  304.     else {
  305.       $this->WORKSHOP_ID = 0;
  306.     }
  307.     $this->SDI = $table_project[13];
  308.     if ($this->STATUT == 'P'{
  309.       $this->PUBLISHED_DATE = $this->_getDate();
  310.     else {
  311.       $this->PUBLISHED_DATE = '0001-01-01';
  312.     }
  313.     
  314.     $this->COMPLETED = $table_project[14];
  315.  
  316.     $mask $this->_HavePublishedDate($table_project[10]);
  317.  
  318.     $query "UPDATE  " $this->TDB_PROJECT . " SET project_name='" $this->NAME . "', project_description='" $this->DESCRIPTION"', project_body='" $this->BODY . "' , project_parent_id='" $this->PARENT_ID . "', project_scale_id='" $this->SCALE_ID . "', project_theme_id='" $this->THEME_ID ."', project_workshop_id='" $this->WORKSHOP_ID ."', project_priority_id='" $this->PRIORITY_ID . "', project_begin_date='" $this->BEGIN_DATE . "', project_estimated_date='" $this->ESTIMATED_DATE . "', project_end_date='".$this->END_DATE."', project_completed=".$this->COMPLETED.", project_statut='" $this->STATUT . "', project_last_modify=NOW() " $mask " WHERE project_id='" $this->ID . "';";
  319.     $result $sql_object->DBQuery($query);
  320.     $result $this->_modifySDI($sql_object);
  321.     
  322.     // Notify the end of the current method
  323.     $this->dispatcher->notify(new sfEvent($this'project.after_modify'array('data' => $table_project'id' => $this->ID)));
  324.  
  325.     return $result;
  326.   }
  327.   
  328.   /**
  329.    * project::changeRanges()
  330.    * changes Project range
  331.    *
  332.    * @access public
  333.    * @param array : Id (key) and ranges (value)
  334.    * @param object $sql_object 
  335.    * @return bool $result
  336.    */
  337.  
  338.   function changeRanges($array$sql_object)
  339.   {
  340.  
  341.     foreach ($array as $key => $value{
  342.       $query "UPDATE " $this->TDB_PROJECT . " set project_range='".$value."' WHERE project_id='" $key "';";
  343.       $result $sql_object->DBQuery($query);
  344.     }
  345.     
  346.     // Notify the beginning of the current method
  347.     $this->dispatcher->notify(new sfEvent($this'project.change_ranges'array('data' => $array)));
  348.  
  349.     return $result;
  350.   }
  351.  
  352.   /**
  353.    * project::_addSDI()
  354.    * associate indicators to project
  355.    *
  356.    * @access private
  357.    */
  358.   function _addSDI($sql_object{
  359.       
  360.       // Notify the beginning of the current method
  361.       $this->dispatcher->notify(new sfEvent($this'project.add_sdi'array('data' => $this->SDI)));
  362.       
  363.     foreach ($this->SDI as &$value{
  364.       $query "INSERT INTO "J_PROJECT_SDI " VALUES(".$this->ID.", ".$value.");";
  365.       $result $sql_object->DBQuery($query);
  366.     }
  367.     return $result;
  368.   }
  369.  
  370.   /**
  371.    * project::_modifySDI()
  372.    * associate indicators to project
  373.    *
  374.    * @access private
  375.    */
  376.   function _modifySDI($sql_object{
  377.       
  378.       // Notify the beginning of the current method
  379.       $this->dispatcher->notify(new sfEvent($this'project.modify_sdi'array('data' => $this->SDI)));
  380.       
  381.     $query "DELETE FROM " J_PROJECT_SDI " WHERE jps_project_id='".$this->ID."';";
  382.     $result $sql_object->DBQuery($query);
  383.     if(count($this->SDI)>0{
  384.       $result $this->_addSDI($sql_object);
  385.     }
  386.  
  387.     return $result;
  388.   }
  389.  
  390.   /**
  391.    * project::_HavePublishedDate()
  392.    * Détermine la date de publication a inserer dans la bdd
  393.    *
  394.    * @access private
  395.    * @param string $current_status : statut actuel de l'actualité
  396.    * @return string $sql_mask
  397.    */
  398.   function _HavePublishedDate($current_status)
  399.   {
  400.     switch ($this->STATUT{
  401.       case 'P':
  402.         if ($current_status == 'D'$sql_mask ", project_published_date= NOW()";
  403.         else $sql_mask '';
  404.         break;
  405.       case 'D':
  406.         $sql_mask ", project_published_date= '0001-01-01'";
  407.         break;
  408.       default:
  409.         $sql_mask '';
  410.     }
  411.     return $sql_mask;
  412.   }
  413. }
  414.  
  415. ?>

Documentation generated on Mon, 08 Apr 2013 18:12:56 +0200 by phpDocumentor 1.4.1