Commit 16db6135 authored by Mahmoud Aglan's avatar Mahmoud Aglan

feat(website): let the branches block announce a location before it opens

Checking the rendered result against the client's own branch data showed the
block was reproducing the wrong rule. Their site lists fifteen branches and dims
nine of them, each captioned with the dates it opens — the dimming tracks
whether the branch is switched on, and the season window is the explanation
shown to the reader, not the test.

Ours filtered `is_active = false` out of the query entirely, so those nine
simply did not exist on the page. A branch under construction is exactly the
thing a marketing site wants to show.

- `getBranches()` takes `$includeInactive`, cached under its own key so the two
  result sets cannot overwrite each other.
- `data_branches` offers `show_inactive`, and treats a branch as dormant when it
  is switched off OR outside its declared season — a branch with no window stays
  open all year, as before.
- Open branches sort first, so an announced-but-closed location never pushes a
  working one below the fold.

Verified on the local replica with two dormant branches alongside seven live
ones: the dormant pair render dimmed with their location and opening dates while
the rest keep the accent border. 22 page/locale combinations answer 200 with no
logged block failures, 137 block/variant combinations render, suite passes.
Co-Authored-By: 's avatarClaude Opus 5 (1M context) <noreply@anthropic.com>
parent 21792905
...@@ -46,6 +46,8 @@ protected function extraFields(): array ...@@ -46,6 +46,8 @@ protected function extraFields(): array
BlockField::toggle('show_phone', 'إظهار الهاتف'), BlockField::toggle('show_phone', 'إظهار الهاتف'),
BlockField::toggle('show_manager', 'إظهار اسم المسؤول'), BlockField::toggle('show_manager', 'إظهار اسم المسؤول'),
BlockField::toggle('show_hours', 'إظهار مواعيد العمل'), BlockField::toggle('show_hours', 'إظهار مواعيد العمل'),
BlockField::toggle('show_inactive', 'إظهار الفروع غير المفعّلة')
->help('تظهر باهتة مع تاريخ الافتتاح، لإعلان فرع قبل بدء العمل به'),
BlockField::toggle('show_season', 'إظهار موسم العمل')->default(true) BlockField::toggle('show_season', 'إظهار موسم العمل')->default(true)
->help('يعرض تاريخ فتح الفرع ويُخفت الفروع خارج موسمها'), ->help('يعرض تاريخ فتح الفرع ويُخفت الفروع خارج موسمها'),
BlockField::text('card_hint', 'نص أسفل البطاقة') BlockField::text('card_hint', 'نص أسفل البطاقة')
......
...@@ -31,7 +31,7 @@ public function for(WebsiteBlock $block, array $context = []): Collection ...@@ -31,7 +31,7 @@ public function for(WebsiteBlock $block, array $context = []): Collection
$limit = (int) ($block->get('limit') ?: 0); $limit = (int) ($block->get('limit') ?: 0);
$items = match ($block->type) { $items = match ($block->type) {
'data_branches' => $this->data->getBranches($academy), 'data_branches' => $this->data->getBranches($academy, (bool) $block->get('show_inactive')),
'data_programs' => $this->data->getPrograms($academy), 'data_programs' => $this->data->getPrograms($academy),
'data_activities' => $this->data->getActivities($academy), 'data_activities' => $this->data->getActivities($academy),
'data_news' => $this->data->getNews($academy, $limit ?: 6), 'data_news' => $this->data->getNews($academy, $limit ?: 6),
......
...@@ -63,17 +63,24 @@ public function getPrograms(Academy $academy): Collection ...@@ -63,17 +63,24 @@ public function getPrograms(Academy $academy): Collection
return $result; return $result;
} }
public function getBranches(Academy $academy): Collection /**
* @param bool $includeInactive also return branches that are switched off,
* so a site can announce a location before it
* opens instead of hiding it until launch day.
*/
public function getBranches(Academy $academy, bool $includeInactive = false): Collection
{ {
$key = "website.{$academy->id}.branches".($includeInactive ? '.all' : '');
$result = Cache::remember( $result = Cache::remember(
"website.{$academy->id}.branches", $key,
3600, 3600,
fn () => $this->branchQuery($academy)->get() fn () => $this->branchQuery($academy, $includeInactive)->get()
); );
if (!$result instanceof Collection) { if (!$result instanceof Collection) {
Cache::forget("website.{$academy->id}.branches"); Cache::forget($key);
return $this->branchQuery($academy)->get(); return $this->branchQuery($academy, $includeInactive)->get();
} }
return $result; return $result;
...@@ -86,12 +93,15 @@ public function getBranches(Academy $academy): Collection ...@@ -86,12 +93,15 @@ public function getBranches(Academy $academy): Collection
* the deleted_at check a branch removed in the ERP keeps appearing on the * the deleted_at check a branch removed in the ERP keeps appearing on the
* website until someone notices. * website until someone notices.
*/ */
private function branchQuery(Academy $academy) private function branchQuery(Academy $academy, bool $includeInactive = false)
{ {
return DB::table('branches') return DB::table('branches')
->where('academy_id', $academy->id) ->where('academy_id', $academy->id)
->where('is_active', true) ->when(! $includeInactive, fn ($q) => $q->where('is_active', true))
->whereNull('deleted_at') ->whereNull('deleted_at')
// Open branches first, so an announced-but-closed location never
// pushes a working one below the fold.
->orderByDesc('is_active')
->orderByDesc('is_main') ->orderByDesc('is_main')
->orderBy('id'); ->orderBy('id');
} }
......
...@@ -47,7 +47,9 @@ class="ec-surface w-full rounded-full px-5 py-3 focus:outline-none focus:ring-2" ...@@ -47,7 +47,9 @@ class="ec-surface w-full rounded-full px-5 py-3 focus:outline-none focus:ring-2"
$name = $ar ? ($branch->name_ar ?? $branch->name) : ($branch->name ?? $branch->name_ar); $name = $ar ? ($branch->name_ar ?? $branch->name) : ($branch->name ?? $branch->name_ar);
$loc = $branch->address ?? $branch->location ?? null; $loc = $branch->address ?? $branch->location ?? null;
$photo = $branch->photo_path ?? null; $photo = $branch->photo_path ?? null;
$open = $inSeason($branch); // A branch reads as dormant when it is switched off, or when
// today falls outside its declared season.
$open = ($branch->is_active ?? true) && $inSeason($branch);
$from = filled($branch->season_starts_on ?? null) ? \Illuminate\Support\Carbon::parse($branch->season_starts_on) : null; $from = filled($branch->season_starts_on ?? null) ? \Illuminate\Support\Carbon::parse($branch->season_starts_on) : null;
$to = filled($branch->season_ends_on ?? null) ? \Illuminate\Support\Carbon::parse($branch->season_ends_on) : null; $to = filled($branch->season_ends_on ?? null) ? \Illuminate\Support\Carbon::parse($branch->season_ends_on) : null;
@endphp @endphp
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment