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 $BUDGET;
  26.   var $COORDINATOR;
  27.   var $PARTNERS;
  28.   var $BEGIN_DATE;
  29.   var $ESTIMATED_DATE;
  30.   var $END_DATE;
  31.   var $COMPLETED;
  32.   var $SDI;
  33.   var $PUBLISHED_DATE;
  34.   var $POSTED_BY;
  35.   var $DATE_CREA;
  36.   var $STATUT;
  37.   var $LAST_MODIFY;
  38.   protected $dispatcher = null;
  39.  
  40.   public function __construct()
  41.   {
  42.     $this->dispatcher = $GLOBALS['dispatcher'];
  43.   }
  44.  
  45.   public function __call($method$arguments)
  46.   {
  47.     $event $this->dispatcher->notifyUntil(new sfEvent($this'project.extensible_function'array(
  48.       'method'    => $method,
  49.       'arguments' => $arguments
  50.     )));
  51.     if (!$event->isProcessed())
  52.     {
  53.       throw new Exception(sprintf('Call to undefined method %s::%s.'get_class($this)$method));
  54.     }
  55.  
  56.     return $event->getReturnValue();
  57.   }
  58.  
  59.   /**
  60.    * project::_getDate()
  61.    * date courante et ajout
  62.    *
  63.    * @access private
  64.    * @param int $m chiffre des mois
  65.    * @param int $d chiffre des jours
  66.    * @param int $y chiffre des années
  67.    * @return string $format_date
  68.    * @return 
  69.    */
  70.   function _getDate($m 0$d 0$y 0)
  71.   {
  72.     $format_date mktime(date("H")date("i")date("s")date("m"$mdate("d"date("Y")-1);
  73.     $format_date strftime('%Y-%m-%d %H:%M:%S'$format_date);
  74.  
  75.     return $format_date;
  76.   }
  77.  
  78.   /**
  79.    * project::CheckDataIntegrity()
  80.    * Vérification intégrité des données
  81.    *
  82.    * @access public
  83.    * @param array $table : contient les composants Nécessaires d'un projet
  84.    * @return boolean true
  85.    *  si verifié, sinon string 'message d'erreur'
  86.    */
  87.  
  88.   function CheckDataIntegrity($table)
  89.   {
  90.       // Filter data event + return value
  91.       $r $this->dispatcher->filter(new sfEvent($this'project.before_datacheck'array('data' => $table))$table);
  92.       $table $r->getReturnValue();
  93.       _debug("budget::".$table[15]);
  94.     if (strlen($table[0]3return _t('project','no_name');
  95.     if (strlen($table[1]3return _t('project','no_description');
  96.     if (strlen($table[2]3return _t('project','no_body');
  97.     if ($table[5<= || !is_numeric($table[5])) return _t('project','no_priority');
  98.     if ($table[4<= || !is_numeric($table[4])) return _t('project','no_scale');
  99.     
  100.     if(!empty($table[6])) {
  101.         $r checkdate_validity($table[6]_t('project','begin_date_err'));
  102.         if(is_string($r)) return $r;
  103.     }
  104.     if(!empty($table[7])) {
  105.         $r checkdate_validity($table[7]_t('project','estimated_date_err'));
  106.         if(is_string($r)) return $r;
  107.     }
  108.     if(!empty($table[8])) {
  109.         $r checkdate_validity($table[8]_t('project','end_date_err'));
  110.         if(is_string($r)) return $r;
  111.     }
  112.     
  113.     if(!is_numeric($table[14]|| $table[14]>100 || $table[14]<return _t('project','progression_error');
  114.     if(!empty($table[15]&& !is_numeric($table[15])) return _t('project','budget_integer');
  115.     
  116.     // Notify the beginning of the current method
  117.     $this->dispatcher->notify(new sfEvent($this'project.after_datacheck'array('data' => $table)));
  118.  
  119.     return true;
  120.   }
  121.  
  122.   /**
  123.    * project::AddProject()
  124.    * Ajout d'un projet
  125.    *
  126.    * @access public
  127.    * @param array $array : contient les composants d'un projet
  128.    * @param object $sql_object 
  129.    * @return integer $last_id
  130.    */
  131.   function AddProject($array$sql_object)
  132.   {
  133.       // Filter data event + return value
  134.       $r $this->dispatcher->filter(new sfEvent($this'project.before_add'array('data' => $array))$array);
  135.       $array $r->getReturnValue();
  136.       
  137.     $array=$sql_object->DBescape($array);
  138.  
  139.     if ($array[0!= ''{
  140.       $this->NAME = strip_input(trim($array[0])true);
  141.     }
  142.     if ($array[1!= ''{
  143.       $this->DESCRIPTION = strip_input(trim($array[1])true);
  144.     }
  145.     if ($array[2!= ''{
  146.       $this->BODY = strip_input(trim($array[2])true);
  147.     }
  148.     if (is_numeric($array[3]&& $array[3!= -1{
  149.       $this->PARENT_ID = $array[3];
  150.     else {
  151.       $this->PARENT_ID = 0;
  152.     }
  153.     if (is_numeric($array[4])) {
  154.       $this->SCALE_ID = $array[4];
  155.     }
  156.     if (is_numeric($array[5])) {
  157.       $this->PRIORITY_ID = $array[5];
  158.     }
  159.     if ($array[6!= ''{
  160.       $this->BEGIN_DATE = formatDate($array[6]true);
  161.     else {
  162.       $this->BEGIN_DATE = '0001-01-01';
  163.     }
  164.     if ($array[7!= ''{
  165.       $this->ESTIMATED_DATE = formatDate($array[7]true);
  166.     else {
  167.       $this->ESTIMATED_DATE = '0001-01-01';
  168.     }
  169.     if ($array[8!= ''{
  170.       $this->END_DATE = formatDate($array[8]true);
  171.     else {
  172.       $this->END_DATE = '0001-01-01';
  173.     }
  174.     if (is_numeric($array[9])) {
  175.       $this->POSTED_BY = $array[9];
  176.     }
  177.     if ($array[10!= ''{
  178.       $this->STATUT = strtoupper($array[10]);
  179.     }
  180.     if (is_numeric($array[11]&& $array[11!= -1{
  181.       $this->THEME_ID = $array[11];
  182.     else {
  183.       $this->THEME_ID = 0;
  184.     }
  185.     if (is_numeric($array[12]&& $array[12!= -1{
  186.       $this->WORKSHOP_ID = $array[12];
  187.     else {
  188.       $this->WORKSHOP_ID = 0;
  189.     }
  190.     $this->SDI = $array[13];
  191.     if ($this->STATUT == 'P'{
  192.       $this->PUBLISHED_DATE = $this->_getDate();
  193.     else {
  194.       $this->PUBLISHED_DATE = '0001-01-01';
  195.     }
  196.  
  197.      $this->COMPLETED = $array[14];
  198.      
  199.      if(!empty($array[15])) {
  200.          $this->BUDGET = str_replace(' '''$array[15]);
  201.      else {
  202.          $this->BUDGET = "NULL";
  203.      }
  204.      
  205.      $this->COORDINATOR = $array[16];
  206.      
  207.      $this->PARTNERS = $array[17];
  208.  
  209.     $query "INSERT INTO " $this->TDB_PROJECT . " (project_name, project_description, project_body, ".
  210.     "project_budget, " .
  211.     "project_parent_id, project_priority_id, project_scale_id, " .
  212.     "project_begin_date, project_estimated_date, project_end_date, ".
  213.     "project_completed, project_theme_id, project_workshop_id, ".
  214.     "project_posted_by, project_published_date, " .
  215.     "project_statut, project_date_crea) " .
  216.     "VALUES('" $this->NAME . "', '" $this->DESCRIPTION . "', '" $this->BODY .
  217.     "', " $this->BUDGET . ", " $this->PARENT_ID . ", " $this->PRIORITY_ID . ", " $this->SCALE_ID .
  218.     ", '" $this->BEGIN_DATE . "', '" $this->ESTIMATED_DATE . "', '" $this->END_DATE .
  219.     "', " $this->COMPLETED . ", " $this->THEME_ID . ", " $this->WORKSHOP_ID .
  220.     ", " $this->POSTED_BY . ", '" $this->PUBLISHED_DATE . "' , '" $this->STATUT .
  221.     "', now());";
  222.      
  223.     $this->ID = $sql_object->DBInsert ($query1);
  224.     $this->_addSDI($sql_object);
  225.     $this->addActors($this->ID$this->COORDINATOR'coordinator');
  226.     $this->addActors($this->ID$this->PARTNERS'partner');
  227.     
  228.     // Notify the end of the current method
  229.     $this->dispatcher->notify(new sfEvent($this'project.after_add'array('data' => $array'id' => $this->ID)));
  230.  
  231.     return $this->ID;
  232.   }
  233.   
  234.   
  235.   /**
  236.    * project::modifyActors()
  237.    * Ajout d'un ou plusieurs acteurs au projet
  238.    *
  239.    * @access private
  240.    * @param int $id identifiant du projet
  241.    * @param string $content acteurs séparés par des virgules
  242.    * @param string $type 
  243.    * @return integer $last_id
  244.    */
  245.   private function modifyActors($id$content$type{
  246.       
  247.       global $sql_object;
  248.        
  249.       // Notify the beginning of the current method
  250.       $this->dispatcher->notify(new sfEvent($this'project.modify_actor'array('id' => $id'content' => $content'type' => $type)));
  251.        
  252.       $query "DELETE FROM " J_PROJECT_ACTOR " WHERE jpa_project_id='".$id."' AND jpa_type='" $type "';";
  253.       $result $sql_object->DBQuery($query);
  254.       
  255.       if(!empty($content)) {
  256.           $result $this->addActors($id$content$type);
  257.       }
  258.   
  259.       return $result;
  260.   }
  261.   
  262.   /**
  263.    * project::addActors()
  264.    * Ajout d'un ou plusieurs acteurs au projet
  265.    *
  266.    * @access private
  267.    * @param int $id identifiant du projet
  268.    * @param string $content acteurs séparés par des virgules
  269.    * @param string $type 
  270.    * @return integer $last_id
  271.    */
  272.   private function addActors($id$content$type)
  273.   {
  274.       global $sql_object;
  275.       
  276.       // Notify the beginning of the current method
  277.       $this->dispatcher->notify(new sfEvent($this'project.add_actor'array('id' => $id'content' => $content'type' => $type)));
  278.        
  279.       // we remove latest comma
  280.       if (substr($content-1== ','{
  281.           $content substr($content0-1);
  282.       }
  283.       // we explode string to array
  284.       $array @explode(','$content);
  285.       $array array_map('trim'$array);
  286.       $array $sql_object->DBEscape($array);
  287.       
  288.       for ($i 0;$i count($array);$i++{
  289.           // we check if actor already exists
  290.           $q "SELECT actor_id FROM " T_ACTOR " WHERE lower(actor_name) = '" strtolower($array[$i]"';";
  291.           $data $sql_object->DBSelect($q);
  292.           
  293.           // if already exists, we retrieve id
  294.           if(isset($data[0]['actor_id'])) {
  295.               $actor_id $data[0]['actor_id'];
  296.           else {
  297.               // else we create it and retrieve id
  298.               $q "INSERT INTO " T_ACTOR " (actor_name) VALUES('" $array[$i"');";
  299.               $last_id $sql_object->DBInsert ($q1);
  300.               $actor_id $last_id;
  301.           }
  302.           // finally we insert tuple in table
  303.           $q "INSERT INTO " J_PROJECT_ACTOR " (jpa_project_id, jpa_actor_id, jpa_type) VALUES(" $id ", " $actor_id ",'" $type "');";
  304.  
  305.           $last_id $sql_object->DBInsert ($q1);
  306.       }
  307.   
  308.       return $last_id;
  309.   }
  310.  
  311.   /**
  312.    * project::DeleteProject()
  313.    * suppression d'un projet
  314.    *
  315.    * @access public
  316.    * @param int $ID : identifiant du projet
  317.    * @param object $sql_object 
  318.    * @return bool $result
  319.    */
  320.  
  321.   function DeleteProject($ID$sql_object)
  322.   {
  323.       // Notify the end of the current method
  324.       $this->dispatcher->notify(new sfEvent($this'project.delete'array('id' => $ID)));
  325.       
  326.     $this->ID = $ID;
  327.  
  328.     $query "UPDATE " $this->TDB_PROJECT . " set project_statut='E', project_last_modify=NOW() WHERE project_id='" $this->ID . "';";
  329.     $result $sql_object->DBQuery($query);
  330.     if($result{
  331.       $query "DELETE FROM " J_PROJECT_SDI " WHERE jps_project_id='".$this->ID."';";
  332.       $res $sql_object->DBQuery($query);
  333.     }
  334.     if($result{
  335.         $query "DELETE FROM " J_PROJECT_ACTOR " WHERE jpa_project_id='".$this->ID."';";
  336.         $res $sql_object->DBQuery($query);
  337.     }
  338.     if($result{
  339.       $query "UPDATE " $this->TDB_PROJECT . " set project_parent_id=0 WHERE project_parent_id='" $this->ID . "';";
  340.       $result $sql_object->DBQuery($query);
  341.     }
  342.     return $result;
  343.   }
  344.  
  345.   /**
  346.    * project::ModifyProject()
  347.    * modification d'un projet
  348.    *
  349.    * @access public
  350.    * @param integer $ID : identifiant du projet
  351.    * @param object $sql_object 
  352.    * @param array $array : contient les composants d'un projet
  353.    * @return boolean $result
  354.    */
  355.   function ModifyProject($ID$array$sql_object)
  356.   {
  357.  
  358.       // Filter data event + return value
  359.       $r $this->dispatcher->filter(new sfEvent($this'project.before_modify'array('data' => $array'id' => $ID))$array);
  360.       $array $r->getReturnValue();
  361.       
  362.     $array=$sql_object->DBescape($array);
  363.  
  364.     if (is_numeric($ID)) {
  365.       $this->ID = $ID;
  366.     }
  367.  
  368.     if ($array[0!= ''{
  369.       $this->NAME = strip_input(trim($array[0])true);
  370.     }
  371.     if ($array[1!= ''{
  372.       $this->DESCRIPTION = strip_input(trim($array[1])true);
  373.     }
  374.     if ($array[2!= ''{
  375.       $this->BODY = strip_input(trim($array[2])true);
  376.     }
  377.     if (is_numeric($array[3]&& $array[3!= -1{
  378.       $this->PARENT_ID = $array[3];
  379.     else {
  380.       $this->PARENT_ID = 0;
  381.     }
  382.     if (is_numeric($array[4])) {
  383.       $this->SCALE_ID = $array[4];
  384.     }
  385.     if (is_numeric($array[5])) {
  386.       $this->PRIORITY_ID = $array[5];
  387.     }
  388.     if ($array[6!= ''{
  389.       $this->BEGIN_DATE = formatDate($array[6]true);
  390.     else {
  391.       $this->BEGIN_DATE = '0001-01-01';
  392.     }
  393.     if ($array[7!= ''{
  394.       $this->ESTIMATED_DATE = formatDate($array[7]true);
  395.     else {
  396.       $this->ESTIMATED_DATE = '0001-01-01';
  397.     }
  398.     if ($array[8!= ''{
  399.       $this->END_DATE = formatDate($array[8]true);
  400.     else {
  401.       $this->END_DATE = '0001-01-01';
  402.     }
  403.     if ($array[9!= ''{
  404.       $this->STATUT = strtoupper($array[9]);
  405.     }
  406.     if (is_numeric($array[11]&& $array[11!= -1{
  407.       $this->THEME_ID = $array[11];
  408.     else {
  409.       $this->THEME_ID = 0;
  410.     }
  411.     if (is_numeric($array[12]&& $array[12!= -1{
  412.       $this->WORKSHOP_ID = $array[12];
  413.     else {
  414.       $this->WORKSHOP_ID = 0;
  415.     }
  416.     $this->SDI = $array[13];
  417.     if ($this->STATUT == 'P'{
  418.       $this->PUBLISHED_DATE = $this->_getDate();
  419.     else {
  420.       $this->PUBLISHED_DATE = '0001-01-01';
  421.     }
  422.     
  423.     $this->COMPLETED = $array[14];
  424.  
  425.     if(!empty($array[15])) {
  426.         $this->BUDGET = str_replace(' '''$array[15]);
  427.     else {
  428.         $this->BUDGET = "NULL";
  429.     }
  430.     
  431.     $this->COORDINATOR = $array[16];
  432.      
  433.     $this->PARTNERS = $array[17];
  434.      
  435.     $this->modifyActors($this->ID$this->COORDINATOR'coordinator');
  436.     $this->modifyActors($this->ID$this->PARTNERS'partner');
  437.  
  438.     $mask $this->_HavePublishedDate($array[10]);
  439.  
  440.         $query "UPDATE  " $this->TDB_PROJECT . " SET project_name='" $this->NAME . "', project_description='" $this->DESCRIPTION"', project_body='" $this->BODY . "', project_budget=" $this->BUDGET . ", 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 . "';";    $result $sql_object->DBQuery($query);
  441.     $result $this->_modifySDI($sql_object);
  442.     
  443.     // Notify the end of the current method
  444.     $this->dispatcher->notify(new sfEvent($this'project.after_modify'array('data' => $array'id' => $this->ID)));
  445.  
  446.     return $result;
  447.   }
  448.   
  449.   /**
  450.    * project::changeRanges()
  451.    * changes Project range
  452.    *
  453.    * @access public
  454.    * @param array : Id (key) and ranges (value)
  455.    * @param object $sql_object 
  456.    * @return bool $result
  457.    */
  458.  
  459.   function changeRanges($array$sql_object)
  460.   {
  461.  
  462.     foreach ($array as $key => $value{
  463.       $query "UPDATE " $this->TDB_PROJECT . " set project_range='".$value."' WHERE project_id='" $key "';";
  464.       $result $sql_object->DBQuery($query);
  465.     }
  466.     
  467.     // Notify the beginning of the current method
  468.     $this->dispatcher->notify(new sfEvent($this'project.change_ranges'array('data' => $array)));
  469.  
  470.     return $result;
  471.   }
  472.  
  473.   /**
  474.    * project::_addSDI()
  475.    * associate indicators to project
  476.    *
  477.    * @access private
  478.    */
  479.   function _addSDI($sql_object{
  480.       
  481.       // Notify the beginning of the current method
  482.       $this->dispatcher->notify(new sfEvent($this'project.add_sdi'array('data' => $this->SDI)));
  483.       
  484.     foreach ($this->SDI as &$value{
  485.       $query "INSERT INTO "J_PROJECT_SDI " VALUES(".$this->ID.", ".$value.");";
  486.       $result $sql_object->DBQuery($query);
  487.     }
  488.     return $result;
  489.   }
  490.  
  491.   /**
  492.    * project::_modifySDI()
  493.    * associate indicators to project
  494.    *
  495.    * @access private
  496.    */
  497.   function _modifySDI($sql_object{
  498.       
  499.       // Notify the beginning of the current method
  500.       $this->dispatcher->notify(new sfEvent($this'project.modify_sdi'array('data' => $this->SDI)));
  501.       
  502.     $query "DELETE FROM " J_PROJECT_SDI " WHERE jps_project_id='".$this->ID."';";
  503.     $result $sql_object->DBQuery($query);
  504.     if(count($this->SDI)>0{
  505.       $result $this->_addSDI($sql_object);
  506.     }
  507.  
  508.     return $result;
  509.   }
  510.  
  511.   /**
  512.    * project::_HavePublishedDate()
  513.    * Détermine la date de publication a inserer dans la bdd
  514.    *
  515.    * @access private
  516.    * @param string $current_status : statut actuel de l'actualité
  517.    * @return string $sql_mask
  518.    */
  519.   function _HavePublishedDate($current_status)
  520.   {
  521.     switch ($this->STATUT{
  522.       case 'P':
  523.         if ($current_status == 'D'$sql_mask ", project_published_date= NOW()";
  524.         else $sql_mask '';
  525.         break;
  526.       case 'D':
  527.         $sql_mask ", project_published_date= '0001-01-01'";
  528.         break;
  529.       default:
  530.         $sql_mask '';
  531.     }
  532.     return $sql_mask;
  533.   }
  534. }
  535.  
  536. ?>

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