51 private $_nodesInfo = [];
65 private $_extTables = [];
100 new Phrase(
'db object does not implement \Magento\Framework\DB\Adapter\AdapterInterface')
106 $conn = $this->_db->getConnection();
107 if ($conn instanceof \PDO) {
108 $conn->setAttribute(\PDO::ATTR_EMULATE_PREPARES,
true);
112 new Phrase(
'The "db object" isn\'t set in config. Set the "db object" and try again.')
116 if (!empty(
$config[
'table'])) {
132 if (!empty(
$config[
'right'])) {
138 if (!empty(
$config[
'level'])) {
175 $this->_left =
$name;
189 $this->_right =
$name;
203 $this->_level =
$name;
231 $this->_table =
$name;
243 $keys[
'id'] = $this->_id;
244 $keys[
'left'] = $this->_left;
245 $keys[
'right'] = $this->_right;
246 $keys[
'pid'] = $this->_pid;
247 $keys[
'level'] = $this->_level;
262 $this->_db->query(
'TRUNCATE ' . $this->_table);
265 $data[$this->_pid] = 0;
266 $data[$this->_left] = 1;
267 $data[$this->_right] = 2;
268 $data[$this->_level] = 0;
271 $this->_db->insert($this->_table,
$data);
272 }
catch (\PDOException $e) {
273 echo $e->getMessage();
275 return $this->_db->lastInsertId();
288 if (empty($this->_nodesInfo[$nodeId])) {
289 $sql =
'SELECT * FROM ' . $this->_table .
' WHERE ' . $this->_id .
'=:id';
290 $res = $this->_db->query($sql, [
'id' => $nodeId]);
291 $data = $res->fetch();
292 $this->_nodesInfo[$nodeId] =
$data;
294 $data = $this->_nodesInfo[$nodeId];
315 $data[$this->_right] =
$info[$this->_right] + 1;
316 $data[$this->_level] =
$info[$this->_level] + 1;
317 $data[$this->_pid] = $nodeId;
321 $this->_db->beginTransaction();
350 $this->_db->query($sql, [
'left' =>
$info[$this->_left],
'right' =>
$info[$this->_right]]);
351 $this->_db->insert($this->_table,
$data);
352 $this->_db->commit();
353 }
catch (\PDOException $p) {
354 $this->_db->rollBack();
355 echo $p->getMessage();
357 }
catch (\Exception $e) {
358 $this->_db->rollBack();
359 echo $e->getMessage();
364 $res = $this->_db->fetchOne(
'select last_insert_id()');
377 $sql = $this->_db->select();
379 [
't1' => $this->_table],
380 [
't1.' . $this->_id,
new \
Zend_Db_Expr(
'COUNT(t1.' . $this->_id .
') AS rep')]
382 [
't2' => $this->_table]
384 [
't3' => $this->_table],
385 new \
Zend_Db_Expr(
'MAX(t3.' . $this->_right .
') AS max_right')
389 't1.' . $this->_left .
' <> t2.' . $this->_left
391 't1.' . $this->_left .
' <> t2.' . $this->_right
393 't1.' . $this->_right .
' <> t2.' . $this->_right
396 $sql->group(
't1.' . $this->_id);
397 $sql->having(
'max_right <> SQRT(4 * rep + 1) + 1');
398 return $this->_db->fetchAll($sql);
415 $this->_db->beginTransaction();
424 $info[$this->_left] .
441 $info[$this->_left] .
445 (
$info[$this->_right] -
446 $info[$this->_left] +
455 (
$info[$this->_right] -
456 $info[$this->_left] +
461 $info[$this->_right];
462 $this->_db->query($sql);
463 $this->_db->commit();
465 }
catch (\Exception $e) {
466 $this->_db->rollBack();
467 echo $e->getMessage();
489 $leftId = $eInfo[$this->_left];
490 $rightId = $eInfo[$this->_right];
491 $level = $eInfo[$this->_level];
493 $leftIdP = $pInfo[$this->_left];
494 $rightIdP = $pInfo[$this->_right];
495 $levelP = $pInfo[$this->_level];
498 $leftId == $leftIdP ||
499 $leftIdP >= $leftId && $leftIdP <= $rightId ||
500 $level == $levelP + 1 && $leftId > $leftIdP && $rightId < $rightIdP
502 echo
"alert('cant_move_tree');";
506 if ($leftIdP < $leftId && $rightIdP > $rightId && $levelP < $level - 1) {
521 -($level - 1) + $levelP
604 }
elseif ($leftIdP < $leftId) {
619 -($level - 1) + $levelP
710 -($level - 1) + $levelP
791 $this->_db->beginTransaction();
793 $this->_db->query($sql);
794 $this->_db->commit();
795 echo
"alert('node moved');";
797 }
catch (\Exception $e) {
798 $this->_db->rollBack();
799 echo
"alert('node not moved: fatal error');";
800 echo $e->getMessage();
831 $level = $eInfo[$this->_level];
832 $leftKey = $eInfo[$this->_left];
833 $rightKey = $eInfo[$this->_right];
837 $levelUp = $pInfo[$this->_level];
845 $rightKeyNear = $this->_db->fetchOne(
'SELECT MAX(' . $this->_right .
') FROM ' . $this->_table);
846 }
elseif ($aId != 0 && $pId == $eInfo[$this->_pid]) {
848 $rightKeyNear = $aInfo[$this->_right];
849 $leftKeyNear = $aInfo[$this->_left];
850 }
elseif ($aId == 0 && $pId == $eInfo[$this->_pid]) {
852 $rightKeyNear = $pInfo[$this->_left];
853 }
elseif ($pId != $eInfo[$this->_pid]) {
854 $rightKeyNear = $pInfo[$this->_right] - 1;
857 $skewLevel = $pInfo[$this->_level] - $eInfo[$this->_level] + 1;
858 $skewTree = $eInfo[$this->_right] - $eInfo[$this->_left] + 1;
860 echo
"alert('" . $rightKeyNear .
"');";
862 if ($rightKeyNear > $rightKey) {
864 echo
"alert('move up');";
865 $skewEdit = $rightKeyNear - $leftKey + 1;
873 $eInfo[$this->_left] .
881 $eInfo[$this->_left] .
893 $eInfo[$this->_left] .
905 $eInfo[$this->_left] .
928 $eInfo[$this->_right];
929 }
elseif ($rightKeyNear < $rightKey) {
931 echo
"alert('move down');";
932 $skewEdit = $rightKeyNear - $leftKey + 1 - $skewTree;
998 $this->_db->beginTransaction();
1000 $this->_db->query($sql);
1001 $this->_db->commit();
1002 }
catch (\Exception $e) {
1003 $this->_db->rollBack();
1004 echo $e->getMessage();
1010 echo
"alert('node added')";
1023 $this->_extTables[
$tableName] = [
'joinCondition' => $joinCondition,
'fields' =>
$fields];
1052 }
catch (\Exception $e) {
1053 echo $e->getMessage();
1057 $dbSelect =
new Select($this->_db);
1061 $this->_left .
' >= :left' 1063 $this->_right .
' <= :right' 1074 if (!empty($startLevel) && empty($endLevel)) {
1075 $dbSelect->where($this->_level .
' = :minLevel');
1076 $data[
'minLevel'] =
$info[$this->_level] + $startLevel;
1080 $data = $this->_db->fetchAll($dbSelect,
$data);
1083 foreach (
$data as $node) {
1084 $nodeSet->addNode(
new Node($node, $this->
getKeys()));
1097 $dbSelect =
new Select($this->_db);
1098 $dbSelect->from($this->_table)->where($this->_table .
'.' . $this->_id .
' >= :id');
1103 $data[
'id'] = $nodeId;
1105 $data = $this->_db->fetchRow($dbSelect,
$data);
elseif(isset( $params[ 'redirect_parent']))
getChildren($nodeId, $startLevel=0, $endLevel=0)
appendChild($nodeId, $data)
moveNode($eId, $pId, $aId=0)
addTable($tableName, $joinCondition, $fields=' *')
_addExtTablesToSelect(Select &$select)
moveNodes($eId, $pId, $aId=0)
foreach( $_productCollection as $_product)() ?>" class $info
if(!isset($_GET['name'])) $name