@@ -12,56 +12,56 @@ |
||
12 | 12 | |
13 | 13 | public function getInputFilter() |
14 | 14 | { |
15 | - if(!$this->inputFilter) { |
|
15 | + if (!$this->inputFilter) { |
|
16 | 16 | $inputFilter = new InputFilter(); |
17 | 17 | |
18 | 18 | $inputFilter->add([ |
19 | 19 | 'name' => 'title', |
20 | 20 | 'required' => true, |
21 | - 'filters' => [['name' => 'StringTrim']], |
|
21 | + 'filters' => [ [ 'name' => 'StringTrim' ] ], |
|
22 | 22 | 'validators' => [ |
23 | - ['name' => 'NotEmpty'], |
|
24 | - ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 100]], |
|
23 | + [ 'name' => 'NotEmpty' ], |
|
24 | + [ 'name' => 'StringLength', 'options' => [ 'min' => 2, 'max' => 100 ] ], |
|
25 | 25 | ], |
26 | 26 | ]); |
27 | 27 | |
28 | 28 | $inputFilter->add([ |
29 | 29 | 'name' => 'sub_title', |
30 | 30 | 'required' => false, |
31 | - 'filters' => [['name' => 'StringTrim']], |
|
31 | + 'filters' => [ [ 'name' => 'StringTrim' ] ], |
|
32 | 32 | 'validators' => [ |
33 | - ['name' => 'NotEmpty'], |
|
34 | - ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 500]], |
|
33 | + [ 'name' => 'NotEmpty' ], |
|
34 | + [ 'name' => 'StringLength', 'options' => [ 'min' => 2, 'max' => 500 ] ], |
|
35 | 35 | ], |
36 | 36 | ]); |
37 | 37 | |
38 | 38 | $inputFilter->add([ |
39 | 39 | 'name' => 'body', |
40 | 40 | 'required' => true, |
41 | - 'filters' => [['name' => 'StringTrim']], |
|
41 | + 'filters' => [ [ 'name' => 'StringTrim' ] ], |
|
42 | 42 | 'validators' => [ |
43 | - ['name' => 'NotEmpty'], |
|
44 | - ['name' => 'StringLength', 'options' => ['min' => 2]], |
|
43 | + [ 'name' => 'NotEmpty' ], |
|
44 | + [ 'name' => 'StringLength', 'options' => [ 'min' => 2 ] ], |
|
45 | 45 | ], |
46 | 46 | ]); |
47 | 47 | |
48 | 48 | $inputFilter->add([ |
49 | 49 | 'name' => 'lead', |
50 | 50 | 'required' => true, |
51 | - 'filters' => [['name' => 'StringTrim']], |
|
51 | + 'filters' => [ [ 'name' => 'StringTrim' ] ], |
|
52 | 52 | 'validators' => [ |
53 | - ['name' => 'NotEmpty'], |
|
54 | - ['name' => 'StringLength', 'options' => ['min' => 2]], |
|
53 | + [ 'name' => 'NotEmpty' ], |
|
54 | + [ 'name' => 'StringLength', 'options' => [ 'min' => 2 ] ], |
|
55 | 55 | ], |
56 | 56 | ]); |
57 | 57 | |
58 | 58 | $inputFilter->add([ |
59 | 59 | 'name' => 'video_url', |
60 | 60 | 'required' => true, |
61 | - 'filters' => [['name' => 'StringTrim']], |
|
61 | + 'filters' => [ [ 'name' => 'StringTrim' ] ], |
|
62 | 62 | 'validators' => [ |
63 | - ['name' => 'NotEmpty'], |
|
64 | - ['name' => 'StringLength'], |
|
63 | + [ 'name' => 'NotEmpty' ], |
|
64 | + [ 'name' => 'StringLength' ], |
|
65 | 65 | ], |
66 | 66 | ]); |
67 | 67 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -declare(strict_types=1); |
|
2 | +declare(strict_types = 1); |
|
3 | 3 | |
4 | 4 | namespace Article\Mapper; |
5 | 5 | |
@@ -34,13 +34,13 @@ discard block |
||
34 | 34 | public function getPaginationSelect($isActive = null) |
35 | 35 | { |
36 | 36 | $select = $this->getSql()->select() |
37 | - ->join('articles', 'article_videos.article_uuid = articles.article_uuid', ['slug', 'published_at', 'status', 'article_id']) |
|
38 | - ->join('admin_users', 'admin_users.admin_user_uuid = articles.admin_user_uuid', ['admin_user_id', 'first_name', 'last_name']) |
|
39 | - ->where(['articles.type' => ArticleType::POST]) |
|
40 | - ->order(['articles.created_at' => 'desc']); |
|
37 | + ->join('articles', 'article_videos.article_uuid = articles.article_uuid', [ 'slug', 'published_at', 'status', 'article_id' ]) |
|
38 | + ->join('admin_users', 'admin_users.admin_user_uuid = articles.admin_user_uuid', [ 'admin_user_id', 'first_name', 'last_name' ]) |
|
39 | + ->where([ 'articles.type' => ArticleType::POST ]) |
|
40 | + ->order([ 'articles.created_at' => 'desc' ]); |
|
41 | 41 | |
42 | - if($isActive !== null) { |
|
43 | - $select->where(['articles.status' => (int)$isActive]); |
|
42 | + if ($isActive !== null) { |
|
43 | + $select->where([ 'articles.status' => (int) $isActive ]); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | return $select; |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | public function get($id) |
50 | 50 | { |
51 | 51 | $select = $this->getSql()->select() |
52 | - ->columns(['title', 'body', 'lead', 'featured_img', 'main_img', 'video_url', 'sub_title']) |
|
52 | + ->columns([ 'title', 'body', 'lead', 'featured_img', 'main_img', 'video_url', 'sub_title' ]) |
|
53 | 53 | ->join('articles', 'article_videos.article_uuid = articles.article_uuid') |
54 | - ->where(['articles.article_id' => $id]); |
|
54 | + ->where([ 'articles.article_id' => $id ]); |
|
55 | 55 | |
56 | 56 | return $this->selectWith($select)->current(); |
57 | 57 | } |
@@ -59,9 +59,9 @@ discard block |
||
59 | 59 | public function getLatest($limit = 50) |
60 | 60 | { |
61 | 61 | $select = $this->getSql()->select() |
62 | - ->join('articles', 'article_videos.article_uuid = articles.article_uuid', ['article_id', 'slug', 'published_at']) |
|
63 | - ->where(['articles.status' => 1]) |
|
64 | - ->order(['published_at' => 'desc']) |
|
62 | + ->join('articles', 'article_videos.article_uuid = articles.article_uuid', [ 'article_id', 'slug', 'published_at' ]) |
|
63 | + ->where([ 'articles.status' => 1 ]) |
|
64 | + ->order([ 'published_at' => 'desc' ]) |
|
65 | 65 | ->limit($limit); |
66 | 66 | |
67 | 67 | return $this->selectWith($select); |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | { |
72 | 72 | $select = $this->getSql()->select() |
73 | 73 | ->join('articles', 'article_videos.article_uuid = articles.article_uuid') |
74 | - ->where(['articles.slug' => $slug]); |
|
74 | + ->where([ 'articles.slug' => $slug ]); |
|
75 | 75 | |
76 | 76 | return $this->selectWith($select)->current(); |
77 | 77 | } |
@@ -10,16 +10,16 @@ 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 | - ->addColumn('sub_title', 'text', ['null' => true]) |
|
16 | + ->addColumn('sub_title', 'text', [ 'null' => true ]) |
|
17 | 17 | ->addColumn('body', 'text') |
18 | 18 | ->addColumn('lead', 'text') |
19 | 19 | ->addColumn('video_url', 'text') |
20 | - ->addColumn('featured_img', 'text', ['null' => true]) |
|
21 | - ->addColumn('main_img', 'text', ['null' => true]) |
|
22 | - ->addForeignKey('article_uuid', 'articles', 'article_uuid', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION']) |
|
20 | + ->addColumn('featured_img', 'text', [ 'null' => true ]) |
|
21 | + ->addColumn('main_img', 'text', [ 'null' => true ]) |
|
22 | + ->addForeignKey('article_uuid', 'articles', 'article_uuid', [ 'delete' => 'NO_ACTION', 'update' => 'NO_ACTION' ]) |
|
23 | 23 | ->create(); |
24 | 24 | |
25 | 25 | // $this->insertDummyData(); |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | |
33 | 33 | private function insertDummyData() |
34 | 34 | { |
35 | - $ids = []; |
|
35 | + $ids = [ ]; |
|
36 | 36 | $rows = $this->fetchAll('select admin_user_uuid from admin_users;'); |
37 | - foreach($rows as $r) { |
|
38 | - $ids[] = $r['admin_user_uuid']; |
|
37 | + foreach ($rows as $r) { |
|
38 | + $ids[ ] = $r[ 'admin_user_uuid' ]; |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | $faker = Faker\Factory::create(); |
@@ -48,19 +48,19 @@ discard block |
||
48 | 48 | ]; |
49 | 49 | |
50 | 50 | // Download N images and set it randomly to posts |
51 | - for($i = 0; $i < 5; $i++) { |
|
51 | + for ($i = 0; $i < 5; $i++) { |
|
52 | 52 | $image = $faker->image(); |
53 | 53 | $destination = $upload->getPath(basename($image)); |
54 | 54 | rename($image, $destination); |
55 | - $mainImg[] = substr($destination, strlen('/var/www/unfinished/public')); |
|
55 | + $mainImg[ ] = substr($destination, strlen('/var/www/unfinished/public')); |
|
56 | 56 | |
57 | 57 | $image = $faker->image(); |
58 | 58 | $destination = $upload->getPath(basename($image)); |
59 | 59 | rename($image, $destination); |
60 | - $featuredImg[] = substr($destination, strlen('/var/www/unfinished/public')); |
|
60 | + $featuredImg[ ] = substr($destination, strlen('/var/www/unfinished/public')); |
|
61 | 61 | } |
62 | 62 | |
63 | - for($i = 0; $i < $count; $i++) { |
|
63 | + for ($i = 0; $i < $count; $i++) { |
|
64 | 64 | $id = $faker->uuid; |
65 | 65 | $mysqluuid = (new Uuid($id))->toFormat(new Binary()); |
66 | 66 | $title = $faker->sentence(7, 20); |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | 'article_id' => $id, |
71 | 71 | 'slug' => strtolower(trim(preg_replace('~[^\pL\d]+~u', '-', $title), '-')), |
72 | 72 | 'status' => 1, |
73 | - 'admin_user_uuid' => $ids[array_rand($ids)], |
|
73 | + 'admin_user_uuid' => $ids[ array_rand($ids) ], |
|
74 | 74 | 'type' => ArticleType::POST |
75 | 75 | ]; |
76 | 76 | |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | 'title' => $title, |
80 | 80 | 'body' => $faker->paragraph(15), |
81 | 81 | 'lead' => $faker->paragraph(5), |
82 | - 'main_img' => $mainImg[array_rand($mainImg)], |
|
83 | - 'featured_img' => $featuredImg[array_rand($featuredImg)], |
|
84 | - 'video_url' => $embedCodes[rand(0, 2)] |
|
82 | + 'main_img' => $mainImg[ array_rand($mainImg) ], |
|
83 | + 'featured_img' => $featuredImg[ array_rand($featuredImg) ], |
|
84 | + 'video_url' => $embedCodes[ rand(0, 2) ] |
|
85 | 85 | ]; |
86 | 86 | |
87 | 87 | $this->insert('articles', $article); |