diff --git a/app/Http/Controllers/HomepageController.php b/app/Http/Controllers/HomepageController.php index 3af22919..1593b598 100644 --- a/app/Http/Controllers/HomepageController.php +++ b/app/Http/Controllers/HomepageController.php @@ -48,7 +48,7 @@ public function index(Request $request): View $promos['components'] = $modularComponents['modularComponents']; } - $articles = $this->article->listing($request->data['base']['site']['news']['application_id']); + $articles['data'] = $this->article->listing($request->data['base']['site']['news']['application_id']); $events = $this->event->getEvents($request->data['base']['site']['id']); diff --git a/app/Repositories/ModularPageRepository.php b/app/Repositories/ModularPageRepository.php index f74cf3e5..0487929e 100644 --- a/app/Repositories/ModularPageRepository.php +++ b/app/Repositories/ModularPageRepository.php @@ -220,7 +220,8 @@ public function configureComponents(array $components, array $promos, array $dat } else { $articles = $this->article->listing($components['components'][$name]['id'], $limit, 1, $component['topics'] ?? []); } - $modularComponents[$name]['data'] = $articles['articles'] ?? []; + $modularComponents[$name]['data'] = $articles['articles']['data'] ?? []; + $modularComponents[$name]['meta'] = $articles['articles']['meta'] ?? []; $modularComponents[$name]['component'] = $components['components'][$name]; } elseif (Str::startsWith($name, 'page-content') || Str::startsWith($name, 'heading')) { // If there's JSON but no news, events or promo data, assign the component array as data diff --git a/factories/Article.php b/factories/Article.php index c98e239a..1e28df7a 100644 --- a/factories/Article.php +++ b/factories/Article.php @@ -20,149 +20,9 @@ public function __construct(Factory $faker) */ public function create($limit = 1, $flatten = false, $options = []) { - $hero = [ - 'featured' => 0, - 'url' => '/styleguide/image/1600x580', - 'caption' => $this->faker->sentence(rand(5, 10)), - 'alt_text' => $this->faker->sentence(rand(5, 10)), - 'type' => 'Hero Image', - ]; + $data['data'] = app(ArticleComponent::class)->create($limit, $flatten, $options); - $social = [ - 'featured' => 0, - 'url' => '/styleguide/image/1600x580', - 'caption' => $this->faker->sentence(rand(5, 10)), - 'alt_text' => $this->faker->sentence(rand(5, 10)), - 'type' => 'Social Image', - ]; - - $featured = [ - 'featured' => 1, - 'url' => '/styleguide/image/770x434', - 'caption' => $this->faker->sentence(rand(5, 10)), - 'alt_text' => $this->faker->sentence(rand(5, 10)), - 'type' => 'Embeddable', - ]; - - $faculty = []; - for ($i = 0; $i < 3; $i++) { - $faculty[] = [ - 'id' => $this->faker->randomDigit(), - 'first_name' => $this->faker->firstName(), - 'last_name' => $this->faker->lastName(), - 'accessid' => $this->faker->randomLetter().$this->faker->randomLetter().$this->faker->randomNumber(4, true), - ]; - } - - $programs = []; - for ($i = 0; $i < 3; $i++) { - $programs[] = [ - 'name' => $this->faker->randomElement(['Accounting (BS)', 'Art Education (BA)', 'Biological Sciences (BA)', 'Chemical Engineering (MS)']), - 'url' => 'https://wayne.edu', - ]; - } - - $assets = []; - for ($i = 0; $i < 3; $i++) { - $assets[] = [ - 'id' => $this->faker->randomDigit(), - 'url' => 'https://wayne.edu', - 'caption' => $this->faker->sentence(), - 'filename' => substr(md5($this->faker->sentence()), 0, 10).'.pdf', - ]; - } - - for ($i = 1; $i <= $limit; $i++) { - $data['data'][$i] = [ - 'id' => $i, - 'user_id' => $this->faker->randomDigit(), - 'application_id' => $this->faker->randomDigit(), - 'favicon_id' => null, - 'title' => $this->faker->sentence(rand(6, 10)), - 'short_title' => $this->faker->sentence(rand(3, 6)), - 'sub_title' => null, - 'permalink' => $this->faker->slug(), - 'meta_description' => $this->faker->sentence(), - 'body' => '

'.$this->faker->paragraph(8).'

-

'.$this->faker->paragraph(8).'

-
- Placeholder -
'.$this->faker->paragraph().'
-
-

'.$this->faker->paragraph().'

-
-

'.$this->faker->paragraph(1).'

-
-

'.$this->faker->paragraph(8).'

-

'.$this->faker->paragraph(8).'

-
-

'.$this->faker->paragraph(1).'

-
-

'.$this->faker->paragraph(8).'

-

'.$this->faker->paragraph(8).'

-

 

-

'.$this->faker->paragraph(1).'

-
- Placeholder -
'.$this->faker->paragraph().'
-
-

'.$this->faker->paragraph(8).'

-

'.$this->faker->paragraph(15).'

-
-

'.$this->faker->paragraph(5).'

-
-

'.$this->faker->paragraph(15).'

-
-
- Placeholder -
'.$this->faker->paragraph().'
-
-
-

'.$this->faker->paragraph(15).'

- Placeholder -

'.$this->faker->paragraph(8).'

-

'.$this->faker->paragraph(15).'

- Placeholder -

'.$this->faker->paragraph(8).'

-

'.$this->faker->paragraph(15).'

-

- Placeholder -

-

'.$this->faker->paragraph(8).'

- ', - 'article_date' => $this->faker->date(), - 'status' => 'Published', - 'link' => '/styleguide/'.config('base.news_view_route').'/item-1', - 'hero_image' => $hero, - 'social_image' => $social, - 'featured' => $featured, - 'files' => [ - 0 => $hero, - 1 => $featured, - ], - 'assets' => $this->faker->randomElements($assets, rand(1, 3)), - 'faculty' => $this->faker->randomElements($faculty, rand(1, 3)), - 'programs' => $this->faker->randomElements($programs, rand(1, 3)), - 'favicon' => null, - 'user' => null, - 'applications' => null, - ]; - - $data['data'][$i] = array_replace_recursive($data['data'][$i], $options); - } - - if ($limit === 1 && $flatten === true) { - $data['data'] = current($data['data']); - } - - $data['meta'] = [ - 'total' => '', - 'per_page' => '', - 'current_page' => '', - 'last_page' => 3, - 'next_page_url' => '', - 'prev_page_url' => '', - ]; + $data['meta'] = app(ArticleMeta::class)->create(1, true); return $data; } diff --git a/factories/ArticleComponent.php b/factories/ArticleComponent.php new file mode 100644 index 00000000..db1f0088 --- /dev/null +++ b/factories/ArticleComponent.php @@ -0,0 +1,160 @@ +faker = $faker->create(); + } + + /** + * {@inheritdoc} + */ + public function create($limit = 1, $flatten = false, $options = []) + { + $hero = [ + 'featured' => 0, + 'url' => '/styleguide/image/1600x580', + 'caption' => $this->faker->sentence(rand(5, 10)), + 'alt_text' => $this->faker->sentence(rand(5, 10)), + 'type' => 'Hero Image', + ]; + + $social = [ + 'featured' => 0, + 'url' => '/styleguide/image/1600x580', + 'caption' => $this->faker->sentence(rand(5, 10)), + 'alt_text' => $this->faker->sentence(rand(5, 10)), + 'type' => 'Social Image', + ]; + + $featured = [ + 'featured' => 1, + 'url' => '/styleguide/image/770x434', + 'caption' => $this->faker->sentence(rand(5, 10)), + 'alt_text' => $this->faker->sentence(rand(5, 10)), + 'type' => 'Embeddable', + ]; + + $faculty = []; + for ($i = 0; $i < 3; $i++) { + $faculty[] = [ + 'id' => $this->faker->randomDigit(), + 'first_name' => $this->faker->firstName(), + 'last_name' => $this->faker->lastName(), + 'accessid' => $this->faker->randomLetter().$this->faker->randomLetter().$this->faker->randomNumber(4, true), + ]; + } + + $programs = []; + for ($i = 0; $i < 3; $i++) { + $programs[] = [ + 'name' => $this->faker->randomElement(['Accounting (BS)', 'Art Education (BA)', 'Biological Sciences (BA)', 'Chemical Engineering (MS)']), + 'url' => 'https://wayne.edu', + ]; + } + + $assets = []; + for ($i = 0; $i < 3; $i++) { + $assets[] = [ + 'id' => $this->faker->randomDigit(), + 'url' => 'https://wayne.edu', + 'caption' => $this->faker->sentence(), + 'filename' => substr(md5($this->faker->sentence()), 0, 10).'.pdf', + ]; + } + + for ($i = 1; $i <= $limit; $i++) { + $data[$i] = [ + 'id' => $i, + 'user_id' => $this->faker->randomDigit(), + 'application_id' => $this->faker->randomDigit(), + 'favicon_id' => null, + 'title' => $this->faker->sentence(rand(6, 10)), + 'short_title' => $this->faker->sentence(rand(3, 6)), + 'sub_title' => null, + 'permalink' => $this->faker->slug(), + 'meta_description' => $this->faker->sentence(), + 'body' => '

'.$this->faker->paragraph(8).'

+

'.$this->faker->paragraph(8).'

+
+ Placeholder +
'.$this->faker->paragraph().'
+
+

'.$this->faker->paragraph().'

+
+

'.$this->faker->paragraph(1).'

+
+

'.$this->faker->paragraph(8).'

+

'.$this->faker->paragraph(8).'

+
+

'.$this->faker->paragraph(1).'

+
+

'.$this->faker->paragraph(8).'

+

'.$this->faker->paragraph(8).'

+

 

+

'.$this->faker->paragraph(1).'

+
+ Placeholder +
'.$this->faker->paragraph().'
+
+

'.$this->faker->paragraph(8).'

+

'.$this->faker->paragraph(15).'

+
+

'.$this->faker->paragraph(5).'

+
+

'.$this->faker->paragraph(15).'

+
+
+ Placeholder +
'.$this->faker->paragraph().'
+
+
+

'.$this->faker->paragraph(15).'

+ Placeholder +

'.$this->faker->paragraph(8).'

+

'.$this->faker->paragraph(15).'

+ Placeholder +

'.$this->faker->paragraph(8).'

+

'.$this->faker->paragraph(15).'

+

+ Placeholder +

+

'.$this->faker->paragraph(8).'

+ ', + 'article_date' => $this->faker->date(), + 'status' => 'Published', + 'link' => '/styleguide/'.config('base.news_view_route').'/item-1', + 'hero_image' => $hero, + 'social_image' => $social, + 'featured' => $featured, + 'files' => [ + 0 => $hero, + 1 => $featured, + ], + 'assets' => $this->faker->randomElements($assets, rand(1, 3)), + 'faculty' => $this->faker->randomElements($faculty, rand(1, 3)), + 'programs' => $this->faker->randomElements($programs, rand(1, 3)), + 'favicon' => null, + 'user' => null, + 'applications' => null, + ]; + + $data[$i] = array_replace_recursive($data[$i], $options); + } + + if ($limit === 1 && $flatten === true) { + $data = current($data); + } + + return $data; + } +} diff --git a/factories/ArticleMeta.php b/factories/ArticleMeta.php new file mode 100644 index 00000000..e30359eb --- /dev/null +++ b/factories/ArticleMeta.php @@ -0,0 +1,34 @@ +faker = $faker->create(); + } + + /** + * {@inheritdoc} + */ + public function create($limit = 1, $flatten = false, $options = []) + { + $data = [ + 'total' => '', + 'per_page' => '', + 'current_page' => '', + 'last_page' => 3, + 'next_page_url' => '', + 'prev_page_url' => '', + ]; + + return $data; + } +} diff --git a/resources/views/components/news-column.blade.php b/resources/views/components/news-column.blade.php index a169a1eb..8452e115 100644 --- a/resources/views/components/news-column.blade.php +++ b/resources/views/components/news-column.blade.php @@ -3,9 +3,9 @@ $url => string '/news/' $link_text => string // 'More news' --}} -@if(!empty($data['data'])) +@if(!empty($data))