File: /var/www/limestate-api/Controllers/MetroController.php
<?php
class MetroController {
public static function actionDefault($id = null) {
$stations = Metro::find($id);
Ajax::success([
'metro' => $stations,
]);
}
public static function actionList() {
$stations = Metro::$db->select('m.*', 'l.color AS line_color', 'l.name AS line_name')
->from(Metro::$table_name . ' m')
->joinLeft(MetroLine::$table_name . ' l', 'l.id = m.line_id')
->fetchAll();
Ajax::success($stations);
}
public static function actionExpandList() {
$stations = Metro::$db->select('m.*', 'l.color AS line_color', 'l.name AS line_name', 'COUNT(c.id) complex_count')
->from(Metro::$table_name . ' m')
->joinLeft(MetroLine::$table_name . ' l', 'l.id = m.line_id')
->joinLeft(Complex::$table_name . ' c', 'm.id = c.metro_id')
->joinLeft(Building::$table_name . ' b', 'b.complex_id = c.id AND b.published = 1')
->joinLeft(Flat::$table_name . ' f', 'f.building_id = b.id AND f.published = 1')
->where('b.published = 1')
->where('c.published = 1')
->group('m.id')
->fetchAll();
Ajax::success($stations);
}
}