load->library('session'); } function getMenuTree(){ $strTree = ""; $idparent = 0; //get Menu $q = $this->getMenuFields($idparent); $row = array(); if ($q->num_rows() > 0) { $row = $q->result(); //$r = count($row); $strTree = "["; foreach($row as $rr){ $strTree .= "{"; //get submenu $qc = $this->getMenuFields($rr->idmenu); $rowc = array(); if ($qc->num_rows() > 0) { $rowc = $qc->result(); $strTree .= $this->getStrTreeProperties($rr, true); $strTree .= ",children:["; //Open children foreach($rowc as $rrc){ $strTree .= "{"; $strTree .= $this->getStrTreeProperties($rrc, false); $strTree .= "},"; } $strTree .="]"; //Close children } else { $strTree .= $this->getStrTreeProperties($rr, false); } $strTree .= "},"; } //$strTree .= $this->getStrTree($row, $strTree); //for recursive, not finished $strTree .="]"; } echo $strTree; } private function getMenuFields_ORI($idparent){ $this->db->select("*"); $this->db->from("v_menu"); $this->db->order_by('kdmenu'); $this->db->where('idsubmenu',$idparent); $this->db->where('idstatus',1); $q = $this->db->get(); return $q; } private function getMenuFields($idparent){ //$otorisasi=$this->input->post("OTOR"); $otorisasi = $this->my_usession->userdata('usernameunlaprivate'); $this->db->select("*"); $this->db->from("v_otoritas"); $this->db->order_by('nmmenu'); $this->db->where('idsubmenu',$idparent); $this->db->where('idstatusklppengguna',1); $this->db->where('idstatus',1); //RH_ADD $this->db->where('nmlengkap',$otorisasi); $q = $this->db->get(); return $q; } private function getStrTree($row, $strTree){ $str = $strTree; foreach($row as $rr){ $str .= "{"; //get submenu $q = $this->getMenuFields($rr->idmenu); $rowc = array(); if ($q->num_rows() > 0) { $rowc = $q->result(); $str .= $this->getStrTreeProperties($rr, true); $str .= ",children:["; //Open children //recursive call getStrTree() $str .= $this->getStrTree($rowc, $str); $str .="]"; //Close children } else { $str .= $this->getStrTreeProperties($rr, false); } $str .= "},"; } return $str; } private function getStrTreeProperties($row, $isHasChild){ $id = "id:'".$row->idmenu."'"; $kode ="kode:'".$row->kdmenu."'"; $text ="text:'".$row->nmmenu."'"; $expanded = "expanded:false"; //($isHasChild)? "expanded:false" : "expanded:false"; $leaf = ($isHasChild)? "leaf:false" : "leaf:true"; $parent = "parent:".$row->idsubmenu; $url = "url:'".$row->url."'"; $icon = ($row->gambar != null)? "iconCls:'".$row->gambar."'" : "iconCls:''"; $ret = $id.",".$kode.",".$text.",".$expanded.",".$leaf.",".$parent.",".$url.",".$icon; //$ret = ($isHasChild)? "{".$ret.",children:[" : "{".$ret."},"; return $ret; } function getNumCols($table,$column,$field,$value){ $q= "select count(".$column.") as numCols from ".$table." where ".$field."='".$value."'"; $query = $this->db->query($q); $numCols = 0; if ($query->num_rows() != 0) { $row = $query->row(); $numCols=$row->numCols; } return $numCols; } }