-
Docs
Backend
-
Behaviors
-
Classes
-
Controllers
-
Database
-
Seeds
-
-
Facades
-
FormWidgets
-
Helpers
-
Exception
- Backend
-
-
Models
-
ReportWidgets
-
Skins
-
Traits
-
Widgets
- ServiceProvider
-
-
Cms
-
Classes
- Asset
- AutoDatasource
- CmsCompoundObject
- CmsController
- CmsException
- CmsObject
- CmsObjectCollection
- CodeBase
- CodeParser
- ComponentBase
- ComponentHelpers
- ComponentManager
- ComponentPartial
- Content
- Controller
- Layout
- LayoutCode
- MediaLibrary
- MediaLibraryItem
- MediaViewHelper
- Meta
- ObjectMemoryCache
- Page
- PageCode
- Partial
- PartialCode
- PartialStack
- Router
- Theme
- ThemeManager
-
Components
-
Contracts
-
Controllers
-
Facades
-
FormWidgets
-
Helpers
-
Models
-
ReportWidgets
-
Traits
-
Twig
- ComponentNode
- ComponentTokenParser
- ContentNode
- ContentTokenParser
- DebugExtension
- DefaultNode
- DefaultTokenParser
- Extension
- FlashNode
- FlashTokenParser
- FrameworkNode
- FrameworkTokenParser
- Loader
- PageNode
- PageTokenParser
- PartialNode
- PartialTokenParser
- PlaceholderNode
- PlaceholderTokenParser
- PutNode
- PutTokenParser
- ScriptsNode
- ScriptsTokenParser
- StylesNode
- StylesTokenParser
-
Widgets
- ServiceProvider
-
-
System
-
Behaviors
-
Classes
-
Console
-
Controllers
-
Database
-
Helpers
-
Models
-
ReportWidgets
-
Traits
-
Twig
- ServiceProvider
-
-
Events
-
backend
-
ajax
-
filter
-
form
-
list
-
menu
-
page
-
user
-
-
cms
-
ajax
-
block
-
combiner
-
component
-
object
-
page
-
router
-
template
-
theme
-
-
halcyon
-
datasource
-
-
mailer
-
media
-
model
-
system
-
assets
-
console
-
mirror
-
theme
-
-
reportwidgets
-
settings
- extendConfigFile
-
-
translator
-
-
Library
-
Argon
-
Auth
-
Models
- AuthException
- Manager
-
-
Config
-
Cookie
-
Middleware
-
-
Database
-
Attach
-
Behaviors
-
Concerns
-
Connections
-
Connectors
-
Models
-
Relations
-
Schema
-
Traits
-
Updates
- README
- Builder
- Collection
- DatabaseServiceProvider
- DataFeed
- Dongle
- MemoryCache
- Model
- ModelBehavior
- ModelException
- NestedTreeScope
- Pivot
- QueryBuilder
- SortableScope
- TreeCollection
- Updater
-
-
Events
-
Exception
-
Extension
-
Filesystem
-
Flash
-
Foundation
-
Bootstrap
-
Console
-
Exception
-
Http
-
Middleware
- Kernel
-
-
Providers
- Application
- Maker
-
-
Halcyon
-
Datasource
-
Exception
-
Processors
-
Traits
- README
- Builder
- Collection
- HalcyonServiceProvider
- MemoryCacheManager
- MemoryRepository
- Model
-
-
Html
-
Mail
-
Network
-
Parse
-
Router
-
Scaffold
-
Support
-
Translation
-
- Documentation
- API
- Library
- Database
- Traits
- SimpleTree
October\Rain\Database\Traits\SimpleTree
Source: ~/vendor/october/rain/src/Database/Traits/SimpleTree.php
Simple Tree model trait
Simple tree implementation, for advanced implementation see: October\Rain\Database\Traits\NestedTree
SimpleTree is the bare minimum needed for tree functionality, the methods defined here should be implemented by all "tree" traits.
Usage:
Model table must have parent_id table column. In the model class definition:
use \October\Rain\Database\Traits\SimpleTree;
General access methods:
$model->getChildren(); // Returns children of this node $model->getChildCount(); // Returns number of all children. $model->getAllChildren(); // Returns all children of this node $model->getAllRoot(); // Returns all root level nodes (eager loaded) $model->getAll(); // Returns everything in correct order.
Query builder methods:
$query->listsNested(); // Returns an indented array of key and value columns.
You can change the sort field used by declaring:
const PARENT_ID = 'my_parent_column';
Public methods
public static void bootSimpleTree()
public October\Rain\Database\Collection getAll()
Returns all nodes and children.
public October\Rain\Database\Collection getAllChildren()
Get a list of children records, with their children (recursive)
public int getChildCount()
Returns number of all children below it.
public October\Rain\Database\Collection getChildren()
Returns direct child nodes.
public string getParentColumnName()
Get parent column name.
public int getParentId()
Get value of the model parent_id column.
public string getQualifiedParentColumnName()
Get fully qualified parent column name.
public void newCollection($models=array())
Return a custom TreeCollection collection
Parameters
- $models
public October\Rain\Database\Collection scopeGetAllRoot($query)
Returns a list of all root nodes, without eager loading.
Parameters
- $query
public Collection scopeGetNested($query)
Non chaining scope, returns an eager loaded hierarchy tree. Children are eager loaded inside the $model->children relation.
Parameters
- $query
public array scopeListsNested(string $column, string $key, string $indent=NULL, $indent=' ')
Gets an array with values of a given column. Values are indented according to their depth.
Parameters
- string $column - Array values
- string $key - Array keys
- string $indent - Character to indent depth
- $indent