2015-04-21 06:47:46 +02:00
|
|
|
<?php
|
|
|
|
|
2016-12-15 04:41:49 +01:00
|
|
|
namespace SilverStripe\Blog\Admin;
|
|
|
|
|
2016-12-16 05:10:38 +01:00
|
|
|
use SilverStripe\Blog\Forms\GridField\GridFieldAddByDBField;
|
2016-12-15 04:41:49 +01:00
|
|
|
use SilverStripe\Blog\Model\CategorisationObject;
|
2019-10-15 04:35:47 +02:00
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
2018-04-06 00:21:26 +02:00
|
|
|
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
|
2016-12-15 04:41:49 +01:00
|
|
|
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
|
2018-01-29 04:13:19 +01:00
|
|
|
use SilverStripe\Forms\GridField\GridFieldDataColumns;
|
2018-04-06 00:21:26 +02:00
|
|
|
use SilverStripe\ORM\SS_List;
|
2016-12-15 04:41:49 +01:00
|
|
|
|
2015-11-21 07:17:29 +01:00
|
|
|
class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor
|
|
|
|
{
|
|
|
|
/**
|
2019-10-15 04:35:47 +02:00
|
|
|
* @param int $itemsPerPage
|
2015-11-21 07:17:29 +01:00
|
|
|
* @param array|SS_List $mergeRecords
|
2019-10-15 04:35:47 +02:00
|
|
|
* @param string $parentType
|
|
|
|
* @param string $parentMethod
|
|
|
|
* @param string $childMethod
|
|
|
|
* @param SiteTree $parent
|
2015-11-21 07:17:29 +01:00
|
|
|
*/
|
2019-10-15 04:35:47 +02:00
|
|
|
public function __construct($itemsPerPage, $mergeRecords, $parentType, $parentMethod, $childMethod, $parent)
|
2015-11-21 07:17:29 +01:00
|
|
|
{
|
|
|
|
parent::__construct($itemsPerPage);
|
|
|
|
|
2018-04-06 00:21:26 +02:00
|
|
|
$this->removeComponentsByType(GridFieldAddNewButton::class);
|
2015-11-21 07:17:29 +01:00
|
|
|
|
|
|
|
$this->addComponent(
|
2017-09-14 01:49:27 +02:00
|
|
|
GridFieldAddByDBField::create('buttons-before-left')
|
2015-11-21 07:17:29 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->addComponent(
|
2017-09-14 01:49:27 +02:00
|
|
|
GridFieldMergeAction::create($mergeRecords, $parentType, $parentMethod, $childMethod)
|
2015-11-21 07:17:29 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var GridFieldDataColumns $columns
|
|
|
|
*/
|
2018-04-06 00:21:26 +02:00
|
|
|
$columns = $this->getComponentByType(GridFieldDataColumns::class);
|
2015-11-21 07:17:29 +01:00
|
|
|
|
2016-12-16 05:10:38 +01:00
|
|
|
$columns->setFieldFormatting(
|
2017-09-14 00:59:01 +02:00
|
|
|
[
|
2019-10-15 04:35:47 +02:00
|
|
|
'BlogPostsCount' => function ($value, CategorisationObject $item) use ($parent) {
|
|
|
|
return $item
|
|
|
|
->BlogPosts()
|
|
|
|
->filter(['ParentID' => $parent->ID])
|
|
|
|
->Count();
|
|
|
|
},
|
|
|
|
'BlogPostsAllCount' => function ($value, CategorisationObject $item) {
|
2016-12-16 05:10:38 +01:00
|
|
|
return $item->BlogPosts()->Count();
|
2019-10-15 04:35:47 +02:00
|
|
|
},
|
2017-09-14 00:59:01 +02:00
|
|
|
]
|
2016-12-16 05:10:38 +01:00
|
|
|
);
|
2016-12-15 04:41:49 +01:00
|
|
|
$columns->setDisplayFields(
|
2017-09-14 00:59:01 +02:00
|
|
|
[
|
2019-10-15 04:35:47 +02:00
|
|
|
'Title' => _t(__CLASS__ . '.Title', 'Title'),
|
|
|
|
'BlogPostsCount' => _t(__CLASS__ . '.PostsThisBlog', 'Posts (This Blog)'),
|
|
|
|
'BlogPostsAllCount' => _t(__CLASS__ . '.PostsAllBlogs', 'Posts (All Blogs)'),
|
|
|
|
'MergeAction' => 'MergeAction',
|
|
|
|
'Actions' => 'Actions'
|
2017-09-14 00:59:01 +02:00
|
|
|
]
|
2016-12-15 04:41:49 +01:00
|
|
|
);
|
2015-11-21 07:17:29 +01:00
|
|
|
}
|
|
|
|
}
|