Created
January 5, 2019 22:38
-
-
Save KevinM2k/c2a2e4215ed7c8cbac390601a94960b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
use SilverStripe\ORM\DataObject; | |
use SilverStripe\Forms\FieldList; | |
use SilverStripe\Forms\TextField; | |
use SilverStripe\Forms\TextareaField; | |
use SilverStripe\Versioned\Versioned; | |
use SilverStripe\Control\Controller; | |
class Event extends DataObject | |
{ | |
private static $summary_fields = [ | |
'Title' => 'Title of Event', | |
'Description' => 'Event Details' | |
]; | |
private static $has_one = [ | |
'EventsPage' => EventsPage::class | |
]; | |
private static $versioned_gridfield_extensions = true; | |
private static $extensions = [ | |
Versioned::class, | |
]; | |
private static $db = [ | |
'Title' => 'Varchar', | |
'Description' => 'Text', | |
]; | |
private static $searchable_fields = [ | |
'Title' | |
]; | |
public function getCMSFields() | |
{ | |
$fields = FieldList::create( | |
TextField::create('Title'), | |
TextareaField::create('Description') | |
); | |
return $fields; | |
} | |
public function Link() | |
{ | |
return $this->EventsPage()->Link('events/show/'.$this->ID); | |
} | |
public function LinkingMode() | |
{ | |
return Controller::curr()->getRequest()->param('ID') == $this->ID ? 'current' : 'link'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
use SilverStripe\Admin\ModelAdmin; | |
class EventAdmin extends ModelAdmin { | |
private static $menu_title = 'Events'; | |
private static $url_segment = 'events'; | |
private static $managed_models = [ | |
Event::class | |
]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
use SilverStripe\Control\HTTPRequest; | |
class EventsPage extends \Page { | |
private static $has_many = [ | |
'Events' => Event::class, | |
]; | |
private static $owns = [ | |
'Events' | |
]; | |
} | |
class EventsPageController extends \PageController { | |
public function LatestEvents() | |
{ | |
return Event::get() | |
->limit(6); | |
} | |
private static $allowed_actions = [ | |
'show' | |
]; | |
public function show(HTTPRequest $request) | |
{ | |
$event = Event::get()->byID($request->param('ID')); | |
if(!$event) { | |
return $this->httpError(404,'That event could not be found'); | |
} | |
return [ | |
'Event' => $event | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment