gmarche/src/Gmarche/Table/AntenneTable.php

66 lines
2.0 KiB
PHP

<?php
namespace App\Gmarche\Table;
use App\Gmarche\Entity\Antenne;
use Framework\Database\Query;
use Framework\Database\Table;
class AntenneTable extends Table
{
protected $entity = Antenne::class;
protected $table = 'antennes';
public function findAllbyRegion(int $region_id): Query
{
$region = new RegionTable($this->pdo);
return $this->makeQuery()
->join($region->getTable() . ' as r', 'a.region_id = r.id')
->select('a.*')
->where("a.region_id = $region_id")
->order('a.name ASC');
}
public function findAllRegions(): Query
{
//$region = new RegionTable($this->pdo);
$table = 'regions';
return $this->makeQuery()
->select('r.*')
->order('r.name ASC');
}
public function findAnyAntennes(string $tri, $antennes_select): Query
{
$region = new RegionTable($this->pdo);
if ($tri == 'tri_alpha') {
$order = 'a.name ASC';
} else {
$order = 'r.name, a.name ASC';
}
return $this->makeQuery()
->join($region->getTable() . ' as r', 'region_id = r.id')
->select('a.id, region_id as regionId, r.name as regionName, a.name as antenneName,
r.slug as regionSlug, a.slug as antenneSlug, edito1, edito2, edito3, edito4, gmarcheAt')
->where("a.id IN ($antennes_select)")
->order($order);
}
public function findAllAntennes(string $tri): Query
{
$region = new RegionTable($this->pdo);
if ($tri == 'tri_alpha') {
$order = 'a.name ASC';
} else {
$order = 'r.name, a.name ASC';
}
return $this->makeQuery()
->join($region->getTable() . ' as r', 'region_id = r.id')
->select('a.id, region_id as regionId, r.name as regionName, a.name as antenneName,
r.slug as regionSlug, a.slug as antenneSlug, edito1, edito2, edito3, edito4, gmarcheAt')
->order($order);
}
}