Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -11,7 +11,7 @@
|
||||
namespace IPS\Helpers\Tree;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -80,17 +80,18 @@ class _Tree
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $url URL where the tree table is displayed
|
||||
* @param string $title Tree Table title
|
||||
* @param callback $getRoots Callback function to get the root rows
|
||||
* @param callback $getRow Callback function to get a single row by ID
|
||||
* @param callback $getRowParentId Callback function to get the parent ID for a row
|
||||
* @param callback $getChildren Callback function to get the child rows for a row
|
||||
* @param callback $searchable Show the search bar?
|
||||
* @param bool $lockParents If true, will prevent any item from being moved out of its current parent, only allowing them to be reordered within their current parent
|
||||
* @param bool $protectRoots If true, root cannot be turned into sub-items, and other items cannot be turned into roots
|
||||
* @param int|null $rootsPerPage Number of roots to show per page (NULL for unlimited). In most cases this doesn't make sense, since it makes re-ordering impossible. But for trees which are not orderable and which may contain a lot of roots, you can set this value
|
||||
* @param callback $getTotalRoots If using $rootsPerPage, a callback function that returns the total number of roots
|
||||
* @param string $url URL where the tree table is displayed
|
||||
* @param string $title Tree Table title
|
||||
* @param callback $getRoots Callback function to get the root rows
|
||||
* @param callback $getRow Callback function to get a single row by ID
|
||||
* @param callback $getRowParentId Callback function to get the parent ID for a row
|
||||
* @param callback $getChildren Callback function to get the child rows for a row
|
||||
* @param callback|null $getRootButtons Callback function to get the root buttons
|
||||
* @param callback $searchable Show the search bar?
|
||||
* @param bool $lockParents If true, will prevent any item from being moved out of its current parent, only allowing them to be reordered within their current parent
|
||||
* @param bool $protectRoots If true, root cannot be turned into sub-items, and other items cannot be turned into roots
|
||||
* @param int|null $rootsPerPage Number of roots to show per page (NULL for unlimited). In most cases this doesn't make sense, since it makes re-ordering impossible. But for trees which are not orderable and which may contain a lot of roots, you can set this value
|
||||
* @param callback $getTotalRoots If using $rootsPerPage, a callback function that returns the total number of roots
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $url, $title, $getRoots, $getRow, $getRowParentId, $getChildren, $getRootButtons=NULL, $searchable=FALSE, $lockParents=FALSE, $protectRoots=FALSE, $rootsPerPage = NULL, $getTotalRoots = NULL )
|
||||
@@ -119,31 +120,37 @@ class _Tree
|
||||
try
|
||||
{
|
||||
/* Get rows */
|
||||
$page = isset( \IPS\Request::i()->page ) ? intval( \IPS\Request::i()->page ) : 1;
|
||||
$page = isset( \IPS\Request::i()->page ) ? \intval( \IPS\Request::i()->page ) : 1;
|
||||
$root = NULL;
|
||||
$rootParent = NULL;
|
||||
|
||||
if( !\IPS\Request::i()->root )
|
||||
{
|
||||
$rows = call_user_func( $this->getRoots, $this->rootsPerPage ? array( ( $page - 1 ) * $this->rootsPerPage, $this->rootsPerPage ) : NULL );
|
||||
$getRootsFunction = $this->getRoots;
|
||||
$rows = $getRootsFunction( $this->rootsPerPage ? array( ( $page - 1 ) * $this->rootsPerPage, $this->rootsPerPage ) : NULL );
|
||||
}
|
||||
else
|
||||
{
|
||||
$rows = call_user_func( $this->getChildren, \IPS\Request::i()->root );
|
||||
$getChildrenFunction = $this->getChildren;
|
||||
$rows = $getChildrenFunction( \IPS\Request::i()->root );
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'trees', 'core' )->rows( $rows, mt_rand() );
|
||||
}
|
||||
|
||||
$root = call_user_func( $this->getRow, \IPS\Request::i()->root, TRUE );
|
||||
$rootParent = call_user_func( $this->getRowParentId, \IPS\Request::i()->root );
|
||||
$getRowFunction = $this->getRow;
|
||||
$root = $getRowFunction( \IPS\Request::i()->root, TRUE );
|
||||
$getRowParentIdFunction = $this->getRowParentId;
|
||||
$rootParent = $getRowParentIdFunction( \IPS\Request::i()->root );
|
||||
}
|
||||
|
||||
/* Pagination? */
|
||||
$pagination = '';
|
||||
if ( $this->rootsPerPage )
|
||||
{
|
||||
$totalNumber = call_user_func( $this->getTotalRoots );
|
||||
$getTotalRootsFunction = $this->getTotalRoots;
|
||||
$totalNumber = $getTotalRootsFunction();
|
||||
if ( $totalNumber )
|
||||
{
|
||||
$pagination = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->pagination( $this->url, ceil( $totalNumber / $this->rootsPerPage ), $page, $this->rootsPerPage );
|
||||
@@ -151,7 +158,8 @@ class _Tree
|
||||
}
|
||||
|
||||
/* Display */
|
||||
return \IPS\Theme::i()->getTemplate( 'trees', 'core' )->template( $this->url, $this->title, $root, $rootParent, $rows, call_user_func( $this->getRootButtons ), $this->lockParents, $this->protectRoots, $this->searchable, $pagination );
|
||||
$getRootButtonsFunction = $this->getRootButtons;
|
||||
return \IPS\Theme::i()->getTemplate( 'trees', 'core' )->template( $this->url, $this->title, $root, $rootParent, $rows, $getRootButtonsFunction(), $this->lockParents, $this->protectRoots, $this->searchable, $pagination );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user