@@ -54,7 +54,7 @@ |
||
54 | 54 | if (!$user) { |
55 | 55 | return $response->withStatus(302)->withHeader( |
56 | 56 | 'Location', |
57 | - $this->router->generateUri('auth', ['action' => 'login']) |
|
57 | + $this->router->generateUri('auth', [ 'action' => 'login' ]) |
|
58 | 58 | ); |
59 | 59 | } |
60 | 60 |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | |
32 | 32 | public function get($id) |
33 | 33 | { |
34 | - return $this->select(['admin_user_id' => $id])->current(); |
|
34 | + return $this->select([ 'admin_user_id' => $id ])->current(); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function getByEmail(string $email) |
44 | 44 | { |
45 | - return $this->select(['email' => $email])->current(); |
|
45 | + return $this->select([ 'email' => $email ])->current(); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function updateLogin(string $userId) : int |
55 | 55 | { |
56 | - return $this->update(['last_login' => date('Y-m-d H:i:s')], ['admin_user_id' => $userId]); |
|
56 | + return $this->update([ 'last_login' => date('Y-m-d H:i:s') ], [ 'admin_user_id' => $userId ]); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | public function getPaginationSelect($userId) |
60 | 60 | { |
61 | - $select = $this->getSql()->select()->order(['created_at' => 'desc']); |
|
61 | + $select = $this->getSql()->select()->order([ 'created_at' => 'desc' ]); |
|
62 | 62 | |
63 | 63 | $select->where->notEqualTo('admin_user_id', $userId); |
64 | 64 |
@@ -29,6 +29,9 @@ discard block |
||
29 | 29 | $this->adapter = $adapter; |
30 | 30 | } |
31 | 31 | |
32 | + /** |
|
33 | + * @param string $id |
|
34 | + */ |
|
32 | 35 | public function get($id) |
33 | 36 | { |
34 | 37 | return $this->select(['admin_user_id' => $id])->current(); |
@@ -38,7 +41,7 @@ discard block |
||
38 | 41 | * Get admin user by email. |
39 | 42 | * |
40 | 43 | * @param string $email email |
41 | - * @return array|\ArrayObject|null |
|
44 | + * @return string |
|
42 | 45 | */ |
43 | 46 | public function getByEmail(string $email) |
44 | 47 | { |
@@ -48,7 +51,6 @@ discard block |
||
48 | 51 | /** |
49 | 52 | * Updates login data. |
50 | 53 | * |
51 | - * @param string $uuid admin user id |
|
52 | 54 | * @return int number of affected rows |
53 | 55 | */ |
54 | 56 | public function updateLogin(string $userId) : int |
@@ -56,6 +58,9 @@ discard block |
||
56 | 58 | return $this->update(['last_login' => date('Y-m-d H:i:s')], ['admin_user_id' => $userId]); |
57 | 59 | } |
58 | 60 | |
61 | + /** |
|
62 | + * @param string $userId |
|
63 | + */ |
|
59 | 64 | public function getPaginationSelect($userId) |
60 | 65 | { |
61 | 66 | $select = $this->getSql()->select()->order(['created_at' => 'desc']); |
@@ -19,37 +19,37 @@ discard block |
||
19 | 19 | |
20 | 20 | public function getInputFilter() |
21 | 21 | { |
22 | - if(!$this->inputFilter){ |
|
22 | + if (!$this->inputFilter) { |
|
23 | 23 | $inputFilter = new InputFilter(); |
24 | 24 | |
25 | 25 | $inputFilter->add([ |
26 | 26 | 'name' => 'first_name', |
27 | 27 | 'required' => true, |
28 | - 'filters' => [['name' => 'StringTrim']], |
|
28 | + 'filters' => [ [ 'name' => 'StringTrim' ] ], |
|
29 | 29 | 'validators' => [ |
30 | - ['name' => 'NotEmpty'], |
|
31 | - ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 255]] |
|
30 | + [ 'name' => 'NotEmpty' ], |
|
31 | + [ 'name' => 'StringLength', 'options' => [ 'min' => 2, 'max' => 255 ] ] |
|
32 | 32 | ], |
33 | 33 | ]); |
34 | 34 | |
35 | 35 | $inputFilter->add([ |
36 | 36 | 'name' => 'last_name', |
37 | 37 | 'required' => true, |
38 | - 'filters' => [['name' => 'StringTrim']], |
|
38 | + 'filters' => [ [ 'name' => 'StringTrim' ] ], |
|
39 | 39 | 'validators' => [ |
40 | - ['name' => 'NotEmpty'], |
|
41 | - ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 255]] |
|
40 | + [ 'name' => 'NotEmpty' ], |
|
41 | + [ 'name' => 'StringLength', 'options' => [ 'min' => 2, 'max' => 255 ] ] |
|
42 | 42 | ], |
43 | 43 | ]); |
44 | 44 | |
45 | 45 | $inputFilter->add([ |
46 | 46 | 'name' => 'email', |
47 | 47 | 'required' => true, |
48 | - 'filters' => [['name' => 'StringTrim']], |
|
48 | + 'filters' => [ [ 'name' => 'StringTrim' ] ], |
|
49 | 49 | 'validators' => [ |
50 | - ['name' => 'NotEmpty'], |
|
51 | - ['name' => 'EmailAddress'], |
|
52 | - ['name' => 'dbnorecordexists', 'options' => ['adapter' => $this->adapter, 'table' => 'admin_users', 'field' => 'email']], |
|
50 | + [ 'name' => 'NotEmpty' ], |
|
51 | + [ 'name' => 'EmailAddress' ], |
|
52 | + [ 'name' => 'dbnorecordexists', 'options' => [ 'adapter' => $this->adapter, 'table' => 'admin_users', 'field' => 'email' ] ], |
|
53 | 53 | |
54 | 54 | ], |
55 | 55 | ]); |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | 'name' => 'password', |
59 | 59 | 'required' => true, |
60 | 60 | 'validators' => [ |
61 | - ['name' => 'NotEmpty'], |
|
62 | - ['name' => 'StringLength', 'options' => ['min' => 7, 'max' => 255]] |
|
61 | + [ 'name' => 'NotEmpty' ], |
|
62 | + [ 'name' => 'StringLength', 'options' => [ 'min' => 7, 'max' => 255 ] ] |
|
63 | 63 | ], |
64 | 64 | ]); |
65 | 65 | |
@@ -67,15 +67,15 @@ discard block |
||
67 | 67 | 'name' => 'confirm_password', |
68 | 68 | 'required' => true, |
69 | 69 | 'validators' => [ |
70 | - ['name' => 'NotEmpty'], |
|
71 | - ['name' => 'Identical', 'options' => ['token' => 'password']], |
|
70 | + [ 'name' => 'NotEmpty' ], |
|
71 | + [ 'name' => 'Identical', 'options' => [ 'token' => 'password' ] ], |
|
72 | 72 | ], |
73 | 73 | ]); |
74 | 74 | |
75 | 75 | $inputFilter->add([ |
76 | 76 | 'name' => 'status', |
77 | 77 | 'required' => true, |
78 | - 'validators' => [['name' => 'NotEmpty'], ['name' => 'Digits']] |
|
78 | + 'validators' => [ [ 'name' => 'NotEmpty' ], [ 'name' => 'Digits' ] ] |
|
79 | 79 | ]); |
80 | 80 | |
81 | 81 | $this->inputFilter = $inputFilter; |
@@ -6,18 +6,18 @@ |
||
6 | 6 | { |
7 | 7 | public function up() |
8 | 8 | { |
9 | - $this->table('articles', ['id' => false, 'primary_key' => 'article_uuid']) |
|
10 | - ->addColumn('article_uuid', 'binary', ['limit' => 16]) |
|
9 | + $this->table('articles', [ 'id' => false, 'primary_key' => 'article_uuid' ]) |
|
10 | + ->addColumn('article_uuid', 'binary', [ 'limit' => 16 ]) |
|
11 | 11 | ->addColumn('article_id', 'text') |
12 | - ->addColumn('slug', 'text', ['null' => true]) |
|
13 | - ->addColumn('created_at', 'datetime', ['default' => 'CURRENT_TIMESTAMP']) |
|
14 | - ->addColumn('published_at', 'datetime', ['default' => 'CURRENT_TIMESTAMP']) |
|
12 | + ->addColumn('slug', 'text', [ 'null' => true ]) |
|
13 | + ->addColumn('created_at', 'datetime', [ 'default' => 'CURRENT_TIMESTAMP' ]) |
|
14 | + ->addColumn('published_at', 'datetime', [ 'default' => 'CURRENT_TIMESTAMP' ]) |
|
15 | 15 | ->addColumn('type', 'integer')// see Core\Entity\ArticleType |
16 | 16 | ->addColumn('status', 'integer')// active, not active, ... |
17 | - ->addColumn('admin_user_uuid', 'binary', ['limit' => 16]) |
|
18 | - ->addForeignKey('admin_user_uuid', 'admin_users', 'admin_user_uuid', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION']) |
|
19 | - ->addIndex('type', ['name' => 'type_INDEX']) |
|
20 | - ->addIndex('published_at', ['name' => 'published_at_INDEX']) |
|
17 | + ->addColumn('admin_user_uuid', 'binary', [ 'limit' => 16 ]) |
|
18 | + ->addForeignKey('admin_user_uuid', 'admin_users', 'admin_user_uuid', [ 'delete' => 'NO_ACTION', 'update' => 'NO_ACTION' ]) |
|
19 | + ->addIndex('type', [ 'name' => 'type_INDEX' ]) |
|
20 | + ->addIndex('published_at', [ 'name' => 'published_at_INDEX' ]) |
|
21 | 21 | ->create(); |
22 | 22 | } |
23 | 23 |
@@ -8,22 +8,22 @@ |
||
8 | 8 | { |
9 | 9 | public function up() |
10 | 10 | { |
11 | - $this->table('admin_users', ['id' => false, 'primary_key' => 'admin_user_uuid']) |
|
12 | - ->addColumn('admin_user_uuid', 'binary', ['limit' => 16]) |
|
11 | + $this->table('admin_users', [ 'id' => false, 'primary_key' => 'admin_user_uuid' ]) |
|
12 | + ->addColumn('admin_user_uuid', 'binary', [ 'limit' => 16 ]) |
|
13 | 13 | ->addColumn('admin_user_id', 'text') |
14 | 14 | ->addColumn('first_name', 'text') |
15 | 15 | ->addColumn('last_name', 'text') |
16 | - ->addColumn('email', 'string', ['limit' => 128]) |
|
17 | - ->addColumn('password', 'char', ['limit' => 60]) |
|
18 | - ->addColumn('status', 'integer', ['default' => 0])// 0 => not active, 1 = active |
|
19 | - ->addColumn('created_at', 'datetime', ['default' => 'CURRENT_TIMESTAMP']) |
|
20 | - ->addColumn('last_login', 'datetime', ['null' => true]) |
|
21 | - ->addIndex(['email'], ['name' => 'email_INDEX']) |
|
16 | + ->addColumn('email', 'string', [ 'limit' => 128 ]) |
|
17 | + ->addColumn('password', 'char', [ 'limit' => 60 ]) |
|
18 | + ->addColumn('status', 'integer', [ 'default' => 0 ])// 0 => not active, 1 = active |
|
19 | + ->addColumn('created_at', 'datetime', [ 'default' => 'CURRENT_TIMESTAMP' ]) |
|
20 | + ->addColumn('last_login', 'datetime', [ 'null' => true ]) |
|
21 | + ->addIndex([ 'email' ], [ 'name' => 'email_INDEX' ]) |
|
22 | 22 | ->create(); |
23 | 23 | |
24 | 24 | $faker = Faker\Factory::create(); |
25 | 25 | $count = rand(100, 150); |
26 | - for($i = 0; $i < $count; $i++){ |
|
26 | + for ($i = 0; $i < $count; $i++) { |
|
27 | 27 | $id = $faker->uuid; |
28 | 28 | $mysqluuid = (new Uuid($id))->toFormat(new Binary()); |
29 | 29 | $data = [ |
@@ -9,8 +9,6 @@ |
||
9 | 9 | use Core\Mapper\AdminUsersMapper; |
10 | 10 | use Core\Filter\AdminUserFilter; |
11 | 11 | use Core\Exception\FilterException; |
12 | -use Zend\Db\TableGateway\TableGateway; |
|
13 | -use Zend\Db\Sql\Predicate\Expression; |
|
14 | 12 | use Zend\Paginator\Adapter\DbSelect; |
15 | 13 | use Zend\Paginator\Paginator; |
16 | 14 | use Zend\Crypt\Password\Bcrypt; |
@@ -57,17 +57,17 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function loginUser($email, $password) |
59 | 59 | { |
60 | - if(!$email || !$password){ |
|
60 | + if (!$email || !$password) { |
|
61 | 61 | throw new \Exception('Both email and password are required.', 400); |
62 | 62 | } |
63 | 63 | |
64 | 64 | $user = $this->adminUsersMapper->getByEmail($email); |
65 | 65 | |
66 | - if(!$user){ |
|
66 | + if (!$user) { |
|
67 | 67 | throw new \Exception('User does not exist.'); |
68 | 68 | } |
69 | 69 | |
70 | - if(!$this->crypt->verify($password, $user->password)){ |
|
70 | + if (!$this->crypt->verify($password, $user->password)) { |
|
71 | 71 | throw new \Exception('Password does not match.'); |
72 | 72 | } |
73 | 73 | |
@@ -113,15 +113,15 @@ discard block |
||
113 | 113 | { |
114 | 114 | $filter = $this->adminUserFilter->getInputFilter()->setData($data); |
115 | 115 | |
116 | - if(!$filter->isValid()){ |
|
116 | + if (!$filter->isValid()) { |
|
117 | 117 | throw new FilterException($filter->getMessages()); |
118 | 118 | } |
119 | 119 | |
120 | 120 | $data = $filter->getValues(); |
121 | - unset($data['confirm_password']); |
|
122 | - $data['password'] = $this->crypt->create($data['password']); |
|
123 | - $data['admin_user_id'] = Uuid::uuid1()->toString(); |
|
124 | - $data['admin_user_uuid'] = (new MysqlUuid($data['admin_user_id']))->toFormat(new Binary); |
|
121 | + unset($data[ 'confirm_password' ]); |
|
122 | + $data[ 'password' ] = $this->crypt->create($data[ 'password' ]); |
|
123 | + $data[ 'admin_user_id' ] = Uuid::uuid1()->toString(); |
|
124 | + $data[ 'admin_user_uuid' ] = (new MysqlUuid($data[ 'admin_user_id' ]))->toFormat(new Binary); |
|
125 | 125 | |
126 | 126 | return $this->adminUsersMapper->insert($data); |
127 | 127 | } |
@@ -135,28 +135,28 @@ discard block |
||
135 | 135 | $filter = $this->adminUserFilter->getInputFilter()->setData($data); |
136 | 136 | |
137 | 137 | // we dont want to force user to enter the password again |
138 | - if($data['password'] == ''){ |
|
138 | + if ($data[ 'password' ] == '') { |
|
139 | 139 | $filter->remove('password'); |
140 | 140 | $filter->remove('confirm_password'); |
141 | 141 | } |
142 | 142 | |
143 | 143 | // if we want to keep same email |
144 | - if($user->email == $data['email']){ |
|
144 | + if ($user->email == $data[ 'email' ]) { |
|
145 | 145 | $filter->remove('email'); |
146 | 146 | } |
147 | 147 | |
148 | - if(!$filter->isValid()){ |
|
148 | + if (!$filter->isValid()) { |
|
149 | 149 | throw new FilterException($filter->getMessages()); |
150 | 150 | } |
151 | 151 | |
152 | 152 | $data = $filter->getValues(); |
153 | 153 | |
154 | - if(isset($data['password'])){ |
|
155 | - unset($data['confirm_password']); |
|
156 | - $data['password'] = $this->crypt->create($data['password']); |
|
154 | + if (isset($data[ 'password' ])) { |
|
155 | + unset($data[ 'confirm_password' ]); |
|
156 | + $data[ 'password' ] = $this->crypt->create($data[ 'password' ]); |
|
157 | 157 | } |
158 | 158 | |
159 | - return $this->adminUsersMapper->update($data, ['admin_user_id' => $userId]); |
|
159 | + return $this->adminUsersMapper->update($data, [ 'admin_user_id' => $userId ]); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -167,6 +167,6 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function delete($userId) |
169 | 169 | { |
170 | - return (bool)$this->adminUsersMapper->delete(['admin_user_id' => $userId]); |
|
170 | + return (bool) $this->adminUsersMapper->delete([ 'admin_user_id' => $userId ]); |
|
171 | 171 | } |
172 | 172 | } |
@@ -4,7 +4,6 @@ |
||
4 | 4 | use MysqlUuid\Formats\Binary; |
5 | 5 | use MysqlUuid\Uuid; |
6 | 6 | use Core\Entity\ArticleType; |
7 | -use MysqlUuid\Formats\PlainString; |
|
8 | 7 | |
9 | 8 | class Discussions extends AbstractMigration |
10 | 9 | { |
@@ -10,11 +10,11 @@ discard block |
||
10 | 10 | { |
11 | 11 | public function up() |
12 | 12 | { |
13 | - $this->table('article_discussions', ['id' => false]) |
|
14 | - ->addColumn('article_uuid', 'binary', ['limit' => 16]) |
|
13 | + $this->table('article_discussions', [ 'id' => false ]) |
|
14 | + ->addColumn('article_uuid', 'binary', [ 'limit' => 16 ]) |
|
15 | 15 | ->addColumn('title', 'text') |
16 | 16 | ->addColumn('body', 'text') |
17 | - ->addForeignKey('article_uuid', 'articles', 'article_uuid', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION']) |
|
17 | + ->addForeignKey('article_uuid', 'articles', 'article_uuid', [ 'delete' => 'NO_ACTION', 'update' => 'NO_ACTION' ]) |
|
18 | 18 | ->create(); |
19 | 19 | |
20 | 20 | // $this->insertDummyData(); |
@@ -27,15 +27,15 @@ discard block |
||
27 | 27 | |
28 | 28 | private function insertDummyData() |
29 | 29 | { |
30 | - $ids = []; |
|
30 | + $ids = [ ]; |
|
31 | 31 | $rows = $this->fetchAll('select admin_user_uuid from admin_users;'); |
32 | - foreach($rows as $r){ |
|
33 | - $ids[] = $r['admin_user_uuid']; |
|
32 | + foreach ($rows as $r) { |
|
33 | + $ids[ ] = $r[ 'admin_user_uuid' ]; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | $faker = Faker\Factory::create(); |
37 | 37 | $count = rand(250, 300); |
38 | - for($i = 0; $i < $count; $i++){ |
|
38 | + for ($i = 0; $i < $count; $i++) { |
|
39 | 39 | $id = $faker->uuid; |
40 | 40 | $mysqluuid = (new Uuid($id))->toFormat(new Binary()); |
41 | 41 | $title = $faker->sentence(5, 15); |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | 'article_id' => $id, |
46 | 46 | 'slug' => strtolower(trim(preg_replace('~[^\pL\d]+~u', '-', $title), '-')), |
47 | 47 | 'status' => 1, |
48 | - 'admin_user_uuid' => $ids[array_rand($ids)], |
|
48 | + 'admin_user_uuid' => $ids[ array_rand($ids) ], |
|
49 | 49 | 'type' => ArticleType::DISCUSSION |
50 | 50 | ]; |
51 | 51 |
@@ -10,15 +10,15 @@ discard block |
||
10 | 10 | { |
11 | 11 | public function up() |
12 | 12 | { |
13 | - $this->table('article_videos', ['id' => false]) |
|
14 | - ->addColumn('article_uuid', 'binary', ['limit' => 16]) |
|
13 | + $this->table('article_videos', [ 'id' => false ]) |
|
14 | + ->addColumn('article_uuid', 'binary', [ 'limit' => 16 ]) |
|
15 | 15 | ->addColumn('title', 'text') |
16 | 16 | ->addColumn('body', 'text') |
17 | 17 | ->addColumn('lead', 'text') |
18 | 18 | ->addColumn('embed_code', 'text') |
19 | - ->addColumn('featured_img', 'text', ['null' => true]) |
|
20 | - ->addColumn('main_img', 'text', ['null' => true]) |
|
21 | - ->addForeignKey('article_uuid', 'articles', 'article_uuid', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION']) |
|
19 | + ->addColumn('featured_img', 'text', [ 'null' => true ]) |
|
20 | + ->addColumn('main_img', 'text', [ 'null' => true ]) |
|
21 | + ->addForeignKey('article_uuid', 'articles', 'article_uuid', [ 'delete' => 'NO_ACTION', 'update' => 'NO_ACTION' ]) |
|
22 | 22 | ->create(); |
23 | 23 | |
24 | 24 | // $this->insertDummyData(); |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | |
32 | 32 | private function insertDummyData() |
33 | 33 | { |
34 | - $ids = []; |
|
34 | + $ids = [ ]; |
|
35 | 35 | $rows = $this->fetchAll('select admin_user_uuid from admin_users;'); |
36 | - foreach($rows as $r){ |
|
37 | - $ids[] = $r['admin_user_uuid']; |
|
36 | + foreach ($rows as $r) { |
|
37 | + $ids[ ] = $r[ 'admin_user_uuid' ]; |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | $faker = Faker\Factory::create(); |
@@ -47,19 +47,19 @@ discard block |
||
47 | 47 | ); |
48 | 48 | |
49 | 49 | // Download N images and set it randomly to posts |
50 | - for($i = 0; $i < 5; $i++){ |
|
50 | + for ($i = 0; $i < 5; $i++) { |
|
51 | 51 | $image = $faker->image(); |
52 | 52 | $destination = $upload->getPath(basename($image)); |
53 | 53 | rename($image, $destination); |
54 | - $mainImg[] = substr($destination, strlen('/var/www/unfinished/public')); |
|
54 | + $mainImg[ ] = substr($destination, strlen('/var/www/unfinished/public')); |
|
55 | 55 | |
56 | 56 | $image = $faker->image(); |
57 | 57 | $destination = $upload->getPath(basename($image)); |
58 | 58 | rename($image, $destination); |
59 | - $featuredImg[] = substr($destination, strlen('/var/www/unfinished/public')); |
|
59 | + $featuredImg[ ] = substr($destination, strlen('/var/www/unfinished/public')); |
|
60 | 60 | } |
61 | 61 | |
62 | - for($i = 0; $i < $count; $i++){ |
|
62 | + for ($i = 0; $i < $count; $i++) { |
|
63 | 63 | $id = $faker->uuid; |
64 | 64 | $mysqluuid = (new Uuid($id))->toFormat(new Binary()); |
65 | 65 | $title = $faker->sentence(7, 20); |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | 'article_id' => $id, |
70 | 70 | 'slug' => strtolower(trim(preg_replace('~[^\pL\d]+~u', '-', $title), '-')), |
71 | 71 | 'status' => 1, |
72 | - 'admin_user_uuid' => $ids[array_rand($ids)], |
|
72 | + 'admin_user_uuid' => $ids[ array_rand($ids) ], |
|
73 | 73 | 'type' => ArticleType::POST |
74 | 74 | ]; |
75 | 75 | |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | 'title' => $title, |
79 | 79 | 'body' => $faker->paragraph(15), |
80 | 80 | 'lead' => $faker->paragraph(5), |
81 | - 'main_img' => $mainImg[array_rand($mainImg)], |
|
82 | - 'featured_img' => $featuredImg[array_rand($featuredImg)], |
|
83 | - 'embed_code' => $embedCodes[rand(0, 2)] |
|
81 | + 'main_img' => $mainImg[ array_rand($mainImg) ], |
|
82 | + 'featured_img' => $featuredImg[ array_rand($featuredImg) ], |
|
83 | + 'embed_code' => $embedCodes[ rand(0, 2) ] |
|
84 | 84 | ]; |
85 | 85 | |
86 | 86 | $this->insert('articles', $article); |
@@ -10,19 +10,19 @@ discard block |
||
10 | 10 | { |
11 | 11 | public function up() |
12 | 12 | { |
13 | - $this->table('article_events', ['id' => false]) |
|
14 | - ->addColumn('article_uuid', 'binary', ['limit' => 16]) |
|
13 | + $this->table('article_events', [ 'id' => false ]) |
|
14 | + ->addColumn('article_uuid', 'binary', [ 'limit' => 16 ]) |
|
15 | 15 | ->addColumn('title', 'text') |
16 | - ->addColumn('sub_title', 'text', ['null' => true]) |
|
16 | + ->addColumn('sub_title', 'text', [ 'null' => true ]) |
|
17 | 17 | ->addColumn('place_name', 'text') |
18 | 18 | ->addColumn('body', 'text') |
19 | 19 | ->addColumn('longitude', 'text') |
20 | 20 | ->addColumn('latitude', 'text') |
21 | - ->addColumn('featured_img', 'text', ['null' => true]) |
|
22 | - ->addColumn('main_img', 'text', ['null' => true]) |
|
21 | + ->addColumn('featured_img', 'text', [ 'null' => true ]) |
|
22 | + ->addColumn('main_img', 'text', [ 'null' => true ]) |
|
23 | 23 | ->addColumn('start_at', 'datetime') |
24 | 24 | ->addColumn('end_at', 'datetime') |
25 | - ->addForeignKey('article_uuid', 'articles', 'article_uuid', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION']) |
|
25 | + ->addForeignKey('article_uuid', 'articles', 'article_uuid', [ 'delete' => 'NO_ACTION', 'update' => 'NO_ACTION' ]) |
|
26 | 26 | ->create(); |
27 | 27 | |
28 | 28 | // $this->insertDummyData(); |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | |
36 | 36 | private function insertDummyData() |
37 | 37 | { |
38 | - $ids = []; |
|
38 | + $ids = [ ]; |
|
39 | 39 | $rows = $this->fetchAll('select admin_user_uuid from admin_users;'); |
40 | - foreach($rows as $r){ |
|
41 | - $ids[] = $r['admin_user_uuid']; |
|
40 | + foreach ($rows as $r) { |
|
41 | + $ids[ ] = $r[ 'admin_user_uuid' ]; |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | $faker = Faker\Factory::create(); |
@@ -46,19 +46,19 @@ discard block |
||
46 | 46 | $count = rand(25, 300); |
47 | 47 | |
48 | 48 | // Download N images and set it randomly to the events |
49 | - for($i = 0; $i < 5; $i++){ |
|
49 | + for ($i = 0; $i < 5; $i++) { |
|
50 | 50 | $image = $faker->image(); |
51 | 51 | $destination = $upload->getPath(basename($image)); |
52 | 52 | rename($image, $destination); |
53 | - $mainImg[] = substr($destination, strlen('/var/www/unfinished/public')); |
|
53 | + $mainImg[ ] = substr($destination, strlen('/var/www/unfinished/public')); |
|
54 | 54 | |
55 | 55 | $image = $faker->image(); |
56 | 56 | $destination = $upload->getPath(basename($image)); |
57 | 57 | rename($image, $destination); |
58 | - $featuredImg[] = substr($destination, strlen('/var/www/unfinished/public')); |
|
58 | + $featuredImg[ ] = substr($destination, strlen('/var/www/unfinished/public')); |
|
59 | 59 | } |
60 | 60 | |
61 | - for($i = 0; $i < $count; $i++){ |
|
61 | + for ($i = 0; $i < $count; $i++) { |
|
62 | 62 | $start = rand(1, 20); |
63 | 63 | $id = $faker->uuid; |
64 | 64 | $mysqluuid = (new Uuid($id))->toFormat(new Binary()); |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | 'article_id' => $id, |
70 | 70 | 'slug' => strtolower(trim(preg_replace('~[^\pL\d]+~u', '-', $title), '-')), |
71 | 71 | 'status' => 1, |
72 | - 'admin_user_uuid' => $ids[array_rand($ids)], |
|
72 | + 'admin_user_uuid' => $ids[ array_rand($ids) ], |
|
73 | 73 | 'type' => ArticleType::EVENT |
74 | 74 | ]; |
75 | 75 | |
@@ -80,8 +80,8 @@ discard block |
||
80 | 80 | 'longitude' => $faker->longitude, |
81 | 81 | 'latitude' => $faker->latitude, |
82 | 82 | 'place_name' => $faker->sentence(1), |
83 | - 'main_img' => $mainImg[array_rand($mainImg)], |
|
84 | - 'featured_img' => $featuredImg[array_rand($featuredImg)], |
|
83 | + 'main_img' => $mainImg[ array_rand($mainImg) ], |
|
84 | + 'featured_img' => $featuredImg[ array_rand($featuredImg) ], |
|
85 | 85 | 'start_at' => date("Y-m-d H:i:s", strtotime("+$start day +$start hours")), |
86 | 86 | 'end_at' => date("Y-m-d H:i:s", strtotime("+$start day +" . ($start + rand(1, 5)) . " hours")) |
87 | 87 | ]; |