-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlowModel.php
More file actions
102 lines (85 loc) · 2.04 KB
/
FlowModel.php
File metadata and controls
102 lines (85 loc) · 2.04 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
namespace App\Model;
use App\Entity\Flow;
use App\Model\Interface\Configurable;
use App\Model\Interface\Exportable;
use App\Model\Interface\Persistable;
use App\Model\Trait\Config;
use App\Model\Trait\Entity;
use App\Model\Trait\Ref;
use App\Model\Trait\Relations;
use Doctrine\ORM\EntityManagerInterface;
/**
* @method int getId()
* @method setId( int $id )
* @method string getName()
* @method setName( string $name )
* @method string getDescription()
* @method setDescription( string $description )
*/
class FlowModel implements Exportable, Configurable, Persistable
{
use Entity {
export as private entityExport;
persist as private entityPersist;
}
use Ref;
use Config;
use Relations;
public function __construct( Flow $flow )
{
$this->entity = $flow;
$this->config = $flow->getConfig();
}
public function persist( EntityManagerInterface $entityManager, $flush = false ): void
{
// Parse steps.
$this->setSteps( $this->getEntity()->getSteps() );
$this->entityPersist( $entityManager, $flush );
}
public static function getFields()
{
// TODO: Implement getFields() method.
}
public static function getEntityClass(): string
{
return Flow::class;
}
/**
* @return StepModel[]
*/
public function getSteps(): array
{
$steps = [];
foreach ( $this->entity->getSteps() as $stepId ) {
$steps[] = StepModel::get( $stepId );
}
return $steps;
}
public function setSteps( array $steps ): void
{
$stepIds = [];
foreach ( $steps as $step ) {
if ( ! $step instanceof StepModel ) {
$step = StepModel::get( $step );
}
if ( $step instanceof StepModel ) {
$stepIds[] = $step->getId();
}
}
$this->entity->setSteps( $stepIds );
}
public function export(): array
{
$export = $this->entityExport();
$export[ $this->getRef() ]['steps'] = [];
foreach ( $this->getSteps() as $step ) {
$ref = $step->getRef();
$export[ $this->getRef() ]['steps'][] = $ref;
if ( ! isset( $export[ $ref ] ) ) {
$export = array_merge( $export, $step->export() );
}
}
return $export;
}
}