Skip to content

Commit

Permalink
Merge branch 'release/8.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
breakdancingcat committed Jul 28, 2023
2 parents 765279a + f1d2b1e commit ae09e5b
Show file tree
Hide file tree
Showing 47 changed files with 2,886 additions and 1,564 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<?php
/*
* Status: Public
* Description: Promo Listing template
* Description: Promo Page template
* Default: false
*/

namespace App\Http\Controllers;

use Contracts\Repositories\PromoRepositoryContract;
use Contracts\Repositories\PromoPageRepositoryContract;
use Illuminate\Http\Request;

class PromoListingController extends Controller
class PromoPageController extends Controller
{
/**
* Construct the controller.
*
* @param PromoRepositoryContract $promo
*/
public function __construct(PromoRepositoryContract $promo)
public function __construct(PromoPageRepositoryContract $promo)
{
$this->promo = $promo;
}
Expand All @@ -34,13 +34,9 @@ public function __construct(PromoRepositoryContract $promo)
*/
public function index(Request $request)
{
$promos = $this->promo->getPromoListingPromos($request->data['base']);
$promos = $this->promo->getPromoPagePromos($request->data['base']);

if (!empty($request->data['base']['data']['grid_promo_group_id'])) {
return view('promo-grid', merge($request->data, $promos));
}

return view('promo-listing', merge($request->data, $promos));
return view('promo-page', merge($request->data, $promos));
}

/**
Expand Down
8 changes: 8 additions & 0 deletions app/Repositories/PeopleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Contracts\Repositories\ProfileRepositoryContract;
use Illuminate\Cache\Repository;
use Waynestate\Youtube\ParseId;
use Illuminate\Support\Str;
use Waynestate\Api\News;
use Waynestate\Api\People;
Expand Down Expand Up @@ -268,6 +269,12 @@ public function getProfile($site_id, $accessid)
if (!empty($profile['data'])) {
$profile['data']['link'] = '/profile/'.$profile['data']['accessid'];

if (!empty($profiles['profiles'][$site_id]['data']['Youtube Videos'])) {
$profiles['profiles'][$site_id]['data']['Youtube Videos'] = collect($profiles['profiles'][$site_id]['data']['Youtube Videos'])->map(function ($youtube_link) {
return ParseId::fromUrl($youtube_link);
});
}

foreach ($profile['data']['field_data'] as $data) {
if ($data['field']['type'] == 'file') {
$profile['data']['data'][$data['field']['name']]['url'] = $data['value'];
Expand Down Expand Up @@ -341,6 +348,7 @@ public function getFields()
'Last Name',
'Picture',
'Photo Download',
'Youtube Videos',
],
// Build the users name based on these fields
'name_fields' => [
Expand Down
9 changes: 9 additions & 0 deletions app/Repositories/ProfileRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Str;
use Waynestate\Api\Connector;
use Illuminate\Cache\Repository;
use Waynestate\Youtube\ParseId;
use Waynestate\Api\News;
use Waynestate\Promotions\ParsePromos;
use Contracts\Repositories\ProfileRepositoryContract;
Expand Down Expand Up @@ -239,6 +240,12 @@ public function getProfile($site_id, $accessid)
return ['profile'=> []];
}

if (!empty($profiles['profiles'][$site_id]['data']['Youtube Videos'])) {
$profiles['profiles'][$site_id]['data']['Youtube Videos'] = collect($profiles['profiles'][$site_id]['data']['Youtube Videos'])->map(function ($youtube_link) {
return ParseId::fromUrl($youtube_link);
});
}

if (!empty($profiles['profiles'])) {
$profiles['profiles']['articles'] = $this->getNewsArticles($accessid, 10);
}
Expand Down Expand Up @@ -298,6 +305,7 @@ public function getFields()
'file_fields' => [
'Curriculum Vitae',
'Syllabi',
'Youtube Videos',
],
// Hide these in the main tube of content
'hidden_fields' => [
Expand All @@ -309,6 +317,7 @@ public function getFields()
'Last Name',
'Picture',
'Photo Download',
'Youtube Videos',
],
// Build the users name based on these fields
'name_fields' => [
Expand Down
229 changes: 229 additions & 0 deletions app/Repositories/PromoPageRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
<?php

namespace App\Repositories;

use Contracts\Repositories\PromoPageRepositoryContract;
use Illuminate\Cache\Repository;
use Illuminate\Support\Str;
use Waynestate\Api\Connector;
use Waynestate\Promotions\ParsePromos;

class PromoPageRepository implements PromoPageRepositoryContract
{
/** @var Connector */
protected $wsuApi;

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

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

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

/**
* {@inheritdoc}
*/
public function getPromoView($id)
{
$promo['promotion'] = [];

$params = [
'method' => 'cms.promotions.info',
'promo_item_id' => $id,
'filename_url' => true,
'is_active' => '1',
];

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

$promo['promo'] = empty($promo['error']) ? $promo['promotion'] : [];

return $promo;
}

/**
* {@inheritdoc}
*/
public function getPromoPagePromos(array $data)
{
// Legacy support for listing
if (!empty($data['data']['listing_promo_group_id'])) {
if (!empty($data['data']['promotion_view_boolean']) && $data['data']['promotion_view_boolean'] === "true") {
$data['data']['promoPage'] = "{\"id\":\"".$data['data']['listing_promo_group_id']."\",\"singlePromoView\":\"true\"}";
} else {
$data['data']['promoPage'] = "{\"id\":\"".$data['data']['listing_promo_group_id']."\"}";
}
}

// Legacy support for grid
if (!empty($data['data']['grid_promo_group_id'])) {
if (!empty($data['data']['promotion_view_boolean']) && $data['data']['promotion_view_boolean'] === "true") {
$data['data']['promoPage'] = "{\"id\":\"".$data['data']['grid_promo_group_id']."\",\"columns\":\"3\",\"singlePromoView\":\"true\"}";
} else {
$data['data']['promoPage'] = "{\"id\":\"".$data['data']['grid_promo_group_id']."\",\"columns\":\"3\"}";
}
}

if (!empty($data['data']['promoPage'])) {
$group_info = $this->parsePromoJSON($data);

// Parse promos
$group_reference[$group_info['id']] = 'promos';
$group_config['promos'] = $group_info['config'];

$params = [
'method' => 'cms.promotions.listing',
'promo_group_id' => array_keys($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, $group_reference, $group_config);

// Manipulate promo data from page field settings
$promos = $this->changePromoItemDisplay($promos, $group_info);

// Organize promos by option
$promos = $this->organizePromoItemsByOption($promos);

// Set number of columns
$promos['template']['columns'] = $group_info['columns'];

return $promos;
} else {
return ['promos' => []];
}
}

/**
* {@inheritdoc}
*/
public function parsePromoJSON($data)
{
$group_info = [];

if (!empty($data['data']['promoPage'])) {
// Remove all spaces and line breaks
$group_info = preg_replace('/\s*\R\s*/', '', $data['data']['promoPage']);

// Last item cannot have comma at the end of it
$group_info = preg_replace('(,})', '}', $group_info);

// JSON into array
$group_info = json_decode($group_info, true);

// Assign expected group info
$group_info['id'] = (!empty($group_info['id']) ? $group_info['id'] : '');
$group_info['config'] = (!empty($group_info['config']) ? $group_info['config'] : '');
$group_info['singlePromoView'] = (!empty($group_info['singlePromoView']) ? $group_info['singlePromoView'] : '');
$group_info['columns'] = (!empty($group_info['columns']) ? $group_info['columns'] : '');
$group_info['showExcerpt'] = (!empty($group_info['showExcerpt']) ? $group_info['showExcerpt'] : '');
$group_info['showDescription'] = (!empty($group_info['showDescription']) ? $group_info['showDescription'] : '');

// Append actual page id to config
if (str_contains($group_info['config'], 'page_id')) {
$group_info['config'] = preg_replace('/\bpage_id\b/', 'page_id:'.$data['page']['id'], $group_info['config']);
}
}

return $group_info;
}

/**
* {@inheritdoc}
*/
public function changePromoItemDisplay($promos, $group_info)
{
// Enable the individual promotion view
if ($group_info['singlePromoView'] == "true") {
$promos['promos'] = collect($promos['promos'])->map(function ($item) {
if (!empty($item)) {
$item['link'] = 'view/'.Str::slug($item['title']).'-'.$item['promo_item_id'];
}

return $item;
})->toArray();
}

// Hide excerpt
if ($group_info['showExcerpt'] == "false") {
$promos['promos'] = collect($promos['promos'])->map(function ($item) {
unset($item['excerpt']);

return $item;
})->toArray();
}

// Hide description
if ($group_info['showDescription'] == "false") {
$promos['promos'] = collect($promos['promos'])->map(function ($item) {
unset($item['description']);

return $item;
})->toArray();
}

return $promos;
}

/**
* {@inheritdoc}
*/
public function organizePromoItemsByOption(array $promos)
{
$options_exist = collect($promos['promos'])->filter(function ($value) {
return !empty($value['option']);
})->isNotEmpty();

if ($options_exist === true) {
$promos['promos'] = collect($promos['promos'])->groupBy('option')->toArray();

if (!empty($promos['promos'][''])) {
$no_option_moved_to_bottom = $promos['promos'][''];
unset($promos['promos']['']);
$promos['promos'][''] = $no_option_moved_to_bottom;
}

$promos['template']['group_by_options'] = true;
} else {
$promos['template']['group_by_options'] = false;
}

return $promos;
}

/**
* {@inheritdoc}
*/
public function getBackToPromoPage($referer = null, $scheme = null, $host = null, $uri = null)
{
// Make sure the referer is coming from the site we are currently on and not the current page
if ($referer === null
|| $referer == $scheme.'://'.$host.$uri
|| strpos($referer, $host) === false
) {
return '';
}

return $referer;
}
}
Loading

0 comments on commit ae09e5b

Please sign in to comment.