Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function _debug_mind_map_nodes( $id ) {
- $x = 0;
- $y = 0;
- $z = 0;
- $index = "0x0";
- $connected_to = 0;
- $last_y = 0; $last_x = 0; $last_connected_to = 0;
- $indexes = array();
- // fetch all nodes from mind map sort by connected_to,x,y
- $query = new EntityFieldQuery();
- $query->entityCondition('entity_type', 'mind_map_node')
- ->entityCondition('bundle', 'mind_map_node')
- ->propertyOrderBy('connected_to', 'ASC')
- ->propertyOrderBy('coordinate_y', 'DESC')
- ->propertyOrderBy('coordinate_x', 'ASC')
- ->propertyCondition('mind_map_id', $id, '=');
- $result= $query->execute();
- $nodes_ids = null;
- $parents_mapping = array();
- if(isset($result['mind_map_node'])) {
- $nodes_ids = array_keys(array_pop($result));
- $nodes = entity_load('mind_map_node', $nodes_ids);
- // dsm($nodes);
- $key = array_keys($nodes);
- $size = sizeOf($key);
- $last_y_node = $nodes[$key[$size-1]];
- $max_y = $last_y_node->coordinate_y;
- // dsm($max_y);
- $max_x_limit = 0;
- $node_x_limit_on_y = array();
- for($i=0;$i<=$max_y;$i++){
- // count query
- $query = new EntityFieldQuery();
- $query->entityCondition('entity_type', 'mind_map_node')
- ->entityCondition('bundle', 'mind_map_node')
- ->propertyCondition('coordinate_y', $i, '=')
- ->propertyCondition('mind_map_id', $id, '=');
- $result= $query->count()->execute();
- $node_x_limit_on_y[] = $result;
- if ( $result > $max_x_limit ) {
- $max_x_limit = $result;
- }
- }
- // dsm($node_x_limit_on_y);
- // $tmp_node_max_limit = 0;
- $x_total_on_y = 0;
- $iteration_on_same_y = 0;
- $iteration_nodes_count_on_y = array();
- $iteration_count_for_all_y = array();
- for ($i=0; $i<$size; $i++) {
- $start_x_on_y = 0;
- $connected_to = $nodes[$key[$i]]->connected_to;
- $y = $nodes[$key[$i]]->coordinate_y;
- $x = $nodes[$key[$i]]->coordinate_x;
- // if( isset($parents_mapping[$nodes[$key[$i]]->connected_to][]) ) {}
- if ( isset( $nodes[$nodes[$key[$i]]->connected_to] ) ) {
- $parents_mapping[$nodes[$key[$i]]->connected_to]['root'] = $nodes[$nodes[$key[$i]]->connected_to]->connected_to;
- } else {
- $parents_mapping[$nodes[$key[$i]]->connected_to]['root'] = 0;
- }
- $parents_mapping[$nodes[$key[$i]]->connected_to][$i] = $key[$i];
- // $indexes['nodes'][$i]['connected_to'] = $nodes[$key[$i]]->connected_to;
- // if($last_y != $y && $x != $last_x && $x != 0) {
- if($last_y != $y) {
- $iteration_nodes_count_on_y = array();
- $iteration_on_same_y = 0;
- // dsm($node_x_limit_on_y[$y]);
- for ($j=0, $last_connected_to_tmp = $nodes[$key[$i+$j]]->connected_to; $j<$node_x_limit_on_y[$y]; $j++) {
- // dsm($nodes[$key[$i+$j]]->connected_to);
- $connected_to_tmp = $nodes[$key[$i+$j]]->connected_to;
- if($last_connected_to_tmp != $connected_to_tmp) {
- $iteration_nodes_count_on_y[$connected_to_tmp]=0;
- $iteration_nodes_count_on_y[$connected_to_tmp]+=1;
- ++$iteration_on_same_y;
- } else {
- if( !isset($iteration_nodes_count_on_y[$last_connected_to_tmp]) ) {
- $iteration_nodes_count_on_y[$last_connected_to_tmp]=0;
- }
- $iteration_nodes_count_on_y[$last_connected_to_tmp]+=1;
- }
- $last_connected_to_tmp = $connected_to_tmp;
- }
- $iteration_count_for_all_y[$y] = $iteration_nodes_count_on_y;
- $iteration_on_same_y = 0;
- // dsm('next y');
- // dsm($iteration_nodes_count_on_y);
- $x_total_on_y = 0;
- if( $node_x_limit_on_y[$y] > $node_x_limit_on_y[$y-1] ) {
- $node_max_x_limit_on_y = $node_x_limit_on_y[$y];
- } else {
- $node_max_x_limit_on_y = $max_x_limit;
- }
- if ( $node_max_x_limit_on_y % 2 == 0 ) {
- $start_x_on_y = -$max_x_limit + $node_max_x_limit_on_y;
- } else {
- $start_x_on_y = -$max_x_limit + $node_max_x_limit_on_y +1;
- }
- } else {
- ++$x_total_on_y;
- $node_max_x_limit_on_y = $node_x_limit_on_y[$y];
- }
- // dsm($node_max_x_limit_on_y);
- // dsm($max_x_limit);
- $last_connected_to = $connected_to;
- $last_y = $y;
- $last_x = $x;
- $index = $connected_to."x".$y."x".$x;
- $indexes['nodes'][$i]['id'] = $index;
- $indexes['nodes'][$i]['x'] = $start_x_on_y + $x_total_on_y +2;
- $indexes['nodes'][$i]['y'] = $y;
- $indexes['nodes'][$i]['size'] = 8;
- $indexes['nodes'][$i]['label'] = $nodes[$key[$i]]->title;
- if( $last_x != 0 ) {
- ++$iteration_on_same_y;
- }
- ++$node_max_x_limit_on_y;
- }
- // dsm($indexes);
- // fix cartesian x for y on each 1+n node on the right
- $count_on_0_level = sizeof($parents_mapping[0])-1;
- $keys = array_keys($parents_mapping[0]);
- // drop first entry : root
- $values = array_values($parents_mapping[0]);
- // $max = count($parents_mapping[0])
- //ommit 1st entry : root
- //dsm($keys);
- $offset = 0;
- $queue = array();
- $width_x_on_y = array();
- for ( $i=0; $i < $count_on_0_level; $i++ ) {
- $subqueue = array($parents_mapping[0][$i]);
- // array_shift($subqueue);
- $done = array();
- while($subqueue) {
- $link = array_shift($subqueue);
- $done[] = $link;
- // echo "<pre>done";var_dump($done);echo "</pre>";
- if(isset($parents_mapping[$link])) {
- $subnode = $parents_mapping[$link];
- // echo "<pre>subnode";var_dump($subnode);echo "</pre>";
- foreach( $subnode as $k=>$v) {
- if((int)$v != 0 && !in_array((int)$v, $done) && !in_array((int)$v, $subqueue)) {
- $subqueue[] = (int)$v;
- }
- }
- // echo "<pre>subqueue";var_dump($subqueue);echo "</pre>";
- }
- // if($i==2){ exit; }
- }
- $queue[] = $done;
- $cnt = count($queue[$i]);
- // dsm(" i = {$i} ");
- // $connected_to = $nodes[$key[$i]]->connected_to;
- for($j = 0; $j < $cnt; $j++ ) {
- $x = $nodes[$queue[$i][$j]]->coordinate_x;
- $y = $nodes[$queue[$i][$j]]->coordinate_y;
- // $connected_to = $parents_mapping[$queue[$j]]->coonencted_to_x;
- if( $y != 0 && $y == $nodes[$queue[$i][$j-1]]->coordinate_y ) {
- $width_x_on_y_for_n_root_child[$i][$y] += 1;
- // dsm('y != 0 and y-1 == y ');
- } else if ( $y != 0 ) {
- $width_x_on_y_for_n_root_child[$i][$y] = 1;
- // dsm('y != 0 but y-1 != y ');
- } else {
- $width_x_on_y_for_n_root_child[$i][0] = 1;
- // dsm('y = 0 ');
- }
- }
- }
- $cnt = count($queue);
- for($i=0;$i<$cnt;$i++) {
- $cnt_in = count($queue[$i]);
- $keys_in = array_keys($queue[$i]);
- $values_in = array_values($queue[$i]);
- $mapped_nodes = array();
- for($j=0;$j<$cnt_in;$j++) {
- $needle = null;
- if(isset($parents_mapping[$values_in[$j]])) {
- // $needle = $parents_mapping[$values_in[$j]]['root'];
- // $mapped_nodes[$parents_mapping[$needle][$keys_in[$j]]] = $values_in[$j];
- }
- }
- // dsm($mapped_nodes);
- }
- dsm($width_x_on_y_for_n_root_child);
- dsm($queue);
- /*
- for ( $i=1; $i < $count_on_0_level; $i++ ) {
- dsm($key[$i]);
- //dsm($parents_mapping[$parents_mapping[0][$i]]);
- //dsm($parents_mapping[$parents_mapping[0][$i]]);
- $max = count($parents_mapping[$parents_mapping[0][$i]]);
- $in_keys = array_keys($parents_mapping[$parents_mapping[0][$i]]);
- // dsm($in_keys);
- for ( $j=0; $j<$max; $j++) {
- if( $j !== 0 ) {
- // dsm($indexes['nodes'][$in_keys[$j]]['x']);
- $indexes['nodes'][$in_keys[$j]]['x'] += $i;
- } else {
- // dsm('root');
- $indexes['nodes'][$keys[$i+1]]['x'] = $indexes['nodes'][$in_keys[$j+1]]['x'] + $i;
- }
- // as $idx => $subnode
- }
- */
- //drupal_set_message($count_on_0_level);
- // $offset += $iteration_count_for_all_y[$indexes[$i]['y']];
- /*
- foreach($count_on_0_level[$keys[$i]] as $k=>$subnode) {
- $indexes[$k]['x'] += $offset;
- }
- */
- }
- dsm($parents_mapping);
- // dsm($iteration_count_for_all_y);
- dsm($indexes);
- dsm($nodes);
- return $indexes;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement