Skip to content

Instantly share code, notes, and snippets.

@benald
Created December 1, 2017 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benald/bd2d34f979583e1c5f9de1b3c02303ed to your computer and use it in GitHub Desktop.
Save benald/bd2d34f979583e1c5f9de1b3c02303ed to your computer and use it in GitHub Desktop.
SIlverstripe 3.5 filters page
<?php
class FiltersPage extends Page {
private static $has_many = array (
'Types' => 'Type',
'Services' => 'Service',
'Industries' => 'Industry',
'Approaches' => 'Approach',
'Projects' => 'Project'
);
static $defaults = array (
'ShowInMenus' => false,
'ShowInSearch' => false
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Filters', GridField::create(
'Types',
'Types on this page',
$this->Types(),
GridFieldConfig_RecordEditor::create()
));
$fields->addFieldToTab('Root.Filters', GridField::create(
'Services',
'Services on this page',
$this->Services(),
GridFieldConfig_RecordEditor::create()
));
$fields->addFieldToTab('Root.Filters', GridField::create(
'Industries',
'Industries on this page',
$this->Industries(),
GridFieldConfig_RecordEditor::create()
));
$fields->addFieldToTab('Root.Filters', GridField::create(
'Approaches',
'Approaches on this page',
$this->Approaches(),
GridFieldConfig_RecordEditor::create()
));
$fields->addFieldToTab('Root.Filters', GridField::create(
'Projects',
'Projects on this page',
$this->Projects(),
GridFieldConfig_RecordEditor::create()
));
return $fields;
}
}
class FiltersPage_Controller extends Page_Controller {
private static $allowed_actions = array (
'showtypes',
'showindustry',
'showapproach',
'showservice'
);
public function ListTypes($tcount = 6) {
return Type::get()
->sort('Created', 'ASC')
->limit($tcount);
}
public function ListIndustries($icount = 6) {
return Industry::get()
->sort('Created', 'ASC')
->limit($icount);
}
public function ListApproaches($acount = 6) {
return Approach::get()
->sort('Created', 'ASC')
->limit($acount);
}
public function ListServices($scount = 20) {
return Service::get()
->sort('Created', 'ASC')
->limit($scount);
}
public function ListProjects($pcount = 20) {
return Project::get()
->sort('Created', 'ASC')
->limit($pcount);
}
public function showservice(SS_HTTPRequest $request) {
$service = Service::get()->byID($request->param('ID'));
if(!$service) {
return $this->httpError(404, 'That service could not be found');
}
return array (
'Service' => $service,
'Title' => $service->Title
);
}
public function showapproach(SS_HTTPRequest $request) {
$approach = Approach::get()->byID($request->param('ID'));
if(!$approach) {
return $this->httpError(404, 'That approach could not be found');
}
return array (
'Approach' => $approach,
'Title' => $approach->Title
);
}
public function showindustry(SS_HTTPRequest $request) {
$industry = Industry::get()->byID($request->param('ID'));
if(!$industry) {
return $this->httpError(404, 'That industry could not be found');
}
return array (
'Industry' => $industry,
'Title' => $industry->Title
);
}
public function showtypes(SS_HTTPRequest $request) {
$type = Type::get()->byID($request->param('ID'));
if(!$type) {
return $this->httpError(404, 'That type could not be found');
}
return array (
'Type' => $type,
'Title' => $type->Title
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment