|
|
@@ -11,6 +11,7 @@ var $_limit;// limit nodes from DB
|
|
|
var $_deep_limit;// limit nodes from DB
|
|
|
var $_nodes_from_db;// how much nodes loaded from DB
|
|
|
var $_opened_nodes_to_save;// nodes forced to open, to save in cookie after show tree,subtree
|
|
|
+ private $_profiler;
|
|
|
|
|
|
|
|
|
function __construct( $table ) {
|
|
|
@@ -27,6 +28,16 @@ function __construct( $table ) {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public function setProfiler($profiler) {
|
|
|
+ $this->_profiler = $profiler;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function log($msg, $groups = array()) {
|
|
|
+ if ($this->_profiler && method_exists($this->_profiler, 'log')) {
|
|
|
+ $this->_profiler->log($msg, $groups);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
function set_parent_id_col( $p_id_col ) {
|
|
|
$this->_sql_parent_id_col = $p_id_col;
|
|
|
}
|
|
|
@@ -281,9 +292,13 @@ function show_rec( $parent_id = 0, $deep = 0 ) {
|
|
|
// return;
|
|
|
//}
|
|
|
|
|
|
+ $this->log("show_rec({$parent_id}, {$deep}) start");
|
|
|
+
|
|
|
$list = $this->get_childrens($parent_id);
|
|
|
if (empty($list)) return;
|
|
|
|
|
|
+ $this->log("show_rec({$parent_id}, {$deep}) -> get_childrens({$parent_id})", array('get_childrens'));
|
|
|
+
|
|
|
echo '<ul>'."\n";
|
|
|
$list_total = count($list);
|
|
|
foreach ($list as $r) {
|
|
|
@@ -327,14 +342,17 @@ function show_rec( $parent_id = 0, $deep = 0 ) {
|
|
|
echo'<div class="btn-open'.$btn_open_cls_add.'" onclick="return '.$this->js_tree_hide_fun.'(this,'.$r->ID.');"></div>';
|
|
|
}
|
|
|
}
|
|
|
+ $this->log("show_rec({$parent_id}, {$deep}) -> show_item start");
|
|
|
$this->show_item($r);
|
|
|
+ $this->log("show_rec({$parent_id}, {$deep}) -> show_item end", array('show_item'));
|
|
|
|
|
|
if ($r->has_childrens) {
|
|
|
$this->show_rec($r->ID, $deep + 1);
|
|
|
}
|
|
|
echo '</li>'."\n";
|
|
|
- }//end foreach
|
|
|
+ }
|
|
|
echo '</ul>'."\n";
|
|
|
+ $this->log("show_rec({$parent_id}, {$deep}) end");
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -362,12 +380,6 @@ function &get_childrens( $parent_id ) {
|
|
|
$sql->select = array();
|
|
|
|
|
|
$sql->select [] = "t.*";
|
|
|
- // has_childrens
|
|
|
- if ($this->_table == 'CRM_LISTA_ZASOBOW') {
|
|
|
- $sql->select [] = "IF(t.`".$this->_sql_parent_id_col."`='".$parent_id."' and t2.`ID` is not null, 1, 0) as has_childrens";
|
|
|
- } else {
|
|
|
- $sql->select [] = "IF(t2.`ID` is not null, 1, 0) as has_childrens";
|
|
|
- }
|
|
|
|
|
|
// PARENT_TYPE dla tabeli CRM_LISTA_ZASOBOW
|
|
|
if ($this->_table == 'CRM_LISTA_ZASOBOW') {
|
|
|
@@ -414,7 +426,6 @@ function &get_childrens( $parent_id ) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $sql->select = implode("\n, ", $sql->select);
|
|
|
$sql->where = implode(" or ", $sql->filter);
|
|
|
$sql->join_filter = implode(" or ", $sql->join_filter);
|
|
|
|
|
|
@@ -438,19 +449,31 @@ function &get_childrens( $parent_id ) {
|
|
|
$sql->order_by = "order by t.`ID` asc";
|
|
|
}
|
|
|
|
|
|
+ // has_childrens
|
|
|
+ # IF((select 1 from `CRM_PROCES` as t2 where t2.`PARENT_ID` = t.`ID` limit 1) > 0, 1, 0) AS has_childrens
|
|
|
+ if ($this->_table == 'CRM_LISTA_ZASOBOW') {
|
|
|
+ //$sql->select [] = "IF(t.`".$this->_sql_parent_id_col."`='".$parent_id."' and t2.`ID` is not null, 1, 0) as has_childrens";
|
|
|
+ $sql->select[] = "IF((select 1 from `{$this->_table}` as t2 where {$sql->join_filter} limit 1) is not null, 1, 0) as has_childrens";
|
|
|
+ } else {
|
|
|
+ //$sql->select [] = "IF(t2.`ID` is not null, 1, 0) as has_childrens";
|
|
|
+ $sql->select[] = "IF((select 1 from `{$this->_table}` as t2 where {$sql->join_filter} limit 1) is not null, 1, 0) as has_childrens";
|
|
|
+ }
|
|
|
+
|
|
|
+ $db = DB::getDB();
|
|
|
+ $sql->select = implode("\n, ", $sql->select);
|
|
|
$sql = "select
|
|
|
".$sql->select."
|
|
|
from `".$this->_table."` as t
|
|
|
- left join `".$this->_table."` as t2 on(".$sql->join_filter.")
|
|
|
+-- left join `".$this->_table."` as t2 on(".$sql->join_filter.")
|
|
|
where
|
|
|
".$sql->where."
|
|
|
- group by t.`ID`
|
|
|
+-- group by t.`ID`
|
|
|
".$sql->order_by."
|
|
|
";
|
|
|
-
|
|
|
- $res = DB::query( $sql );
|
|
|
+ if('123' == V::get('DBG_SQL', '', $_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
|
|
|
+ $res = $db->query($sql);
|
|
|
$ile = 0;
|
|
|
- while ($r = DB::fetch( $res )) {
|
|
|
+ while ($r = $db->fetch($res)) {
|
|
|
$ret[$r->ID] = $r;
|
|
|
$ile++;
|
|
|
}
|