HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers95/rentman.io/app/Helpers/Atomic.php
<?php
/**
 * Created by PhpStorm.
 * User: pascallemmen
 * Date: 22/11/2018
 * Time: 11:19
 */

namespace App\Helpers;

use App\Komma\CustomerStories\CustomerStoryService;

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...
     * If we don't resolve this in the type model then we should refactor the stuff below
     * to make a generic loop instead of for each (almost the same) loop
     *
     * @param $component
     * @return object
     */
    public static function createCardsViewComponent($component)
    {
        // Create Card View Component
        $cardViewComponent = (object) [
            'cardModifiers' => [],
            'boxed' => false,
            'webinar' => false,
            'row_heading' => '',
            'cards' => collect(),
        ];

        $cardViewComponent->row_heading = $component->row_heading;
        $cardViewComponent->hover_layout = $component->hover_layout;
        $cardViewComponent->webinar = $component->webinar ? $component->webinar : false;

        $hasIcons = false;

        // 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;
                }
            }

            $icon = $component->{'icon_'.$whileCounter};
            $image = $component->{'image_'.$whileCounter};

            // Grab the desired attribute from the component
            $card = (object) [
                'icon' => (isset($icon) && $icon != 'null') ? $icon : null,
                'image' => (! empty($image) && $image != 'null') ? $image : null,
                'title' => $component->{'title_'.$whileCounter},
                'description' => $component->{'description_'.$whileCounter},
                'button_link' => $component->{'button_'.$whileCounter.'_link'},
                'button_label' => $component->{'button_'.$whileCounter.'_label'},
            ];

            if ($card->icon != null) {
                $hasIcons = true;
            }

            $cardViewComponent->cards->push($card);
            $whileCounter++;

            // Safety break at 50
        } while ($whileCounter <= 50);

        $cardViewComponent->hasIcons = $hasIcons;

        return $cardViewComponent;
    }

    /**
     * For the time being we create a card view here...
     * If we don't resolve this in the type model then we should refactor the stuff below
     * to make a generic loop instead of for each (almost the same) loop
     *
     * @param $component
     * @return object
     */
    public static function createTileViewComponent($component)
    {
        // Create Card View Component
        $tileViewComponent = (object) [
            'tiles' => collect(),
        ];

        $hasIcons = false;

        $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;
                }
            }

            $icon = $component->{'icon_'.$whileCounter};
            $image = $component->{'image_'.$whileCounter};

            // Grab the desired attribute from the component
            $tile = (object) [
                'icon' => (isset($icon) && $icon != 'null') ? $icon : null,
                'image' => (! empty($image) && $image != 'null') ? $image : null,
                'title' => $component->{'title_'.$whileCounter},
                'subtitle' => $component->{'subtitle_'.$whileCounter},
                'description' => $component->{'description_'.$whileCounter},
                'button_link' => $component->{'button_'.$whileCounter.'_link'},
                'button_label' => $component->{'button_'.$whileCounter.'_label'},
            ];

            if ($tile->icon != null) {
                $hasIcons = true;
            }

            $tileViewComponent->tiles->push($tile);
            $whileCounter++;

            // Safety break at 50
        } while ($whileCounter <= 50);

        $tileViewComponent->hasIcons = $hasIcons;

        return $tileViewComponent;
    }

    /**
     * For the time being we create a usp view here...
     * If we don't resolve this in the type model then we should refactor the stuff below
     * to make a generic loop instead of for each (almost the same) loop
     *
     * @param $component
     * @return object
     */
    public static function createUspViewComponent($component)
    {
        // Create Card View Component
        $uspViewComponent = (object) [
            'usp' => 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
            $uspObject = (object) [
                'title' => $component->{'title_'.$whileCounter},
                'description' => $component->{'description_'.$whileCounter},
            ];

            $uspViewComponent->usp->push($uspObject);
            $whileCounter++;

            // Safety break at 50
        } while ($whileCounter <= 50);

        return $uspViewComponent;
    }

    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;
    }

    public static function createCustomerStoryTabViewComponent($component)
    {
        $customerStorytabsComponent = (object) [
            'items' => collect(),
        ];

        $customerStoryIds = [];

        $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;
                }
            }

            // We later grab the stories at once to prevent the amount of queries
            $customerStoryId = $component->{'customer_story_'.$whileCounter};
            if (! in_array($customerStoryId, $customerStoryIds)) {
                $customerStoryIds[] = $customerStoryId;
            }

            // Grab the desired attribute from the component
            $tabItem = (object) [
                'title' => $component->{'title_'.$whileCounter},
                'description' => $component->{'description_'.$whileCounter},
                'button_link' => $component->{'button_'.$whileCounter.'_link'},
                'button_label' => $component->{'button_'.$whileCounter.'_label'},
                'customer_story_id' => $customerStoryId,
            ];

            $customerStorytabsComponent->items->push($tabItem);
            $whileCounter++;

            // Safety break at 50
        } while ($whileCounter <= 50);

        $customerStoryService = \App::make(CustomerStoryService::class);
        $customerStories = $customerStoryService->getCustomerStoriesByIds($customerStoryIds);

        // Append the story to the tabs
        foreach ($customerStorytabsComponent->items as &$tab) {
            $tab->customerStory = $customerStories->find($tab->customer_story_id);
        }

        return $customerStorytabsComponent;
    }

    public static function createTextImageTabViewComponent($component)
    {
        $textImagetabsComponent = (object) [
            'items' => collect(),
        ];

        $textImageIds = [];

        $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;
                }
            }

            // We later grab the stories at once to prevent the amount of queries
            $textImageId = $component->{'customer_story_'.$whileCounter};
            if (! in_array($textImageId, $textImageIds)) {
                $textImageIds[] = $textImageId;
            }

//            dd($component);

            // Grab the desired attribute from the component
            $tabItem = (object) [
                'title' => $component->{'title_'.$whileCounter},
                'description' => $component->{'description_'.$whileCounter},
                'image' => $component->{'image_'.$whileCounter},
            ];

            $textImagetabsComponent->items->push($tabItem);
            $whileCounter++;

            // Safety break at 50
        } while ($whileCounter <= 50);

        return $textImagetabsComponent;
    }

    public static function createCustomerStorySliderViewComponent($component)
    {
        $customerStorySliderComponent = (object) [
            'items' => collect(),
        ];

        $customerStoryIds = [];
        $whileCounter = 0;
        do {
            // Break if a variable the first value of the to grab items isn't found
            if (! isset($component->{'customer_story_'.$whileCounter}) || $component->{'customer_story_'.$whileCounter} == '') {
                // If zero continue just continue, because sometimes it starts from 1
                if ($whileCounter == 0) {
                    $whileCounter++;
                    continue;
                } else {
                    break;
                }
            }

            // We later grab the stories at once to prevent the amount of queries
            $customerStoryId = $component->{'customer_story_'.$whileCounter};
            if (! in_array($customerStoryId, $customerStoryIds)) {
                $customerStoryIds[] = $customerStoryId;
            }

            // Grab the desired attribute from the component
            $tabItem = (object) [
                'images' => $component->{'image_'.$whileCounter},
                'person' => $component->{'person_'.$whileCounter},
                'description' => $component->{'description_'.$whileCounter},
                'customer_story_id' => $customerStoryId,
            ];

            $customerStorySliderComponent->items->push($tabItem);
            $whileCounter++;

            // Safety break at 50
        } while ($whileCounter <= 50);

        $customerStoryService = \App::make(CustomerStoryService::class);
        $customerStories = $customerStoryService->getCustomerStoriesByIds($customerStoryIds);

        // Append the story to the tabs
        foreach ($customerStorySliderComponent->items as &$tab) {
            $tab->customerStory = $customerStories->find($tab->customer_story_id);
        }

        return $customerStorySliderComponent;
    }

    public static function createStorySliderViewComponent($component)
    {
        $storySliderComponent = (object) [
            'items' => collect(),
        ];

        $customerStoryIds = [];
        $whileCounter = 0;
        do {
            // Break if a variable the first value of the to grab items isn't found
            if (! isset($component->{'person_'.$whileCounter}) || $component->{'person_'.$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
            $tabItem = (object) [
                'images' => $component->{'image_'.$whileCounter},
                'person' => $component->{'person_'.$whileCounter},
                'function' => $component->{'function_'.$whileCounter},
                'description' => $component->{'description_'.$whileCounter},
            ];

            $storySliderComponent->items->push($tabItem);
            $whileCounter++;

            // Safety break at 50
        } while ($whileCounter <= 50);

        return $storySliderComponent;
    }

    public static function createImageTextTabViewComponent($component)
    {
        $customerStorytabsComponent = (object) [
            'items' => collect(),
        ];

        $customerStoryIds = [];

        $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;
                }
            }

            // We later grab the stories at once to prevent the amount of queries
            $customerStoryId = $component->{'customer_story_'.$whileCounter};
            if (! in_array($customerStoryId, $customerStoryIds)) {
                $customerStoryIds[] = $customerStoryId;
            }

            // Grab the desired attribute from the component
            $tabItem = (object) [
                'title' => $component->{'title_'.$whileCounter},
                'text' => $component->{'description_'.$whileCounter},
                'image' => $component->{'impression_'.$whileCounter},
                'button_link' => $component->{'button_'.$whileCounter.'_link'},
                'button_label' => $component->{'button_'.$whileCounter.'_label'},
                'reversed' => $component->{'reversed_'.$whileCounter},
                'filled_button' => $component->{'filled_button_'.$whileCounter},
            ];

            $customerStorytabsComponent->items->push($tabItem);
            $whileCounter++;

            // Safety break at 50
        } while ($whileCounter <= 50);

        return $customerStorytabsComponent;
    }
}