1
|
|
|
<?php |
2
|
|
|
//[PHPCOMPRESSOR(remove,start)] |
3
|
|
|
/** |
4
|
|
|
* Created by Vitaly Iegorov <[email protected]>. |
5
|
|
|
* on 23.03.16 at 14:51 |
6
|
|
|
*/ |
7
|
|
|
namespace samsoncms\api\generator; |
8
|
|
|
|
9
|
|
|
use samsonphp\generator\Generator; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* SamsonCMS application classes generator. |
13
|
|
|
* |
14
|
|
|
* @package samsoncms\application\generator |
15
|
|
|
*/ |
16
|
|
|
class Application extends \samsoncms\api\generator\Generic |
17
|
|
|
{ |
18
|
|
|
/** Default control class name */ |
19
|
|
|
const DEFAULT_GENERIC_CONTROL_TYPE = 'Control'; |
20
|
|
|
|
21
|
|
|
/** Path to index view of main page */ |
22
|
|
|
const MAIN_INDEX_VIEW = 'www/main_application/index'; |
23
|
|
|
|
24
|
|
|
/** Path to item view of main page */ |
25
|
|
|
const MAIN_ITEM_VIEW = 'www/main_application/row'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Query constructor. |
29
|
|
|
* |
30
|
|
|
* @param Generator $generator |
31
|
|
|
* @param $metadata |
32
|
|
|
*/ |
33
|
|
|
public function __construct(Generator $generator, $metadata) |
34
|
|
|
{ |
35
|
|
|
parent::__construct($generator, $metadata); |
36
|
|
|
|
37
|
|
|
$this->className .= 'Application'; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function createSubMenuView(Metadata $metadata, $namespace = __NAMESPACE__) |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
|
43
|
|
|
$code = <<<'EOD' |
44
|
|
|
|
45
|
|
|
<li> |
46
|
|
|
<a class="sub_menu_a <?php if(isv('all_materials')):?>active<?php endif?>" href="<?php module_url()?>"> |
47
|
|
|
<i class="icon2 icon2-list"></i> |
48
|
|
|
<?=$appName?> |
49
|
|
|
</a> |
50
|
|
|
</li> |
51
|
|
|
<li> |
52
|
|
|
<a class="sub_menu_a <?php if(isv('new_material')):?>active<?php endif?>" href="<?php module_url('new');?>"> |
53
|
|
|
<i class="icon2 icon2-plus"></i> <?php t('Add'); ?> <?=lcfirst($appName);?> <?php t('item')?> |
54
|
|
|
</a> |
55
|
|
|
</li> |
56
|
|
|
|
57
|
|
|
EOD; |
58
|
|
|
|
59
|
|
|
return str_replace('{{fields}}', implode(',', array_merge(array(), array("\n\t\t\t" . 'new Control()'. "\n\t\t"))), $code); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Render method for rendering view of entity on main page |
64
|
|
|
* @param $entityName |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
public function renderViewsOnMainPage($entityName) |
68
|
|
|
{ |
69
|
|
|
|
70
|
|
|
$code = <<<'EOD' |
71
|
|
|
|
72
|
|
|
/** Output for main page1 */ |
73
|
|
|
public function main() |
74
|
|
|
{ |
75
|
|
|
// Get module id |
76
|
|
|
$moduleId = $this->id; |
77
|
|
|
|
78
|
|
|
// Get module description |
79
|
|
|
$navName = $this->description; |
80
|
|
|
|
81
|
|
|
// Get path to views |
82
|
|
|
$mainIndexView = $this->mainIndexView; |
83
|
|
|
$mainItemView = $this->mainItemView; |
84
|
|
|
|
85
|
|
|
// Return material block HTML on main page |
86
|
|
|
/*return (new \samsoncms\api\generated\{{collection_name}}Collection($this)) |
87
|
|
|
// Render index |
88
|
|
|
->indexView(function($html, $renderer) use ($navName, $mainIndexView) { |
89
|
|
|
return $renderer->view($mainIndexView) |
90
|
|
|
->set($html, \samsoncms\api\renderable\Collection::ITEMS_VIEW_VARIABLE) |
91
|
|
|
->navName($navName) |
92
|
|
|
->output(); |
93
|
|
|
}) |
94
|
|
|
// Render item |
95
|
|
|
->itemView(function($item, $renderer) use ($moduleId, $mainItemView) { |
96
|
|
|
return $renderer->view($mainItemView) |
97
|
|
|
->set($item, \samsoncms\api\renderable\Collection::ITEM_VIEW_VARIABLE) |
98
|
|
|
//->user(m('social')->user()) |
99
|
|
|
->moduleId($moduleId) |
100
|
|
|
->output(); |
101
|
|
|
}) |
102
|
|
|
->output();*/ |
103
|
|
|
} |
104
|
|
|
EOD; |
105
|
|
|
|
106
|
|
|
return str_replace(array('{{collection_name}}'), array($entityName), $code); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Class definition generation part. |
111
|
|
|
* |
112
|
|
|
* @param \samsoncms\api\generator\metadata\ApplicationMetadata $metadata Entity metadata |
113
|
|
|
*/ |
114
|
|
|
protected function createDefinition($metadata) |
115
|
|
|
{ |
116
|
|
|
$this->generator |
117
|
|
|
->multiComment(array('Class application for "' . $metadata->name . '"')) |
118
|
|
|
->defClass($this->className, '\\' . \samsoncms\app\material\Application::class); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Class fields generation part. |
123
|
|
|
* |
124
|
|
|
* @param \samsoncms\api\generator\metadata\ApplicationMetadata $metadata Entity metadata |
125
|
|
|
*/ |
126
|
|
|
protected function createFields($metadata) |
127
|
|
|
{ |
128
|
|
|
$this->generator |
129
|
|
|
->commentVar('string', 'Application name') |
130
|
|
|
->defVar('public $name', $metadata->name) |
131
|
|
|
->commentVar('string', 'Application description') |
132
|
|
|
->defVar('public $description', $metadata->description) |
133
|
|
|
->commentVar('string', 'Identifier') |
134
|
|
|
->defVar('protected $id', $metadata->entity) |
135
|
|
|
->commentVar('string', 'Icon class') |
136
|
|
|
->defVar('public $icon', $metadata->iconApplication) |
137
|
|
|
->commentVar('bool', 'Flag for hiding Application icon in main menu') |
138
|
|
|
->defClassVar('$hide', 'public', !$metadata->showApplication ? 1 : 0) |
139
|
|
|
->commentVar('string', 'Path to rendering index view in main page') |
140
|
|
|
->defClassVar('$mainIndexView', 'public', self::MAIN_INDEX_VIEW) |
141
|
|
|
->commentVar('string', 'Path to rendering item view in main page') |
142
|
|
|
->defClassVar('$mainItemView', 'public', self::MAIN_ITEM_VIEW) |
143
|
|
|
->commentVar('array', 'Collection of structures related to entity') |
144
|
|
|
->defClassVar('$navigation', 'public static', (int)$metadata->identifier) |
145
|
|
|
->commentVar('array', 'All structures which have to have material at creation') |
146
|
|
|
->defClassVar('$structures', 'public static', array_merge(array($metadata->entityID), $metadata->childNavigationIDs)) |
147
|
|
|
->commentVar('string', 'Collection class name for rendering entities collection') |
148
|
|
|
->defClassVar('$collectionClass', 'protected', $metadata->entityClassName . 'Collection'); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Class constructor generation part. |
153
|
|
|
* |
154
|
|
|
* @param \samsoncms\api\generator\metadata\VirtualMetadata $metadata Entity metadata |
155
|
|
|
*/ |
156
|
|
|
protected function createConstructor($metadata) |
157
|
|
|
{ |
158
|
|
|
$constructorCode = <<<'EOD' |
159
|
|
|
/** |
160
|
|
|
* Render materials list with pager |
161
|
|
|
* |
162
|
|
|
* @param string $navigationId Structure identifier |
163
|
|
|
* @param string $search Keywords to filter table |
164
|
|
|
* @param int $page Current table page |
165
|
|
|
* @return array Asynchronous response containing status and materials list with pager on success |
166
|
|
|
* or just status on asynchronous controller failure |
167
|
|
|
*/ |
168
|
|
|
public function __async_collection($navigationId = '0', $search = '', $page = 1) |
169
|
|
|
{ |
170
|
|
|
return parent::__async_collection(self::$navigation, $search, $page); |
171
|
|
|
} |
172
|
|
|
EOD; |
173
|
|
|
|
174
|
|
|
$this->generator->text($constructorCode); |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
//[PHPCOMPRESSOR(remove,end)] |
178
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.