<?php

namespace App\Models;

use App\Core\Model;

class FooterModel extends Model
{
    protected string $table = 'footer_columns';

    public function getKolom(): array
    {
        $stmt = $this->db->query("SELECT * FROM {$this->table} ORDER BY urutan ASC");
        $kolom = $stmt->fetchAll();

        foreach ($kolom as &$k) {
            if ($k['tipe'] === 'tautan') {
                $links = $this->db->prepare(
                    "SELECT * FROM footer_links WHERE footer_column_id = :id ORDER BY urutan ASC"
                );
                $links->execute(['id' => $k['id']]);
                $k['links'] = $links->fetchAll();
            } else {
                $k['links'] = [];
            }
        }

        return $kolom;
    }
}
