Stuardo Rodríguez 8ff6f4c84a fixed #724, categories in different order
Chrome browsers sort the properties, but Firefox leaves them as defined.
Changed the code to put the elements in an simple array (json array) instead of
associative arrays (json objects) so that the elments are not reordered.

* forces the export for the categories, dishes and options, to be added as a
  regular array of items, not as an associative array with the id as key
* added dockblock to help the IDE with the return elements for the exports
2013-02-18 17:08:38 -05:00

66 lines
1.5 KiB
PHP

<?php
/**
* Dish categories to group the dishes in a restaurant.
*
* @package Crunchbutton.Category
* @category model
*
* @property int id_restaurant
* @property int id_category
* @property string name
* @property int sort
*/
class Crunchbutton_Category extends Cana_Table {
public function restaurant() {
return Restaurant::o($this->id_restaurant);
}
public function community() {
return $this->restaurant()->community();
}
/**
* Return the dishes ffor the current category
*
* @param array $where Associative array with the WHERE filters
*
* @return Crunchbutton_Dish[]
*/
public function dishes($where = []) {
if (!isset($this->_dishes)) {
$defaultFilters = [
'id_restaurant' => $this->id_restaurant,
'id_category' => $this->id_category,
'active' => 1,
];
if (isset($_SESSION['admin'])) {
$where['active'] = NULL;
}
$whereSql = $this->_mergeWhere($defaultFilters, $where);
$sql = "SELECT * FROM dish WHERE $whereSql ORDER BY sort ASC";
$this->_dishes = Dish::q($sql);
}
return $this->_dishes;
}
public function exports() {
$out = $this->properties();
foreach ($this->dishes() as $dish) {
$out['_dishes'][] = $dish->exports();
}
return $out;
}
public function name() {
return $this->name.($this->loc ? (' '.$this->community()->prep.' '.$this->community()->name) : '');
}
public function __construct($id = null) {
parent::__construct();
$this
->table('category')
->idVar('id_category')
->load($id);
}
}