|
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\UserRole as UserRoleModel; |
|
13
|
|
|
use gplcart\modules\faker\models\Generator as FakerModuleGenerator; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Manages basic behaviors and data related to users |
|
17
|
|
|
*/ |
|
18
|
|
|
class User extends FakerModuleGenerator |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* User role model class instance |
|
23
|
|
|
* @var \gplcart\core\models\UserRole $user_role |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $user_role; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param UserRoleModel $user_role |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct(UserRoleModel $user_role) |
|
31
|
|
|
{ |
|
32
|
|
|
parent::__construct(); |
|
33
|
|
|
|
|
34
|
|
|
$this->user_role = $user_role; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Returns the generator name |
|
39
|
|
|
* @return string |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getName() |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->translation->text('User'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Returns a random role ID |
|
48
|
|
|
* @return integer |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function getRoleId() |
|
51
|
|
|
{ |
|
52
|
|
|
static $roles = null; |
|
53
|
|
|
if (!isset($roles)) { |
|
54
|
|
|
$roles = $this->user_role->getList(array('limit' => array(0, 100))); |
|
55
|
|
|
} |
|
56
|
|
|
return array_rand($roles); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Generate a single user |
|
61
|
|
|
* @return bool |
|
62
|
|
|
*/ |
|
63
|
|
|
public function create() |
|
64
|
|
|
{ |
|
65
|
|
|
$user = array( |
|
66
|
|
|
'name' => $this->faker->name(), |
|
67
|
|
|
'role_id' => $this->getRoleId(), |
|
68
|
|
|
'email' => $this->faker->email(), |
|
69
|
|
|
'store_id' => $this->getStoreId(), |
|
70
|
|
|
'status' => $this->faker->boolean(), |
|
71
|
|
|
'password' => $this->faker->password() |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
return (bool) $this->user->add($user); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|