Skip to content

Commit

Permalink
Merge branch 'feature/refactor-3' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
breakdancingcat committed Jan 31, 2024
2 parents ea52c58 + b378baf commit 2867154
Show file tree
Hide file tree
Showing 40 changed files with 784 additions and 158 deletions.
44 changes: 42 additions & 2 deletions app/Repositories/EventRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ public function getEvents($site_id, $limit = 4)
$params = [
'method' => 'calendar.events.listing',
'site' => $site_id,
'limit' => $limit ?? 4,
'end_date' => $end_date ?? date('Y-m-d', strtotime('+6 month')),
'limit' => $limit,
'start_date' => date('Y-m-d', strtotime('+1 month')),
'end_date' => date('Y-m-d', strtotime('+6 month')),
];

$events['events'] = $this->cache->remember($params['method'].md5(serialize($params)), config('cache.ttl'), function () use ($params) {
Expand All @@ -56,4 +57,43 @@ public function getEvents($site_id, $limit = 4)

return $events;
}

/**
* {@inheritdoc}
*/
public function getEventsFullListing($site_id, $limit = 4)
{
$params = [
'method' => 'calendar.events.fulllisting',
'site' => $site_id,
'limit' => 50,
'end_date' => $end_date ?? date('Y-m-d', strtotime('+6 month')),
];

$events['events'] = $this->cache->remember($params['method'].md5(serialize($params)), config('cache.ttl'), function () use ($params, $limit) {
$this->wsuApi->nextRequestProduction();

$events_listing = $this->wsuApi->sendRequest($params['method'], $params);

if (!empty($events_listing['events'])) {
$events = collect($events_listing['events'])
->map(function ($event) {
if (!empty($event['images'])) {
$event['display_image'] = collect($event['images'])->first();
} else {
$event['display_image']['full_url'] = 'https://wayne.edu/opengraph/wsu-social-share-square.jpg';
$event['display_image']['description'] = 'Event on wayne.edu';
}

return $event;
})
->take($limit)
->toArray();
}

return $events ?? [];
});

return $events;
}
}
17 changes: 11 additions & 6 deletions app/Repositories/ModularPageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,34 @@ public function getModularComponents(array $data): array
foreach($components['components'] as $name => $component) {
if(Str::startsWith($name, 'events')) {
$components['components'][$name]['id'] = $component['id'] ?? $data['site']['id'];
$events = $this->event->getEvents($component['id'] ?? $data['site']['id']);
$limit = $components['components'][$name]['limit'] ?? 4;
if(strpos($name, 'events-column') !== false) {
$events = $this->event->getEvents($component['id'] ?? $data['site']['id'], $limit);
} else {
$events = $this->event->getEventsFullListing($component['id'] ?? $data['site']['id'], $limit);
}
$modularComponents[$name]['data'] = $events['events'] ?? [];
$modularComponents[$name]['component'] = $components['components'][$name];
if (empty($modularComponents[$name]['component']['cal_name']) && !empty($data['site']['events']['path'])) {
$modularComponents[$name]['component']['cal_name'] = $data['site']['events']['path'];
}
} elseif(Str::startsWith($name, 'news')) {
$components['components'][$name]['id'] = $component['id'] ?? $data['site']['news']['application_id'];
$components['components'][$name]['limit'] = $component['limit'] ?? 4;
$limit = $component['limit'] ?? 4;
$components['components'][$name]['news_route'] = $component['news_route'] ?? config('base.news_listing_route');
if (!empty($component['featured']) && $component['featured'] === true) {
$articles = $this->article->listing($components['components'][$name]['id'], 50, 1, $component['topics'] ?? []);
$articles['articles']['data'] = collect($articles['articles']['data'])->filter(function ($article) {
return !empty($article['featured']['featured']) && $article['featured']['featured'] === 1;
})->take($component['limit'] ?? 4)->toArray();
})->take($limit)->toArray();
} else {
$articles = $this->article->listing($components['components'][$name]['id'], $component['limit'] ?? 4, 1, $component['topics'] ?? []);
$articles = $this->article->listing($components['components'][$name]['id'], $limit, 1, $component['topics'] ?? []);
}
$modularComponents[$name]['data'] = $articles['articles'] ?? [];
$modularComponents[$name]['component'] = $components['components'][$name];
} elseif(Str::startsWith($name, 'page-content') || Str::startsWith($name, 'page-heading')) {
} 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
// Page-content and page-heading components
// Page-content and heading components
$modularComponents[$name]['data'][] = $components['components'][$name] ?? [];
$modularComponents[$name]['component'] = $components['components'][$name] ?? [];
unset($modularComponents[$name]['component']['heading']);
Expand Down
61 changes: 61 additions & 0 deletions factories/EventFullListing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Factories;

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

