23/02/2012 11:26pm

PHP | Problem -


<?php

/**
* EventAdmin displays a slice of the SiteTree centered on the first EventsLandingPage it can find.
* Then we filter all entries to show only EventPages, and sort them by their Event Date.
*/

class EventAdmin extends CMSMain {

static $url_segment = 'events';

static $url_rule = '/$Action/$ID';

static $menu_title = 'Events';

private $otherMarkingFunction = null;

function init() {
parent::init();

Requirements::javascript('mysite/javascript/EventAdmin.js');
}

/**
* Allow only section specific page types.
*/
function filterMarking($node) {
// But we have to honour the other filtered passed to getSiteTreeFor.
if ($this->otherMarkingFunction) {
$otherResult = call_user_func($this->otherMarkingFunction, $node);
if (!$otherResult) return false;
}

return (
$node->ClassName=='EventsLandingPage'
||
$node->ClassName=='EventPage'
||
$node->ClassName=='Holder');
}

/**
* Changes the root of the site tree to be shown.
*/
function getSiteTreeFor($className, $rootID = null, $childrenMethod = null, $numChildrenMethod = null, $filterFunction = null, $minNodeCount = 30) {
$news = DataObject::get_one('EventsLandingPage');
if (!$news) {
$siteTree = "<p>No EventsLandingPage found!</p><p>Please create one now via <a href='".Director::baseURL()."admin/'>Pages section</a>";
return $siteTree;
}

// Default childrenMethod and numChildrenMethod
if (!$childrenMethod) $childrenMethod = 'AllChildrenIncludingDeleted';
if (!$numChildrenMethod) $numChildrenMethod = 'numChildren';

// Get the tree root, default to NewsLandingPage
$obj = $rootID ? $this->getRecord($rootID) : $this->getRecord($news->ID);

// Mark the nodes of the tree to return
if ($filterFunction) {
// First store the other filter, it will be called manually by our replacement filter.
// Otherwise search wouldn't work.
$this->otherMarkingFunction = $filterFunction;
}
$obj->setMarkingFilterFunction(array($this, 'filterMarking'));

$obj->markPartialTree($minNodeCount, $this, $childrenMethod, $numChildrenMethod);

// Ensure current page is exposed
if($p = $this->currentPage()) $obj->markToExpose($p);

// NOTE: SiteTree/CMSMain coupling :-(
SiteTree::prepopuplate_permission_cache('CanEditType', $obj->markedNodeIDs(), 'SiteTree::can_edit_multiple');

// getChildrenAsUL is a flexible and complex way of traversing the tree
$titleEval = '
"<li id=\"record-$child->ID\" class=\"" . $child->CMSTreeClasses($extraArg) . "\">" .
"<a href=\"" . Controller::join_links(substr($extraArg->Link(),0,-1), "show", $child->ID) . "\" class=\"" . $child->CMSTreeClasses($extraArg) . "\" title=\"' . _t('LeftAndMain.PAGETYPE','Page type: ') . '".$child->class."\" >" .
($child->TreeTitle()) .
"</a>"
';
$siteTree = $obj->getChildrenAsUL(
"",
$titleEval,
$this,
true,
$childrenMethod,
$numChildrenMethod,
$minNodeCount
);

// Wrap the root if needs be.

if(!$rootID) {
$rootLink = $this->Link('show') . '/' . $news->ID;
$siteTree = "<ul id=\"sitetree\" class=\"tree unformatted\"><li id=\"record-$news->ID\" class=\"Root nodelete\"><a href=\"$rootLink\"><strong>$news->Title</strong></a>"
. $siteTree . "</li></ul>";
}

return $siteTree;
}
}


Post Comment