_tableName_ = 'favorites'; parent::__construct($fromArray); $this->setRelation('user', 'userId', 'User', 'id', self::TO_ONE); $this->setRelation('point', 'pointId', 'Point', 'id', self::TO_ONE); } static function model() { return new self(); } public static function addRemove($pointId) { if (!App::$user || !App::$user->id || !$pointId) return false; $res = self::model()->getAll(array('where' => '`userId` = ' . (int) App::$user->id . ' AND `pointId` = ' . (int) $pointId, 'limit' => 1)); if ($res) { return Helper::boolval(Favorite::model()->delete($res->id)); } else { return Favorite::model()->add(array('userId' => App::$user->id, 'pointId' => $pointId)); } } public function getAllMy() { if (!App::$user || !App::$user->id) return false; return $this->getAll(array('where' => '`userId` = ' . (int) App::$user->id)); } public function checkIsMy($pointId) { if (!App::$user || !App::$user->id || !$pointId) return false; return Helper::boolval($this->getAll(array('where' => '`userId` = ' . (int) App::$user->id . ' AND `pointId` = ' . (int) $pointId))); } }