1 | <?php |
||||
2 | |||||
3 | // ------------------------------------------------------------------------- |
||||
4 | // OVIDENTIA http://www.ovidentia.org |
||||
5 | // Ovidentia is free software; you can redistribute it and/or modify |
||||
6 | // it under the terms of the GNU General Public License as published by |
||||
7 | // the Free Software Foundation; either version 2, or (at your option) |
||||
8 | // any later version. |
||||
9 | // |
||||
10 | // This program is distributed in the hope that it will be useful, but |
||||
11 | // WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||
13 | // See the GNU General Public License for more details. |
||||
14 | // |
||||
15 | // You should have received a copy of the GNU General Public License |
||||
16 | // along with this program; if not, write to the Free Software |
||||
17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
||||
18 | // USA. |
||||
19 | // ------------------------------------------------------------------------- |
||||
20 | /** |
||||
21 | * @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL) |
||||
22 | * @copyright Copyright (c) 2022 by SI4YOU ({@link https://www.siforyou.com}) |
||||
23 | */ |
||||
24 | namespace Capwelton\LibApp\Set; |
||||
25 | |||||
26 | use bab_functionality; |
||||
27 | |||||
28 | $test = bab_functionality::get("LibOrm"); |
||||
29 | use Capwelton\LibApp\Func_App; |
||||
30 | use Capwelton\LibApp\Exceptions\AppSaveException; |
||||
31 | use function Capwelton\LibOrm\ORM_StringField; |
||||
0 ignored issues
–
show
introduced
by
![]() |
|||||
32 | use function Capwelton\LibOrm\ORM_TextField; |
||||
0 ignored issues
–
show
|
|||||
33 | use function Capwelton\LibOrm\ORM_EnumField; |
||||
0 ignored issues
–
show
|
|||||
34 | use function Capwelton\LibOrm\ORM_BoolField; |
||||
0 ignored issues
–
show
|
|||||
35 | use Capwelton\LibOrm\ORMRecord; |
||||
0 ignored issues
–
show
The type
Capwelton\LibOrm\ORMRecord was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
36 | use Capwelton\LibOrm\Criteria\ORMCriteria; |
||||
0 ignored issues
–
show
The type
Capwelton\LibOrm\Criteria\ORMCriteria was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
37 | use Capwelton\LibApp\Set\AppCustomField; |
||||
38 | |||||
39 | /** |
||||
40 | * @property ORM_StringField $name |
||||
41 | * @property ORM_StringField $fieldname |
||||
42 | * @property ORM_TextField $description |
||||
43 | * @property ORM_EnumField $object |
||||
44 | * @property ORM_EnumField $fieldtype |
||||
45 | * @property ORM_TextField $enumvalues |
||||
46 | * @property ORM_BoolField $mandatory |
||||
47 | * |
||||
48 | * @method app_CustomField get(mixed $criteria) |
||||
49 | * @method app_CustomField request(mixed $criteria) |
||||
50 | * @method app_CustomField[] select(\ORM_Criteria $criteria = null) |
||||
51 | * @method app_CustomField newRecord() |
||||
52 | * @method Func_App App() |
||||
53 | */ |
||||
54 | class AppCustomFieldSet extends AppTraceableRecordSet |
||||
55 | { |
||||
56 | |||||
57 | /** |
||||
58 | * @param Func_App $App |
||||
59 | */ |
||||
60 | public function __construct(Func_App $App = null) |
||||
61 | { |
||||
62 | parent::__construct($App); |
||||
0 ignored issues
–
show
It seems like
$App can also be of type null ; however, parameter $App of Capwelton\LibApp\Set\App...ecordSet::__construct() does only seem to accept Capwelton\LibApp\Func_App , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
63 | $this->setTableName("app_customfield"); |
||||
64 | |||||
65 | $this->setDescription('Custom field'); |
||||
66 | |||||
67 | $this->setPrimaryKey('id'); |
||||
68 | |||||
69 | $this->addFields( |
||||
70 | ORM_StringField('name')->setDescription('Field label'), |
||||
71 | ORM_StringField('fieldname')->setDescription('Name of field used in table, not modifiable'), |
||||
72 | ORM_TextField('description')->setDescription('Description'), |
||||
73 | ORM_EnumField('object', $this->getObjects())->setDescription('Applies to'), |
||||
74 | ORM_EnumField('fieldtype', $this->getFieldTypes())->setDescription('Field type'), |
||||
75 | ORM_TextField('enumvalues')->setDescription('serialized array of values for enum fields'), |
||||
76 | ORM_BoolField('mandatory')->setDescription('Mandatory'), |
||||
77 | ORM_StringField('section')->setDescription($App->translate('Section')), |
||||
0 ignored issues
–
show
The method
translate() does not exist on null .
(
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. ![]() |
|||||
78 | ORM_BoolField('importable')->setOutputOptions($App->translate('No'), $App->translate('Yes'))->setDescription($App->translate('Importable')), |
||||
79 | ORM_BoolField('searchable')->setOutputOptions($App->translate('No'), $App->translate('Yes'))->setDescription($App->translate('Searchable')), |
||||
80 | ORM_BoolField('visible')->setOutputOptions($App->translate('No'), $App->translate('Yes'))->setDescription($App->translate('Column in list')) |
||||
81 | ); |
||||
82 | |||||
83 | if($App->onlineShop){ |
||||
0 ignored issues
–
show
The property
onlineShop does not exist on Capwelton\LibApp\Func_App . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||
84 | $this->addFields(ORM_BoolField('visible_in_shop')); |
||||
85 | } |
||||
86 | } |
||||
87 | |||||
88 | public function save(ORMRecord $record, $noTrace = false) |
||||
89 | { |
||||
90 | if(! $record->fieldname){ |
||||
91 | $record->fieldname = $this->getFieldName($record->name); |
||||
92 | } |
||||
93 | |||||
94 | return parent::save($record, $noTrace); |
||||
95 | } |
||||
96 | |||||
97 | /** |
||||
98 | * Get a field name from a custom field name |
||||
99 | * |
||||
100 | * @param string $name |
||||
101 | * @throws AppSaveException |
||||
102 | * @return string |
||||
103 | */ |
||||
104 | public function getFieldName($name) |
||||
105 | { |
||||
106 | // create the field name automatically |
||||
107 | $name = bab_removeDiacritics($name); |
||||
108 | $name = preg_replace('/[^a-zA-Z0-9]+/', '', $name); |
||||
109 | $name = mb_strtolower($name); |
||||
110 | |||||
111 | if(empty($name)){ |
||||
112 | throw new AppSaveException($this->App()->translate('The name is mandatory')); |
||||
113 | } |
||||
114 | |||||
115 | return '_' . $name; |
||||
116 | } |
||||
117 | |||||
118 | /** |
||||
119 | * List of objects where custom fields are applicable. |
||||
120 | * |
||||
121 | * @return string[] |
||||
122 | */ |
||||
123 | public function getObjects() |
||||
124 | { |
||||
125 | $App = $this->App(); |
||||
126 | |||||
127 | $arr = array(); |
||||
128 | |||||
129 | if(isset($App->Article)){ |
||||
0 ignored issues
–
show
The property
Article does not exist on Capwelton\LibApp\Func_App . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||
130 | $arr['Article'] = $App->translate('Products database'); |
||||
131 | } |
||||
132 | |||||
133 | return $arr; |
||||
134 | } |
||||
135 | |||||
136 | /** |
||||
137 | * list of ORM fields to use for a custom field |
||||
138 | */ |
||||
139 | public function getFieldTypes() |
||||
140 | { |
||||
141 | $App = $this->App(); |
||||
142 | |||||
143 | return array( |
||||
144 | 'String' => $App->translate('Line edit'), |
||||
145 | 'Text' => $App->translate('Text edit'), |
||||
146 | 'Bool' => $App->translate('Checkbox'), |
||||
147 | 'Int' => $App->translate('Integer number'), |
||||
148 | 'Decimal' => $App->translate('Decimal number'), |
||||
149 | 'Date' => $App->translate('Date'), |
||||
150 | 'DateTime' => $App->translate('Date and time'), |
||||
151 | 'Time' => $App->translate('Time'), |
||||
152 | 'Enum' => $App->translate('Selection list'), |
||||
153 | 'Set' => $App->translate('Multi-selection list'), |
||||
154 | 'Url' => $App->translate('Url'), |
||||
155 | 'Email' => $App->translate('Email address'), |
||||
156 | 'File' => $App->translate('File') |
||||
157 | ); |
||||
158 | } |
||||
159 | |||||
160 | /** |
||||
161 | * {@inheritdoc} |
||||
162 | * @see AppRecordSet::isCreatable() |
||||
163 | */ |
||||
164 | public function isCreatable() |
||||
165 | { |
||||
166 | return true; |
||||
167 | } |
||||
168 | |||||
169 | /** |
||||
170 | * @return ORMCriteria |
||||
171 | */ |
||||
172 | public function isReadable() |
||||
173 | { |
||||
174 | return $this->all(); |
||||
175 | } |
||||
176 | |||||
177 | /** |
||||
178 | * @return ORMCriteria |
||||
179 | */ |
||||
180 | public function isUpdatable() |
||||
181 | { |
||||
182 | return $this->all(); |
||||
183 | } |
||||
184 | |||||
185 | /** |
||||
186 | * @return ORMCriteria |
||||
187 | */ |
||||
188 | public function isDeletable() |
||||
189 | { |
||||
190 | return $this->isUpdatable(); |
||||
191 | } |
||||
192 | } |