-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserActive.php
More file actions
63 lines (51 loc) · 1.61 KB
/
UserActive.php
File metadata and controls
63 lines (51 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
declare(strict_types=1);
/*
* This file is part of the QuidPHP package <https://quidphp.com>
* Author: Pierre-Philippe Emond <emondpph@gmail.com>
* License: https://github.com/quidphp/core/blob/master/LICENSE
*/
namespace Quid\Core\Col;
use Quid\Base;
use Quid\Orm;
// userActive
// class for the column which manages the active field for the user row
class UserActive extends YesAlias
{
// config
protected static array $config = [];
// onSet
// sur changement de active
// une exception attrapable peut être envoyé
final protected function onSet($value,?Orm\Cell $cell,array $row,array $option)
{
$return = null;
$table = $this->table();
$primary = $table->primary();
$session = static::boot()->session();
$user = $session->user();
$id = $row[$primary] ?? null;
$return = $user['active']->value();
if(is_array($value) && !empty($value))
{
$value = Base\Arr::cast($value);
$value = current($value);
}
if($id === $user->primary() && $value !== $return)
static::catchable(null,'userActiveSelf');
else
{
$return = (empty($value))? null:$value;
$hasChanged = (!empty($cell))? ($cell->value() !== $return):true;
if($hasChanged === true)
{
$closure = fn(Orm\Cell $cell) => $cell->row()->callThis(fn() => $this->onChangeActive($option));
$this->setCommittedCallback('onCommitted',$closure,$cell);
}
}
return $return;
}
}
// init
UserActive::__init();
?>