Skip to content

Commit

Permalink
Merge branch 'integration'
Browse files Browse the repository at this point in the history
  • Loading branch information
chillu committed Apr 11, 2012
2 parents 363dc9a + 81cc214 commit 73a466c
Show file tree
Hide file tree
Showing 15 changed files with 523 additions and 187 deletions.
7 changes: 0 additions & 7 deletions _config.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@
'$URLSegment//$Action/$ID/$OtherID' => 'ModelAsController',
));

// Register default side reports
SS_Report::register("SideReport", "SideReport_EmptyPages");
SS_Report::register("SideReport", "SideReport_RecentlyEdited");
if (class_exists('SubsiteReportWrapper')) SS_Report::register('ReportAdmin', 'SubsiteReportWrapper("BrokenLinksReport")',-20);
else SS_Report::register('ReportAdmin', 'BrokenLinksReport',-20);


/**
* Register the default internal shortcodes.
*/
Expand Down
103 changes: 101 additions & 2 deletions code/controllers/CMSMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
'SiteTreeAsUL',
'getshowdeletedsubtree',
'batchactions',
'ListView',
'getListView',
'listchildren',
);

public function init() {
Expand Down Expand Up @@ -157,7 +160,6 @@ public function SiteTreeAsUL() {
function SearchForm() {
// get all page types in a dropdown-compatible format
$pageTypes = SiteTree::page_type_classes();
array_unshift($pageTypes, _t('CMSMain.PAGETYPEANYOPT','Any'));
$pageTypes = array_combine($pageTypes, $pageTypes);
asort($pageTypes);

Expand Down Expand Up @@ -456,6 +458,7 @@ public function getRecord($id, $versionID = null) {
* @return Form
*/
public function getEditForm($id = null, $fields = null) {

if(!$id) $id = $this->currentPageID();
$form = parent::getEditForm($id);

Expand Down Expand Up @@ -528,7 +531,6 @@ public function getEditForm($id = null, $fields = null) {
}

$this->extend('updateEditForm', $form);

return $form;
} else if($id) {
return new Form($this, "EditForm", new FieldList(
Expand All @@ -537,6 +539,95 @@ public function getEditForm($id = null, $fields = null) {
}
}

/**
* Returns the pages meet a certain criteria as {@see CMSSiteTreeFilter} or the subpages of a parent page
* defaulting to no filter and show all pages in first level.
* Doubles as search results, if any search parameters are set through {@link SearchForm()}.
*
* @return SS_List
*/
public function getList(&$filterOn) {
$list = new DataList($this->stat('tree_class'));

$request = $this->request;
$filter = null;
$ids = array();
if($filterClass = $request->requestVar('FilterClass')){
if(!is_subclass_of($filterClass, 'CMSSiteTreeFilter')) {
throw new Exception(sprintf('Invalid filter class passed: %s', $filterClass));
}
$filter = new $filterClass($request->requestVars());
$filterOn = true;
foreach($pages=$filter->pagesIncluded() as $pageMap){
$ids[] = $pageMap['ID'];
}
if(count($ids)) $list->where('"'.$this->stat('tree_class').'"."ID" IN ('.implode(",", $ids).')');
}else{
$parentID = 0;
if($this->urlParams['Action'] == 'listchildren' && $this->urlParams['ID']){
$parentID = $this->urlParams['ID'];
}
$list->filter("ParentID", $parentID);
}

return $list;
}

public function getListView(){
$filterOn = false;
$list = $this->getList($filterOn);
$gridFieldConfig = GridFieldConfig::create()->addComponents(
new GridFieldSortableHeader(),
new GridFieldDataColumns(),
new GridFieldPaginator(15)
);
$gridField = new GridField('Page','Pages', $list, $gridFieldConfig);

if($filterOn){
$gridField->setDisplayFields(array(
'getTreeTitle' => _t('SiteTree.PAGETITLE', 'Page Title'),
'Created' => _t('SiteTree.CREATED', 'Date Created'),
'LastEdited' => _t('SiteTree.LASTUPDATED', 'Last Updated'),
));
}else{
$gridField->setDisplayFields(array(
'listChildrenLink' => "",
'getTreeTitle' => _t('SiteTree.PAGETITLE', 'Page Title'),
'Created' => _t('SiteTree.CREATED', 'Date Created'),
'LastEdited' => _t('SiteTree.LASTUPDATED', 'Last Updated'),
));
}

$gridField->setFieldCasting(array(
'Created' => 'Date->Ago',
'LastEdited' => 'Date->Ago',
));

$gridField->setFieldFormatting(array(
'getTreeTitle' => '<a class=\"cms-panel-link\" href=\"admin/page/edit/show/$ID\">$value</a>'
));

$listview = new Form(
$this,
'ListView',
new FieldList($gridField),
new FieldList()
);

$this->extend('updateListView', $listview);

$listview->disableSecurityToken();
return $listview;
}

public function getListViewHTML(){
return $this->getListView()->forTemplate();
}

public function ListView() {
return $this->getListView();
}

public function currentPageID() {
$id = parent::currentPageID();

Expand All @@ -549,6 +640,14 @@ public function currentPageID() {

return $id;
}

public function listchildren(){
if(Director::is_ajax()){
return $this->getListViewHTML();
}else{
return $this;
}
}

//------------------------------------------------------------------------------------------//
// Data saving handlers
Expand Down
2 changes: 1 addition & 1 deletion code/controllers/CMSSiteTreeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function pagesIncluded() {
switch($name) {
// Match against URLSegment, Title, MenuTitle & Content
case 'Term':
$where[] = "\"URLSegment\" LIKE '%$val%' OR \"Title\" LIKE '%$val%' OR \"MenuTitle\" LIKE '%$val%' OR \"Content\" LIKE '%$val%'";
if($val) $where[] = "\"URLSegment\" LIKE '%$val%' OR \"Title\" LIKE '%$val%' OR \"MenuTitle\" LIKE '%$val%' OR \"Content\" LIKE '%$val%'";
break;
// Match against date
case 'LastEditedFrom':
Expand Down
2 changes: 1 addition & 1 deletion code/controllers/ContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ function successfullyinstalled() {
&nbsp; &nbsp; Email: $username<br />
&nbsp; &nbsp; Password: $password<br />
</p>
<div style="background:#ddd; border:1px solid #ccc; padding:5px; margin:5px;"><img src="cms/images/dialogs/alert.gif" style="border: none; margin-right: 10px; float: left;" /><p style="color:red;">For security reasons you should now delete the install files, unless you are planning to reinstall later (<em>requires admin login, see above</em>). The web server also now only needs write access to the "assets" folder, you can remove write access from all other folders. <a href="home/deleteinstallfiles" style="text-align: center;">Click here to delete the install files.</a></p></div>
<div style="background:#fcf8f2; border-radius:4px; border: 1px solid #ffc28b; padding:5px; margin:5px;"><img src="cms/images/dialogs/alert.gif" style="border: none; margin-right: 10px; float: left; height:48px; width:48px" /><p style="color: #cb6a1c; margin-bottom:0;">For security reasons you should now delete the install files, unless you are planning to reinstall later (<em>requires admin login, see above</em>). The web server also now only needs write access to the "assets" folder, you can remove write access from all other folders. <a href="home/deleteinstallfiles" style="text-align: center;">Click here to delete the install files.</a></p></div>
HTML
);

Expand Down
133 changes: 120 additions & 13 deletions code/controllers/ReportAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,34 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider {

static $url_segment = 'reports';

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

static $menu_title = 'Reports';

static $template_path = null; // defaults to (project)/templates/email

static $tree_class = 'SS_Report';

public static $url_handlers = array(
'$ReportClass/$Action' => 'handleAction'
);

/**
* Variable that describes which report we are currently viewing based on the URL (gets set in init method)
* @var String
*/
protected $reportClass;

protected $reportObject;

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

//set the report we are currently viewing from the URL
$this->reportClass = (isset($this->urlParams['ReportClass'])) ? $this->urlParams['ReportClass'] : null;
$allReports = SS_Report::get_reports();
$this->reportObject = (isset($allReports[$this->reportClass])) ? $allReports[$this->reportClass] : null;

Requirements::css(CMS_DIR . '/css/screen.css');

// Set custom options for TinyMCE specific to ReportAdmin
Expand Down Expand Up @@ -58,12 +75,6 @@ function canView($member = null) {
return false;
}

function currentPageID() {
$id = parent::currentPageID();
$reports = SS_Report::get_reports('ReportAdmin');
return (isset($reports[$id])) ? $reports[$id] : null;
}

/**
* Return a SS_List of SS_Report subclasses
* that are available for use.
Expand All @@ -72,7 +83,7 @@ function currentPageID() {
*/
public function Reports() {
$output = new ArrayList();
foreach(SS_Report::get_reports('ReportAdmin') as $report) {
foreach(SS_Report::get_reports() as $report) {
if($report->canView()) $output->push($report);
}
return $output;
Expand All @@ -90,12 +101,39 @@ public function Reports() {
* @return boolean
*/
public static function has_reports() {
return sizeof(SS_Report::get_reports('ReportAdmin')) > 0;
return sizeof(SS_Report::get_reports()) > 0;
}

public function updatereport() {
// FormResponse::load_form($this->EditForm()->forTemplate());
// return FormResponse::respond();

/**
* Returns the Breadcrumbs for the ReportAdmin
* @return ArrayList
*/
public function Breadcrumbs() {
$items = parent::Breadcrumbs();

// The root element should explicitly point to the root node.
// Uses session state for current record otherwise.
$items[0]->Link = singleton('ReportAdmin')->Link();

if ($this->reportObject) {
//build breadcrumb trail to the current report
$items->push(new ArrayData(array(
'Title' => $this->reportObject->title(),
'Link' => Controller::join_links($this->Link(), '?' . http_build_query(array('q' => $this->request->requestVar('q'))))
)));
}

return $items;
}

/**
* Returns the link to the report admin section, or the specific report that is currently displayed
* @return String
*/
public function Link($action = null) {
$link = parent::Link($action);
if ($this->reportObject) $link = $this->reportObject->getLink($action);
return $link;
}

function providePermissions() {
Expand All @@ -107,5 +145,74 @@ function providePermissions() {
)
);
}

public function getEditForm($id = null, $fields = null) {
$fields = new FieldList();

$report = $this->reportObject;

if($report) {
// List all reports
$gridFieldConfig = GridFieldConfig::create()->addComponents(
new GridFieldToolbarHeader(),
new GridFieldSortableHeader(),
new GridFieldDataColumns(),
new GridFieldPaginator(),
new GridFieldPrintButton(),
new GridFieldExportButton()
);
$gridField = new GridField('Report',$report->title(), $report->sourceRecords(array(), null, null), $gridFieldConfig);
$displayFields = array();
$fieldCasting = array();
$fieldFormatting = array();

// Parse the column information
foreach($report->columns() as $source => $info) {
if(is_string($info)) $info = array('title' => $info);

if(isset($info['formatting'])) $fieldFormatting[$source] = $info['formatting'];
if(isset($info['csvFormatting'])) $csvFieldFormatting[$source] = $info['csvFormatting'];
if(isset($info['casting'])) $fieldCasting[$source] = $info['casting'];

if(isset($info['link']) && $info['link']) {
$link = singleton('CMSPageEditController')->Link('show');
$fieldFormatting[$source] = '<a href=\"' . $link . '/$ID\">$value</a>';
}

$displayFields[$source] = isset($info['title']) ? $info['title'] : $source;
}
$gridField->setDisplayFields($displayFields);
$gridField->setFieldCasting($fieldCasting);
$gridField->setFieldFormatting($fieldFormatting);

$fields->push($gridField);
} else {
// List all reports
$gridFieldConfig = GridFieldConfig::create()->addComponents(
new GridFieldToolbarHeader(),
new GridFieldSortableHeader(),
new GridFieldDataColumns(),
new GridFieldPaginator()
);
$gridField = new GridField('Reports','Reports', $this->Reports(), $gridFieldConfig);
$gridField->setDisplayFields(array(
'title' => 'Title',
'description' => 'Description'
));
$gridField->setFieldFormatting(array(
'title' => '<a href=\"$Link\">$value</a>'
));
$gridField->addExtraClass('all-reports-gridfield');
$fields->push($gridField);
}

$actions = new FieldList();
$form = new Form($this, "EditForm", $fields, $actions);
$form->addExtraClass('cms-edit-form cms-panel-padded center ' . $this->BaseCSSClasses());

$this->extend('updateEditForm', $form);

return $form;
}
}

7 changes: 7 additions & 0 deletions code/model/SiteTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -2475,6 +2475,13 @@ function TreeTitle() {
Deprecation::notice('3.0', 'Use getTreeTitle() instead.');
return $this->getTreeTitle();
}

function listChildrenLink(){
if($num = $this->numChildren()){
$link = singleton('CMSPagesController')->Link('listchildren')."/".$this->ID;
return '<a href="'.$link.'" class="list-children-link">'.$num.'</a>';
}
}

/**
* getTreeTitle will return three <span> html DOM elements, an empty <span> with
Expand Down
Loading

0 comments on commit 73a466c

Please sign in to comment.