Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/portal/classes/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/portal/classes/PageContent.php

<?php
/**
 * PageContent Helper Class
 * Retrieves and manages page content from database
 */
class PageContent {
    private $db;
    private $cache = [];
    
    public function __construct() {
        $this->db = Database::getInstance()->getConnection();
    }
    
    /**
     * Get content for a specific page
     * @param string $pageName - The page name (about, contact, features)
     * @return array - Array of content grouped by section
     */
    public function getPageContent($pageName) {
        if (isset($this->cache[$pageName])) {
            return $this->cache[$pageName];
        }
        
        try {
            $stmt = $this->db->prepare("
                SELECT * FROM page_content 
                WHERE page_name = :page AND is_active = 1 
                ORDER BY display_order ASC
            ");
            $stmt->execute(['page' => $pageName]);
            $content = $stmt->fetchAll(PDO::FETCH_ASSOC);
            
            // Group by section
            $grouped = [];
            foreach ($content as $item) {
                $grouped[$item['section_name']][$item['content_key']] = $item['content_value'];
            }
            
            $this->cache[$pageName] = $grouped;
            return $grouped;
            
        } catch (Exception $e) {
            error_log("Error fetching page content: " . $e->getMessage());
            return [];
        }
    }
    
    /**
     * Get a specific content value
     * @param string $pageName
     * @param string $sectionName  
     * @param string $contentKey
     * @param string $default - Default value if not found
     * @return string
     */
    public function get($pageName, $sectionName, $contentKey, $default = '') {
        $content = $this->getPageContent($pageName);
        return $content[$sectionName][$contentKey] ?? $default;
    }
    
    /**
     * Get all content for a section
     * @param string $pageName
     * @param string $sectionName
     * @return array
     */
    public function getSection($pageName, $sectionName) {
        $content = $this->getPageContent($pageName);
        return $content[$sectionName] ?? [];
    }
}
?>

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists