|
1
|
|
|
<?php |
|
2
|
|
|
namespace keeko\tools\generator\name; |
|
3
|
|
|
|
|
4
|
|
|
use keeko\framework\utils\NameUtils; |
|
5
|
|
|
use keeko\tools\model\Relationship; |
|
6
|
|
|
use phootwork\lang\Text; |
|
7
|
|
|
use Propel\Generator\Model\Table; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Generates action titles |
|
11
|
|
|
* |
|
12
|
|
|
* @author gossi |
|
13
|
|
|
*/ |
|
14
|
|
|
class ActionTitleGenerator extends AbstractModelNameGenerator { |
|
15
|
|
|
|
|
16
|
|
|
// |
|
17
|
|
|
// Model generators |
|
18
|
|
|
// |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Generates the title for a list action |
|
22
|
|
|
* |
|
23
|
|
|
* @param Table $model |
|
24
|
|
|
* @return string |
|
25
|
|
|
*/ |
|
26
|
|
|
public function generateModelPaginate(Table $model) { |
|
27
|
|
|
return 'Paginates ' . NameUtils::pluralize($model->getOriginCommonName()); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Generates the title for a create action |
|
32
|
|
|
* |
|
33
|
|
|
* @param Table $model |
|
34
|
|
|
* @return string |
|
35
|
|
|
*/ |
|
36
|
|
|
public function generateModelCreate(Table $model) { |
|
37
|
|
|
$title = $model->getOriginCommonName(); |
|
38
|
|
|
return 'Creates ' . (in_array($title[0], ['a', 'e', 'i', 'o', 'u']) ? 'an' : 'a') . ' ' . $title; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Generates the title for a read action |
|
43
|
|
|
* |
|
44
|
|
|
* @param Table $model |
|
45
|
|
|
* @return string |
|
46
|
|
|
*/ |
|
47
|
|
|
public function generateModelRead(Table $model) { |
|
48
|
|
|
$title = $model->getOriginCommonName(); |
|
49
|
|
|
return 'Reads ' . (in_array($title[0], ['a', 'e', 'i', 'o', 'u']) ? 'an' : 'a') . ' ' . $title; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Generates the title for an update action |
|
54
|
|
|
* |
|
55
|
|
|
* @param Table $model |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
|
|
public function generateModelUpdate(Table $model) { |
|
59
|
|
|
$title = $model->getOriginCommonName(); |
|
60
|
|
|
return 'Updates ' . (in_array($title[0], ['a', 'e', 'i', 'o', 'u']) ? 'an' : 'a') . ' ' . $title; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Generates the title for a delete action |
|
65
|
|
|
* |
|
66
|
|
|
* @param Table $model |
|
67
|
|
|
* @return string |
|
68
|
|
|
*/ |
|
69
|
|
|
public function generateModelDelete(Table $model) { |
|
70
|
|
|
$name = $model->getOriginCommonName(); |
|
71
|
|
|
return 'Deletes ' . (in_array($name[0], ['a', 'e', 'i', 'o', 'u']) ? 'an' : 'a') . ' ' . $name; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
// |
|
75
|
|
|
// Relationship generators |
|
76
|
|
|
// |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Generates a relationship read action title |
|
80
|
|
|
* |
|
81
|
|
|
* @param Relationship $relationship |
|
82
|
|
|
* @return string |
|
83
|
|
|
*/ |
|
84
|
|
|
public function generateRelationshipRead(Relationship $relationship) { |
|
85
|
|
|
return Text::create('Reads the relationship of {model} to {related}')->supplant([ |
|
86
|
|
|
'{model}' => $relationship->getModel()->getOriginCommonName(), |
|
87
|
|
|
'{related}' => NameUtils::toSnakeCase($relationship->getRelatedName()) |
|
88
|
|
|
])->toString(); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Generates a relationship update action title |
|
93
|
|
|
* |
|
94
|
|
|
* @param Relationship $relationship |
|
95
|
|
|
* @return string |
|
96
|
|
|
*/ |
|
97
|
|
|
public function generateRelationshipUpdate(Relationship $relationship) { |
|
98
|
|
|
return Text::create('Updates the relationship of {model} to {related}')->supplant([ |
|
99
|
|
|
'{model}' => $relationship->getModel()->getOriginCommonName(), |
|
100
|
|
|
'{related}' => NameUtils::toSnakeCase($relationship->getRelatedName()) |
|
101
|
|
|
])->toString(); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Generates a relationship add action title |
|
106
|
|
|
* |
|
107
|
|
|
* @param Relationship $relationship |
|
108
|
|
|
* @return string |
|
109
|
|
|
*/ |
|
110
|
|
|
public function generateRelationshipAdd(Relationship $relationship) { |
|
111
|
|
|
return Text::create('Adds {related} as relationship to {model}')->supplant([ |
|
112
|
|
|
'{model}' => $relationship->getModel()->getOriginCommonName(), |
|
113
|
|
|
'{related}' => NameUtils::toSnakeCase($relationship->getRelatedName()) |
|
114
|
|
|
])->toString(); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Generates a relationship remove action title |
|
119
|
|
|
* |
|
120
|
|
|
* @param Relationship $relationship |
|
121
|
|
|
* @return string |
|
122
|
|
|
*/ |
|
123
|
|
|
public function generateRelationshipRemove(Relationship $relationship) { |
|
124
|
|
|
return Text::create('Removes {related} as relationship to {model}')->supplant([ |
|
125
|
|
|
'{model}' => $relationship->getModel()->getOriginCommonName(), |
|
126
|
|
|
'{related}' => NameUtils::toSnakeCase($relationship->getRelatedName()) |
|
127
|
|
|
])->toString(); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
} |