Magento Library
@SuppressWarnings(PHPMD.CouplingBetweenObjects)
- Deprecated:
- Not used anymore.
Definition at line 21 of file Tree.php.
◆ __construct()
__construct |
( |
|
$config = [] | ) |
|
- Parameters
-
- Exceptions
-
LocalizedException | @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity) |
- Deprecated:
- Not used anymore.
Definition at line 85 of file Tree.php.
99 throw new LocalizedException(
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);
111 throw new LocalizedException(
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'])) {
◆ _addExtTablesToSelect()
_addExtTablesToSelect |
( |
Select & |
$select | ) |
|
|
protected |
- Parameters
-
- Returns
- void
- Deprecated:
- Not used anymore.
Definition at line 1032 of file Tree.php.
foreach( $_productCollection as $_product)() ?>" class $info
◆ 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.
1023 $this->_extTables[
$tableName] = [
'joinCondition' => $joinCondition,
'fields' =>
$fields];
◆ 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.
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()');
foreach( $_productCollection as $_product)() ?>" class $info
◆ checkNodes()
- Returns
- array
- Deprecated:
- Not used anymore.
Definition at line 375 of file Tree.php.
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);
◆ clear()
Clear table and add root element
- Parameters
-
- Returns
- string
- Deprecated:
- Not used anymore.
Definition at line 259 of file Tree.php.
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();
◆ 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.
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);
1082 $nodeSet =
new NodeSet();
1083 foreach (
$data as $node) {
1084 $nodeSet->addNode(
new Node($node, $this->
getKeys()));
_addExtTablesToSelect(Select &$select)
foreach( $_productCollection as $_product)() ?>" class $info
◆ getKeys()
- Returns
- array
- Deprecated:
- Not used anymore.
Definition at line 240 of file Tree.php.
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;
◆ getNode()
- Parameters
-
- Returns
- Node
- Deprecated:
- Not used anymore.
Definition at line 1095 of file Tree.php.
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);
_addExtTablesToSelect(Select &$select)
◆ getNodeInfo()
Get node information
- Parameters
-
- Returns
- array
- Deprecated:
- Not used anymore.
Definition at line 286 of file Tree.php.
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];
◆ 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.
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();
elseif(isset( $params[ 'redirect_parent']))
◆ 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.
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')";
elseif(isset( $params[ 'redirect_parent']))
◆ removeNode()
- Parameters
-
- 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.
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();
foreach( $_productCollection as $_product)() ?>" class $info
◆ setIdField()
set name of id field
- Parameters
-
- Returns
- $this
- Deprecated:
- Not used anymore.
Definition at line 159 of file Tree.php.
if(!isset($_GET['name'])) $name
◆ setLeftField()
set name of left field
- Parameters
-
- Returns
- $this
- Deprecated:
- Not used anymore.
Definition at line 173 of file Tree.php.
175 $this->_left =
$name;
if(!isset($_GET['name'])) $name
◆ setLevelField()
set name of level field
- Parameters
-
- Returns
- $this
- Deprecated:
- Not used anymore.
Definition at line 201 of file Tree.php.
203 $this->_level =
$name;
if(!isset($_GET['name'])) $name
◆ setPidField()
set name of pid Field
- Parameters
-
- Returns
- $this
- Deprecated:
- Not used anymore.
Definition at line 215 of file Tree.php.
if(!isset($_GET['name'])) $name
◆ setRightField()
set name of right field
- Parameters
-
- Returns
- $this
- Deprecated:
- Not used anymore.
Definition at line 187 of file Tree.php.
189 $this->_right =
$name;
if(!isset($_GET['name'])) $name
◆ setTable()
set table name
- Parameters
-
- Returns
- $this
- Deprecated:
- Not used anymore.
Definition at line 229 of file Tree.php.
231 $this->_table =
$name;
if(!isset($_GET['name'])) $name
The documentation for this class was generated from the following file: