Skip to content

Commit 802ec53

Browse files
author
Flaviu Chelaru
committed
initial commit
1 parent b7489e1 commit 802ec53

File tree

4,322 files changed

+424264
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,322 files changed

+424264
-2
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea/
2+
3+
!**/.gitkeep

README.md

+55-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,55 @@
1-
# phalcon-nested-sets
2-
Nested Set Model implementation for Phalcon Framework
1+
Nested Set Behaviour
2+
---
3+
4+
Phalcon implementation for tree / hierarchy through nested sets implementation.
5+
It will calculate edges and depth for a category on creation, update and delete.
6+
7+
Moving "branches" is not supported (o sub-node with all it's sub-nodes) and won't be. This tool is meant to "react" to changes on a single record and keep the rest of the tree position in place.
8+
9+
prerequisites
10+
---
11+
Your DB must have parent, left, right, depth columns.
12+
Example:
13+
14+
```SQL
15+
CREATE TABLE `categories` (
16+
`id` INT(11) NOT NULL AUTO_INCREMENT,
17+
`name` CHAR(50) NULL DEFAULT NULL,
18+
`parent_id` INT(11) NULL DEFAULT NULL,
19+
`_left` INT(11) NULL DEFAULT NULL,
20+
`_right` INT(11) NULL DEFAULT NULL,
21+
`_depth` INT(11) NULL DEFAULT NULL,
22+
PRIMARY KEY (`id`)
23+
);
24+
```
25+
26+
usage
27+
---
28+
29+
```php
30+
31+
class MyModel extends \Phalcon\Mvc\Model {
32+
public function initialize() {
33+
$this->addBehaviour(new \P4BGroup\NestedSets\Behaviour());
34+
}
35+
}
36+
37+
```
38+
39+
references
40+
---
41+
* https://en.wikipedia.org/wiki/Nested_set_model
42+
* https://explainextended.com/2009/09/29/adjacency-list-vs-nested-sets-mysql/
43+
* https://medium.com/@Sumurai8/nested-sets-performant-attribute-calculation-on-collections-10289a30c0ab
44+
45+
usage
46+
---
47+
this behaviour will automatically calculate the edges and depth of each node on save / delete
48+
49+
Similar implementations on other frameworks
50+
---
51+
* https://github.com/etrepat/baum - laravel
52+
* https://github.com/lazychaser/laravel-nestedset - laravel
53+
* https://github.com/blt04/doctrine2-nestedset - doctrine
54+
* https://github.com/bartko-s/stefano-tree - zend / pdo
55+
* https://github.com/creocoder/yii2-nested-sets - yii

composer.json

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "p4bgroup/phalcon-nested-sets",
3+
"type": "library",
4+
"description": "Phalcon Nested Set Models. Nested set models for Phalcon Framework",
5+
"keywords": [
6+
"phalcon",
7+
"nested set",
8+
"tree",
9+
"hierarchy",
10+
"mysql",
11+
"sqlite",
12+
"mssql",
13+
"pdo"
14+
],
15+
"license": "MIT",
16+
"require": {
17+
"php": ">= 7.2",
18+
"ext-pdo": "*",
19+
"ext-phalcon": "^3.4"
20+
},
21+
"require-dev": {
22+
"phalcon/ide-stubs": "^3.4",
23+
"phpmd/phpmd": "^2.6",
24+
"phpunit/phpunit": "~8.4",
25+
"roave/security-advisories": "dev-master",
26+
"squizlabs/php_codesniffer": "^3.3"
27+
},
28+
"autoload": {
29+
"psr-4": {
30+
"P4BGroup\\NestedSets\\": "src/"
31+
}
32+
},
33+
"autoload-dev": {
34+
"psr-4": {
35+
"P4BGroup\\NestedSets\\tests\\": "tests/"
36+
}
37+
},
38+
"scripts": {
39+
"test": [
40+
"phpmd src,tests text cleancode,codesize,controversial,design,unusedcode,naming --ignore-violations-on-exit",
41+
"phpcs --config-set ignore_errors_on_exit 1",
42+
"phpcs --standard=PSR12 src tests",
43+
"phpunit --configuration=phpunit.xml --teamcity"
44+
]
45+
}
46+
}

0 commit comments

Comments
 (0)