Source of file Event.php
Size: 2,846 Bytes - Last Modified: 2022-02-21T10:00:34+00:00
/var/www/docs.ssmods.com/process/src/code/models/Event.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 | <?php class Event extends DataObject implements PermissionProvider { private static $db = array( 'Title' => 'Varchar(255)', 'NumberOfSessions'=>'Int', 'PreferencesPerSession'=>'Int', 'MealOption'=>'Boolean', 'Accommodation'=>'Int', 'DisableFavourite'=>'Boolean', 'EnableLuckyDip'=>'Boolean', 'AppEmail'=>'Varchar(255)' ); private static $has_one = array( 'Parent' => 'SiteConfig' ); private static $has_many = array( 'Games'=>'Game', 'Registrations'=>'Registration' ); private static $summary_fields = array( 'Title' => 'Title', 'NumberOfSessions' => 'Number Of Sessions', ); private static $defaults = array( "NumberOfSessions" => 1, "PreferencesPerSession" => 1 ); public function getCMSFields() { $fields = parent::getCMSFields(); $fields->removeByName('ParentID'); $accom = $fields->dataFieldByName('Accommodation'); $accom->setDescription('Number of nights accommodation offered, or 0 if not applicable'); $accom->setTitle("Accommodation (Num. nights)"); $fav = $fields->dataFieldByName('DisableFavourite'); $fav->setDescription('Disable the ability for users to mark a game as their favourite'); $luckyDip = $fields->dataFieldByName('EnableLuckyDip'); $luckyDip->setDescription('Allows extra "Lucky Dip" options during game selection'); $fields->addFieldToTab('Root.Main', $email = EmailField::create('AppEmail')); $email->setDescription('Will recieve all registration data in csv files, as it comes in'); return $fields; } public function canCreate($member = null) { return Permission::check('EVENTS_CREATE'); } public function canEdit($member = null) { return Permission::check('EVENTS_EDIT'); } // We want to make sure events can't be deleted if there is related event data. public function canDelete($member = null) { if(!Permission::check('EVENTS_DELETE')) { return false; } $game = Game::get()->filter('ParentID', $this->ID); $reg = Registration::get()->filter('ParentID', $this->ID); $pg = PlayerGame::get()->filter('EventID', $this->ID); if ($game->count() > 0 || $reg->count() > 0 || $pg->count() > 0) { return false; } return Permission::check('EVENTS_DELETE'); } public function canView($member = null) { return Permission::check('EVENTS_VIEW'); } /** * Get an array of {@link Permission} definitions that this object supports * * @return array */ public function providePermissions() { return array( 'EVENTS_VIEW' => array( 'name' => 'View event data', 'category' => 'Events', ), 'EVENTS_EDIT' => array( 'name' => 'Edit event data', 'category' => 'Events', ), 'EVENTS_DELETE' => array( 'name' => 'Delete event data', 'category' => 'Events', ), 'EVENTS_CREATE' => array( 'name' => 'Create event data', 'category' => 'Events' ) ); } } |