sunnysideup /
silverstripe-cms-niceties
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace Sunnysideup\CMSNiceties\Traits; |
||||||
| 4 | |||||||
| 5 | use SilverStripe\ORM\ArrayList; |
||||||
| 6 | use SilverStripe\Security\Permission; |
||||||
| 7 | use SilverStripe\Security\Security; |
||||||
| 8 | |||||||
| 9 | trait CMSNicetiesTraitForCanMethods |
||||||
| 10 | { |
||||||
| 11 | public function canCreate($member = null, $context = []) |
||||||
| 12 | { |
||||||
| 13 | if (! $member) { |
||||||
| 14 | $member = Security::getCurrentUser(); |
||||||
| 15 | } |
||||||
| 16 | |||||||
| 17 | if ($this->hasMethod('canEditingOwnerObject')) { |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 18 | $obj = $this->canEditingOwnerObject(); |
||||||
|
0 ignored issues
–
show
The method
canEditingOwnerObject() does not exist on Sunnysideup\CMSNiceties\...etiesTraitForCanMethods. Did you maybe mean canEdit()?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 19 | if ($obj instanceof ArrayList) { |
||||||
| 20 | $outcome = true; |
||||||
| 21 | foreach ($obj as $item) { |
||||||
| 22 | if (! $item->canCreate($member, $context)) { |
||||||
| 23 | $outcome = false; |
||||||
| 24 | |||||||
| 25 | break; |
||||||
| 26 | } |
||||||
| 27 | } |
||||||
| 28 | |||||||
| 29 | if ($outcome) { |
||||||
| 30 | return parent::canCreate($member, $context); |
||||||
| 31 | } |
||||||
| 32 | |||||||
| 33 | return false; |
||||||
| 34 | } |
||||||
| 35 | |||||||
| 36 | return $obj->canCreate($member, $context); |
||||||
| 37 | } |
||||||
| 38 | |||||||
| 39 | $groupCodes = $this->hasMethod('canEditingGroupsCodes') ? $this->canEditingGroupsCodes() : [ |
||||||
|
0 ignored issues
–
show
The method
canEditingGroupsCodes() does not exist on Sunnysideup\CMSNiceties\...etiesTraitForCanMethods. Did you maybe mean canEdit()?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 40 | 'CMS_ACCESS_CMSMain', |
||||||
| 41 | ]; |
||||||
| 42 | $groupCodes = array_merge(['ADMIN'], $groupCodes); |
||||||
| 43 | |||||||
| 44 | foreach ($groupCodes as $groupCode) { |
||||||
| 45 | if (Permission::checkMember($member, $groupCode)) { |
||||||
| 46 | return parent::canCreate($member, $context); |
||||||
| 47 | } |
||||||
| 48 | } |
||||||
| 49 | |||||||
| 50 | return false; |
||||||
| 51 | } |
||||||
| 52 | |||||||
| 53 | public function canEdit($member = null) |
||||||
| 54 | { |
||||||
| 55 | return $this->canCreate($member); |
||||||
| 56 | } |
||||||
| 57 | |||||||
| 58 | public function canDelete($member = null) |
||||||
| 59 | { |
||||||
| 60 | return $this->canCreate($member); |
||||||
| 61 | } |
||||||
| 62 | } |
||||||
| 63 |