graph = new stdClass(); $this->graph->htmlID = 'graph_proces_id_' . $id_proces; $this->graph->procesTreeFlat = array(); $this->graph->procesTreeGoto = array(); $this->graph->treeItems = array(); $this->graph->elements = new stdClass(); $this->graph->elements->nodes = array(); $this->graph->elements->edges = array(); } function set_mysql_zas_id($mysql_zas_id) { $this->mysql_zas_id=$mysql_zas_id; } function set_gis_zas_id($gis_zas_id) { $this->gis_zas_id=$gis_zas_id; $this->gdb=DB::getDB($this->gis_zas_id); } function get_opt_objects($src_table,$src_index,$src_name,$map_table_id,$map_table_name,$parent_table_id,$parent_table,$limit=null,$ids_ok) { $sql='select \''.$src_table.'\' as src_table , "'.$src_index.'" as src_index '; if(!empty($src_name)) $sql.=', "'.$src_name.'" as src_name '; $sql.=', "'.$parent_table_id.'" as parent_table_id , \''.$parent_table.'\' as parent_table from "'.$src_table.'" '.$limit.' ;'; $res=$this->gdb->query($sql); while($h=$this->gdb->fetch($res)) { if(!empty($limit)) { //bierzemy wszystkie rekordy bo byl limit $arr[]=$h; $this->tables->$src_table->src_index[]=$h->src_index; } else { //tylko te rekordy dla ktorych byly powiazania if(in_array($h->parent_table_id, $this->tables->$parent_table->src_index)) { $this->tables->$src_table->src_index[]=$h->src_index; // echo "
id ".$h->parent_table_id." IS found in ".$parent_table." parent table"; $arr[]=$h; } //else echo "
id ".$h->parent_table_id." not found in ".$parent_table." parent table"; } } return $arr; } function get_opt_objects_parent($src_table,$src_index,$src_name,$map_table_id,$map_table_name,$parent_table_id,$parent_table,$limit=null,$child_table,$child_joinfield,$child_index){ $i=0; $where_in=implode(",", $this->tables->$child_table->src_index); $sql='select \''.$src_table.'\' as src_table , t1."'.$src_index.'" as src_index '; if(!empty($src_name)) $sql.=', t1."'.$src_name.'" as src_name '; $sql.=', t1."'.$parent_table_id.'" as parent_table_id , \''.$parent_table.'\' as parent_table from "'.$src_table.'" as t1 inner join "'.$child_table.'" as t2 on t1."'.$src_index.'"=t2."'.$child_joinfield.'" where t2."'.$child_index.'" in ('.$where_in.') ;'; echo "
sql: ".$sql; $res=$this->gdb->query($sql); while($h=$this->gdb->fetch($res)) { $i++; // if($i>5) continue; if(!in_array($h->src_index, $this->tables->$src_table->src_index)) { $this->tables->$src_table->src_index[]=$h->src_index; $arr[]=$h; } } return $arr; } function add_array_to_graph($array,$PROCES_INIT) { foreach($array as $link) { if(!empty($link->parent_table_id)) $parent=$link->parent_table.$link->parent_table_id; else $parent=null; self::graph__addNodeID($link->src_table.$link->src_index, $this->graph,$link->src_name,null,$parent,$PROCES_INIT); } } function graph__addNodeID($id, $graph,$name=null,$path,$parent=null,$type) { //if (!array_key_exists($id, $this->graph->treeItems)) { $this->graph->treeItems[$id]= true; if(empty($name)) $name=$id; //else $name.="".$id; if(!empty($path)) { $name=$name." ".implode(',', $path);// $path=array(); } //DEBUG_S(-3,'added id,name,path,parent',array($id,$name,$path,$parent),__FILE__,__FUNCTION__,__LINE__); if($type=='PROCES_INIT') $type_init='procesInit'; else $type_init=null; //echo $type_init.$id; $this->graph->elements->nodes[] = array('data'=>array('id'=>"".$id."", 'name'=>$name , 'type'=>$type_init)); //echo "
w AddNode:ID".$id." parent".$parent; //} if(!empty($parent)) { $this->graph->elements->edges[] = array('data'=>array('source'=>$parent, 'target'=>$id )); } } function to_html() { foreach($this->graph->elements->edges as $data) { // DEBUG_S(-3,'data',$data,__FILE__,__FUNCTION__,__LINE__); if(empty($this->graph->treeItems[$data['data']['source']])) { self::graph__addNodeID($data['data']['source'], $this->graph,$data['data']['source'],null,null,null); echo "
Empty ".$data['data']['source']; } } DEBUG_S(-3,'Graph obj',$this->graph,__FILE__,__FUNCTION__,__LINE__); DEBUG_S(-3,'tables',$this->tables,__FILE__,__FUNCTION__,__LINE__); ?>
init(); $cp->set_gis_zas_id($gis_zas_id); $wezly=$cp->get_opt_objects('opt_przelacznice_mufy','id_0','Nazwa','id_wezel','Rozdzielcza_wezly','id_opt_lokalizacja','opt_lokalizacje',"where \"Nazwa\" like '%test%'"); $tacki=$cp->get_opt_objects('opt_tacki','id_0',null,null,null,'id_przelac','opt_przelacznice_mufy'); $spawy=$cp->get_opt_objects('opt_spawy','id_0',null,null,null,'id_tacka','opt_tacki'); $wlokna=$cp->get_opt_objects('opt_wlokna','id',null,null,null,'id_spaw_a','opt_spawy'); $wlokna2=$cp->get_opt_objects('opt_wlokna','id',null,null,null,'id_spaw_b','opt_spawy'); $spawy_b=$cp->get_opt_objects_parent('opt_spawy','id_0',null,null,null,'id_tacka','opt_tacki','1=1','opt_wlokna','id_spaw_b','id'); //chce znalezc te sprawy ktore sa w wloknach jako B $spawy_b2=$cp->get_opt_objects_parent('opt_spawy','id_0',null,null,null,'id_tacka','opt_tacki','1=1','opt_wlokna','id_spaw_a','id'); //chce znalezc te sprawy ktore sa w wloknach jako B $tacki_b=$cp->get_opt_objects_parent('opt_tacki','id_0',null,null,null,'id_przelac','opt_przelacznice_mufy','1=1','opt_spawy','id_tacka','id_0'); //chce znalezc te sprawy ktore sa w wloknach jako B $wezly_b=$cp->get_opt_objects_parent('opt_przelacznice_mufy','id_0','Nazwa','id_wezel','Rozdzielcza_wezly','id_opt_lokalizacja','opt_lokalizacje','1=1','opt_tacki','id_przelac','id_0'); $cp->add_array_to_graph($wezly,'PROCES_INIT'); $cp->add_array_to_graph($tacki,null); $cp->add_array_to_graph($spawy,null); $cp->add_array_to_graph($wlokna,null); $cp->add_array_to_graph($wlokna2,null); $cp->add_array_to_graph($spawy_b,null); $cp->add_array_to_graph($spawy_b2,null); $cp->add_array_to_graph($tacki_b,null); $cp->add_array_to_graph($wezly_b,'PROCES_INIT'); DEBUG_S(-3,'Wezly do dodania',$wezly,__FILE__,__FUNCTION__,__LINE__); $cp->to_html(); die(); // foreach($obj->INTERNAL_LINK as $link) graph__addNodeID($id, $graph,$tree->Viev_Zpc[$link]->DESC,null,$link,null); // foreach($obj->EXTERNAL_LINK as $link) graph__addNodeID($link, $graph,$tree->Viev_Zpc[$link]->DESC,null,$id,'PROCES_INIT'); } ?>