2012-07-12 14:59:53 -04:00

38 lines
996 B
PHP

<?php
class Crunchbutton_Community extends Cana_Table {
public static function all() {
return self::q('select community.* from community order by name');
}
public function restaurants() {
if (!isset($this->_restaurants)) {
$this->_restaurants = Restaurant::q('
select restaurant.* from restaurant
left join restaurant_community using(id_restaurant)
where id_community="'.$this->id_community.'"
order by restaurant.delivery asc
');
}
return $this->_restaurants;
}
public function exports() {
$out = $this->properties();
foreach ($this->restaurants() as $restaurant) {
$out['_restaurants'][$restaurant->id_restaurant] = $restaurant->exports();
}
return $out;
}
public static function permalink($permalink) {
return self::q('select * from community where permalink="'.$permalink.'"')->get(0);
}
public function __construct($id = null) {
parent::__construct();
$this
->table('community')
->idVar('id_community')
->load($id);
}
}