File: /var/www/limestate-api/Models/Complex.php
<?php
class Complex extends Db_Model
{
static $table_name = 'complexes';
public static function getStartPrice($complexId)
{
self::$db->select('f.price')->from(Flat::$table_name . ' f')
->join(Building::$table_name . ' b', 'b.id = f.building_id')
->where('b.complex_id = ?', $complexId)
->where('b.published = 1')
->where('f.published = 1')
->order('f.price')
->fetchOne();
}
public static function getByOldId($oldId)
{
return self::$db->select()->from(self::$table_name)->where('old_ID = ?', $oldId)->fetchRow();
}
public static function fillGallery($complex, $gallery = null)
{
$gallery = is_null($gallery) ? Attachment::getComplexGallery($complex->id) : $gallery;
$complex->gallery = [];
$complex->gallery_thumbs = [];
$complex->full_thumbs = [];
foreach ($gallery as $image) {
$complex->gallery[] = $image->file;
$complex->gallery_thumbs[] = $image->file_thumb;
$complex->full_thumbs = array_merge($complex->full_thumbs, $image->full_thumbs);
}
}
}