| 1 | <?php |
||||||||
| 2 | |||||||||
| 3 | namespace LeKoala\CommonExtensions; |
||||||||
| 4 | |||||||||
| 5 | use SilverStripe\ORM\DataObject; |
||||||||
| 6 | use SilverStripe\Forms\FieldList; |
||||||||
| 7 | use SilverStripe\ORM\DataExtension; |
||||||||
| 8 | use LeKoala\CmsActions\CustomAction; |
||||||||
| 9 | |||||||||
| 10 | /** |
||||||||
| 11 | * Makes record locked |
||||||||
| 12 | * |
||||||||
| 13 | * Unlocking require special action |
||||||||
| 14 | * |
||||||||
| 15 | * @property \LeKoala\CommonExtensions\LockableExtension|DataObject $owner |
||||||||
| 16 | * @property boolean $IsLocked |
||||||||
| 17 | */ |
||||||||
| 18 | class LockableExtension extends DataExtension |
||||||||
| 19 | { |
||||||||
| 20 | private static $db = [ |
||||||||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||||||||
| 21 | "IsLocked" => "Boolean" |
||||||||
| 22 | ]; |
||||||||
| 23 | |||||||||
| 24 | public function updateCMSFields(FieldList $fields) |
||||||||
| 25 | { |
||||||||
| 26 | $fields->removeByName('IsLocked'); |
||||||||
| 27 | } |
||||||||
| 28 | |||||||||
| 29 | /** |
||||||||
| 30 | * Use this in your model. It has to run last and cannot be done automatically |
||||||||
| 31 | * |
||||||||
| 32 | * if($this->hasExtension(LockableExtension::class)) { |
||||||||
| 33 | * $this->lockFields($fields); |
||||||||
| 34 | * } |
||||||||
| 35 | * |
||||||||
| 36 | * @param FieldList $fields |
||||||||
| 37 | * @return void |
||||||||
| 38 | */ |
||||||||
| 39 | public function lockFields(FieldList $fields) |
||||||||
| 40 | { |
||||||||
| 41 | if (!$this->owner->IsLocked) { |
||||||||
| 42 | return; |
||||||||
| 43 | } |
||||||||
| 44 | $fields->makeReadonly(); |
||||||||
| 45 | } |
||||||||
| 46 | |||||||||
| 47 | public function canEdit($member) |
||||||||
| 48 | { |
||||||||
| 49 | if ($this->owner->IsLocked) { |
||||||||
| 50 | return false; |
||||||||
| 51 | } |
||||||||
| 52 | return parent::canEdit($member); |
||||||||
|
0 ignored issues
–
show
Are you sure the usage of
parent::canEdit($member) targeting SilverStripe\ORM\DataExtension::canEdit() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||||||||
| 53 | } |
||||||||
| 54 | |||||||||
| 55 | public function updateCMSActions(FieldList $actions) |
||||||||
| 56 | { |
||||||||
| 57 | if ($this->owner->ID && !$this->owner->IsLocked) { |
||||||||
|
0 ignored issues
–
show
|
|||||||||
| 58 | $lockRecord = new CustomAction("LockRecord", "Lock"); |
||||||||
| 59 | $lockRecord->setConfirmation("Are you sure to lock this record?"); |
||||||||
| 60 | $actions->push($lockRecord); |
||||||||
| 61 | } |
||||||||
| 62 | } |
||||||||
| 63 | |||||||||
| 64 | public function LockRecord($data, $form, $controller) |
||||||||
|
0 ignored issues
–
show
The parameter
$controller is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
The parameter
$data is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
The parameter
$form is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||||||
| 65 | { |
||||||||
| 66 | $this->owner->IsLocked = true; |
||||||||
| 67 | $this->owner->write(); |
||||||||
|
0 ignored issues
–
show
The method
write() does not exist on LeKoala\CommonExtensions\LockableExtension.
(
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...
|
|||||||||
| 68 | |||||||||
| 69 | return 'Record locked'; |
||||||||
| 70 | } |
||||||||
| 71 | } |
||||||||
| 72 |