1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Prateekkarki\Laragen\Models; |
4
|
|
|
|
5
|
|
|
class Module |
6
|
|
|
{ |
7
|
|
|
protected $module; |
8
|
|
|
|
9
|
|
|
protected $data; |
10
|
|
|
|
11
|
|
|
protected $images; |
12
|
|
|
|
13
|
|
|
protected $name; |
14
|
|
|
|
15
|
|
|
public function __construct($module) |
16
|
|
|
{ |
17
|
|
|
$this->module = (object)$module; |
18
|
|
|
$this->data = $this->module->data; |
19
|
|
|
$this->name = $this->module->name; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function getName() |
23
|
|
|
{ |
24
|
|
|
return $this->name; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function getData() |
28
|
|
|
{ |
29
|
|
|
return $this->data; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function getNativeColumns() |
33
|
|
|
{ |
34
|
|
|
$data = []; |
35
|
|
|
foreach ($this->data as $column => $optionString) { |
36
|
|
|
$optionArray = explode(':', $optionString); |
37
|
|
|
if (in_array($optionArray[0], ['string', 'int', 'text', 'bool', 'date'])) { |
38
|
|
|
$data[] = $column; |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
return $data; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getNativeData() |
45
|
|
|
{ |
46
|
|
|
$data = []; |
47
|
|
|
foreach ($this->data as $column => $optionString) { |
48
|
|
|
$optionArray = explode(':', $optionString); |
49
|
|
|
if (in_array($optionArray[0], ['string', 'int', 'text', 'bool', 'date', 'datetime'])) { |
50
|
|
|
$data[] = [$column => $optionArray[0]]; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
return $data; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getForeignColumns($type = 'all') |
57
|
|
|
{ |
58
|
|
|
if(is_array($type)) |
59
|
|
|
$types = $type; |
60
|
|
|
else |
61
|
|
|
$types = ($type == "all") ? ['parent', 'related'] : [$type]; |
62
|
|
|
|
63
|
|
|
$data = []; |
64
|
|
|
foreach ($this->data as $column => $optionString) { |
65
|
|
|
$optionArray = explode(':', $optionString); |
66
|
|
|
if (in_array($optionArray[0], $types)) { |
67
|
|
|
$data[] = [$column => $optionArray[1]]; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
return $data; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getModuleName() |
74
|
|
|
{ |
75
|
|
|
return $this->name; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getModelName() |
79
|
|
|
{ |
80
|
|
|
return ucfirst(camel_case(str_singular($this->name))); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function getModelNamePlural() |
84
|
|
|
{ |
85
|
|
|
return ucfirst(camel_case($this->name)); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getModelNameSingularLowercase() |
89
|
|
|
{ |
90
|
|
|
return str_singular($this->name); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|