_tableName_ = 'notifications'; parent::__construct($fromArray); $this->setRelation('RefUser', 'userId', 'User', 'id', self::TO_ONE); $this->setRelation('RefFromUser', 'fromUserId', 'User', 'id', self::TO_ONE); $this->setRelation('RefPoint', 'objectId', 'Point', 'id', self::TO_ONE); $this->setRelation('RefComment', 'objectId', 'Comment', 'id', self::TO_ONE); } static function model() { return new self(); } public static function getUnreadedCount() { if (!App::$user) { return 0; } if (self::$count === NULL) { self::$count = self::model()->getCount(array( 'where' => '`userId` = '.App::$user->id.' AND `readed` = 0', )); } return (int) self::$count; } public function setAllReaded() { if (!App::$user) { throw new Exception('Попытка пометить все новости прочитанными у неизвестного пользователя.'); } return App::DB()->query('UPDATE `' . $this->_tableName_ . '` SET `readed` = 1 WHERE `userId` = ' . App::$user->id); } }