IMPR: code linting

This commit is contained in:
Tony Air 2022-01-13 11:54:33 +02:00
parent 6dae2f685d
commit 86a71bbb4e
2 changed files with 67 additions and 63 deletions

View File

@ -4,15 +4,15 @@
// extends global Page class // extends global Page class
//namespace App\Pages; //namespace App\Pages;
use SilverStripe\CMS\Model\SiteTree;
use DNADesign\Elemental\Models\ElementContent; use DNADesign\Elemental\Models\ElementContent;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\FontAwesome\FontAwesomeField; use SilverStripe\FontAwesome\FontAwesomeField;
use TractorCow\Fluent\Extension\FluentSiteTreeExtension; use TractorCow\Fluent\Extension\FluentSiteTreeExtension;
class Page extends SiteTree class Page extends SiteTree
{ {
private static $default_container_class = 'container';
protected $_cached = []; protected $_cached = [];
private static $default_container_class = 'container';
private static $db = [ private static $db = [
'BlockIcon' => 'Varchar(255)', 'BlockIcon' => 'Varchar(255)',
]; ];
@ -21,7 +21,6 @@ class Page extends SiteTree
'ElementalAreaID', 'ElementalAreaID',
]; ];
public static function DefaultContainer() public static function DefaultContainer()
{ {
return self::config()->get('default_container_class'); return self::config()->get('default_container_class');
@ -51,6 +50,7 @@ class Page extends SiteTree
$summary = $this->getField('Summary'); $summary = $this->getField('Summary');
if ($summary) { if ($summary) {
$this->_cached['summary' . $wordsToDisplay] = $summary; $this->_cached['summary' . $wordsToDisplay] = $summary;
return $this->_cached['summary' . $wordsToDisplay]; return $this->_cached['summary' . $wordsToDisplay];
} }
@ -61,16 +61,19 @@ class Page extends SiteTree
if ($element) { if ($element) {
$this->_cached['summary' . $wordsToDisplay] = $element->dbObject('HTML')->Summary($wordsToDisplay); $this->_cached['summary' . $wordsToDisplay] = $element->dbObject('HTML')->Summary($wordsToDisplay);
return $this->_cached['summary' . $wordsToDisplay]; return $this->_cached['summary' . $wordsToDisplay];
} }
$content = $this->getField('Content'); $content = $this->getField('Content');
if ($content) { if ($content) {
$this->_cached['summary' . $wordsToDisplay] = $this->dbObject('Content')->Summary($wordsToDisplay); $this->_cached['summary' . $wordsToDisplay] = $this->dbObject('Content')->Summary($wordsToDisplay);
return $this->_cached['summary' . $wordsToDisplay]; return $this->_cached['summary' . $wordsToDisplay];
} }
$this->_cached['summary' . $wordsToDisplay] = false; $this->_cached['summary' . $wordsToDisplay] = false;
return $this->_cached['summary' . $wordsToDisplay]; return $this->_cached['summary' . $wordsToDisplay];
} }

View File

@ -4,26 +4,26 @@
// extends global PageController class // extends global PageController class
//namespace App\Pages; //namespace App\Pages;
use SilverStripe\Control\Controller; use A2nt\CMSNiceties\Templates\DeferredRequirements;
use A2nt\ElementalBasics\Models\TeamMember;
use DNADesign\Elemental\Models\ElementalArea;
use DNADesign\Elemental\Models\ElementContent;
use DNADesign\ElementalUserForms\Control\ElementFormController;
use SilverStripe\CMS\Controllers\ContentController; use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\Control\Director;
use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\View\ArrayData;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\ORM\PaginatedList; use SilverStripe\Control\Controller;
use SilverStripe\Forms\Form; use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Core\Config\Config;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField; use SilverStripe\Forms\Form;
use SilverStripe\Forms\FormAction; use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\RequiredFields; use SilverStripe\Forms\RequiredFields;
use SilverStripe\Control\HTTPRequest; use SilverStripe\Forms\TextField;
use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\ArrayList;
use DNADesign\Elemental\Models\ElementContent; use SilverStripe\ORM\FieldType\DBDatetime;
use DNADesign\Elemental\Models\ElementalArea; use SilverStripe\ORM\PaginatedList;
use DNADesign\ElementalUserForms\Control\ElementFormController; use SilverStripe\View\ArrayData;
use A2nt\ElementalBasics\Models\TeamMember;
use A2nt\CMSNiceties\Templates\DeferredRequirements;
class PageController extends ContentController class PageController extends ContentController
{ {
@ -42,13 +42,6 @@ class PageController extends ContentController
private $site_message; private $site_message;
private $search_term; private $search_term;
protected function init()
{
DeferredRequirements::Auto();
return parent::init();
}
public function index(HTTPRequest $request) public function index(HTTPRequest $request)
{ {
$search = $request->getVar('q'); $search = $request->getVar('q');
@ -66,7 +59,7 @@ class PageController extends ContentController
public function ElementalArea() public function ElementalArea()
{ {
if (!$this->getAction() || $this->getAction() === 'index') { if (! $this->getAction() || 'index' === $this->getAction()) {
return ElementalArea::get()->byID($this->getField('ElementalAreaID')); return ElementalArea::get()->byID($this->getField('ElementalAreaID'));
} }
@ -87,6 +80,7 @@ class PageController extends ContentController
public function SearchForm(): Form public function SearchForm(): Form
{ {
$config = $this->SiteConfig(); $config = $this->SiteConfig();
return Form::create( return Form::create(
$this, $this,
__FUNCTION__, __FUNCTION__,
@ -117,22 +111,6 @@ class PageController extends ContentController
return $this->renderWith([__CLASS__ . '_search', 'Page']); return $this->renderWith([__CLASS__ . '_search', 'Page']);
} }
private static function getSearchObjects($classNames, $term): ArrayList
{
$elements = ArrayList::create();
foreach ($classNames as $class) {
$fields = Config::inst()->get($class, 'frontend_searchable_fields');
$find = array_combine($fields, $fields);
$find = array_map(static function () use ($term) {
return $term;
}, $find);
$elements->merge($class::get()->filterAny($find)->sort('Created DESC'));
}
return $elements;
}
public function SearchResults() public function SearchResults()
{ {
$term = $this->search_term; $term = $this->search_term;
@ -234,4 +212,27 @@ class PageController extends ContentController
{ {
return Director::isDev(); return Director::isDev();
} }
protected function init()
{
DeferredRequirements::Auto();
return parent::init();
}
private static function getSearchObjects($classNames, $term): ArrayList
{
$elements = ArrayList::create();
foreach ($classNames as $class) {
$fields = Config::inst()->get($class, 'frontend_searchable_fields');
$find = array_combine($fields, $fields);
$find = array_map(static function () use ($term) {
return $term;
}, $find);
$elements->merge($class::get()->filterAny($find)->sort('Created DESC'));
}
return $elements;
}
} }