|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package Faker |
|
5
|
|
|
* @author Iurii Makukh <[email protected]> |
|
6
|
|
|
* @author Skeleton https://github.com/gplcart/skeleton |
|
7
|
|
|
* @copyright Copyright (c) 2017, Iurii Makukh <[email protected]> |
|
8
|
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License 3.0 |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace gplcart\modules\faker\controllers; |
|
12
|
|
|
|
|
13
|
|
|
use gplcart\core\controllers\backend\Controller; |
|
14
|
|
|
use gplcart\modules\faker\models\Generator as GeneratorModel; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Handles incoming requests and outputs data related to Faker module |
|
18
|
|
|
*/ |
|
19
|
|
|
class Generator extends Controller |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Route page callback to display the generator page |
|
24
|
|
|
*/ |
|
25
|
|
|
public function editGenerator() |
|
26
|
|
|
{ |
|
27
|
|
|
$this->setTitleEditGenerator(); |
|
28
|
|
|
$this->setBreadcrumbEditGenerator(); |
|
29
|
|
|
|
|
30
|
|
|
$this->setData('generators', $this->getListGenerator()); |
|
31
|
|
|
|
|
32
|
|
|
$this->submitGenerator(); |
|
33
|
|
|
$this->outputEditGenerator(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Returns an array of generator names |
|
38
|
|
|
* @return array |
|
39
|
|
|
*/ |
|
40
|
|
|
protected function getListGenerator() |
|
41
|
|
|
{ |
|
42
|
|
|
$list = array(); |
|
43
|
|
|
|
|
44
|
|
|
foreach (GeneratorModel::getList() as $id => $model) { |
|
45
|
|
|
$list[$id] = $model->getName(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return gplcart_array_split($list, 4); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Handles submitted data |
|
53
|
|
|
*/ |
|
54
|
|
|
protected function submitGenerator() |
|
55
|
|
|
{ |
|
56
|
|
|
$entity = $this->getPosted('generate', null, true, 'string'); |
|
57
|
|
|
|
|
58
|
|
|
if (empty($entity)) { |
|
59
|
|
|
return null; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
$generator = GeneratorModel::get($entity); |
|
63
|
|
|
|
|
64
|
|
|
if (empty($generator)) { |
|
65
|
|
|
return null; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$limit = $this->config("module_faker_{$entity}_limit", 20); |
|
69
|
|
|
$result = $generator->generate($limit); |
|
70
|
|
|
|
|
71
|
|
|
if (empty($result)) { |
|
72
|
|
|
$this->redirect('', $this->text('Content has not been generated'), 'warning'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
$this->redirect('', $this->text('Generated @num entities', array('@num' => $result)), 'success'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Set titles on the generator page |
|
80
|
|
|
*/ |
|
81
|
|
|
protected function setTitleEditGenerator() |
|
82
|
|
|
{ |
|
83
|
|
|
$breadcrumb = array( |
|
84
|
|
|
'url' => $this->url('admin'), |
|
85
|
|
|
'text' => $this->text('Dashboard') |
|
86
|
|
|
); |
|
87
|
|
|
|
|
88
|
|
|
$this->setBreadcrumb($breadcrumb); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Set breadcrumbs on the generator page |
|
93
|
|
|
*/ |
|
94
|
|
|
protected function setBreadcrumbEditGenerator() |
|
95
|
|
|
{ |
|
96
|
|
|
$this->setTitle($this->text('Generate content')); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Render and output the generator page |
|
101
|
|
|
*/ |
|
102
|
|
|
protected function outputEditGenerator() |
|
103
|
|
|
{ |
|
104
|
|
|
$this->output('faker|generator'); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
|