AlkantarClanX12

Your IP : 216.73.216.59


Current Path : /www/capitalgmcbuickregina_830/public/wp-content/themes/lbx-egypt/app/View/Composers/
Upload File :
Current File : /www/capitalgmcbuickregina_830/public/wp-content/themes/lbx-egypt/app/View/Composers/Lineup.php

<?php

namespace App\View\Composers;

use Roots\Acorn\View\Composer;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use App\View\Composers\GraphqlData;
use App\Facades\Genius;

/**
 * Composer created for Lineup component.
 *
 * @author Bryan Silva
 * @author Leonardo Guillen
 */
class Lineup extends Composer
{
    /**
     * List of views served by this composer.
     *
     * @var array
     */
    protected static $views = [
      'cl.lineup.*'
    ];

    /**
     * Data to be passed to view before rendering.
     *
     * @return array
     */
    public function with()
    {
        return [
          $this->enqueueScripts(),
          'lineupSelectedCategory' => isFrench() ? Genius::get('lineup.data.selected-category-fr') : Genius::get('lineup.data.selected-category-en'),
          'lineupOrder' => Genius::get('lineup.data.lineup-order') !== null ? Genius::get('lineup.data.lineup-order') : '',
          'lineupData' => $this->getLineupData(),
          'selected_category' => isFrench() ? Str::replace([' ', '&'], ['', '\&'], Genius::get('lineup.data.selected-category-fr')) : Str::replace([' ', '&'], ['', '\&'], Genius::get('lineup.data.selected-category-en'))
        ];
    }

    //   _____ ____  __  __ _____   ____   _____ ______ _____       ______ _    _ _   _  _____ _______ _____ ____  _   _  _____ 
    //   / ____/ __ \|  \/  |  __ \ / __ \ / ____|  ____|  __ \     |  ____| |  | | \ | |/ ____|__   __|_   _/ __ \| \ | |/ ____|
    //  | |   | |  | | \  / | |__) | |  | | (___ | |__  | |__) |    | |__  | |  | |  \| | |       | |    | || |  | |  \| | (___  
    //  | |   | |  | | |\/| |  ___/| |  | |\___ \|  __| |  _  /     |  __| | |  | | . ` | |       | |    | || |  | | . ` |\___ \ 
    //  | |___| |__| | |  | | |    | |__| |____) | |____| | \ \     | |    | |__| | |\  | |____   | |   _| || |__| | |\  |____) |
    //   \_____\____/|_|  |_|_|     \____/|_____/|______|_|  \_\    |_|     \____/|_| \_|\_____|  |_|  |_____\____/|_| \_|_____/ 

    /**
     * Enqueue of the scripts belonging to the component.
     *
     * @return mixed
     */
    protected function enqueueScripts()
    {
      return add_action('wp_enqueue_scripts', function() {
        wp_register_script('leadbox-lineup-script-defer', asset('scripts/bladeScripts/lineup.js')->uri(), [], false, true);
        wp_enqueue_script('leadbox-lineup-script-defer');
        wp_localize_script('leadbox-lineup-script-defer', 'lineup_ajax_object', 
          array(
            'selected_category' => isFrench() ? Str::replace([' ', '&'], ['', ''], Genius::get('lineup.data.selected-category-fr')) : Str::replace([' ', '&'], ['', ''], Genius::get('lineup.data.selected-category-en'))
          )
		    );
      });
    }

    /**
     * Returns the collection at position ['modelData'] of the array where all the lineup information is located.
     *
     * @return array
     */

    public function getLineupData() : array
    {
      $query = '
        {
        modelLists(first: 100, where: { search: "'.get_leadbox_manufacturer().'" }) {
          nodes {
            modelData {
              year
              make
              model
              category
              model
              startingPrice
              colorizer {
                colorName
                colorNameFr
                images {
                  url
                  imageType
                  image {
                    sourceUrl(size: LARGE)
                    medium: sourceUrl(size: MEDIUM)
                    thumbnail: sourceUrl(size: THUMBNAIL)
                  }
                }
              }
              jellybean {
                sourceUrl(size: MEDIUM)
              }
            }
            }
          }
        }
      ';
      return (new GraphqlData)->getGraphData($query)
        ->reject(function ($row) {
          $opts = get_option('dealer-settings-showroom-options', []);
          if (!is_array($opts)) {
            return false;
          }

          $excludedModelsOption = Str::lower((string)($opts['excluded_models'] ?? ''));
          if ($excludedModelsOption === '') {
            return false;
          }

          $excludedModels = collect(explode(',', $excludedModelsOption))
            ->map(fn ($m) => (string) Str::of($m)->trim()->lower())
            ->filter()
            ->values()
            ->all();

          $year  = (string) ($row['modelData']['year']  ?? '');
          $model = (string) ($row['modelData']['model'] ?? '');
          $current = strtolower(trim($year . ' ' . $model));

          return in_array($current, $excludedModels, true);
        })

        /*
        ->reject(function ($row) {
          if (is_array($row)) {
            // If the model contains the Future Vehicles category, reject it.
            return in_array('Future Vehicles', $row['modelData']['category']);
          }
        })
        */
        ->map(function ($row) {
            if (!is_array($row)) {
                return $row;
            }

            $orientation = Str::lower((string) Genius::get('lineup.data.colorizer-orientation'));

            // Extract url + medium + thumbnail from a single image entry, keeping the
            // three variants in sync (they must all come from the same source image).
            $extractVariants = function ($image) {
                return [
                    'imageSelected'          => !empty($image['url'])
                        ? $image['url']
                        : ($image['image']['sourceUrl'] ?? null),
                    'imageSelectedMedium'    => $image['image']['medium']    ?? null,
                    'imageSelectedThumbnail' => $image['image']['thumbnail'] ?? null,
                ];
            };

            $colorizers = collect($row['modelData']['colorizer'] ?? [])
                ->transform(function ($colorizer) use ($orientation, $extractVariants) {
                    $colorizer['colorName']   = Str::headline((string)($colorizer['colorName']   ?? ''));
                    $colorizer['colorNameFr'] = Str::headline((string)($colorizer['colorNameFr'] ?? ''));

                    $images = collect($colorizer['images'] ?? []);

                    $primary = $images
                        ->first(function ($image) use ($orientation) {
                            return Str::lower((string)($image['imageType'] ?? '')) === $orientation;
                        });

                    $fallback = $images
                        ->first(function ($image) use ($orientation) {
                            return Str::lower((string)($image['imageType'] ?? '')) !== $orientation;
                        });

                    $primaryVariants  = $primary  ? $extractVariants($primary)  : ['imageSelected' => null, 'imageSelectedMedium' => null, 'imageSelectedThumbnail' => null];
                    $fallbackVariants = $fallback ? $extractVariants($fallback) : ['imageSelected' => null, 'imageSelectedMedium' => null, 'imageSelectedThumbnail' => null];

                    $colorizer['imageSelected']          = $primaryVariants['imageSelected'];
                    $colorizer['imageSelectedMedium']    = $primaryVariants['imageSelectedMedium'];
                    $colorizer['imageSelectedThumbnail'] = $primaryVariants['imageSelectedThumbnail'];

                    // Last-resort variants (any other orientation).
                    $colorizer['imageFallback']          = $fallbackVariants['imageSelected'];
                    $colorizer['imageFallbackMedium']    = $fallbackVariants['imageSelectedMedium'];
                    $colorizer['imageFallbackThumbnail'] = $fallbackVariants['imageSelectedThumbnail'];

                    return $colorizer;
                });

            // Cascade fallback when a color is configured in Genius for this model:
            //   1. configured color with the requested orientation
            //   2. first available color with the requested orientation
            //   3. configured color with any other orientation
            $selector = Genius::get("lineup.data.colorizer-selector");
            $modelKey = Str::lower((string)($row['modelData']['model'] ?? ''));
            $hasSelector = is_array($selector) && Arr::exists($selector, $modelKey);

            if ($hasSelector) {
                $selectedColor = Str::lower((string) Arr::get($selector, $modelKey));
                $configured = $colorizers->first(function ($colorizer) use ($selectedColor) {
                    return Str::lower((string)($colorizer['colorName'] ?? '')) === $selectedColor;
                });

                if ($configured && !empty($configured['imageSelected'])) {
                    $picked = $configured;
                } else {
                    $anyWithOrientation = $colorizers->first(function ($colorizer) {
                        return !empty($colorizer['imageSelected']);
                    });

                    if ($anyWithOrientation) {
                        $picked = $anyWithOrientation;
                    } elseif ($configured && !empty($configured['imageFallback'])) {
                        $configured['imageSelected']          = $configured['imageFallback'];
                        $configured['imageSelectedMedium']    = $configured['imageFallbackMedium'];
                        $configured['imageSelectedThumbnail'] = $configured['imageFallbackThumbnail'];
                        $picked = $configured;
                    } else {
                        $picked = null;
                    }
                }

                $row['modelData']['colorizer'] = $picked ? [$picked] : [];
            } else {
                $row['modelData']['colorizer'] = $colorizers->values()->all();
            }

            return $row;
        })
        ->pluck('modelData')
        // Drop any model that came back incomplete from the content server
        // (e.g. a model set to draft on Minerva). Instead of letting a null /
        // malformed row reach the blades and blow them up with a fatal
        // TypeError (in_array/count/usort over null), we simply don't render it.
        ->filter(function ($model) {
            return is_array($model)
                && !empty($model['model'])
                && !empty($model['year'])
                && is_array($model['category'] ?? null);
        })
        ->sortBy(['startingPrice', 'desc'])
        ->values()
        ->all();
    }
}

Home - Capital GMC Buick Regina

No data

Welcome to Capital GMC BUICK – REGINA

Thank you for choosing Capital GMC Buick | Regina, your premier certified Buick and GMC dealership proudly serving drivers in Regina and the surrounding communities. Whether you’re searching for a brand-new Buick or GMC vehicle or a meticulously inspected pre-owned model, we have a diverse selection to match your needs and lifestyle.

Beyond our impressive inventory, we offer a seamless and stress-free financing experience through our well-connected finance centre, where our team of experts is dedicated to securing the best loan or lease options for you, quickly, transparently, and hassle-free.

But our commitment to you doesn’t stop at the sale. Our state-of-the-art service centre is staffed with skilled Buick and GMC technicians who use the latest equipment and genuine OEM parts to keep your vehicle running at its best. From routine maintenance to complex repairs, we’ve got you covered.

Experience top-tier customer service, quality vehicles, and expert care, all in one place. Visit Capital GMC Buick | Regina today or call us at 306-205-8072 with any questions. We’re here to help!

Ask a Question