Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

News data array adjusted for component loop #769

Merged
merged 5 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Http/Controllers/HomepageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

Expand Down
3 changes: 2 additions & 1 deletion app/Repositories/ModularPageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
144 changes: 2 additions & 142 deletions factories/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '<p>'.$this->faker->paragraph(8).'</p>
<p>'.$this->faker->paragraph(8).'</p>
<figure class="figure" style="padding-bottom:10px; float:right">
<img alt="Placeholder" height="400" src="/styleguide/image/300x400?text=Figure%20float%20right" style="padding:10px" width="300">
<figcaption>'.$this->faker->paragraph().'</figcaption>
</figure>
<p>'.$this->faker->paragraph().'</p>
<blockquote class="blockquote1">
<p>'.$this->faker->paragraph(1).'</p>
</blockquote>
<p>'.$this->faker->paragraph(8).'</p>
<p>'.$this->faker->paragraph(8).'</p>
<blockquote class="blockquote2">
<p>'.$this->faker->paragraph(1).'</p>
</blockquote>
<p>'.$this->faker->paragraph(8).'</p>
<p>'.$this->faker->paragraph(8).'</p>
<p>&nbsp;</p>
<h2>'.$this->faker->paragraph(1).'</h2>
<figure class="figure" style="padding-bottom:10px; float:left">
<img alt="Placeholder" height="600" src="/styleguide/image/800x600?text=Figure%20float%20left" style="padding:10px" width="800">
<figcaption>'.$this->faker->paragraph().'</figcaption>
</figure>
<p>'.$this->faker->paragraph(8).'</p>
<p>'.$this->faker->paragraph(15).'</p>
<blockquote class="blockquote3">
<p>'.$this->faker->paragraph(5).'</p>
</blockquote>
<p>'.$this->faker->paragraph(15).'</p>
<div style="text-align:center">
<figure class="figure" style="display:inline-block">
<img alt="Placeholder" height="450" src="/styleguide/image/800x450?text=Figure%20centered" style="padding:10px" width="800">
<figcaption>'.$this->faker->paragraph().'</figcaption>
</figure>
</div>
<p>'.$this->faker->paragraph(15).'</p>
<img alt="Placeholder" height="400" src="/styleguide/image/300x400?text=Image%20float%20right" style="padding:10px; float:right" width="300">
<p>'.$this->faker->paragraph(8).'</p>
<p>'.$this->faker->paragraph(15).'</p>
<img alt="Placeholder" height="300" src="/styleguide/image/400x300?text=Image%20float%20left" style="padding:10px; float:left" width="400">
<p>'.$this->faker->paragraph(8).'</p>
<p>'.$this->faker->paragraph(15).'</p>
<p style="text-align:center">
<img alt="Placeholder" height="350" src="/styleguide/image/800x350?text=Image%20centered" style="padding:10px" width="800">
</p>
<p>'.$this->faker->paragraph(8).'</p>
',
'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;
}
Expand Down
160 changes: 160 additions & 0 deletions factories/ArticleComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<?php

namespace Factories;

use Contracts\Factories\FactoryContract;
use Faker\Factory;

class ArticleComponent implements FactoryContract
{
/**
* Construct the factory.
*/
public function __construct(Factory $faker)
{
$this->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' => '<p>'.$this->faker->paragraph(8).'</p>
<p>'.$this->faker->paragraph(8).'</p>
<figure class="figure" style="padding-bottom:10px; float:right">
<img alt="Placeholder" height="400" src="/styleguide/image/300x400?text=Figure%20float%20right" style="padding:10px" width="300">
<figcaption>'.$this->faker->paragraph().'</figcaption>
</figure>
<p>'.$this->faker->paragraph().'</p>
<blockquote class="blockquote1">
<p>'.$this->faker->paragraph(1).'</p>
</blockquote>
<p>'.$this->faker->paragraph(8).'</p>
<p>'.$this->faker->paragraph(8).'</p>
<blockquote class="blockquote2">
<p>'.$this->faker->paragraph(1).'</p>
</blockquote>
<p>'.$this->faker->paragraph(8).'</p>
<p>'.$this->faker->paragraph(8).'</p>
<p>&nbsp;</p>
<h2>'.$this->faker->paragraph(1).'</h2>
<figure class="figure" style="padding-bottom:10px; float:left">
<img alt="Placeholder" height="600" src="/styleguide/image/800x600?text=Figure%20float%20left" style="padding:10px" width="800">
<figcaption>'.$this->faker->paragraph().'</figcaption>
</figure>
<p>'.$this->faker->paragraph(8).'</p>
<p>'.$this->faker->paragraph(15).'</p>
<blockquote class="blockquote3">
<p>'.$this->faker->paragraph(5).'</p>
</blockquote>
<p>'.$this->faker->paragraph(15).'</p>
<div style="text-align:center">
<figure class="figure" style="display:inline-block">
<img alt="Placeholder" height="450" src="/styleguide/image/800x450?text=Figure%20centered" style="padding:10px" width="800">
<figcaption>'.$this->faker->paragraph().'</figcaption>
</figure>
</div>
<p>'.$this->faker->paragraph(15).'</p>
<img alt="Placeholder" height="400" src="/styleguide/image/300x400?text=Image%20float%20right" style="padding:10px; float:right" width="300">
<p>'.$this->faker->paragraph(8).'</p>
<p>'.$this->faker->paragraph(15).'</p>
<img alt="Placeholder" height="300" src="/styleguide/image/400x300?text=Image%20float%20left" style="padding:10px; float:left" width="400">
<p>'.$this->faker->paragraph(8).'</p>
<p>'.$this->faker->paragraph(15).'</p>
<p style="text-align:center">
<img alt="Placeholder" height="350" src="/styleguide/image/800x350?text=Image%20centered" style="padding:10px" width="800">
</p>
<p>'.$this->faker->paragraph(8).'</p>
',
'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;
}
}
34 changes: 34 additions & 0 deletions factories/ArticleMeta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Factories;

use Contracts\Factories\FactoryContract;
use Faker\Factory;

class ArticleMeta implements FactoryContract
{
/**
* Construct the factory.
*/
public function __construct(Factory $faker)
{
$this->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;
}
}
4 changes: 2 additions & 2 deletions resources/views/components/news-column.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
$url => string '/news/'
$link_text => string // 'More news'
--}}
@if(!empty($data['data']))
@if(!empty($data))
<ul>
@foreach($data['data'] as $item)
@foreach($data as $item)
<li class="mb-4">
<a href="{{ $item['link'] }}" class="underline hover:no-underline font-normal">
{{ $item['title'] }}
Expand Down
4 changes: 2 additions & 2 deletions resources/views/components/news-featured-column.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
$url => string '/news/'
$link_text => string // 'More news'
--}}
@if(!empty($data['data']))
@if(!empty($data))
<ul>
@foreach($data['data'] as $item)
@foreach($data as $item)
@if($loop->iteration === 1)
<li class="bg-green-800">
<a href="{{ $item['link'] }}" class="relative block mb-6 group">
Expand Down
Loading
Loading