Test Failed
Push — master ( 507036...762659 )
by Julien
21:33
created

RecordAbstract   A

Complexity

Total Complexity 37

Size/Duplication

Total Lines 626
Duplicated Lines 0 %

Test Coverage

Coverage 86.21%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 123
c 1
b 0
f 0
dl 0
loc 626
ccs 125
cts 145
cp 0.8621
rs 9.44
wmc 37

37 Methods

Rating   Name   Duplication   Size   Complexity  
A getCreatedAt() 0 3 1
A setDeletedAs() 0 3 1
A getName() 0 3 1
A setCreatedAt() 0 3 1
A addDefaultValidations() 0 23 1
A getId() 0 3 1
A getRestoredAt() 0 3 1
A columnMap() 0 20 1
A getRestoredBy() 0 3 1
A setUpdatedAs() 0 3 1
A setTableId() 0 3 1
A getTableId() 0 3 1
A setRestoredBy() 0 3 1
A setCreatedBy() 0 3 1
A setUpdatedBy() 0 3 1
A setCreatedAs() 0 3 1
A setUuid() 0 3 1
A getCreatedBy() 0 3 1
A getDeletedAs() 0 3 1
A setDeleted() 0 3 1
A setWorkspaceId() 0 3 1
A getUpdatedAs() 0 3 1
A addDefaultRelationships() 0 51 1
A setName() 0 3 1
A getCreatedAs() 0 3 1
A setDeletedAt() 0 3 1
A getDeletedBy() 0 3 1
A getUuid() 0 3 1
A getUpdatedBy() 0 3 1
A getDeleted() 0 3 1
A setDeletedBy() 0 3 1
A getWorkspaceId() 0 3 1
A setRestoredAt() 0 3 1
A setId() 0 3 1
A getUpdatedAt() 0 3 1
A getDeletedAt() 0 3 1
A setUpdatedAt() 0 3 1
1
<?php
2
/**
3
 * This file is part of the Zemit Framework.
4
 *
5
 * (c) Zemit Team <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE.txt
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace Zemit\Models\Abstracts;
14
15
use Phalcon\Db\RawValue;
16
use Zemit\Filter\Validation;
17
use Zemit\Models\AbstractModel;
18
use Zemit\Models\Data;
19
use Zemit\Models\Workspace;
20
use Zemit\Models\Table;
21
use Zemit\Models\Column;
22
use Zemit\Models\User;
23
use Zemit\Models\Abstracts\Interfaces\RecordAbstractInterface;
24
25
/**
26
 * Class RecordAbstract
27
 *
28
 * This class defines a Record abstract model that extends the AbstractModel class and implements the RecordAbstractInterface.
29
 * It provides properties and methods for managing Record data.
30
 * 
31
 * @property Data[] $datalist
32
 * @property Data[] $DataList
33
 * @method Data[] getDataList(?array $params = null)
34
 *
35
 * @property Workspace[] $dataworkspacelist
36
 * @property Workspace[] $DataWorkspaceList
37
 * @method Workspace[] getDataWorkspaceList(?array $params = null)
38
 *
39
 * @property Table[] $datatablelist
40
 * @property Table[] $DataTableList
41
 * @method Table[] getDataTableList(?array $params = null)
42
 *
43
 * @property Column[] $datacolumnlist
44
 * @property Column[] $DataColumnList
45
 * @method Column[] getDataColumnList(?array $params = null)
46
 *
47
 * @property Workspace $workspaceentity
48
 * @property Workspace $WorkspaceEntity
49
 * @method Workspace getWorkspaceEntity(?array $params = null)
50
 *
51
 * @property Table $tableentity
52
 * @property Table $TableEntity
53
 * @method Table getTableEntity(?array $params = null)
54
 *
55
 * @property User $createdbyentity
56
 * @property User $CreatedByEntity
57
 * @method User getCreatedByEntity(?array $params = null)
58
 *
59
 * @property User $createdasentity
60
 * @property User $CreatedAsEntity
61
 * @method User getCreatedAsEntity(?array $params = null)
62
 *
63
 * @property User $updatedbyentity
64
 * @property User $UpdatedByEntity
65
 * @method User getUpdatedByEntity(?array $params = null)
66
 *
67
 * @property User $updatedasentity
68
 * @property User $UpdatedAsEntity
69
 * @method User getUpdatedAsEntity(?array $params = null)
70
 *
71
 * @property User $deletedasentity
72
 * @property User $DeletedAsEntity
73
 * @method User getDeletedAsEntity(?array $params = null)
74
 *
75
 * @property User $deletedbyentity
76
 * @property User $DeletedByEntity
77
 * @method User getDeletedByEntity(?array $params = null)
78
 *
79
 * @property User $restoredbyentity
80
 * @property User $RestoredByEntity
81
 * @method User getRestoredByEntity(?array $params = null)
82
 */
83
abstract class RecordAbstract extends AbstractModel implements RecordAbstractInterface
84
{
85
    /**
86
     * Column: id
87
     * Attributes: First | Primary | NotNull | Numeric | Unsigned | AutoIncrement
88
     * @var mixed
89
     */
90
    public mixed $id = null;
91
        
92
    /**
93
     * Column: workspace_id
94
     * Attributes: NotNull | Numeric | Unsigned
95
     * @var mixed
96
     */
97
    public mixed $workspaceId = null;
98
        
99
    /**
100
     * Column: table_id
101
     * Attributes: NotNull | Numeric | Unsigned
102
     * @var mixed
103
     */
104
    public mixed $tableId = null;
105
        
106
    /**
107
     * Column: uuid
108
     * Attributes: NotNull | Size(36) | Type(5)
109
     * @var mixed
110
     */
111
    public mixed $uuid = null;
112
        
113
    /**
114
     * Column: name
115
     * Attributes: NotNull | Size(255) | Type(2)
116
     * @var mixed
117
     */
118
    public mixed $name = null;
119
        
120
    /**
121
     * Column: deleted
122
     * Attributes: NotNull | Numeric | Unsigned | Type(26)
123
     * @var mixed
124
     */
125
    public mixed $deleted = 0;
126
        
127
    /**
128
     * Column: created_at
129
     * Attributes: NotNull | Type(4)
130
     * @var mixed
131
     */
132
    public mixed $createdAt = null;
133
        
134
    /**
135
     * Column: created_by
136
     * Attributes: Numeric | Unsigned
137
     * @var mixed
138
     */
139
    public mixed $createdBy = null;
140
        
141
    /**
142
     * Column: created_as
143
     * Attributes: Numeric | Unsigned
144
     * @var mixed
145
     */
146
    public mixed $createdAs = null;
147
        
148
    /**
149
     * Column: updated_at
150
     * Attributes: Type(4)
151
     * @var mixed
152
     */
153
    public mixed $updatedAt = null;
154
        
155
    /**
156
     * Column: updated_by
157
     * Attributes: Numeric | Unsigned
158
     * @var mixed
159
     */
160
    public mixed $updatedBy = null;
161
        
162
    /**
163
     * Column: updated_as
164
     * Attributes: Numeric | Unsigned
165
     * @var mixed
166
     */
167
    public mixed $updatedAs = null;
168
        
169
    /**
170
     * Column: deleted_at
171
     * Attributes: Type(4)
172
     * @var mixed
173
     */
174
    public mixed $deletedAt = null;
175
        
176
    /**
177
     * Column: deleted_as
178
     * Attributes: Numeric | Unsigned
179
     * @var mixed
180
     */
181
    public mixed $deletedAs = null;
182
        
183
    /**
184
     * Column: deleted_by
185
     * Attributes: Numeric | Unsigned
186
     * @var mixed
187
     */
188
    public mixed $deletedBy = null;
189
        
190
    /**
191
     * Column: restored_at
192
     * Attributes: Type(4)
193
     * @var mixed
194
     */
195
    public mixed $restoredAt = null;
196
        
197
    /**
198
     * Column: restored_by
199
     * Attributes: Numeric | Unsigned
200
     * @var mixed
201
     */
202
    public mixed $restoredBy = null;
203
    
204
    /**
205
     * Returns the value of field id
206
     * Column: id
207
     * Attributes: First | Primary | NotNull | Numeric | Unsigned | AutoIncrement
208
     * @return mixed
209
     */
210 2
    public function getId(): mixed
211
    {
212 2
        return $this->id;
213
    }
214
    
215
    /**
216
     * Sets the value of field id
217
     * Column: id 
218
     * Attributes: First | Primary | NotNull | Numeric | Unsigned | AutoIncrement
219
     * @param mixed $id
220
     * @return void
221
     */
222 1
    public function setId(mixed $id): void
223
    {
224 1
        $this->id = $id;
225
    }
226
    
227
    /**
228
     * Returns the value of field workspaceId
229
     * Column: workspace_id
230
     * Attributes: NotNull | Numeric | Unsigned
231
     * @return mixed
232
     */
233 2
    public function getWorkspaceId(): mixed
234
    {
235 2
        return $this->workspaceId;
236
    }
237
    
238
    /**
239
     * Sets the value of field workspaceId
240
     * Column: workspace_id 
241
     * Attributes: NotNull | Numeric | Unsigned
242
     * @param mixed $workspaceId
243
     * @return void
244
     */
245 1
    public function setWorkspaceId(mixed $workspaceId): void
246
    {
247 1
        $this->workspaceId = $workspaceId;
248
    }
249
    
250
    /**
251
     * Returns the value of field tableId
252
     * Column: table_id
253
     * Attributes: NotNull | Numeric | Unsigned
254
     * @return mixed
255
     */
256 2
    public function getTableId(): mixed
257
    {
258 2
        return $this->tableId;
259
    }
260
    
261
    /**
262
     * Sets the value of field tableId
263
     * Column: table_id 
264
     * Attributes: NotNull | Numeric | Unsigned
265
     * @param mixed $tableId
266
     * @return void
267
     */
268 1
    public function setTableId(mixed $tableId): void
269
    {
270 1
        $this->tableId = $tableId;
271
    }
272
    
273
    /**
274
     * Returns the value of field uuid
275
     * Column: uuid
276
     * Attributes: NotNull | Size(36) | Type(5)
277
     * @return mixed
278
     */
279 2
    public function getUuid(): mixed
280
    {
281 2
        return $this->uuid;
282
    }
283
    
284
    /**
285
     * Sets the value of field uuid
286
     * Column: uuid 
287
     * Attributes: NotNull | Size(36) | Type(5)
288
     * @param mixed $uuid
289
     * @return void
290
     */
291 1
    public function setUuid(mixed $uuid): void
292
    {
293 1
        $this->uuid = $uuid;
294
    }
295
    
296
    /**
297
     * Returns the value of field name
298
     * Column: name
299
     * Attributes: NotNull | Size(255) | Type(2)
300
     * @return mixed
301
     */
302 2
    public function getName(): mixed
303
    {
304 2
        return $this->name;
305
    }
306
    
307
    /**
308
     * Sets the value of field name
309
     * Column: name 
310
     * Attributes: NotNull | Size(255) | Type(2)
311
     * @param mixed $name
312
     * @return void
313
     */
314 1
    public function setName(mixed $name): void
315
    {
316 1
        $this->name = $name;
317
    }
318
    
319
    /**
320
     * Returns the value of field deleted
321
     * Column: deleted
322
     * Attributes: NotNull | Numeric | Unsigned | Type(26)
323
     * @return mixed
324
     */
325 2
    public function getDeleted(): mixed
326
    {
327 2
        return $this->deleted;
328
    }
329
    
330
    /**
331
     * Sets the value of field deleted
332
     * Column: deleted 
333
     * Attributes: NotNull | Numeric | Unsigned | Type(26)
334
     * @param mixed $deleted
335
     * @return void
336
     */
337 1
    public function setDeleted(mixed $deleted): void
338
    {
339 1
        $this->deleted = $deleted;
340
    }
341
    
342
    /**
343
     * Returns the value of field createdAt
344
     * Column: created_at
345
     * Attributes: NotNull | Type(4)
346
     * @return mixed
347
     */
348 2
    public function getCreatedAt(): mixed
349
    {
350 2
        return $this->createdAt;
351
    }
352
    
353
    /**
354
     * Sets the value of field createdAt
355
     * Column: created_at 
356
     * Attributes: NotNull | Type(4)
357
     * @param mixed $createdAt
358
     * @return void
359
     */
360 1
    public function setCreatedAt(mixed $createdAt): void
361
    {
362 1
        $this->createdAt = $createdAt;
363
    }
364
    
365
    /**
366
     * Returns the value of field createdBy
367
     * Column: created_by
368
     * Attributes: Numeric | Unsigned
369
     * @return mixed
370
     */
371 2
    public function getCreatedBy(): mixed
372
    {
373 2
        return $this->createdBy;
374
    }
375
    
376
    /**
377
     * Sets the value of field createdBy
378
     * Column: created_by 
379
     * Attributes: Numeric | Unsigned
380
     * @param mixed $createdBy
381
     * @return void
382
     */
383 1
    public function setCreatedBy(mixed $createdBy): void
384
    {
385 1
        $this->createdBy = $createdBy;
386
    }
387
    
388
    /**
389
     * Returns the value of field createdAs
390
     * Column: created_as
391
     * Attributes: Numeric | Unsigned
392
     * @return mixed
393
     */
394 2
    public function getCreatedAs(): mixed
395
    {
396 2
        return $this->createdAs;
397
    }
398
    
399
    /**
400
     * Sets the value of field createdAs
401
     * Column: created_as 
402
     * Attributes: Numeric | Unsigned
403
     * @param mixed $createdAs
404
     * @return void
405
     */
406 1
    public function setCreatedAs(mixed $createdAs): void
407
    {
408 1
        $this->createdAs = $createdAs;
409
    }
410
    
411
    /**
412
     * Returns the value of field updatedAt
413
     * Column: updated_at
414
     * Attributes: Type(4)
415
     * @return mixed
416
     */
417 2
    public function getUpdatedAt(): mixed
418
    {
419 2
        return $this->updatedAt;
420
    }
421
    
422
    /**
423
     * Sets the value of field updatedAt
424
     * Column: updated_at 
425
     * Attributes: Type(4)
426
     * @param mixed $updatedAt
427
     * @return void
428
     */
429 1
    public function setUpdatedAt(mixed $updatedAt): void
430
    {
431 1
        $this->updatedAt = $updatedAt;
432
    }
433
    
434
    /**
435
     * Returns the value of field updatedBy
436
     * Column: updated_by
437
     * Attributes: Numeric | Unsigned
438
     * @return mixed
439
     */
440 2
    public function getUpdatedBy(): mixed
441
    {
442 2
        return $this->updatedBy;
443
    }
444
    
445
    /**
446
     * Sets the value of field updatedBy
447
     * Column: updated_by 
448
     * Attributes: Numeric | Unsigned
449
     * @param mixed $updatedBy
450
     * @return void
451
     */
452 1
    public function setUpdatedBy(mixed $updatedBy): void
453
    {
454 1
        $this->updatedBy = $updatedBy;
455
    }
456
    
457
    /**
458
     * Returns the value of field updatedAs
459
     * Column: updated_as
460
     * Attributes: Numeric | Unsigned
461
     * @return mixed
462
     */
463 2
    public function getUpdatedAs(): mixed
464
    {
465 2
        return $this->updatedAs;
466
    }
467
    
468
    /**
469
     * Sets the value of field updatedAs
470
     * Column: updated_as 
471
     * Attributes: Numeric | Unsigned
472
     * @param mixed $updatedAs
473
     * @return void
474
     */
475 1
    public function setUpdatedAs(mixed $updatedAs): void
476
    {
477 1
        $this->updatedAs = $updatedAs;
478
    }
479
    
480
    /**
481
     * Returns the value of field deletedAt
482
     * Column: deleted_at
483
     * Attributes: Type(4)
484
     * @return mixed
485
     */
486 2
    public function getDeletedAt(): mixed
487
    {
488 2
        return $this->deletedAt;
489
    }
490
    
491
    /**
492
     * Sets the value of field deletedAt
493
     * Column: deleted_at 
494
     * Attributes: Type(4)
495
     * @param mixed $deletedAt
496
     * @return void
497
     */
498 1
    public function setDeletedAt(mixed $deletedAt): void
499
    {
500 1
        $this->deletedAt = $deletedAt;
501
    }
502
    
503
    /**
504
     * Returns the value of field deletedAs
505
     * Column: deleted_as
506
     * Attributes: Numeric | Unsigned
507
     * @return mixed
508
     */
509 2
    public function getDeletedAs(): mixed
510
    {
511 2
        return $this->deletedAs;
512
    }
513
    
514
    /**
515
     * Sets the value of field deletedAs
516
     * Column: deleted_as 
517
     * Attributes: Numeric | Unsigned
518
     * @param mixed $deletedAs
519
     * @return void
520
     */
521 1
    public function setDeletedAs(mixed $deletedAs): void
522
    {
523 1
        $this->deletedAs = $deletedAs;
524
    }
525
    
526
    /**
527
     * Returns the value of field deletedBy
528
     * Column: deleted_by
529
     * Attributes: Numeric | Unsigned
530
     * @return mixed
531
     */
532 2
    public function getDeletedBy(): mixed
533
    {
534 2
        return $this->deletedBy;
535
    }
536
    
537
    /**
538
     * Sets the value of field deletedBy
539
     * Column: deleted_by 
540
     * Attributes: Numeric | Unsigned
541
     * @param mixed $deletedBy
542
     * @return void
543
     */
544 1
    public function setDeletedBy(mixed $deletedBy): void
545
    {
546 1
        $this->deletedBy = $deletedBy;
547
    }
548
    
549
    /**
550
     * Returns the value of field restoredAt
551
     * Column: restored_at
552
     * Attributes: Type(4)
553
     * @return mixed
554
     */
555 2
    public function getRestoredAt(): mixed
556
    {
557 2
        return $this->restoredAt;
558
    }
559
    
560
    /**
561
     * Sets the value of field restoredAt
562
     * Column: restored_at 
563
     * Attributes: Type(4)
564
     * @param mixed $restoredAt
565
     * @return void
566
     */
567 1
    public function setRestoredAt(mixed $restoredAt): void
568
    {
569 1
        $this->restoredAt = $restoredAt;
570
    }
571
    
572
    /**
573
     * Returns the value of field restoredBy
574
     * Column: restored_by
575
     * Attributes: Numeric | Unsigned
576
     * @return mixed
577
     */
578 2
    public function getRestoredBy(): mixed
579
    {
580 2
        return $this->restoredBy;
581
    }
582
    
583
    /**
584
     * Sets the value of field restoredBy
585
     * Column: restored_by 
586
     * Attributes: Numeric | Unsigned
587
     * @param mixed $restoredBy
588
     * @return void
589
     */
590 1
    public function setRestoredBy(mixed $restoredBy): void
591
    {
592 1
        $this->restoredBy = $restoredBy;
593
    }
594
595
    /**
596
     * Adds the default relationships to the model.
597
     * @return void
598
     */
599 1
    public function addDefaultRelationships(): void
600
    {
601 1
        $this->hasMany('id', Data::class, 'recordId', ['alias' => 'DataList']);
602
603 1
        $this->hasManyToMany(
604 1
            'id',
605 1
            Data::class,
606 1
            'recordId',
607 1
            'workspaceId',
608 1
            Workspace::class,
609 1
            'id',
610 1
            ['alias' => 'DataWorkspaceList']
611 1
        );
612
613 1
        $this->hasManyToMany(
614 1
            'id',
615 1
            Data::class,
616 1
            'recordId',
617 1
            'tableId',
618 1
            Table::class,
619 1
            'id',
620 1
            ['alias' => 'DataTableList']
621 1
        );
622
623 1
        $this->hasManyToMany(
624 1
            'id',
625 1
            Data::class,
626 1
            'recordId',
627 1
            'columnId',
628 1
            Column::class,
629 1
            'id',
630 1
            ['alias' => 'DataColumnList']
631 1
        );
632
633 1
        $this->belongsTo('workspaceId', Workspace::class, 'id', ['alias' => 'WorkspaceEntity']);
634
635 1
        $this->belongsTo('tableId', Table::class, 'id', ['alias' => 'TableEntity']);
636
637 1
        $this->belongsTo('createdBy', User::class, 'id', ['alias' => 'CreatedByEntity']);
638
639 1
        $this->belongsTo('createdAs', User::class, 'id', ['alias' => 'CreatedAsEntity']);
640
641 1
        $this->belongsTo('updatedBy', User::class, 'id', ['alias' => 'UpdatedByEntity']);
642
643 1
        $this->belongsTo('updatedAs', User::class, 'id', ['alias' => 'UpdatedAsEntity']);
644
645 1
        $this->belongsTo('deletedAs', User::class, 'id', ['alias' => 'DeletedAsEntity']);
646
647 1
        $this->belongsTo('deletedBy', User::class, 'id', ['alias' => 'DeletedByEntity']);
648
649 1
        $this->belongsTo('restoredBy', User::class, 'id', ['alias' => 'RestoredByEntity']);
650
    }
651
    
652
    /**
653
     * Adds the default validations to the model.
654
     * @param Validation|null $validator
655
     * @return Validation
656
     */
657
    public function addDefaultValidations(?Validation $validator = null): Validation
658
    {
659
        $validator ??= new Validation();
660
    
661
        $this->addUnsignedIntValidation($validator, 'id', true);
662
        $this->addUnsignedIntValidation($validator, 'workspaceId', false);
663
        $this->addUnsignedIntValidation($validator, 'tableId', false);
664
        $this->addStringLengthValidation($validator, 'uuid', 0, 36, false);
665
        $this->addStringLengthValidation($validator, 'name', 0, 255, false);
666
        $this->addUnsignedIntValidation($validator, 'deleted', false);
667
        $this->addDateTimeValidation($validator, 'createdAt', false);
668
        $this->addUnsignedIntValidation($validator, 'createdBy', true);
669
        $this->addUnsignedIntValidation($validator, 'createdAs', true);
670
        $this->addDateTimeValidation($validator, 'updatedAt', true);
671
        $this->addUnsignedIntValidation($validator, 'updatedBy', true);
672
        $this->addUnsignedIntValidation($validator, 'updatedAs', true);
673
        $this->addDateTimeValidation($validator, 'deletedAt', true);
674
        $this->addUnsignedIntValidation($validator, 'deletedAs', true);
675
        $this->addUnsignedIntValidation($validator, 'deletedBy', true);
676
        $this->addDateTimeValidation($validator, 'restoredAt', true);
677
        $this->addUnsignedIntValidation($validator, 'restoredBy', true);
678
        
679
        return $validator;
680
    }
681
682
        
683
    /**
684
     * Returns an array that maps the column names of the database
685
     * table to the corresponding property names of the model.
686
     * 
687
     * @returns array The array mapping the column names to the property names
688
     */
689 1
    public function columnMap(): array
690
    {
691 1
        return [
692 1
            'id' => 'id',
693 1
            'workspace_id' => 'workspaceId',
694 1
            'table_id' => 'tableId',
695 1
            'uuid' => 'uuid',
696 1
            'name' => 'name',
697 1
            'deleted' => 'deleted',
698 1
            'created_at' => 'createdAt',
699 1
            'created_by' => 'createdBy',
700 1
            'created_as' => 'createdAs',
701 1
            'updated_at' => 'updatedAt',
702 1
            'updated_by' => 'updatedBy',
703 1
            'updated_as' => 'updatedAs',
704 1
            'deleted_at' => 'deletedAt',
705 1
            'deleted_as' => 'deletedAs',
706 1
            'deleted_by' => 'deletedBy',
707 1
            'restored_at' => 'restoredAt',
708 1
            'restored_by' => 'restoredBy',
709 1
        ];
710
    }
711
}
712