class EventFullListing implements FactoryContract
{
/**
* Construct the factory.
*/
public function __construct(Factory $faker)
{
$this->faker = $faker->create();
}

/**
* {@inheritdoc}
*/
public function create($limit = 1, $flatten = false, $options = [])
{
for ($i = 1; $i <= $limit; $i++) {
$date = $this->faker->dateTimeBetween('+10 days', '+15 days')->format('Y-m-d');
$title = $this->faker->sentence(rand(6, 10));
$imagex = $this->faker->randomElement([
'/styleguide/image/600x600?text=600x600:'.$i,
''
]);
$description = $this->faker->text(100);
$image = '/styleguide/image/600x600?text=600x600:'.$i;

$event = [
'event_id' => $i,
'url' => 'https://wayne.edu',
'title' => $title,
'date' => $date,
'start_time' => $this->faker->time('H:i:s', 'now'),
'end_time' => $this->faker->time('H:i:s', '+5 hours'),
'repeat_end_date' => $this->faker->dateTimeBetween('+1 month', '+2 months')->format('Y-m-d'),
'end_date' => $this->faker->dateTimeBetween('+10 days', '+15 days')->format('Y-m-d'),
'images' => [
0 => [
'full_url' => $image,
'description' => $description,
],
],
'display_image' => [
'full_url' => $image,
'description' => $description,
],
'is_all_day' => $this->faker->boolean,
];
$event = array_replace_recursive($event, $options);

$data[$i] = $event;
}

return $data;
}
}
46 changes: 46 additions & 0 deletions factories/EventFullListingNoImage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Factories;

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

class EventFullListingNoImage implements FactoryContract
{
/**
* Construct the factory.
*/
public function __construct(Factory $faker)
{
$this->faker = $faker->create();
}

/**
* {@inheritdoc}
*/
public function create($limit = 1, $flatten = false, $options = [])
{
for ($i = 1; $i <= $limit; $i++) {
$date = $this->faker->dateTimeBetween('+10 days', '+15 days')->format('Y-m-d');
$title = $this->faker->sentence(rand(6, 10));

$event = [
'event_id' => $i,
'url' => 'https://wayne.edu',
'title' => $title,
'date' => $date,
'start_time' => $this->faker->time('H:i:s', 'now'),
'end_time' => $this->faker->time('H:i:s', '+5 hours'),
'repeat_end_date' => $this->faker->dateTimeBetween('+1 month', '+2 months')->format('Y-m-d'),
'end_date' => $this->faker->dateTimeBetween('+10 days', '+15 days')->format('Y-m-d'),
'images' => '',
'is_all_day' => $this->faker->boolean,
];
$event = array_replace_recursive($event, $options);

$data[$i] = $event;
}

return $data;
}
}
2 changes: 1 addition & 1 deletion factories/HeroImageRotate.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function create($limit = 1, $flatten = false, $options = [])
'filename_alt_text' => 'Example background image',
'secondary_relative_url' => '/styleguide/image/400x250?text=Secondary%20image%20('.$i.')',
'secondary_alt_text' => 'Example secondary image',
'option' => $this->faker->randomElement(['Text Overlay', 'Half', 'Logo Overlay', '']),
'option' => $this->faker->randomElement(['Text Overlay', 'Half', 'Logo Overlay', 'Banner large']),
];

$data[$i] = array_replace_recursive($data[$i], $options);
Expand Down
10 changes: 5 additions & 5 deletions resources/views/components/events-column.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
</div>
</li>
@endforeach
@if($dates == end($data) && (!empty($component['cal_name']) || !empty($base['site']['events']['path'])))
<li class="flex -mx-2 ml-17">
<a href="//events.wayne.edu/{{ $component['cal_name'] ?? $base['site']['events']['path'].'main/' }}upcoming" class="hover:underline">{{ $component['link_text'] ?? 'More events' }}</a>
</li>
@endif
@endforeach
</ul>
@if(!empty($component['cal_name']) || !empty($base['site']['events']['path']))
<div class="mt-4">
<a class="button" href="//events.wayne.edu/{{ $component['cal_name'] ?? $base['site']['events']['path'].'main/' }}upcoming">{{ $component['link_text'] ?? 'More events' }}</a>
</div>
@endif
24 changes: 24 additions & 0 deletions resources/views/components/events-featured-column.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<ul>
@if(!empty($data))
@foreach($data as $item)
<li class="mb-6">
<a href="{{$item['url']}}" class="flex w-full group">
<div class="w-1/3 shrink-0">
<img data-src="{{$item['display_image']['full_url']}}" alt="{{($item['display_image']['description']) ? $item['display_image']['description'] : ''}}" class="lazy" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==">
</div>
<div class="ml-4 pt-3 font-bold">
@if(!empty($item['date']))
<div class="text-sm uppercase mb-1">{{ date('F j', strtotime($item['date'])) }}</div>
@endif
<div class="group-hover:underline">{{$item['title']}}</div>
</div>
</a>
</li>
@endforeach
@endif
</ul>
@if(!empty($component['cal_name']) || !empty($base['site']['events']['path']))
<div class="mt-4">
<a class="button" href="//events.wayne.edu/{{ $component['cal_name'] ?? $base['site']['events']['path'].'main/' }}upcoming">{{ $component['link_text'] ?? 'More events' }}</a>
</div>
@endif
24 changes: 24 additions & 0 deletions resources/views/components/events-featured-row.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<ul class="grid gap-4 {{ !empty($component['columns']) && $component['columns'] % 2 == 0 ? (count($data) >= 4 ? ' sm:grid-cols-2 md:grid-cols-3 xl:grid-cols-'.($component['columns']) : ' md:grid-cols-'.$component['columns']) : (count($data) >= 3 ? ' sm:grid-cols-1 md:grid-cols-3' : ' md:grid-cols-'.$component['columns']) }}">
@if(!empty($data))
@foreach($data as $item)
<li>
<a href="{{$item['url']}}" class="block w-full group">
<div class="w-full">
<img data-src="{{$item['display_image']['full_url']}}" alt="{{($item['display_image']['description']) ? $item['display_image']['description'] : ''}}" class="lazy" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==">
</div>
<div class="mt-2 font-bold">
@if(!empty($item['date']))
<div class="text-sm uppercase mb-1">{{ date('F j', strtotime($item['date'])) }}</div>
@endif
<div class="group-hover:underline">{{$item['title']}}</div>
</div>
</a>
</li>
@endforeach
@endif
</ul>
@if(!empty($component['cal_name']) || !empty($base['site']['events']['path']))
<div class="text-center mt-6">
<a class="button" href="//events.wayne.edu/{{ $component['cal_name'] ?? $base['site']['events']['path'].'main/' }}upcoming">{{ $component['link_text'] ?? 'More events' }}</a>
</div>
@endif
42 changes: 20 additions & 22 deletions resources/views/components/events-row.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,31 @@
$link_text => string // 'More events'
$button_class => string // 'green-gradient-button'
--}}
<ul class="lg:col-count-2 my-4">
@foreach($data as $key => $dates)
@foreach($dates as $event)
<li class="flex items-start break-avoid mb-6">
<div class="flex-shrink-0 mt-1 border-2 border-green rounded-sm text-center">
<div class="w-12 bg-green text-white leading-none border-b-2 border-green text-sm">{{ apdatetime(date('M' , strtotime($key))) }}</div>
<div class="text-green text-2xl leading-tight">{{ apdatetime(date('j' , strtotime($event['date']))) }}</div>
</div>
<ul class="grid gap-8 {{ !empty($component['columns']) && $component['columns'] % 2 == 0 ? ($component['columns'] >= 4 ? ' grid-cols-2' : ' sm-grid-cols-2').' md:grid-cols-3 xl:grid-cols-'.($component['columns']) : ' sm:grid-cols-2 md:grid-cols-3' }}">
@foreach($data as $key => $event)
<li class="flex items-start break-avoid mb-6">
<div class="flex-shrink-0 mt-1 border-2 border-green rounded-sm text-center">
<div class="w-12 bg-green text-white leading-none border-b-2 border-green text-sm">{{ apdatetime(date('M' , strtotime($event['date']))) }}</div>
<div class="text-green text-2xl leading-tight">{{ apdatetime(date('j' , strtotime($event['date']))) }}</div>
</div>

