Skip to content

Commit

Permalink
Merge branch 'release/8.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
breakdancingcat committed Oct 26, 2023
2 parents b5cf312 + 1f03324 commit a395503
Show file tree
Hide file tree
Showing 39 changed files with 1,364 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ npm-debug.log
yarn-error.log
cs_fixer_tmp*
.php_cs.cache
.phpunit.cache
.php-cs-fixer.cache
/public/mix-manifest.json
/*.diff
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function show(Request $request): View|Redirector|RedirectResponse
$request->data['base']['hero'][]['relative_url'] = $article['article']['data']['hero_image']['url'];
}

$image = $this->article->getImage($article['article']['data']);
$image = $this->article->getSocialImage($article['article']['data']);

$request->data['base']['meta']['image'] = $image['url'];
$request->data['base']['meta']['image_alt'] = $image['alt_text'];
Expand Down
36 changes: 36 additions & 0 deletions app/Http/Controllers/ModularPageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/*
* Status: Private
* Description: Modular Template
* Default: false
*/

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Contracts\Repositories\ModularPageRepositoryContract;

class ModularPageController extends Controller
{
/**
* Construct the controller.
*
*/
public function __construct(ModularPageRepositoryContract $modular)
{
$this->modular = $modular;
}

/**
* Display the homepage view.
*
* @param Request $request
* @return \Illuminate\View\View
*/
public function index(Request $request)
{
$components['components'] = $this->modular->getModularComponents($request->data['base']);

return view('modular/modularpage', merge($request->data, $components));
}
}
16 changes: 15 additions & 1 deletion app/Repositories/ArticleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,22 @@ public function find($id, $application_ids, $preview = null)
/**
* {@inheritdoc}
*/
public function getImage($article)
public function getSocialImage($article)
{
if (!empty($article['social_image'])) {
return [
'url' => $article['social_image']['url'],
'alt_text' => $article['social_image']['alt_text'],
];
}

if (!empty($article['featured'])) {
return [
'url' => $article['featured']['url'],
'alt_text' => $article['featured']['alt_text'],
];
}

if (!empty($article['hero_image'])) {
return [
'url' => $article['hero_image']['url'],
Expand Down
170 changes: 170 additions & 0 deletions app/Repositories/ModularPageRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<?php

namespace App\Repositories;

use Contracts\Repositories\ModularPageRepositoryContract;
use Contracts\Repositories\EventRepositoryContract;
use Contracts\Repositories\ArticleRepositoryContract;
use Illuminate\Cache\Repository;
use Illuminate\Support\Str;
use Waynestate\Api\Connector;
use Waynestate\Promotions\ParsePromos;

class ModularPageRepository implements ModularPageRepositoryContract
{
/** @var Connector */
protected $wsuApi;

/** @var ParsePromos */
protected $parsePromos;

/** @var Repository */
protected $cache;

/**
* Construct the repository.
*
* @param Connector $wsuApi
* @param ParsePromos $parsePromos
* @param Repository $cache
* @param ArticleRepositoryContract $article
* @param EventRepositoryContract $event
*/
public function __construct(
Connector $wsuApi,
ParsePromos $parsePromos,
Repository $cache,
ArticleRepositoryContract $article,
EventRepositoryContract $event
) {
$this->wsuApi = $wsuApi;
$this->parsePromos = $parsePromos;
$this->cache = $cache;
$this->article = $article;
$this->event = $event;
}

/**
* {@inheritdoc}
*/
public function getModularComponents(array $data): array
{
if(empty($data['data'])) {
return [];
}

$modularComponents = [];

$components = $this->parseData($data);
$promos = $this->getPromos($components);

foreach($components['components'] as $name => $component) {
if(Str::startsWith($name, 'events') && !empty($component['id'])) {
$events = $this->event->getEvents($component['id']);
$modularComponents[$name]['data'] = $events['events'] ?? [];
$modularComponents[$name]['component'] = $components['components'][$name];
} elseif(Str::startsWith($name, 'news') && !empty($component['id'])) {
$articles = $this->article->listing($component['id']);
$modularComponents[$name]['data'] = $articles['articles'] ?? [];
$modularComponents[$name]['component'] = $components['components'][$name];
} else {
$modularComponents[$name]['data'] = $promos[$name]['data'] ?? [];
$modularComponents[$name]['component'] = $promos[$name]['component'] ?? [];
}
}

return $modularComponents;
}

public function parseData(array $data)
{
$components = [];
$group_reference = [];
$group_config = [];

foreach($data['data'] as $pageField => $value) {
if(Str::startsWith($pageField, 'modular-')) {
$name = Str::replaceFirst('modular-', '', $pageField);

if(Str::isJson($value)) {
$components[$name] = json_decode($value, true);
if(!empty($components[$name]['config'])) {
$config = explode('|', $components[$name]['config']);
foreach($config as $key => $value) {
if(Str::startsWith($value, 'page_id')) {
$config[$key] = 'page_id:'.$data['page']['id'];
}

if(Str::startsWith($value, 'first')) {
unset($config[$key]);
}
}
$components[$name]['config'] = implode('|', $config);
}
$components[$name]['filename'] = preg_replace('/-\d+$/', '', $name);
} else {
$components[$name]['id'] = (int)$value;
}

if(!Str::startsWith($name, ['events', 'news']) && !empty($components[$name]['id'])) {
$group_reference[$components[$name]['id']] = $name;
if(!empty($components[$name]['config'])) {
$group_config[$name] = $components[$name]['config'];
}
}
}
}

return [
'components' => $components,
'group_reference' => $group_reference,
'group_config' => $group_config,
];
}

public function getPromos($components)
{
$params = [
'method' => 'cms.promotions.listing',
'promo_group_id' => array_keys($components['group_reference']),
'filename_url' => true,
'is_active' => '1',
];

$promos = $this->cache->remember($params['method'] . md5(serialize($params)), config('cache.ttl'), function () use ($params) {
return $this->wsuApi->sendRequest($params['method'], $params);
});

$promos = $this->parsePromos->parse($promos, $components['group_reference'], $components['group_config']);

foreach ($promos as $name => $data) {
$promos[$name] = [
'data' => $data,
'component' => $components['components'][$name],
];

foreach($promos[$name]['data'] as $key => $promo) {
$promos[$name]['data'][$key] = $this->adjustPromoData($promo, $promos[$name]['component']);
}
}

return $promos;
}

public function adjustPromoData($data, $component)
{
if(isset($component['singlePromoView']) && $component['singlePromoView'] === true) {
$data['link'] = 'view/'.Str::slug($data['title']).'-'.$data['promo_item_id'];
}

if(isset($component['showExcerpt']) && $component['showExcerpt'] === false) {
unset($data['excerpt']);
}

if(isset($component['showDescription']) && $component['showDescription'] === false) {
unset($data['description']);
}

return $data;
}
}
2 changes: 1 addition & 1 deletion app/Repositories/PromoPageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function getPromoPagePromos(array $data)
/**
* {@inheritdoc}
*/
public function parsePromoJSON($data)
public function parsePromoJSON($data, $pagei_id = 0)
{
$group_info = [];

Expand Down
2 changes: 1 addition & 1 deletion contracts/Repositories/ArticleRepositoryContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function find($id, $application_ids, $preview);
* @param array $article
* @return array
*/
public function getImage($article);
public function getSocialImage($article);

/**
* Set the paging.
Expand Down
13 changes: 13 additions & 0 deletions contracts/Repositories/ModularPageRepositoryContract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Contracts\Repositories;

interface ModularPageRepositoryContract
{
/**
* Get promotions for the listing.
*
* @return array
*/
public function getModularComponents(array $data);
}
2 changes: 1 addition & 1 deletion contracts/Repositories/PromoPageRepositoryContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function getPromoPagePromos(array $data);
*
* @return array
*/
public function parsePromoJSON($data);
public function parsePromoJSON($data, $page_id);

/**
*
Expand Down
18 changes: 18 additions & 0 deletions factories/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ public function create($limit = 1, $flatten = false, $options = [])
'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/1600x580',
Expand All @@ -46,6 +54,14 @@ public function create($limit = 1, $flatten = false, $options = [])
];
}

$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[] = [
Expand Down Expand Up @@ -118,13 +134,15 @@ public function create($limit = 1, $flatten = false, $options = [])
'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,
Expand Down
4 changes: 2 additions & 2 deletions factories/GenericPromo.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public function create($limit = 1, $flatten = false, $options = [])
{
$promo_group_id = $this->faker->randomNumber(5);

for ($i = 1; $i <= $limit; $i++) {
for ($i = 0; $i <= $limit - 1; $i++) {
$data[$i] = [
'title' => ucfirst(implode(' ', $this->faker->words(3))),
'excerpt' => $this->faker->sentence(),
'description' => '<p>' . $this->faker->text(100) . ' <a href="https://wayne.edu">'. $this->faker->sentence(3) .'</a></p>',
'link' => 'https://wayne.edu',
'promo_item_id' => strval($this->faker->randomNumber(5)),
'promo_item_id' => $i,
'promo_group_id' => strval($promo_group_id),
'relative_url' => '/styleguide/image/600x450?text=600x450:'.$i, // 4:3
//'relative_url' => '/styleguide/image/450x600', // 3:4
Expand Down

0 comments on commit a395503

Please sign in to comment.