1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Faker |
5
|
|
|
* @author Iurii Makukh <[email protected]> |
6
|
|
|
* @copyright Copyright (c) 2017, Iurii Makukh <[email protected]> |
7
|
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License 3.0 |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace gplcart\modules\faker\models\generators; |
11
|
|
|
|
12
|
|
|
use gplcart\core\models\CategoryGroup as CategoryGroupModel; |
13
|
|
|
use gplcart\modules\faker\models\Generator as FakerModuleGenerator; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Manages basic behaviors and data related to categories |
17
|
|
|
*/ |
18
|
|
|
class Category extends FakerModuleGenerator |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Category group model class instance |
23
|
|
|
* @var \gplcart\core\models\CategoryGroup $category_group |
24
|
|
|
*/ |
25
|
|
|
protected $category_group; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param CategoryGroupModel $category_group |
29
|
|
|
*/ |
30
|
|
|
public function __construct(CategoryGroupModel $category_group) |
31
|
|
|
{ |
32
|
|
|
parent::__construct(); |
33
|
|
|
|
34
|
|
|
$this->category_group = $category_group; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Returns the generator name |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
|
|
public function getName() |
42
|
|
|
{ |
43
|
|
|
return $this->translation->text('Category'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Generate a single page |
48
|
|
|
* @return bool |
49
|
|
|
*/ |
50
|
|
|
public function create() |
51
|
|
|
{ |
52
|
|
|
$group = $this->getCategoryGroup(); |
53
|
|
|
|
54
|
|
|
$category = array( |
55
|
|
|
'weight' => $this->faker->numberBetween(0, 20), |
56
|
|
|
'user_id' => $this->getUserId(), |
57
|
|
|
'title' => $this->faker->text(100), |
58
|
|
|
'status' => $this->faker->boolean(), |
59
|
|
|
'description_1' => $this->faker->text(1000), |
60
|
|
|
'description_2' => $this->faker->text(1000), |
61
|
|
|
'parent_id' => $this->getCategoryId($group['type']), |
62
|
|
|
'category_group_id' => $group['category_group_id'], |
63
|
|
|
'meta_title' => $this->faker->text(60), |
64
|
|
|
'meta_description' => $this->faker->text(160), |
65
|
|
|
'alias' => $this->getAlias(), |
66
|
|
|
'images' => $this->getImages() |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
return (bool) $this->category->add($category); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Returns a random category group |
74
|
|
|
* @return array |
75
|
|
|
*/ |
76
|
|
|
protected function getCategoryGroup() |
77
|
|
|
{ |
78
|
|
|
static $groups = null; |
79
|
|
|
|
80
|
|
|
if (!isset($groups)) { |
81
|
|
|
$groups = $this->category_group->getList(array('limit' => array(0, 100))); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $groups[array_rand($groups)]; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
|