Last active
September 15, 2017 03:27
-
-
Save Firesphere/90f2ce579ae458531dc75cbb1a68c934 to your computer and use it in GitHub Desktop.
Permission managed via the Security menu
This file contains hidden or 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 | |
/** | |
* Class Category | |
* | |
* @property string $Title | |
* @property string $CMSSummary | |
*/ | |
class Category extends DataObject implements PermissionProvider | |
{ | |
private static $db = array( | |
'Title' => 'Varchar(255)', | |
'CMSSummary' => 'Text' | |
); | |
private static $has_one = array(); | |
/** | |
* Permissions | |
*/ | |
public function providePermissions() | |
{ | |
return array( | |
'CREATE_CATEGORY' => array( | |
'name' => _t('Category.PERMISSION_CREATE_DESCRIPTION', 'Create categories'), | |
'category' => _t('Permissions.CONTENT_CATEGORY', 'Content permissions'), | |
'help' => _t('Category.PERMISSION_CREATE_HELP', 'Permission required to create new categories.') | |
), | |
'EDIT_CATEGORY' => array( | |
'name' => _t('Category.PERMISSION_EDIT_DESCRIPTION', 'Edit categories'), | |
'category' => _t('Permissions.CONTENT_CATEGORY', 'Content permissions'), | |
'help' => _t('Category.PERMISSION_EDIT_HELP', 'Permission required to edit existing categories.') | |
), | |
'DELETE_CATEGORY' => array( | |
'name' => _t('Category.PERMISSION_DELETE_DESCRIPTION', 'Delete categories'), | |
'category' => _t('Permissions.CONTENT_CATEGORY', 'Content permissions'), | |
'help' => _t('Category.PERMISSION_DELETE_HELP', | |
'Permission required to delete existing categories.') | |
), | |
'VIEW_CATEGORY' => array( | |
'name' => _t('Category.PERMISSION_VIEW_DESCRIPTION', 'View categories'), | |
'category' => _t('Permissions.CONTENT_CATEGORY', 'Content permissions'), | |
'help' => _t('Category.PERMISSION_VIEW_HELP', 'Permission required to view existing categories.') | |
), | |
); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function canCreate($member = null) | |
{ | |
return Permission::checkMember($member, array('CREATE_CATEGORY', 'CMS_ACCESS_CategoryAdmin')); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function canEdit($member = null) | |
{ | |
return Permission::checkMember($member, array('EDIT_CATEGORY', 'CMS_ACCESS_CategoryAdmin')); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function canDelete($member = null) | |
{ | |
return Permission::checkMember($member, array('DELETE_CATEGORY', 'CMS_ACCESS_CategoryAdmin')); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function canView($member = null) | |
{ | |
return Permission::checkMember($member, array('VIEW_CATEGORY', 'CMS_ACCESS_CategoryAdmin')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment