Neyi Nerede Göstereceğiz? - Spotify Business Pattern
Spotify Business'ın yaptığı gibi: Farklı sayfalarda farklı koleksiyonlar göstermek!
placement_rules JSON field ekleyeceğiz
{
"placement_rules": {
"pages": ["sector_show"],
"sector_ids": [1],
"position": 1
}
}
{
"placement_rules": {
"pages": ["home"],
"sector_ids": null,
"position": 2
}
}
{
"placement_rules": {
"pages": ["sector_show"],
"sector_ids": null,
"position": 3
}
}
muzibu_content_collections: - display_rules JSON - visibility_conditions JSON - priority INT
muzibu_content_collections:
- display_rules JSON
- visibility_conditions JSON
- placement_rules JSON ⭐ YENİ!
- priority INT
{
"pages": ["home", "sector_show", "sector_index", "playlists_index"],
"sector_ids": [1, 2, 3], // null = tüm sektörler
"category_ids": [5, 6], // null = tüm kategoriler
"tag_ids": [2, 3], // null = tüm taglar
"position": 1, // Sayfa içinde sıralama (1,2,3...)
"zone": "main" // "main", "sidebar", "footer"
}
public function getCollectionsForPage(
string $page,
$sectorId = null,
$categoryId = null,
$tagId = null,
$user = null
): Collection {
$now = now();
$dayOfWeek = $now->format('D');
$currentTime = $now->format('H:i');
return ContentCollection::where('is_active', true)
->get()
->filter(function($collection) use (
$page, $sectorId, $categoryId, $tagId,
$user, $dayOfWeek, $currentTime
) {
// 1. Placement Rules Check ⭐ YENİ!
if (!$this->checkPlacementRules(
$collection,
$page,
$sectorId,
$categoryId,
$tagId
)) {
return false;
}
// 2. Display Rules Check (mevcut)
if (!$this->checkDisplayRules(
$collection,
$dayOfWeek,
$currentTime,
$sectorId
)) {
return false;
}
// 3. Visibility Conditions Check (mevcut)
if (!$this->checkVisibilityConditions(
$collection,
$user
)) {
return false;
}
return true;
})
->sortBy(function($collection) {
return $collection->placement_rules['position'] ?? 999;
});
}
private function checkPlacementRules(
$collection,
$page,
$sectorId,
$categoryId,
$tagId
): bool {
$rules = $collection->placement_rules;
// Page check
if (isset($rules['pages']) && !in_array($page, $rules['pages'])) {
return false;
}
// Sector check
if (isset($rules['sector_ids']) && $rules['sector_ids'] !== null) {
if ($sectorId && !in_array($sectorId, $rules['sector_ids'])) {
return false;
}
}
// Category check
if (isset($rules['category_ids']) && $rules['category_ids'] !== null) {
if ($categoryId && !in_array($categoryId, $rules['category_ids'])) {
return false;
}
}
// Tag check
if (isset($rules['tag_ids']) && $rules['tag_ids'] !== null) {
if ($tagId && !in_array($tagId, $rules['tag_ids'])) {
return false;
}
}
return true;
}
{
"placement_rules": {
"pages": ["home", "sector_show"],
"sector_ids": [1],
"position": 1,
"zone": "main"
}
}
Cafe işletmeniz için özel seçilmiş müzikler
Barista favourites
placement_rules ile neyi nerede göstereceğimizi dinamik olarak kontrol ediyoruz
placement_rules JSON field eklegetCollectionsForPage() method ekle