Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions
Tree Class Reference

Public Member Functions

 __construct ($config=[])
 
 setIdField ($name)
 
 setLeftField ($name)
 
 setRightField ($name)
 
 setLevelField ($name)
 
 setPidField ($name)
 
 setTable ($name)
 
 getKeys ()
 
 clear ($data=[])
 
 getNodeInfo ($nodeId)
 
 appendChild ($nodeId, $data)
 
 checkNodes ()
 
 removeNode ($nodeId)
 
 moveNode ($eId, $pId, $aId=0)
 
 moveNodes ($eId, $pId, $aId=0)
 
 addTable ($tableName, $joinCondition, $fields=' *')
 
 getChildren ($nodeId, $startLevel=0, $endLevel=0)
 
 getNode ($nodeId)
 

Protected Member Functions

 _addExtTablesToSelect (Select &$select)
 

Detailed Description

Magento Library

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Deprecated:
Not used anymore.

Definition at line 21 of file Tree.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $config = [])
Parameters
array$config
Exceptions
LocalizedException@SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity)
Deprecated:
Not used anymore.

Definition at line 85 of file Tree.php.

86  {
87  // set a \Zend_Db_Adapter connection
88  if (!empty($config['db'])) {
89  // convenience variable
90  $connection = $config['db'];
91 
92  // use an object from the registry?
93  if (is_string($connection)) {
94  $connection = \Zend::registry($connection);
95  }
96 
97  // make sure it's a \Magento\Framework\DB\Adapter\AdapterInterface
98  if (!$connection instanceof \Magento\Framework\DB\Adapter\AdapterInterface) {
99  throw new LocalizedException(
100  new Phrase('db object does not implement \Magento\Framework\DB\Adapter\AdapterInterface')
101  );
102  }
103 
104  // save the connection
105  $this->_db = $connection;
106  $conn = $this->_db->getConnection();
107  if ($conn instanceof \PDO) {
108  $conn->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
109  }
110  } else {
111  throw new LocalizedException(
112  new Phrase('The "db object" isn\'t set in config. Set the "db object" and try again.')
113  );
114  }
115 
116  if (!empty($config['table'])) {
117  $this->setTable($config['table']);
118  }
119 
120  if (!empty($config['id'])) {
121  $this->setIdField($config['id']);
122  } else {
123  $this->setIdField('id');
124  }
125 
126  if (!empty($config['left'])) {
127  $this->setLeftField($config['left']);
128  } else {
129  $this->setLeftField('left_key');
130  }
131 
132  if (!empty($config['right'])) {
133  $this->setRightField($config['right']);
134  } else {
135  $this->setRightField('right_key');
136  }
137 
138  if (!empty($config['level'])) {
139  $this->setLevelField($config['level']);
140  } else {
141  $this->setLevelField('level');
142  }
143 
144  if (!empty($config['pid'])) {
145  $this->setPidField($config['pid']);
146  } else {
147  $this->setPidField('parent_id');
148  }
149  }
$config
Definition: fraud_order.php:17
$connection
Definition: bulk.php:13

Member Function Documentation

◆ _addExtTablesToSelect()

_addExtTablesToSelect ( Select $select)
protected
Parameters
Select$select
Returns
void
Deprecated:
Not used anymore.

Definition at line 1032 of file Tree.php.

1033  {
1034  foreach ($this->_extTables as $tableName => $info) {
1035  $select->joinInner($tableName, $info['joinCondition'], $info['fields']);
1036  }
1037  }
$tableName
Definition: trigger.php:13
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52

◆ addTable()

addTable (   $tableName,
  $joinCondition,
  $fields = '*' 
)
Parameters
string$tableName
string$joinCondition
string$fields
Returns
void
Deprecated:
Not used anymore.

Definition at line 1021 of file Tree.php.

1022  {
1023  $this->_extTables[$tableName] = ['joinCondition' => $joinCondition, 'fields' => $fields];
1024  }
$tableName
Definition: trigger.php:13
$fields
Definition: details.phtml:14

◆ appendChild()

appendChild (   $nodeId,
  $data 
)
Parameters
string | int$nodeId
array$data
Returns
false|string @SuppressWarnings(PHPMD.ExitExpression)
Deprecated:
Not used anymore.

Definition at line 307 of file Tree.php.

308  {
309  $info = $this->getNodeInfo($nodeId);
310  if (!$info) {
311  return false;
312  }
313 
314  $data[$this->_left] = $info[$this->_right];
315  $data[$this->_right] = $info[$this->_right] + 1;
316  $data[$this->_level] = $info[$this->_level] + 1;
317  $data[$this->_pid] = $nodeId;
318 
319  // creating a place for the record being inserted
320  if ($nodeId) {
321  $this->_db->beginTransaction();
322  try {
323  $sql = 'UPDATE ' .
324  $this->_table .
325  ' SET' .
326  ' `' .
327  $this->_left .
328  '` = IF( `' .
329  $this->_left .
330  '` > :left,' .
331  ' `' .
332  $this->_left .
333  '`+2, `' .
334  $this->_left .
335  '`),' .
336  ' `' .
337  $this->_right .
338  '` = IF( `' .
339  $this->_right .
340  '`>= :right,' .
341  ' `' .
342  $this->_right .
343  '`+2, `' .
344  $this->_right .
345  '`)' .
346  ' WHERE `' .
347  $this->_right .
348  '` >= :right';
349 
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();
356  exit;
357  } catch (\Exception $e) {
358  $this->_db->rollBack();
359  echo $e->getMessage();
360  echo $sql;
361  exit;
362  }
363  // TODO: change to ZEND LIBRARY
364  $res = $this->_db->fetchOne('select last_insert_id()');
365  return $res;
366  }
367  return false;
368  }
exit
Definition: redirect.phtml:12
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52

◆ checkNodes()

checkNodes ( )
Returns
array
Deprecated:
Not used anymore.

Definition at line 375 of file Tree.php.

376  {
377  $sql = $this->_db->select();
378  $sql->from(
379  ['t1' => $this->_table],
380  ['t1.' . $this->_id, new \Zend_Db_Expr('COUNT(t1.' . $this->_id . ') AS rep')]
381  )->from(
382  ['t2' => $this->_table]
383  )->from(
384  ['t3' => $this->_table],
385  new \Zend_Db_Expr('MAX(t3.' . $this->_right . ') AS max_right')
386  );
387 
388  $sql->where(
389  't1.' . $this->_left . ' <> t2.' . $this->_left
390  )->where(
391  't1.' . $this->_left . ' <> t2.' . $this->_right
392  )->where(
393  't1.' . $this->_right . ' <> t2.' . $this->_right
394  );
395 
396  $sql->group('t1.' . $this->_id);
397  $sql->having('max_right <> SQRT(4 * rep + 1) + 1');
398  return $this->_db->fetchAll($sql);
399  }

◆ clear()

clear (   $data = [])

Clear table and add root element

Parameters
array$data
Returns
string
Deprecated:
Not used anymore.

Definition at line 259 of file Tree.php.

260  {
261  // clearing table
262  $this->_db->query('TRUNCATE ' . $this->_table);
263 
264  // prepare data for root element
265  $data[$this->_pid] = 0;
266  $data[$this->_left] = 1;
267  $data[$this->_right] = 2;
268  $data[$this->_level] = 0;
269 
270  try {
271  $this->_db->insert($this->_table, $data);
272  } catch (\PDOException $e) {
273  echo $e->getMessage();
274  }
275  return $this->_db->lastInsertId();
276  }

◆ getChildren()

getChildren (   $nodeId,
  $startLevel = 0,
  $endLevel = 0 
)
Parameters
string | int$nodeId
int$startLevel
int$endLevel
Returns
NodeSet @SuppressWarnings(PHPMD.ExitExpression)
Deprecated:
Not used anymore.

Definition at line 1048 of file Tree.php.

1049  {
1050  try {
1051  $info = $this->getNodeInfo($nodeId);
1052  } catch (\Exception $e) {
1053  echo $e->getMessage();
1054  exit;
1055  }
1056 
1057  $dbSelect = new Select($this->_db);
1058  $dbSelect->from(
1059  $this->_table
1060  )->where(
1061  $this->_left . ' >= :left'
1062  )->where(
1063  $this->_right . ' <= :right'
1064  )->order(
1065  $this->_left
1066  );
1067 
1068  $this->_addExtTablesToSelect($dbSelect);
1069 
1070  $data = [];
1071  $data['left'] = $info[$this->_left];
1072  $data['right'] = $info[$this->_right];
1073 
1074  if (!empty($startLevel) && empty($endLevel)) {
1075  $dbSelect->where($this->_level . ' = :minLevel');
1076  $data['minLevel'] = $info[$this->_level] + $startLevel;
1077  }
1078 
1079  //echo $dbSelect->__toString();
1080  $data = $this->_db->fetchAll($dbSelect, $data);
1081 
1082  $nodeSet = new NodeSet();
1083  foreach ($data as $node) {
1084  $nodeSet->addNode(new Node($node, $this->getKeys()));
1085  }
1086  return $nodeSet;
1087  }
_addExtTablesToSelect(Select &$select)
Definition: Tree.php:1032
exit
Definition: redirect.phtml:12
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52

◆ getKeys()

getKeys ( )
Returns
array
Deprecated:
Not used anymore.

Definition at line 240 of file Tree.php.

241  {
242  $keys = [];
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;
248  return $keys;
249  }

◆ getNode()

getNode (   $nodeId)
Parameters
string | int$nodeId
Returns
Node
Deprecated:
Not used anymore.

Definition at line 1095 of file Tree.php.

1096  {
1097  $dbSelect = new Select($this->_db);
1098  $dbSelect->from($this->_table)->where($this->_table . '.' . $this->_id . ' >= :id');
1099 
1100  $this->_addExtTablesToSelect($dbSelect);
1101 
1102  $data = [];
1103  $data['id'] = $nodeId;
1104 
1105  $data = $this->_db->fetchRow($dbSelect, $data);
1106 
1107  return new Node($data, $this->getKeys());
1108  }
_addExtTablesToSelect(Select &$select)
Definition: Tree.php:1032

◆ getNodeInfo()

getNodeInfo (   $nodeId)

Get node information

Parameters
string | int$nodeId
Returns
array
Deprecated:
Not used anymore.

Definition at line 286 of file Tree.php.

287  {
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;
293  } else {
294  $data = $this->_nodesInfo[$nodeId];
295  }
296  return $data;
297  }

◆ moveNode()

moveNode (   $eId,
  $pId,
  $aId = 0 
)
Parameters
string | int$eId
string | int$pId
string | int$aId
Returns
bool @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.ExcessiveMethodLength) @SuppressWarnings(PHPMD.UnusedFormalParameter) @SuppressWarnings(PHPMD.ExitExpression)
Deprecated:
Not used anymore.

Definition at line 484 of file Tree.php.

