<?php

class User extends Model
{

	function __construct($fromArray = array())
	{
		$this->_tableName_ = 'users';
		parent::__construct($fromArray);
		$this->setRelation('points', 'id', 'Point', 'id', self::TO_MANY);
	}

	static function model()
	{
		return new self();
	}

	function getByUID($uid)
	{
		$res = App::DB()->query('SELECT `id` FROM `' . $this->_tableName_ . '` WHERE `uid` = "' . $uid . '"');
		if ($res) {
			$res = $res->fetch(PDO::FETCH_ASSOC);
			$user = $this->getByPK((int) $res['id']);

			return $user;
		} else {
			return false;
		}
	}

	function getPointsCount()
	{
		return Point::model()->getCountByUser($this->id);
	}

}
