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__);
?>