485  {
486  $eInfo = $this->getNodeInfo($eId);
487  $pInfo = $this->getNodeInfo($pId);
488 
489  $leftId = $eInfo[$this->_left];
490  $rightId = $eInfo[$this->_right];
491  $level = $eInfo[$this->_level];
492 
493  $leftIdP = $pInfo[$this->_left];
494  $rightIdP = $pInfo[$this->_right];
495  $levelP = $pInfo[$this->_level];
496 
497  if ($eId == $pId ||
498  $leftId == $leftIdP ||
499  $leftIdP >= $leftId && $leftIdP <= $rightId ||
500  $level == $levelP + 1 && $leftId > $leftIdP && $rightId < $rightIdP
501  ) {
502  echo "alert('cant_move_tree');";
503  return false;
504  }
505 
506  if ($leftIdP < $leftId && $rightIdP > $rightId && $levelP < $level - 1) {
507  $sql = 'UPDATE ' .
508  $this->_table .
509  ' SET ' .
510  $this->_level .
511  ' = CASE WHEN ' .
512  $this->_left .
513  ' BETWEEN ' .
514  $leftId .
515  ' AND ' .
516  $rightId .
517  ' THEN ' .
518  $this->_level .
519  sprintf(
520  '%+d',
521  -($level - 1) + $levelP
522  ) .
523  ' ELSE ' .
524  $this->_level .
525  ' END, ' .
526  $this->_right .
527  ' = CASE WHEN ' .
528  $this->_right .
529  ' BETWEEN ' .
530  ($rightId +
531  1) .
532  ' AND ' .
533  ($rightIdP -
534  1) .
535  ' THEN ' .
536  $this->_right .
537  '-' .
538  ($rightId -
539  $leftId +
540  1) .
541  ' ' .
542  'WHEN ' .
543  $this->_left .
544  ' BETWEEN ' .
545  $leftId .
546  ' AND ' .
547  $rightId .
548  ' THEN ' .
549  $this->_right .
550  '+' .
551  (($rightIdP -
552  $rightId -
553  $level +
554  $levelP) / 2 * 2 +
555  $level -
556  $levelP -
557  1) .
558  ' ELSE ' .
559  $this->_right .
560  ' END, ' .
561  $this->_left .
562  ' = CASE WHEN ' .
563  $this->_left .
564  ' BETWEEN ' .
565  ($rightId +
566  1) .
567  ' AND ' .
568  ($rightIdP -
569  1) .
570  ' THEN ' .
571  $this->_left .
572  '-' .
573  ($rightId -
574  $leftId +
575  1) .
576  ' ' .
577  'WHEN ' .
578  $this->_left .
579  ' BETWEEN ' .
580  $leftId .
581  ' AND ' .
582  $rightId .
583  ' THEN ' .
584  $this->_left .
585  '+' .
586  (($rightIdP -
587  $rightId -
588  $level +
589  $levelP) / 2 * 2 +
590  $level -
591  $levelP -
592  1) .
593  ' ELSE ' .
594  $this->_left .
595  ' END ' .
596  'WHERE ' .
597  $this->_left .
598  ' BETWEEN ' .
599  ($leftIdP +
600  1) .
601  ' AND ' .
602  ($rightIdP -
603  1);
604  } elseif ($leftIdP < $leftId) {
605  $sql = 'UPDATE ' .
606  $this->_table .
607  ' SET ' .
608  $this->_level .
609  ' = CASE WHEN ' .
610  $this->_left .
611  ' BETWEEN ' .
612  $leftId .
613  ' AND ' .
614  $rightId .
615  ' THEN ' .
616  $this->_level .
617  sprintf(
618  '%+d',
619  -($level - 1) + $levelP
620  ) .
621  ' ELSE ' .
622  $this->_level .
623  ' END, ' .
624  $this->_left .
625  ' = CASE WHEN ' .
626  $this->_left .
627  ' BETWEEN ' .
628  $rightIdP .
629  ' AND ' .
630  ($leftId -
631  1) .
632  ' THEN ' .
633  $this->_left .
634  '+' .
635  ($rightId -
636  $leftId +
637  1) .
638  ' ' .
639  'WHEN ' .
640  $this->_left .
641  ' BETWEEN ' .
642  $leftId .
643  ' AND ' .
644  $rightId .
645  ' THEN ' .
646  $this->_left .
647  '-' .
648  ($leftId -
649  $rightIdP) .
650  ' ELSE ' .
651  $this->_left .
652  ' END, ' .
653  $this->_right .
654  ' = CASE WHEN ' .
655  $this->_right .
656  ' BETWEEN ' .
657  $rightIdP .
658  ' AND ' .
659  $leftId .
660  ' THEN ' .
661  $this->_right .
662  '+' .
663  ($rightId -
664  $leftId +
665  1) .
666  ' ' .
667  'WHEN ' .
668  $this->_right .
669  ' BETWEEN ' .
670  $leftId .
671  ' AND ' .
672  $rightId .
673  ' THEN ' .
674  $this->_right .
675  '-' .
676  ($leftId -
677  $rightIdP) .
678  ' ELSE ' .
679  $this->_right .
680  ' END ' .
681  'WHERE (' .
682  $this->_left .
683  ' BETWEEN ' .
684  $leftIdP .
685  ' AND ' .
686  $rightId .
687  ' ' .
688  'OR ' .
689  $this->_right .
690  ' BETWEEN ' .
691  $leftIdP .
692  ' AND ' .
693  $rightId .
694  ')';
695  } else {
696  $sql = 'UPDATE ' .
697  $this->_table .
698  ' SET ' .
699  $this->_level .
700  ' = CASE WHEN ' .
701  $this->_left .
702  ' BETWEEN ' .
703  $leftId .
704  ' AND ' .
705  $rightId .
706  ' THEN ' .
707  $this->_level .
708  sprintf(
709  '%+d',
710  -($level - 1) + $levelP
711  ) .
712  ' ELSE ' .
713  $this->_level .
714  ' END, ' .
715  $this->_left .
716  ' = CASE WHEN ' .
717  $this->_left .
718  ' BETWEEN ' .
719  $rightId .
720  ' AND ' .
721  $rightIdP .
722  ' THEN ' .
723  $this->_left .
724  '-' .
725  ($rightId -
726  $leftId +
727  1) .
728  ' ' .
729  'WHEN ' .
730  $this->_left .
731  ' BETWEEN ' .
732  $leftId .
733  ' AND ' .
734  $rightId .
735  ' THEN ' .
736  $this->_left .
737  '+' .
738  ($rightIdP -
739  1 -
740  $rightId) .
741  ' ELSE ' .
742  $this->_left .
743  ' END, ' .
744  $this->_right .
745  ' = CASE WHEN ' .
746  $this->_right .
747  ' BETWEEN ' .
748  ($rightId +
749  1) .
750  ' AND ' .
751  ($rightIdP -
752  1) .
753  ' THEN ' .
754  $this->_right .
755  '-' .
756  ($rightId -
757  $leftId +
758  1) .
759  ' ' .
760  'WHEN ' .
761  $this->_right .
762  ' BETWEEN ' .
763  $leftId .
764  ' AND ' .
765  $rightId .
766  ' THEN ' .
767  $this->_right .
768  '+' .
769  ($rightIdP -
770  1 -
771  $rightId) .
772  ' ELSE ' .
773  $this->_right .
774  ' END ' .
775  'WHERE (' .
776  $this->_left .
777  ' BETWEEN ' .
778  $leftId .
779  ' AND ' .
780  $rightIdP .
781  ' ' .
782  'OR ' .
783  $this->_right .
784  ' BETWEEN ' .
785  $leftId .
786  ' AND ' .
787  $rightIdP .
788  ')';
789  }
790 
791  $this->_db->beginTransaction();
792  try {
793  $this->_db->query($sql);
794  $this->_db->commit();
795  echo "alert('node moved');";
796  return true;
797  } catch (\Exception $e) {
798  $this->_db->rollBack();
799  echo "alert('node not moved: fatal error');";
800  echo $e->getMessage();
801  echo "<br>\r\n";
802  echo $sql;
803  echo "<br>\r\n";
804  exit;
805  }
806  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
exit
Definition: redirect.phtml:12

◆ moveNodes()

moveNodes (   $eId,
  $pId,
  $aId = 0 
)
Parameters
string | int$eId
string | int$pId
string | int$aId
Returns
void @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity) @SuppressWarnings(PHPMD.ExcessiveMethodLength) @SuppressWarnings(PHPMD.UnusedLocalVariable) @SuppressWarnings(PHPMD.ExitExpression)
Deprecated:
Not used anymore.

Definition at line 821 of file Tree.php.

822  {
823  $eInfo = $this->getNodeInfo($eId);
824  if ($pId != 0) {
825  $pInfo = $this->getNodeInfo($pId);
826  }
827  if ($aId != 0) {
828  $aInfo = $this->getNodeInfo($aId);
829  }
830 
831  $level = $eInfo[$this->_level];
832  $leftKey = $eInfo[$this->_left];
833  $rightKey = $eInfo[$this->_right];
834  if ($pId == 0) {
835  $levelUp = 0;
836  } else {
837  $levelUp = $pInfo[$this->_level];
838  }
839 
840  $rightKeyNear = 0;
841  $leftKeyNear = 0;
842 
843  if ($pId == 0) {
844  //move to root
845  $rightKeyNear = $this->_db->fetchOne('SELECT MAX(' . $this->_right . ') FROM ' . $this->_table);
846  } elseif ($aId != 0 && $pId == $eInfo[$this->_pid]) {
847  // if we have after ID
848  $rightKeyNear = $aInfo[$this->_right];
849  $leftKeyNear = $aInfo[$this->_left];
850  } elseif ($aId == 0 && $pId == $eInfo[$this->_pid]) {
851  // if we do not have after ID
852  $rightKeyNear = $pInfo[$this->_left];
853  } elseif ($pId != $eInfo[$this->_pid]) {
854  $rightKeyNear = $pInfo[$this->_right] - 1;
855  }
856 
857  $skewLevel = $pInfo[$this->_level] - $eInfo[$this->_level] + 1;
858  $skewTree = $eInfo[$this->_right] - $eInfo[$this->_left] + 1;
859 
860  echo "alert('" . $rightKeyNear . "');";
861 
862  if ($rightKeyNear > $rightKey) {
863  // up
864  echo "alert('move up');";
865  $skewEdit = $rightKeyNear - $leftKey + 1;
866  $sql = 'UPDATE ' .
867  $this->_table .
868  ' SET ' .
869  $this->_right .
870  ' = IF(' .
871  $this->_left .
872  ' >= ' .
873  $eInfo[$this->_left] .
874  ', ' .
875  $this->_right .
876  ' + ' .
877  $skewEdit .
878  ', IF(' .
879  $this->_right .
880  ' < ' .
881  $eInfo[$this->_left] .
882  ', ' .
883  $this->_right .
884  ' + ' .
885  $skewTree .
886  ', ' .
887  $this->_right .
888  ')), ' .
889  $this->_level .
890  ' = IF(' .
891  $this->_left .
892  ' >= ' .
893  $eInfo[$this->_left] .
894  ', ' .
895  $this->_level .
896  ' + ' .
897  $skewLevel .
898  ', ' .
899  $this->_level .
900  '), ' .
901  $this->_left .
902  ' = IF(' .
903  $this->_left .
904  ' >= ' .
905  $eInfo[$this->_left] .
906  ', ' .
907  $this->_left .
908  ' + ' .
909  $skewEdit .
910  ', IF(' .
911  $this->_left .
912  ' > ' .
913  $rightKeyNear .
914  ', ' .
915  $this->_left .
916  ' + ' .
917  $skewTree .
918  ', ' .
919  $this->_left .
920  '))' .
921  ' WHERE ' .
922  $this->_right .
923  ' > ' .
924  $rightKeyNear .
925  ' AND ' .
926  $this->_left .
927  ' < ' .
928  $eInfo[$this->_right];
929  } elseif ($rightKeyNear < $rightKey) {
930  // down
931  echo "alert('move down');";
932  $skewEdit = $rightKeyNear - $leftKey + 1 - $skewTree;
933  $sql = 'UPDATE ' .
934  $this->_table .
935  ' SET ' .
936  $this->_left .
937  ' = IF(' .
938  $this->_right .
939  ' <= ' .
940  $rightKey .
941  ', ' .
942  $this->_left .
943  ' + ' .
944  $skewEdit .
945  ', IF(' .
946  $this->_left .
947  ' > ' .
948  $rightKey .
949  ', ' .
950  $this->_left .
951  ' - ' .
952  $skewTree .
953  ', ' .
954  $this->_left .
955  ')), ' .
956  $this->_level .
957  ' = IF(' .
958  $this->_right .
959  ' <= ' .
960  $rightKey .
961  ', ' .
962  $this->_level .
963  ' + ' .
964  $skewLevel .
965  ', ' .
966  $this->_level .
967  '), ' .
968  $this->_right .
969  ' = IF(' .
970  $this->_right .
971  ' <= ' .
972  $rightKey .
973  ', ' .
974  $this->_right .
975  ' + ' .
976  $skewEdit .
977  ', IF(' .
978  $this->_right .
979  ' <= ' .
980  $rightKeyNear .
981  ', ' .
982  $this->_right .
983  ' - ' .
984  $skewTree .
985  ', ' .
986  $this->_right .
987  '))' .
988  ' WHERE ' .
989  $this->_right .
990  ' > ' .
991  $leftKey .
992  ' AND ' .
993  $this->_left .
994  ' <= ' .
995  $rightKeyNear;
996  }
997 
998  $this->_db->beginTransaction();
999  try {
1000  $this->_db->query($sql);
1001  $this->_db->commit();
1002  } catch (\Exception $e) {
1003  $this->_db->rollBack();
1004  echo $e->getMessage();
1005  echo "<br>\r\n";
1006  echo $sql;
1007  echo "<br>\r\n";
1008  exit;
1009  }
1010  echo "alert('node added')";
1011  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
exit
Definition: redirect.phtml:12

◆ removeNode()

removeNode (   $nodeId)
Parameters
string | int$nodeId
Returns
bool|Node|void
Deprecated:
Not used anymore.

DELETE FROM my_tree WHERE left_key >= $left_key AND right_key <= $right_key

UPDATE my_tree SET left_key = IF(left_key > $left_key, left_key – ($right_key - $left_key + 1), left_key), right_key = right_key – ($right_key - $left_key + 1) WHERE right_key > $right_key

Definition at line 407 of file Tree.php.

408  {
409  $info = $this->getNodeInfo($nodeId);
410  if (!$info) {
411  return false;
412  }
413 
414  if ($nodeId) {
415  $this->_db->beginTransaction();
416  try {
420  $this->_db->delete(
421  $this->_table,
422  $this->_left .
423  ' >= ' .
424  $info[$this->_left] .
425  ' AND ' .
426  $this->_right .
427  ' <= ' .
428  $info[$this->_right]
429  );
434  $sql = 'UPDATE ' .
435  $this->_table .
436  ' SET ' .
437  $this->_left .
438  ' = IF(' .
439  $this->_left .
440  ' > ' .
441  $info[$this->_left] .
442  ', ' .
443  $this->_left .
444  ' - ' .
445  ($info[$this->_right] -
446  $info[$this->_left] +
447  1) .
448  ', ' .
449  $this->_left .
450  '), ' .
451  $this->_right .
452  ' = ' .
453  $this->_right .
454  ' - ' .
455  ($info[$this->_right] -
456  $info[$this->_left] +
457  1) .
458  ' WHERE ' .
459  $this->_right .
460  ' > ' .
461  $info[$this->_right];
462  $this->_db->query($sql);
463  $this->_db->commit();
464  return new Node($info, $this->getKeys());
465  } catch (\Exception $e) {
466  $this->_db->rollBack();
467  echo $e->getMessage();
468  }
469  }
470  }
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52

◆ setIdField()

setIdField (   $name)

set name of id field

Parameters
string$name
Returns
$this
Deprecated:
Not used anymore.

Definition at line 159 of file Tree.php.

160  {
161  $this->_id = $name;
162  return $this;
163  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setLeftField()

setLeftField (   $name)

set name of left field

Parameters
string$name
Returns
$this
Deprecated:
Not used anymore.

Definition at line 173 of file Tree.php.

174  {
175  $this->_left = $name;
176  return $this;
177  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setLevelField()

setLevelField (   $name)

set name of level field

Parameters
string$name
Returns
$this
Deprecated:
Not used anymore.

Definition at line 201 of file Tree.php.

202  {
203  $this->_level = $name;
204  return $this;
205  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setPidField()

setPidField (   $name)

set name of pid Field

Parameters
string$name
Returns
$this
Deprecated:
Not used anymore.

Definition at line 215 of file Tree.php.

216  {
217  $this->_pid = $name;
218  return $this;
219  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setRightField()

setRightField (   $name)

set name of right field

Parameters
string$name
Returns
$this
Deprecated:
Not used anymore.

Definition at line 187 of file Tree.php.

188  {
189  $this->_right = $name;
190  return $this;
191  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setTable()

setTable (   $name)

set table name

Parameters
string$name
Returns
$this
Deprecated:
Not used anymore.

Definition at line 229 of file Tree.php.

230  {
231  $this->_table = $name;
232  return $this;
233  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

The documentation for this class was generated from the following file: