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/Sitemap.php

<?php

namespace App\View\Composers;

use Roots\Acorn\View\Composer;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;

use App\View\Composers\Lineup;
use App\View\Composers\GraphqlData;
use App\Facades\Genius;

class Sitemap extends Composer
{
    /**
     * List of views served by this composer.
     *
     * @var array
     */
    protected static $views = [
      'template-sitemap'
    ];

    /**
     * Data to be passed to view before rendering.
     *
     * @return array
     */
    public function with()
    {
        return [
          'sitemapModelTrims' => $this->getModelTrims(),
          'sitemapModelsTrims' => $this->getModelTrimsSitemap(),
          'lineupDataSitemap' => $this->getLineupDataSitemap(),
          'showroomDataSitemap' => $this->getShowroomDataSitemap(),
        ];
    }

    /**
     * Get the models from manufacturer.
     *
     * @return array
     */
    public function getModels() : array
    {
      return Cache::remember('sitemap-models', now()->endOfDay(), function () {
        return collect((New Lineup)->getLineupData())
        ->transform(function ($item) {
          return $item = Str::of(Str::lower($item['year'] . '-' . $item['make'] . '-' . str_replace(' ', '-', $item['model'])))->slug();
        })
        ->all();
      });
    }

    /**
     * Get the model trims from manufacturer.
     *
     * @return array
     */
    public function getModelTrims() : array
    {
      return Cache::remember('sitemap-model-trims', now()->endOfDay(), function () {
        $query = '
          {
            modelLists(first: 200, where: { search: "'.get_leadbox_manufacturer().'" }) {
              nodes {
                modelData {
                  trims {
                    ...on ModelTrim {
                      slug
                    }
                  }
                }
              }
            }
          }
        ';
        return (New GraphqlData)->getGraphData($query)
          ->pluck('modelData.trims')
          ->flatten()
          ->reject(function ($trim) {
            return $trim === null;
          })
          ->all();
      });
    }

    public function getModelTrimsSitemap(): array
    {
        $lbsettings = get_leadbox_settings(); 
        $other_makes = $lbsettings['all_brands'] ?? '';
        // Si no te pasan other_makes, intenta leerlos del settings
        if ($other_makes === '') {
            $lb = get_leadbox_settings();
            $other_makes = is_array($lb['all_brands'] ?? null)
                ? implode(',', $lb['all_brands'])
                : (string) ($lb['all_brands'] ?? '');
        }

        // 1) Lista de makes: principal + adicionales (si vienen)
        $primaryMake = (string) get_leadbox_manufacturer();

        $makes = collect(array_merge(
            [$primaryMake],
            array_map('trim', explode(',', (string) $other_makes))
        ))
            ->map(fn ($m) => (string) $m)
            ->filter()       // quita vacíos
            ->unique()       // evita duplicados
            ->map(function ($m) { // sanitizar: letras, números, espacio y guion
                return preg_replace('/[^a-z0-9 \-]/i', '', $m) ?? '';
            })
            ->filter()
            ->values();

        // Cache per set de makes
        $cacheKey = 'sitemap-model-trims:' . md5($makes->implode(','));

        return Cache::remember($cacheKey, now()->endOfDay(), function () use ($makes) {
            $all = collect();

            foreach ($makes as $make) {
                $query = '
                {
                  modelLists(first: 200, where: { search: "'.addslashes($make).'" }) {
                    nodes {
                      modelData {
                        trims {
                          ... on ModelTrim {
                            slug
                          }
                        }
                      }
                    }
                  }
                }
                ';

                $chunk = (new GraphqlData)->getGraphData($query);

                // Normaliza a Collection y concatena trims
                if ($chunk instanceof \Illuminate\Support\Collection) {
                    $all = $all->concat(
                        $chunk->pluck('modelData.trims')->flatten()
                    );
                } elseif (is_array($chunk)) {
                    $all = $all->concat(
                        collect($chunk)->pluck('modelData.trims')->flatten()
                    );
                } elseif ($chunk instanceof \stdClass) {
                    $all = $all->concat(
                        collect((array) $chunk)->pluck('modelData.trims')->flatten()
                    );
                }
            }

            // Limpieza final
            return $all
                ->reject(fn ($trim) => $trim === null)
                // si quieres deduplicar por slug:
                ->unique(function ($trim) {
                    return is_array($trim) ? ($trim['slug'] ?? null) : (is_object($trim) ? ($trim->slug ?? null) : $trim);
                })
                ->values()
                ->all();
        });
    }

    /**
     * Get the showroom models from manufacturer.
     *
     * @return array
     */
    public function getShowroomModels() : array
    {
      return Cache::remember('sitemap-showroom-models', now()->endOfDay(), function () {
        $query = '
          {
          modelLists(first: 100, where: { search: "'.get_leadbox_manufacturer().'" }) {
            nodes {
              databaseId
              modelData {
                category
                year
                make
                model
              }
              }
            }
          }
        ';
        return (New GraphqlData)->getGraphData($query)
          ->reject(function ($row) {
            $excludedModelsOption = Str::lower(get_option('dealer-settings-showroom-options')['excluded_models']);
            if( strlen($excludedModelsOption) > 0 ) {
              $excludedModels = Str::of($excludedModelsOption)
                ->explode(',')
                ->transform(function ($model) {
                  return Str::of($model)->trim();
                })
                ->all();
                
              return in_array(Str::lower($row['modelData']['model']), $excludedModels);
            } else {
              return null;
            }
          })
          ->transform(function ($row) {
            return $row = Str::lower($row['modelData']['year'] . '-' . $row['modelData']['make'] . '-' . str_replace(' ', '-', $row['modelData']['model'])) . '_' . $row['databaseId'];
          })
          ->all();
      });
    }

    /**
     * Get showroom data for all brands (manufacturer + other brands).
     *
     * @return array
     */
    public function getShowroomDataSitemap(): array
    {
        $lbsettings = get_leadbox_settings();
        $other_makes = $lbsettings['all_brands'] ?? '';

        $primaryMake = (string) get_leadbox_manufacturer();

        $makes = collect(array_merge(
            [$primaryMake],
            array_map('trim', explode(',', (string) $other_makes))
        ))
            ->map(fn ($m) => (string) $m)
            ->filter()
            ->unique()
            ->values();

        $cacheKey = 'sitemap-showroom-data:' . md5($makes->implode(','));

        return Cache::remember($cacheKey, now()->endOfDay(), function () use ($makes) {
            $all = collect();

            foreach ($makes as $make) {
                $query = '
                {
                  modelLists(first: 100, where: { search: "'.addslashes($make).'", orderby: {field: DATE, order: ASC} }) {
                    nodes {
                      date
                      databaseId
                      modelData {
                        category
                        year
                        make
                        model
                        startingPrice
                        jellybean {
                          sourceUrl(size: MEDIUM)
                        }
                      }
                    }
                  }
                }
                ';

                $chunk = (new GraphqlData)->getGraphData($query);

                if ($chunk instanceof \Illuminate\Support\Collection) {
                    $all = $all->concat($chunk);
                } elseif (is_array($chunk)) {
                    $all = $all->concat($chunk);
                } elseif ($chunk instanceof \stdClass) {
                    $all = $all->concat((array) $chunk);
                }
            }

            if ($all->isEmpty()) {
                return [];
            }

            return $all
                ->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);
                })
                ->map(function ($row) {
                    $row['modelData']['id'] = $row['databaseId'];
                    $row['modelData']['date'] = $row['date'];
                    return $row;
                })
                ->pluck('modelData')
                ->sortBy(['date', 'asc'])
                ->all();
        });
    }

    public function getLineupDataSitemap(): array
    {   
        $lbsettings = get_leadbox_settings(); 
        $other_makes = $lbsettings['all_brands'] ?? '';

        $primaryMake = (string) get_leadbox_manufacturer();

        $makes = collect(array_merge(
            [$primaryMake],
            array_map('trim', explode(',', (string) $other_makes))
        ))
            ->map(fn ($m) => (string) $m)
            ->filter() 
            ->unique() 
            ->values();

        $all = collect();

        foreach ($makes as $make) {
            $query = '
            {
              modelLists(first: 100, where: { search: "'.addslashes($make).'" }) {
                nodes {
                  modelData {
                    year
                    make
                    model
                    category
                    model
                    startingPrice
                    colorizer {
                      colorName
                      colorNameFr
                      images {
                        url
                        imageType
                        image { sourceUrl(size: LARGE) }
                      }
                    }
                    jellybean { sourceUrl(size: MEDIUM) }
                  }
                }
              }
            }
            ';

            $chunk = (new GraphqlData)->getGraphData($query);

            if ($chunk instanceof \Illuminate\Support\Collection) {
                $all = $all->concat($chunk);
            } elseif (is_array($chunk)) {
                $all = $all->concat($chunk);
            } elseif ($chunk instanceof \stdClass) {
                $all = $all->concat((array) $chunk);
            }
        }

        if ($all->isEmpty()) {
            return [];
        }

        return $all
            ->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);
            })
            ->map(function ($row) {
                if (!is_array($row)) {
                    return $row;
                }

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

                        $colorizer['imageSelected'] = collect($colorizer['images'] ?? [])
                            ->filter(function ($image) {
                                return Str::lower((string)($image['imageType'] ?? '')) ===
                                      Str::lower((string) Genius::get('lineup.data.colorizer-orientation'));
                            })
                            ->map(function ($image) {
                                return !empty($image['url'])
                                    ? $image['url']
                                    : ($image['image']['sourceUrl'] ?? null);
                            })
                            ->first();

                        return $colorizer;
                    })
                    ->filter(function ($colorizer) use ($row) {
                        $selector = Genius::get("lineup.data.colorizer-selector");
                        $modelKey = Str::lower((string)($row['modelData']['model'] ?? ''));

                        if (is_array($selector) && \Illuminate\Support\Arr::exists($selector, $modelKey)) {
                            return Str::lower((string)($colorizer['colorName'] ?? '')) ===
                                  Str::lower((string) \Illuminate\Support\Arr::get($selector, $modelKey));
                        }

                        return true;
                    })
                    ->values()
                    ->all();

                return $row;
            })
            ->pluck('modelData')
            ->sortBy(['make', 'asc'],)
            ->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