Skip to content

Commit c6d79bb

Browse files
authored
Merge branch 'master' into patch-1
2 parents 70922c6 + 9039cb6 commit c6d79bb

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,24 @@ Note that the 'inputs' parameter is writable and is an array. The array may cont
766766

767767
The 'before' function allows modification of the request parameters and can (for instance) be used to implement soft delete behavior.
768768

769+
```php
770+
'before'=>function(&$cmd, &$db, &$tab, &$id, &$in) {
771+
if ($cmd == 'delete') {
772+
$cmd = 'update'; // change command to update
773+
foreach($in as $k => $o) {
774+
$in[$k]->deleted = date('Y-m-d H:i:s', time());
775+
}
776+
}
777+
778+
},
779+
'column_authorizer'=>function($cmd, $db ,$tab, $col) {
780+
return ( ! in_array($col, array('deleted')));
781+
},
782+
'record_filter'=>function($cmd,$db,$tab) {
783+
return array('deleted,is,null');
784+
}
785+
```
786+
769787
## Custom actions
770788

771789
After any operation the 'after' function is called that allows you to do some custom actions.

api.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,22 +1873,26 @@ protected function getParameters($settings) {
18731873
if ($tenancy_function) $this->applyTenancyFunction($tenancy_function,$action,$database,$fields,$filters);
18741874
if ($column_authorizer) $this->applyColumnAuthorizer($column_authorizer,$action,$database,$fields);
18751875

1876+
// input
18761877
$multi = strpos($key[0],',')!==false;
18771878
$inputs = array();
1879+
$contexts = array();
18781880
if (strlen($post)) {
1879-
// input
18801881
$multi = $post[0]=='[';
18811882
$contexts = $this->retrieveInputs($post);
1882-
foreach ($contexts as $context) {
1883-
$input = $this->filterInputByFields($context,$fields[$tables[0]]);
1883+
}
1884+
if ($before) {
1885+
$this->applyBeforeHandler($action,$database,$tables[0],$key[0],$before,$contexts);
1886+
}
1887+
foreach ($contexts as $context) {
1888+
$input = $this->filterInputByFields($context,$fields[$tables[0]]);
18841889

1885-
if ($tenancy_function) $this->applyInputTenancy($tenancy_function,$action,$database,$tables[0],$input,$fields[$tables[0]]);
1886-
if ($input_sanitizer) $this->applyInputSanitizer($input_sanitizer,$action,$database,$tables[0],$input,$fields[$tables[0]]);
1887-
if ($input_validator) $this->applyInputValidator($input_validator,$action,$database,$tables[0],$input,$fields[$tables[0]],$context);
1890+
if ($tenancy_function) $this->applyInputTenancy($tenancy_function,$action,$database,$tables[0],$input,$fields[$tables[0]]);
1891+
if ($input_sanitizer) $this->applyInputSanitizer($input_sanitizer,$action,$database,$tables[0],$input,$fields[$tables[0]]);
1892+
if ($input_validator) $this->applyInputValidator($input_validator,$action,$database,$tables[0],$input,$fields[$tables[0]],$context);
18881893

1889-
$this->convertInputs($input,$fields[$tables[0]]);
1890-
$inputs[] = $input;
1891-
}
1894+
$this->convertInputs($input,$fields[$tables[0]]);
1895+
$inputs[] = $input;
18921896
}
18931897

18941898
return compact('action','database','tables','key','page','filters','fields','orderings','transform','multi','inputs','collect','select','before','after');

0 commit comments

Comments
 (0)