<div class="ml-4 flex-grow">
<a class="mt-0 block hover:underline" href="{{ $event['url'] }}">
{{ $event['title'] }}
<span class="visually-hidden"> on {{ apdatetime(date('M d, Y' , strtotime($event['date']))) }}
@if(!(bool)$event['is_all_day']) at {{ apdatetime(date('g:i a' , strtotime($event['start_time']))) }}@endif
</span>
</a>
<time class="text-sm text-gray-500" datetime="{{ $event['date'] }}T{{ $event['start_time'] }}{{ date('P') }}">
@if(!(bool)$event['is_all_day']){{ apdatetime(date('g:i a' , strtotime($event['start_time']))) }}@else All day @endif
</time>
</div>
</li>
@endforeach
<div class="ml-4 flex-grow">
<a class="mt-0 block hover:underline" href="{{ $event['url'] }}">
{{ $event['title'] }}
<span class="visually-hidden"> on {{ apdatetime(date('M d, Y' , strtotime($event['date']))) }}
@if(!(bool)$event['is_all_day']) at {{ apdatetime(date('g:i a' , strtotime($event['start_time']))) }}@endif
</span>
</a>
<time class="text-sm text-gray-500" datetime="{{ $event['date'] }}T{{ $event['start_time'] }}{{ date('P') }}">
@if(!(bool)$event['is_all_day']){{ apdatetime(date('g:i a' , strtotime($event['start_time']))) }}@else All day @endif
</time>
</div>
</li>
@endforeach
</ul>

@if(!empty($component['cal_name']) || !empty($base['site']['events']['path']))
<div class="lg:text-right mt-4">
<div class="text-center mt-6">
<a class="button" href="//events.wayne.edu/{{ $component['cal_name'] ?? $base['site']['events']['path'].'main/' }}upcoming">{{ $component['link_text'] ?? 'More events' }}</a>
</div>
@endif
10 changes: 10 additions & 0 deletions resources/views/components/heading.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{--
Label: "heading-1"
Data: {
"heading": "My heading"
}
--}}

@foreach ($data as $item)
<h2 class="mt-0 -mb-3" id="{{ Str::slug($item['heading']) }}">{{ $item['heading'] }}</h2>
@endforeach
2 changes: 1 addition & 1 deletion resources/views/components/hero.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@if(!empty($hero['option']))
@include('components/hero/'.Str::slug($hero['option']))
@else
@include('components/hero/default')
@include('components/hero/banner-small')
@endif
@endif
@endforeach
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{{--
$hero => array // ['relative_url', 'title']
--}}

<div class="hero__wrapper w-full">
<div class="hero__bg h-hero max-h-hero w-full bg-cover bg-center relative{{ $loop->first !== true ? ' lazy' : '' }}" @if($loop->first === true) style="background-image: url('{{ $hero['relative_url'] }}')" @else data-src="{{ $hero['relative_url'] }}"@endif></div>
</div>
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{{--
$hero => array // ['relative_url', 'title']
--}}

<div class="hero__wrapper w-full">
<div class="hero__primary-image w-full h-hero-skinny max-h-hero-skinny bg-cover bg-center relative" style="background-image: url('{{ $hero['relative_url'] }}')"></div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion resources/views/components/news-column.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@
@endforeach
</ul>

<a href="/{{ $component['news_route'] ?? config('base.news_listing_route') }}" class="block my-4 underline hover:no-underline">{{ $component['link_text'] ?? 'More news' }}</a>
<div class="mt-6">
<a href="/{{ !empty($base['site']['subsite-folder']) ?? '' }}{{ $component['news_route'] ?? config('base.news_listing_route') }}" class="button">{{ $component['link_text'] ?? 'More news' }}</a>
</div>
@endif
Loading

0 comments on commit 2867154

Please sign in to comment.