-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.php
More file actions
102 lines (93 loc) · 3.79 KB
/
Copy pathUtils.php
File metadata and controls
102 lines (93 loc) · 3.79 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 Lambda\Dataform;
trait Utils
{
//For specific ID
public function setID()
{
foreach ($this->schema as $s) {
// Sub forms
if ($s->formType == 'SubForm') {
$subForm = new \stdClass();
$subForm->data = request()->get($s->model);
$subForm->parent = $s->parent;
$subForm->model = $s->model;
foreach ($s->schema as $sch) {
if ($s->identity == $sch->model) {
if ($sch->extra == '' || $sch->extra == null) {
$subForm->generateID = true;
$subForm->identity = $sch->model;
} else {
$subForm->generateID = false;
}
}
}
array_push($subForms, $subForm);
} //Main form
else {
array_push($models, $s->model);
if ($this->dbSchema->identity == $s->model) {
if ($s->extra == '' || $s->extra == null) {
$generatedID = (string)Uuid::generate();
$identityModel = $s->model;
} else {
continue;
}
}
if (($s->model == 'created_at' || $s->model == 'updated_at') && $this->dbSchema->timestamp) {
continue;
}
}
}
}
public function callTrigger($action, $qrOrData, $id = null)
{
if (!property_exists($this->dbSchema, 'triggers')) {
return $qrOrData;
}
if (!property_exists($this->dbSchema->triggers, 'namespace')) {
return $qrOrData;
}
switch ($action) {
case 'beforeInsert':
return $this->execTrigger($this->dbSchema->triggers->namespace, $this->dbSchema->triggers->insert->before, $qrOrData);
case 'afterInsert':
return $this->execTrigger($this->dbSchema->triggers->namespace, $this->dbSchema->triggers->insert->after, $qrOrData, $id);
break;
case 'beforeUpdate':
return $this->execTrigger($this->dbSchema->triggers->namespace, $this->dbSchema->triggers->update->before, $qrOrData, $id);
case 'afterUpdate':
return $this->execTrigger($this->dbSchema->triggers->namespace, $this->dbSchema->triggers->update->after, $qrOrData, $id);
break;
case 'beforeDelete':
return $this->execTrigger($this->dbSchema->triggers->namespace, $this->dbSchema->triggers->delete->before, $qrOrData, $id);
break;
case 'afterDelete':
return $this->execTrigger($this->dbSchema->triggers->namespace, $this->dbSchema->triggers->delete->after, $qrOrData, $id);
break;
}
}
public function execTrigger($namespace, $trigger, $data, $id = null)
{
if ($trigger == null || $trigger == '') {
return $data;
}
$trigger = explode('@', $trigger);
if (is_array($trigger)) {
if (method_exists(app($namespace . "\\" . $trigger[0]), $trigger[1])) {
if ($id == null) {
$modifiedData = app($namespace . "\\" . $trigger[0])->{$trigger[1]}($data);
if ($modifiedData !== null) {
return $modifiedData;
}
} else {
$modifiedData = app($namespace . "\\" . $trigger[0])->{$trigger[1]}($data, $id);
if ($modifiedData !== null) {
return $modifiedData;
}
}
}
}
return $data;
}
}