Skip to content

Instantly share code, notes, and snippets.

@muskie9
Created October 19, 2016 14:47
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 muskie9/332a831647f0ae32c024377dd4e0af4e to your computer and use it in GitHub Desktop.
Save muskie9/332a831647f0ae32c024377dd4e0af4e to your computer and use it in GitHub Desktop.
<?php
/**
* Class MyDealer
*
* @property string $Title
* @method Configurations|HasManyList $Configurations
*/
class MyDealer extends DataObject implements PermissionProvider
{
/**
* @var string
*/
private static $singular_name = 'My Dealer';
/**
* @var string
*/
private static $plural_name = 'My Dealers';
/**
* @var string
*/
private static $description = 'A My dealer.';
/**
* @var array
*/
private static $db = [
'Title' => 'Varchar(255)',
];
/**
* @var array
*/
private static $has_many = [
'Configurations' => 'TemplateConfiguration',
];
/**
* @return FieldList
*/
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldToTab(
'Root.Main',
TextField::create('Title')
->setTitle('Title')
);
$fields->removeByName('Configurations');
if ($this->Configurations()->exists()) {
$fields->addFieldToTab(
'Root.CompletedConfigurations',
GridField::create(
'Configurations',
'Template Configurations',
$this->Configurations()->filterByCallback(function ($config) {
return !$config->hasRemainingSlots();
}),
GridFieldConfig_RecordViewer::create()
)
);
$fields->addFieldToTab(
'Root.IncompleteConfigurations',
GridField::create(
'Configurations',
'Template Configurations',
$this->Configurations()->filterByCallback(function ($config) {
return $config->hasRemainingSlots();
}),
GridFieldConfig_RecordViewer::create()
)
);
}
return $fields;
}
/**
* @param null|Member $member
*
* @return bool
*/
public function canView($member = null)
{
return true;
}
/**
* @param null|Member $member
* @return bool|int
*/
public function canEdit($member = null)
{
return Permission::check('CMS_ACCESS_MyDealer_CREATE', 'any', $member);
}
/**
* @param null|Member $member
* @return bool|int
*/
public function canDelete($member = null)
{
return Permission::check('CMS_ACCESS_MyDealer_DELETE', 'any', $member);
}
/**
* @param null|Member $member
* @return bool|int
*/
public function canCreate($member = null)
{
return Permission::check('CMS_ACCESS_MyDealer_EDIT', 'any', $member);
}
/**
* @return array
*/
public function providePermissions()
{
$dealerGrouping = 'My Dealer';
return array(
'CMS_ACCESS_MyDealer_EDIT' => array(
'name' => 'Edit a My Dealer',
'category' => $dealerGrouping,
),
'CMS_ACCESS_MyDealer_DELETE' => array(
'name' => 'Delete a My Dealer',
'category' => $dealerGrouping,
),
'CMS_ACCESS_MyDealer_CREATE' => array(
'name' => 'Create a My Dealer',
'category' => $dealerGrouping,
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment