function getLanguages() { $langs = LanguageModel::all(); $result = array(); foreach ($langs as $lang) { $result[] = Activerecord::createArrayFromModel($lang); } return $result; }
static function getCategoryArrayWithLanguages($category_id, $language_id = null) { $categoryObj = CategoryModel::find_by_id($category_id); if ($categoryObj != null) { $cat = Activerecord::returnArrayWithLang($categoryObj, $language_id); return $cat; } return null; }
static function getProducts($limit, $offset, $filters = null) { // TODO implement filterings $productObjects = ProductModel::all(array('limit' => $limit, 'offset' => $offset)); $products = array(); foreach ($productObjects as $p) { $products[] = Activerecord::returnArrayWithLang($p); } return $products; }
static function returnArrayWithLang($model, $language_id = null) { if ($language_id == null) { $language_obj = LanguageModel::getDefault(); $language_id = $language_obj->id; } $obj = Activerecord::createArrayFromModel($model); $lang_ref = $model::$lang_ref; $langObjects = $model->{$lang_ref}; $langArray = array(); foreach ($langObjects as $langObj) { $lang_id_field = $langObj::$lang_id_field; $lang_fields = $langObj::$fields; $lang = Activerecord::createArrayFromModel($langObj); $langArray[] = $lang; if ($langObj->{$lang_id_field} == $language_id) { foreach ($lang_fields as $f) { $obj[$f] = $langObj->{$f}; } } } $obj["lang"] = $langArray; return $obj; }
function getProduct($params) { $product = ProductModel::find_by_id($params); // GET ALL OTHER DETAILS... return Activerecord::createArrayFromModel($product, array("id", "code", "price")); }