tangra logo
   
[ class tree: tangra_lib ] [ index: tangra_lib ] [ all elements ]
 

Source for file tangra_module_release_relation_dbc.class.php

Documentation is available at tangra_module_release_relation_dbc.class.php

  1. <?php
  2.  
  3. /**
  4.  * Contains class Tangra_Module_Installer
  5.  *
  6.  * @package  tangra_lib
  7.  * @subpackage  modules_manager
  8.  */
  9.  
  10. /**
  11.  *
  12.  */
  13. require_once(TANGRA_MAIN_DIR.'interfaces/i_db_storable.class.php');
  14.  
  15.  
  16. /**
  17.  *
  18.  */
  19. require_once('tangra_module_release_relation.class.php');
  20.  
  21.  
  22. /**
  23.  * Tangra_Module_Release_Relation_DBC
  24.  *
  25.  * @package  tangra_lib
  26.  * @subpackage  modules_manager
  27.  */
  28.     /**
  29.      * Saves the record
  30.      *
  31.      * @param DB_Connection $dbc 
  32.      * @return integer On success returns module ID, on failure - false
  33.      */
  34.     public function save(DB_Connection $dbc{
  35.         $ret false;
  36.  
  37.         if ($this->get_id()) {
  38.             $ret $this->update($dbc);
  39.         else {
  40.             $ret $this->insert($dbc);
  41.             $this->set_id($ret);
  42.         }
  43.  
  44.         return $ret;
  45.     }
  46.  
  47.  
  48.     /**
  49.      * Loads record by id
  50.      *
  51.      * @param DB_Connection $dbc 
  52.      * @param integer $id 
  53.      * @return integer On success returns module ID, on failure - false
  54.      */
  55.     public function load_by_id(DB_Connection $dbc$id{
  56.         tangra_if_not_int_throw_e($id);
  57.  
  58.  
  59.         $ret false;
  60.  
  61.         $sql "select id, type, module_release, relation_to, version_requirement from tmod_release_relations where id = $id";
  62.         $rez $dbc->execute($sql);
  63.  
  64.         if (!$rez->is_eof()) {
  65.             $rez_obj $rez->fetch_object();
  66.  
  67.             $this->set_id($id);
  68.             $this->set_type($rez_obj->TYPE);
  69.             $this->set_module_release($rez_obj->MODULE_RELEASE);
  70.             $this->set_relation_to(stripslashes($rez_obj->RELATION_TO));
  71.             $this->set_version_requirement(stripslashes($rez_obj->VERSION_REQUIREMENT));
  72.  
  73.             $ret $id;
  74.         }
  75.  
  76.         return $ret;
  77.     }
  78.  
  79.  
  80.     /**
  81.      * Inserts new DB record
  82.      *
  83.      * @param DB_Connection $dbc 
  84.      * @return integer On success returns module ID, on failure - false
  85.      * @internal
  86.      */
  87.     protected function insert(DB_Connection $dbc{
  88.         $ret false;
  89.  
  90.         $id $dbc->generate_id('tmod_release_relations_seq');
  91.         $type $this->get_type();
  92.         $module_release $this->get_module_release();
  93.         $relation_to addslashes($this->get_relation_to());
  94.         $version_requirement addslashes($this->get_version_requirement());
  95.  
  96.         if ($id{
  97.             $sql "insert into tmod_release_relations (id, ".
  98.                                           "type, ".
  99.                                           "module_release, ".
  100.                                           "relation_to, ".
  101.                                           "version_requirement ".
  102.                                           ") ".
  103.                                 "values ".
  104.                                           "($id,".
  105.                                           "$type".
  106.                                           "$module_release".
  107.                                           "'$relation_to', ".
  108.                                           "'$version_requirement".
  109.                                           ")";
  110.             $dbc->execute($sql);
  111.             $ret $id;
  112.         else {
  113.             throw new TE_Exception('ID not generated - settings_seq');
  114.         }
  115.  
  116.         return $ret;
  117.     }
  118.  
  119.  
  120.     /**
  121.      * Updates existing DB record
  122.      *
  123.      * @param DB_Connection $dbc 
  124.      * @return integer On success returns module ID, on failure - false
  125.      * @internal
  126.      */
  127.     protected function update(DB_Connection $dbc{
  128.         $id $this->get_id();
  129.         $type $this->get_type();
  130.         $module_release $this->get_module_release();
  131.         $relation_to addslashes($this->get_relation_to());
  132.         $version_requirement addslashes($this->get_version_requirement());
  133.  
  134.         $sql "update tmod_release_relations set ".
  135.                         "type = $type".
  136.                         "module_release = $module_release".
  137.                         "relation_to = '$relation_to', ".
  138.                         "version_requirement = '$version_requirement".
  139.                     "where id = ".$id;
  140.  
  141.         $dbc->execute($sql);
  142.         $ret $id;
  143.  
  144.         return $ret;
  145.     }
  146.  
  147.  
  148.     /**
  149.      * Deletes record
  150.      *
  151.      * @param DB_Connection $dbc 
  152.      * @param integer $param_id Parameter ID
  153.      */
  154.     public static function delete(DB_Connection $dbc$id{
  155.         tangra_if_not_int_throw_e($id);
  156.         $sql "delete from tmod_release_relations where id = $id";
  157.  
  158.         $dbc->execute($sql);
  159.     }
  160.  
  161.  
  162.     public static function delete_relations_for_module(DB_Connection $dbc$module_id{
  163.         tangra_if_not_int_throw_e($module_id);
  164.  
  165.         $sql "select id from tmod_release_relations where module = $module_id";
  166.  
  167.         $rez $dbc->execute($sql);
  168.         while($rez_obj $rez->fetch_object()) {
  169.             Tangra_Module_Relation_DBC::delete($dbc$rez_obj->ID);
  170.         }
  171.     }
  172.  
  173.  
  174.     /**
  175.      * Gets SQL for grid
  176.      *
  177.      * @param integer $mod_rel_id Release ID
  178.      * @return string SQL statement
  179.      */
  180.     public static function get_sql_for_grid($mod_rel_id{
  181.         tangra_if_not_int_throw_e($mod_rel_id);
  182.  
  183.         $sql "select rr.id, ".
  184.                         "rt.name, ".
  185.                         "rr.relation_to, ".
  186.                         "rr.version_requirement ".
  187.                     "from tmod_release_relations rr, ".
  188.                             "tmod_relation_types rt ".
  189.                     "where rr.module_release = $mod_rel_id and ".
  190.                             "rr.type = rt.id ".
  191.                     "order by rr.relation_to asc";
  192.  
  193.         return $sql;
  194.     }
  195.  
  196.  
  197.     /**
  198.      * Gets count SQL for grid
  199.      *
  200.      * @param integer $mod_rel_id Release ID
  201.      * @return string SQL statement
  202.      */
  203.     public static function get_sql_count_for_grid($mod_rel_id{
  204.         tangra_if_not_int_throw_e($mod_rel_id);
  205.  
  206.         $sql "select count(rc.id) as total_rows ".
  207.                     "from tmod_release_relations rc ".
  208.                     "where rc.module_release = $mod_rel_id";
  209.  
  210.         return $sql;
  211.     }
  212.  
  213.  
  214.     /**
  215.      * Loads options-labels map for form_field_select
  216.      *
  217.      * @param DB_Connection $dbc 
  218.      * @return array 
  219.      */
  220.     public static function load_types_ol_map(DB_Connection $dbc{
  221.         $sql "select id, name from tmod_relation_types order by id asc";
  222.         $rez $dbc->execute($sql);
  223.  
  224.         $ret array();
  225.         $ids array();
  226.  
  227.         while($rez_obj $rez->fetch_object()) {
  228.             array_push($ids$rez_obj->ID);
  229.             $ret['ol_map'][$rez_obj->ID$rez_obj->NAME;
  230.         }
  231.  
  232.         if ($ids{
  233.             $ret['ids'$ids;
  234.         }
  235.  
  236.         return $ret;
  237.     }
  238.  
  239.     /**
  240.      * Loads all relations for type for release
  241.      *
  242.      * @param DB_Connection $dbc 
  243.      * @param integer $module_release_id Release ID
  244.      * @param integer $type_id Type ID
  245.      * @return array 
  246.      */
  247.     public static function select_for_release_by_type(DB_Connection $dbc$module_release_id$type_id{
  248.         tangra_if_not_int_throw_e($module_release_id);
  249.         tangra_if_not_int_throw_e($type_id);
  250.  
  251.         $sql "select relation_to, ".
  252.                         "version_requirement ".
  253.                     "from tmod_release_relations ".
  254.                     "where module_release = $module_release_id and ".
  255.                             "type = $type_id ".
  256.                     "order by relation_to asc";
  257.         $rez $dbc->execute($sql);
  258.         $ret array();
  259.         while ($rez_obj $rez->fetch_object()) {
  260.             $ret[array('hid' => $rez_obj->RELATION_TO'version_requirement' => $rez_obj->VERSION_REQUIREMENT);
  261.         }
  262.  
  263.         return $ret;
  264.     }
  265.  
  266.  
  267.     /**
  268.      * Deletes all relation for release
  269.      *
  270.      * @param DB_Connection $dbc 
  271.      * @param integer $module_release_id Release ID
  272.      */
  273.     public static function delete_for_release(DB_Connection $dbc$module_release_id{
  274.         tangra_if_not_int_throw_e($module_release_id);
  275.  
  276.         $sql "delete from tmod_release_relations where module_release = $module_release_id";
  277.         $dbc->execute($sql);
  278.     }
  279.  
  280.  
  281.     /**
  282.      * Copyes relation from one release to other
  283.      *
  284.      * @param DB_Connection $dbc 
  285.      * @param integer $from_id Source release ID
  286.      * @param integer $to_id Target release ID
  287.      */
  288.     public static function copy_relations(DB_Connection $dbc$from_id$to_id{
  289.         tangra_if_not_int_throw_e($from_id);
  290.         tangra_if_not_int_throw_e($to_id);
  291.  
  292.         $sql "select id from tmod_release_relations where module_release = $from_id";
  293.         $rez $dbc->execute($sql);
  294.         while ($rez_obj $rez->fetch_object()) {
  295.             $tmp_from new Tangra_Module_Release_Relation_DBC();
  296.             $tmp_from->load_by_id($dbc$rez_obj->ID);
  297.             $tmp_from->set_id(0);
  298.             $tmp_from->set_module_release($to_id);
  299.             $tmp_from->save($dbc);
  300.         }
  301.     }
  302. }