SHARE
TWEET

Btree.php

a guest Aug 14th, 2019 137 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.   /**
  4.    *
  5.    */
  6.   class Btree
  7.   {
  8.  
  9.  
  10. private $ci;
  11.  
  12. public $data = array();
  13.  
  14. public $left_child = array();
  15.  
  16. public $right_child = array();
  17.  
  18. public $is_parent = array();
  19.  
  20.  
  21.       public function __construct()
  22.         {
  23.           $this->ci =& get_instance();
  24.         }
  25.  
  26.       // MENJUMLAHKAN TOTAL ANAK
  27.       function leftcount($id)   //Function to calculate all right children count
  28.         {
  29.           $array = $this->ci->db->get_where("trans_member",['id_member'=>$id])->row_array();
  30.           $count = 0;
  31.           if(!empty($array['l_mem']))
  32.           {
  33.               $count+= $this->allcount($array['l_mem'])+1;
  34.           }
  35.           return $count;
  36.         }
  37.  
  38.       function rightcount($id)   //Function to calculate all right children count
  39.         {
  40.             $array = $this->ci->db->get_where("trans_member",['id_member'=>$id])->row_array();
  41.             $count = 0;
  42.             if(!empty($array['r_mem']))
  43.             {
  44.                 $count+= ($this->allcount($array['r_mem'])+1);
  45.             }
  46.             return $count;
  47.         }
  48.  
  49.  
  50.       function allcount($id)   //Function to calculate all children count
  51.         {
  52.           $array = $this->ci->db->get_where("trans_member",['id_member'=>$id])->row_array();
  53.           $count = 0;
  54.           if(!empty($array['r_mem']))
  55.           {
  56.               $count+=($this->allcount($array['r_mem'])+1);
  57.           }
  58.           if(!empty($array['l_mem']))
  59.           {
  60.               $count+=($this->allcount($array['l_mem'])+1);
  61.           }
  62.           return $count;
  63.         }
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.         //MENAMPILKAN ID ANAK
  72.         function get_left_id_children($id){ //Function get id left children
  73.  
  74.           $array = $this->ci->db->get_where("trans_member",['id_member'=>$id])->row();
  75.  
  76.           if(!empty($array->l_mem)) {
  77.               array_push($this->left_child, $array->l_mem);
  78.               $left_child[]= $this->get_all_left_id_child($array->l_mem);
  79.           }
  80.  
  81.           return array_filter($this->left_child);
  82.         }
  83.  
  84.  
  85.         function get_all_left_id_child($id) { //Function get id all children
  86.  
  87.             $array = $this->ci->db->get_where("trans_member",['id_member'=>$id])->row();
  88.  
  89.             if(!empty($array->r_mem)) {
  90.                 array_push($this->left_child, $array->r_mem);
  91.                 $left_child[]= $this->get_all_left_id_child($array->r_mem);
  92.             }
  93.  
  94.             if(!empty($array->l_mem)) {
  95.                 array_push($this->left_child, $array->l_mem);
  96.                 $left_child[]= $this->get_all_left_id_child($array->l_mem);
  97.             }
  98.  
  99.             return array_filter($this->left_child);
  100.         }
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.         function get_right_id_children($id){ //Function get id right children
  114.  
  115.           $array = $this->ci->db->get_where("trans_member",['id_member'=>$id])->row();
  116.  
  117.           if(!empty($array->r_mem)) {
  118.               array_push($this->right_child, $array->r_mem);
  119.               $right_child[]= $this->get_all_right_id_child($array->r_mem);
  120.           }
  121.  
  122.           return array_filter($this->right_child);
  123.         }
  124.  
  125.  
  126.         function get_all_right_id_child($id) { //Function get id all children
  127.  
  128.             $array = $this->ci->db->get_where("trans_member",['id_member'=>$id])->row();
  129.  
  130.             if(!empty($array->r_mem)) {
  131.                 array_push($this->right_child, $array->r_mem);
  132.                 $right_child[]= $this->get_all_right_id_child($array->r_mem);
  133.             }
  134.  
  135.             if(!empty($array->l_mem)) {
  136.                 array_push($this->right_child, $array->l_mem);
  137.                 $right_child[]= $this->get_all_right_id_child($array->l_mem);
  138.             }
  139.  
  140.             return array_filter($this->right_child);
  141.         }
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.           function get_all_id_children($id) { //Function get id all children
  157.  
  158.               $array = $this->ci->db->get_where("trans_member",['id_member'=>$id])->row();
  159.  
  160.               if(!empty($array->r_mem)) {
  161.                   array_push($this->data, $array->r_mem);
  162.                   $data[]= $this->get_all_id_children($array->r_mem);
  163.               }
  164.  
  165.               if(!empty($array->l_mem)) {
  166.                   array_push($this->data, $array->l_mem);
  167.                   $data[]= $this->get_all_id_children($array->l_mem);
  168.               }
  169.  
  170.               return array_filter($this->data);
  171.           }
  172.  
  173.  
  174.  
  175.  
  176.     function cek_is_parent($id)
  177.     {
  178.       $array = $this->ci->db->get_where("trans_member",['id_member'=>$id])->row();
  179.  
  180.       if($array->id_parent!=0) {
  181.           array_push($this->is_parent, $array->id_parent);
  182.           $is_parent[]= $this->cek_is_parent($array->id_parent);
  183.       }
  184.  
  185.       return array_filter($this->is_parent);
  186.     }
  187.  
  188.  
  189.  
  190.  
  191. } //end class
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top