wikipoints/models/Category.php

44 lines
1.0 KiB
PHP

<?php
class Category extends Model
{
private static $categories = NULL;
public static $paidIds = array(24,25,26);
function __construct($fromArray = array())
{
$this->_tableName_ = 'categories';
parent::__construct($fromArray);
$this->setRelation('points', 'id', 'Point', 'categoryId', self::TO_MANY);
}
static function model()
{
return new self();
}
static function getIcoById($id)
{
if (self::$categories === NULL) {
self::$categories = self::model()->getAll(array('asArray'=>true));
}
return (isset(self::$categories[$id])) ? self::$categories[$id]['icon'] : NULL;
}
public function getCategoriesForChoise()
{
if (App::$user && App::$user->isAdmin == 1) {
return $this->getAll(array('order' => 'ord ASC', 'asArray' => true));
} else {
return $this->getAll(array('where' => '`id` NOT IN ('. implode(',', self::$paidIds).')', 'order' => 'ord ASC', 'asArray' => true));
}
}
public static function isPaidCategory($id)
{
return array_search($id, self::$paidIds) !== FALSE;
}
}