"; $output .= "

Campaign Folders (" . count($assetList) . " found)

"; foreach ($assetList as $index => $asset) { $output .= "
"; // Basic asset info $assetName = self::getMetadataValue($asset, 'FERRERO.FIELD.CAMPAIGN_NAME') ?? 'Unnamed Campaign'; $output .= "

Campaign " . ($index + 1) . ": " . htmlspecialchars($assetName) . "

"; $output .= "

Asset ID: " . htmlspecialchars($asset['asset_id'] ?? 'N/A') . "

"; $output .= "

Type: " . htmlspecialchars($asset['data_type'] ?? 'N/A') . "

"; // Campaign metadata if (isset($asset['metadata'])) { $output .= "
"; $output .= "
Campaign Information:
"; // Campaign ID $campaignId = self::getMetadataValue($asset, 'FERRERO.FIELD.CAMPAIGN ID'); if ($campaignId) { $output .= "

Campaign ID: " . htmlspecialchars($campaignId) . "

"; } // Campaign Name $campaignName = self::getMetadataValue($asset, 'FERRERO.FIELD.CAMPAIGN NAME'); if ($campaignName) { $output .= "

Campaign Name: " . htmlspecialchars($campaignName) . "

"; } // Campaign Type $campaignType = self::getMetadataValue($asset, 'FERRERO.FIELD.CAMPAIGN TYPE'); if ($campaignType) { $output .= "

Campaign Type: " . htmlspecialchars($campaignType) . "

"; } // Brand $brand = self::getMetadataValue($asset, 'FERRERO.FIELD.CAMPAIGN_BRAND'); if ($brand) { $output .= "

Brand: " . htmlspecialchars($brand) . "

"; } // Market $market = self::getMetadataValue($asset, 'FERRERO.FIELD.CAMPAIGN_MARKET'); if ($market) { $output .= "

Market: " . htmlspecialchars($market) . "

"; } // Fiscal Year $fiscalYear = self::getMetadataValue($asset, 'FERRERO.FIELD.CAMPAIGN FISCAL YEAR'); if ($fiscalYear) { $output .= "

Fiscal Year: " . htmlspecialchars($fiscalYear) . "

"; } // Stage $stage = self::getMetadataValue($asset, 'FERRERO.FIELD.SG.STAGE'); if ($stage) { $output .= "

Stage: " . htmlspecialchars($stage) . "

"; } $output .= "
"; } // Dates if (isset($asset['date_imported'])) { $output .= "

Imported: " . htmlspecialchars($asset['date_imported']) . "

"; } if (isset($asset['date_last_updated'])) { $output .= "

Last Updated: " . htmlspecialchars($asset['date_last_updated']) . "

"; } // Show all campaigns without filtering for now $campaignType = self::getMetadataValue($asset, 'FERRERO.FIELD.CAMPAIGN TYPE'); $stage = self::getMetadataValue($asset, 'FERRERO.FIELD.SG.STAGE'); $output .= "
"; $output .= "📊 Campaign Status:
"; $output .= "Type: " . htmlspecialchars($campaignType ?? 'Not specified') . "
"; $output .= "Stage: " . htmlspecialchars($stage ?? 'Not specified'); $output .= "
"; $output .= "
"; } $output .= ""; // Analysis Summary $typeAnalysis = []; $stageAnalysis = []; $brandAnalysis = []; $marketAnalysis = []; foreach ($assetList as $asset) { // Campaign Types $type = self::getMetadataValue($asset, 'FERRERO.FIELD.CAMPAIGN TYPE'); if ($type) { $typeAnalysis[$type] = ($typeAnalysis[$type] ?? 0) + 1; } // Stages $stage = self::getMetadataValue($asset, 'FERRERO.FIELD.SG.STAGE'); if ($stage) { $stageAnalysis[$stage] = ($stageAnalysis[$stage] ?? 0) + 1; } // Brands $brand = self::getMetadataValue($asset, 'FERRERO.FIELD.CAMPAIGN_BRAND'); if ($brand) { $brandAnalysis[$brand] = ($brandAnalysis[$brand] ?? 0) + 1; } // Markets $market = self::getMetadataValue($asset, 'FERRERO.FIELD.CAMPAIGN_MARKET'); if ($market) { $marketAnalysis[$market] = ($marketAnalysis[$market] ?? 0) + 1; } } $output .= "
"; $output .= "

Campaign Analysis

"; $output .= "

Total Campaigns Found: " . count($assetList) . "

"; // Campaign Types Breakdown if (!empty($typeAnalysis)) { $output .= "
"; $output .= "
Campaign Types:
"; arsort($typeAnalysis); foreach ($typeAnalysis as $type => $count) { $output .= "
"; $output .= "" . htmlspecialchars($type) . ": " . $count . " campaigns"; $output .= "
"; } $output .= "
"; } // Stage Breakdown if (!empty($stageAnalysis)) { $output .= "
"; $output .= "
Campaign Stages:
"; arsort($stageAnalysis); foreach ($stageAnalysis as $stage => $count) { $output .= "
"; $output .= "" . htmlspecialchars($stage) . ": " . $count . " campaigns"; $output .= "
"; } $output .= "
"; } // Brand Breakdown (top 10) if (!empty($brandAnalysis)) { $output .= "
"; $output .= "
Top Brands:
"; arsort($brandAnalysis); $topBrands = array_slice($brandAnalysis, 0, 10, true); foreach ($topBrands as $brand => $count) { $output .= "
"; $output .= "" . htmlspecialchars($brand) . ": " . $count; $output .= "
"; } $output .= "
"; } // Market Breakdown if (!empty($marketAnalysis)) { $output .= "
"; $output .= "
Markets:
"; arsort($marketAnalysis); foreach ($marketAnalysis as $market => $count) { $output .= "
"; $output .= "" . htmlspecialchars($market) . ": " . $count; $output .= "
"; } $output .= "
"; } $output .= "
"; return $output; } private static function getMetadataValue($asset, $fieldId) { if (!isset($asset['metadata']['metadata_element_list'])) { return null; } foreach ($asset['metadata']['metadata_element_list'] as $category) { if (!isset($category['metadata_element_list'])) { continue; } foreach ($category['metadata_element_list'] as $element) { if ($element['id'] === $fieldId && isset($element['value']['value']['value'])) { return $element['value']['value']['value']; } // Handle tabular fields (like brand, market) if (isset($element['metadata_element_list'])) { foreach ($element['metadata_element_list'] as $tableField) { if ($tableField['id'] === $fieldId && isset($tableField['value']['value']['value'])) { return $tableField['value']['value']['value']; } // Handle domain values if ($tableField['id'] === $fieldId && isset($tableField['value']['value']['field_value']['value'])) { return $tableField['value']['value']['display_value'] ?? $tableField['value']['value']['field_value']['value']; } } } } } return null; } private static function doesCampaignNeedAction($asset) { // Get campaign type and stage to determine if action is needed $campaignType = self::getMetadataValue($asset, 'FERRERO.FIELD.CAMPAIGN TYPE'); $stage = self::getMetadataValue($asset, 'FERRERO.FIELD.SG.STAGE'); // Example criteria - adjust based on your business logic $actionableTypes = [ 'Local adaptation of global comm', 'Local campaign creation', 'Active' ]; $actionableStages = [ '3 - Production & execution', '4 – Campaign Approved' ]; if ($campaignType && in_array($campaignType, $actionableTypes)) { return true; } if ($stage && in_array($stage, $actionableStages)) { return true; } return false; } public static function formatAssetFolders($jsonResponse) { $data = json_decode($jsonResponse, true); if (!$data || !isset($data['items'])) { return "No asset folders found or invalid response format."; } $output = "
"; $output .= "

Asset Folders (" . count($data['items']) . " found)

"; foreach ($data['items'] as $index => $folder) { $output .= "
"; $output .= "

Folder " . ($index + 1) . ": " . htmlspecialchars($folder['name'] ?? 'Unnamed') . "

"; $output .= "

ID: " . htmlspecialchars($folder['id'] ?? 'N/A') . "

"; $output .= "

Type: " . htmlspecialchars($folder['type'] ?? 'N/A') . "

"; // Check if it's a master asset or final asset folder $folderName = strtolower($folder['name'] ?? ''); if (strpos($folderName, 'master') !== false) { $output .= "Master Asset Folder"; } elseif (strpos($folderName, 'final') !== false) { $output .= "Final Asset Folder"; } $output .= "
"; } $output .= "
"; return $output; } public static function formatAssets($jsonResponse) { $data = json_decode($jsonResponse, true); if (!$data || !isset($data['items'])) { return "No assets found or invalid response format."; } $output = "
"; $output .= "

Assets (" . count($data['items']) . " found)

"; foreach ($data['items'] as $index => $asset) { $output .= "
"; $output .= "

Asset " . ($index + 1) . ": " . htmlspecialchars($asset['name'] ?? 'Unnamed') . "

"; $output .= "

ID: " . htmlspecialchars($asset['id'] ?? 'N/A') . "

"; $output .= "

Type: " . htmlspecialchars($asset['type'] ?? 'N/A') . "

"; if (isset($asset['file_size'])) { $output .= "

File Size: " . self::formatFileSize($asset['file_size']) . "

"; } if (isset($asset['mime_type'])) { $output .= "

MIME Type: " . htmlspecialchars($asset['mime_type']) . "

"; } $output .= "
"; } $output .= "
"; return $output; } private static function formatFileSize($bytes) { $units = ['B', 'KB', 'MB', 'GB']; $bytes = max($bytes, 0); $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); $pow = min($pow, count($units) - 1); $bytes /= (1 << (10 * $pow)); return round($bytes, 2) . ' ' . $units[$pow]; } public static function formatGenericResponse($jsonResponse) { $data = json_decode($jsonResponse, true); if (!$data) { return "Invalid JSON response."; } return "
" . 
               htmlspecialchars(json_encode($data, JSON_PRETTY_PRINT)) . 
               "
"; } }