73 lines
1.8 KiB
PHP
73 lines
1.8 KiB
PHP
<?php
|
||
|
||
namespace App\Models;
|
||
|
||
use Config\Database;
|
||
|
||
/**
|
||
* IDEE-5 — lecture proto Radar (exceptions + fils + skills).
|
||
* Le moteur Gmail/Gemini n’écrit pas encore ici.
|
||
*/
|
||
class RadarModel
|
||
{
|
||
private function db()
|
||
{
|
||
return Database::connect();
|
||
}
|
||
|
||
public function tablesExist(): bool
|
||
{
|
||
$row = $this->db()->query("SHOW TABLES LIKE 'radar_threads'")->getRowArray();
|
||
|
||
return !empty($row);
|
||
}
|
||
|
||
public function listExceptions(): array
|
||
{
|
||
return $this->db()->table('radar_exceptions')
|
||
->where('active', 1)
|
||
->orderBy('kind', 'ASC')
|
||
->orderBy('value', 'ASC')
|
||
->get()
|
||
->getResultArray();
|
||
}
|
||
|
||
public function listThreads(): array
|
||
{
|
||
$rows = $this->db()->table('radar_threads')
|
||
->orderBy('received_at', 'DESC')
|
||
->orderBy('id', 'DESC')
|
||
->get()
|
||
->getResultArray();
|
||
|
||
if ($rows === []) {
|
||
return [];
|
||
}
|
||
|
||
$ids = array_column($rows, 'id');
|
||
$skillRows = $this->db()->table('radar_thread_skills')
|
||
->whereIn('thread_id', $ids)
|
||
->get()
|
||
->getResultArray();
|
||
|
||
$byThread = [];
|
||
foreach ($skillRows as $s) {
|
||
$byThread[(int) $s['thread_id']][] = $s['skill'];
|
||
}
|
||
|
||
foreach ($rows as &$row) {
|
||
$id = (int) $row['id'];
|
||
$row['skills'] = $byThread[$id] ?? [];
|
||
$row['client_url'] = !empty($row['client_id'])
|
||
? '/index.php/clients/form/' . (int) $row['client_id']
|
||
: '';
|
||
$row['projet_url'] = !empty($row['projet_id'])
|
||
? '/index.php/projets/form/' . (int) $row['projet_id']
|
||
: '';
|
||
}
|
||
unset($row);
|
||
|
||
return $rows;
|
||
}
|
||
}
|