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\modules\faker\models\Generator as FakerModuleGenerator; |
14
|
|
|
use gplcart\core\controllers\backend\Controller as BackendController; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Handles incoming requests and outputs data related to Faker module |
18
|
|
|
*/ |
19
|
|
|
class Generator extends BackendController |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Constructor |
24
|
|
|
*/ |
25
|
|
|
public function __construct() |
26
|
|
|
{ |
27
|
|
|
parent::__construct(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Route page callback to display the generator page |
32
|
|
|
*/ |
33
|
|
|
public function editGenerator() |
34
|
|
|
{ |
35
|
|
|
$this->setTitleEditGenerator(); |
36
|
|
|
$this->setBreadcrumbEditGenerator(); |
37
|
|
|
|
38
|
|
|
$this->setData('generators', $this->getListGenerator()); |
39
|
|
|
|
40
|
|
|
$this->submitGenerator(); |
41
|
|
|
$this->outputEditGenerator(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Returns an array of generator names |
46
|
|
|
* @return array |
47
|
|
|
*/ |
48
|
|
|
protected function getListGenerator() |
49
|
|
|
{ |
50
|
|
|
$list = array(); |
51
|
|
|
|
52
|
|
|
foreach (FakerModuleGenerator::getList() as $id => $model) { |
53
|
|
|
$list[$id] = $model->getName(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return gplcart_array_split($list, 4); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Handles submitted data |
61
|
|
|
*/ |
62
|
|
|
protected function submitGenerator() |
63
|
|
|
{ |
64
|
|
|
$entity = $this->getPosted('generate', null, true, 'string'); |
65
|
|
|
|
66
|
|
|
if (empty($entity)) { |
67
|
|
|
return null; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$generator = FakerModuleGenerator::get($entity); |
71
|
|
|
|
72
|
|
|
if (empty($generator)) { |
73
|
|
|
return null; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$limit = $this->config("module_faker_{$entity}_limit", 20); |
77
|
|
|
$result = $generator->generate($limit); |
78
|
|
|
|
79
|
|
|
if (empty($result)) { |
80
|
|
|
$this->redirect('', $this->text('Content has not been generated'), 'warning'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$this->redirect('', $this->text('Generated @num entities', array('@num' => $result)), 'success'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Set titles on the generator page |
88
|
|
|
*/ |
89
|
|
|
protected function setTitleEditGenerator() |
90
|
|
|
{ |
91
|
|
|
$this->setBreadcrumbBackend(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Set breadcrumbs on the generator page |
96
|
|
|
*/ |
97
|
|
|
protected function setBreadcrumbEditGenerator() |
98
|
|
|
{ |
99
|
|
|
$this->setTitle($this->text('Generate content')); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Render and output the generator page |
104
|
|
|
*/ |
105
|
|
|
protected function outputEditGenerator() |
106
|
|
|
{ |
107
|
|
|
$this->output('faker|generator'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
|