PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / trunk
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration vtrunk
2.0.15 2.0.12 2.0.10 2.0.4 2.0.1 2.0.0 1.95.3 1.95.2 1.95 1.91.6 trunk 1.11 1.12 1.13 1.20 1.21 1.22 1.23 1.30 1.31 1.32 1.35 1.40 1.41 1.45 All 41 releases
fluent-boards / app / Models / Model.php

Model.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration trunk, at app/Models/Model.php

82 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBoards\App\Models;
4
5 use DateTimeInterface;
6 use FluentBoards\Framework\Database\Orm\Model as BaseModel;
7
8 class Model extends BaseModel
9 {
10 protected $guarded = ['id', 'ID'];
11
12 protected $nullableTimestampAttributes = [];
13
14 public function setAttribute($key, $value)
15 {
16 if ($this->isNullableTimestampAttribute($key)) {
17 $value = $this->normalizeNullableTimestampValue($value);
18 }
19
20 return parent::setAttribute($key, $value);
21 }
22
23 public function getAttributeValue($key)
24 {
25 $value = parent::getAttributeValue($key);
26
27 if ($this->isNullableTimestampAttribute($key)) {
28 return $this->normalizeNullableTimestampValue($value);
29 }
30
31 return $value;
32 }
33
34 protected function isNullableTimestampAttribute($key)
35 {
36 return is_string($key) && in_array($key, $this->nullableTimestampAttributes, true);
37 }
38
39 protected function normalizeNullableTimestampValue($value)
40 {
41 if ($value instanceof DateTimeInterface) {
42 return (int) $value->format('Y') < 1900 ? null : $this->fromDateTime($value);
43 }
44
45 if ($value === null) {
46 return null;
47 }
48
49 if (is_bool($value)) {
50 return null;
51 }
52
53 if (is_string($value)) {
54 $value = trim($value);
55
56 if ($value === '') {
57 return null;
58 }
59
60 $normalizedValue = strtolower($value);
61
62 if (in_array($normalizedValue, ['none', 'null'], true)) {
63 return null;
64 }
65
66 if (in_array($value, ['0000-00-00', '0000-00-00 00:00:00'], true)) {
67 return null;
68 }
69
70 if (preg_match('/^(\d{4})-/', $value, $matches) && (int) $matches[1] < 1900) {
71 return null;
72 }
73
74 if (strtotime($value) === false) {
75 return null;
76 }
77 }
78
79 return $value;
80 }
81 }
82