API Enable tree filter highlighting

Decoupling of CMS / Framework
This commit is contained in:
Damian Mooyman 2015-04-30 17:14:45 +12:00
parent f4f226927d
commit c5e0c8f007
2 changed files with 43 additions and 20 deletions

View File

@ -13,7 +13,7 @@
* @package cms
* @subpackage content
*/
abstract class CMSSiteTreeFilter extends Object {
abstract class CMSSiteTreeFilter extends Object implements LeftAndMain_SearchFilter {
/**
* @var Array Search parameters, mostly properties on {@link SiteTree}.
@ -22,9 +22,21 @@ abstract class CMSSiteTreeFilter extends Object {
protected $params = array();
/**
* @var Array
* List of filtered items and all their parents
*
* @var array
*/
protected $_cache_ids = null;
/**
* Subset of $_cache_ids which include only items that appear directly in search results.
* When highlighting these, item IDs in this subset should be visually distinguished from
* others in the complete set.
*
* @var array
*/
protected $_cache_highlight_ids = null;
/**
* @var Array
@ -75,22 +87,25 @@ abstract class CMSSiteTreeFilter extends Object {
parent::__construct();
}
/**
* Method on {@link Hierarchy} objects which is used to traverse into children relationships.
*
* @return String
*/
public function getChildrenMethod() {
return $this->childrenMethod;
}
/**
* Method on {@link Hierarchy} objects which is used find the number of children for a parent page
*/
public function getNumChildrenMethod() {
return $this->numChildrenMethod;
}
public function getPageClasses($page) {
if($this->_cache_ids === NULL) {
$this->populateIDs();
}
// If directly selected via filter, apply highlighting
if(!empty($this->_cache_highlight_ids[$page->ID])) {
return 'filtered-item';
}
}
/**
* Gets the list of filtered pages
*
@ -113,6 +128,7 @@ abstract class CMSSiteTreeFilter extends Object {
protected function populateIDs() {
$parents = array();
$this->_cache_ids = array();
$this->_cache_highlight_ids = array();
if($pages = $this->pagesIncluded()) {
@ -121,6 +137,7 @@ abstract class CMSSiteTreeFilter extends Object {
foreach($pages as $pageArr) {
$parents[$pageArr['ParentID']] = true;
$this->_cache_ids[$pageArr['ID']] = true;
$this->_cache_highlight_ids[$pageArr['ID']] = true;
}
while(!empty($parents)) {
@ -136,17 +153,12 @@ abstract class CMSSiteTreeFilter extends Object {
}
}
/**
* Returns TRUE if the given page should be included in the tree.
* Caution: Does NOT check view permissions on the page.
*
* @param SiteTree $page
* @return Boolean
*/
public function isPageIncluded($page) {
if($this->_cache_ids === NULL) $this->populateIDs();
if($this->_cache_ids === NULL) {
$this->populateIDs();
}
return (isset($this->_cache_ids[$page->ID]) && $this->_cache_ids[$page->ID]);
return !empty($this->_cache_ids[$page->ID]);
}
/**

View File

@ -19,7 +19,18 @@ $ExtraTreeTools
</div>
<% end_if %>
<div class="cms-tree" data-url-tree="$LinkWithSearch($Link(getsubtree))" data-url-savetreenode="$Link(savetreenode)" data-url-updatetreenodes="$Link(updatetreenodes)" data-url-addpage="{$LinkPageAdd('AddForm/?action_doAdd=1', 'ParentID=%s&amp;PageType=%s')}" data-url-editpage="$LinkPageEdit('%s')" data-url-duplicate="{$Link('duplicate/%s')}" data-url-duplicatewithchildren="{$Link('duplicatewithchildren/%s')}" data-url-listview="{$Link('?view=list')}" data-hints="$SiteTreeHints.XML" data-childfilter="$Link('childfilter')" data-extra-params="SecurityID=$SecurityID">
<div class="cms-tree <% if $TreeIsFiltered %>filtered-list<% end_if %>"
data-url-tree="$LinkWithSearch($Link(getsubtree))"
data-url-savetreenode="$Link(savetreenode)"
data-url-updatetreenodes="$Link(updatetreenodes)"
data-url-addpage="{$LinkPageAdd('AddForm/?action_doAdd=1', 'ParentID=%s&amp;PageType=%s')}"
data-url-editpage="$LinkPageEdit('%s')"
data-url-duplicate="{$Link('duplicate/%s')}"
data-url-duplicatewithchildren="{$Link('duplicatewithchildren/%s')}"
data-url-listview="{$Link('?view=list')}"
data-hints="$SiteTreeHints.XML"
data-childfilter="$Link('childfilter')"
data-extra-params="SecurityID=$SecurityID">
$SiteTreeAsUL
</div>
</div>