File: D:/HostingSpaces/SBogers10/boldt.komma.pro/app/Helpers/Atomic.php
<?php
/**
* Created by PhpStorm.
* User: pascallemmen
* Date: 22/11/2018
* Time: 11:19
*/
namespace App\Helpers;
class Atomic
{
/**
* Generate the modifies string for the given className
*
* @param string $className
* @param $modifiers
*/
public static function modifiers(string $className, $modifiers)
{
if(!empty($modifiers)){
// If $modifiers is a string instead of a array, put it a array
if(!is_array($modifiers) && is_string($modifiers)){
$modifiers = [$modifiers];
}
$modifierClasses = '';
foreach ($modifiers as $modifier) $modifierClasses .= ' '.$className.'--'.$modifier;
echo $modifierClasses;
}
}
/**
* For the time being we create a card view here...
*
* @param $component
* @return object
*/
public static function createCardsViewComponent($component)
{
// Create Card View Component
$cardViewComponent = (object)[
'cardModifiers' => [],
'boxed' => false,
'cards' => collect(),
];
// Set boxed property and add modifier to cardModifier
if($component->boxed){
$cardViewComponent->cardModifiers[] = 'box';
$cardViewComponent->boxed = true;
}
$whileCounter = 0;
do {
// Break if a variable the first value of the to grab items isn't found
if (!isset($component->{'title_' . $whileCounter}) || $component->{'title_' . $whileCounter} == '') {
// If zero continue just continue, because sometimes it starts from 1
if ($whileCounter == 0){
$whileCounter++;
continue;
}
else {
break;
}
}
// Grab the desired attribute from the component
$card = (object)[
'icon' => $component->{'icon_' . $whileCounter},
'title' => $component->{'title_' . $whileCounter},
'description' => $component->{'description_' . $whileCounter},
'button_link' => $component->{'button_' . $whileCounter . '_link'},
'button_label' => $component->{'button_' . $whileCounter . '_label'},
];
$cardViewComponent->cards->push($card);
$whileCounter++;
// Safety break at 50
} while($whileCounter <= 50);
return $cardViewComponent;
}
public static function createAccordionViewComponent($component)
{
$accordionComponent = (object)[
'items' => collect(),
];
$whileCounter = 0;
do {
// Break if a variable the first value of the to grab items isn't found
if (!isset($component->{'title_' . $whileCounter}) || $component->{'title_' . $whileCounter} == '') {
// If zero continue just continue, because sometimes it starts from 1
if ($whileCounter == 0){
$whileCounter++;
continue;
}
else {
break;
}
}
// Grab the desired attribute from the component
$accordionItem = (object)[
'title' => $component->{'title_' . $whileCounter},
'description' => $component->{'description_' . $whileCounter},
'button_link' => $component->{'button_' . $whileCounter . '_link'},
'button_label' => $component->{'button_' . $whileCounter . '_label'},
];
$accordionComponent->items->push($accordionItem);
$whileCounter++;
// Safety break at 50
} while($whileCounter <= 50);
return $accordionComponent;
}
}