1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-06-30 21:45:01 +03:00
ifhub.club/application/classes/modules/user/entity/Friend.entity.class.php
2014-10-08 15:49:34 +07:00

198 lines
5.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/*
* LiveStreet CMS
* Copyright © 2013 OOO "ЛС-СОФТ"
*
* ------------------------------------------------------
*
* Official site: www.livestreetcms.com
* Contact e-mail: office@livestreetcms.com
*
* GNU General Public License, version 2:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
* ------------------------------------------------------
*
* @link http://www.livestreetcms.com
* @copyright 2013 OOO "ЛС-СОФТ"
* @author Maxim Mzhelskiy <rus.engine@gmail.com>
*
*/
/**
* Сущность дружбу - связи пользователей друг с другом
*
* @package application.modules.user
* @since 1.0
*/
class ModuleUser_EntityFriend extends Entity
{
/**
* При переданном параметре $sUserId возвращает тот идентификатор,
* который не равен переданному
*
* @param string|null $sUserId ID пользователя
* @return string
*/
public function getFriendId($sUserId = null)
{
if (!$sUserId) {
$sUserId = $this->getUserId();
}
if ($this->_getDataOne('user_from') == $sUserId) {
return $this->_aData['user_to'];
}
if ($this->_getDataOne('user_to') == $sUserId) {
return $this->_aData['user_from'];
}
return false;
}
/**
* Получает идентификатор пользователя,
* относительно которого был сделан запрос
*
* @return int
*/
public function getUserId()
{
return $this->_getDataOne('user');
}
/**
* Возвращает ID пользователя, который приглашает в друзья
*
* @return int|null
*/
public function getUserFrom()
{
return $this->_getDataOne('user_from');
}
/**
* Возвращает ID пользователя, которого пришлашаем в друзья
*
* @return int|null
*/
public function getUserTo()
{
return $this->_getDataOne('user_to');
}
/**
* Возвращает статус заявки на добавления в друзья у отправителя
*
* @return int|null
*/
public function getStatusFrom()
{
return $this->_getDataOne('status_from');
}
/**
* Возвращает статус заявки на добавления в друзья у получателя
*
* @return int|null
*/
public function getStatusTo()
{
return $this->_getDataOne('status_to') ? $this->_getDataOne('status_to') : ModuleUser::USER_FRIEND_NULL;
}
/**
* Возвращает статус дружбы
*
* @return int|null
*/
public function getFriendStatus()
{
return $this->getStatusFrom() + $this->getStatusTo();
}
/**
* Возвращает статус дружбы для конкретного пользователя
*
* @param int $sUserId ID пользователя
* @return bool|int
*/
public function getStatusByUserId($sUserId)
{
if ($sUserId == $this->getUserFrom()) {
return $this->getStatusFrom();
}
if ($sUserId == $this->getUserTo()) {
return $this->getStatusTo();
}
return false;
}
/**
* Устанавливает ID пользователя, который приглашает в друзья
*
* @param int $data
*/
public function setUserFrom($data)
{
$this->_aData['user_from'] = $data;
}
/**
* Устанавливает ID пользователя, которого пришлашаем в друзья
*
* @param int $data
*/
public function setUserTo($data)
{
$this->_aData['user_to'] = $data;
}
/**
* Устанавливает статус заявки на добавления в друзья у отправителя
*
* @param int $data
*/
public function setStatusFrom($data)
{
$this->_aData['status_from'] = $data;
}
/**
* Возвращает статус заявки на добавления в друзья у получателя
*
* @param int $data
*/
public function setStatusTo($data)
{
$this->_aData['status_to'] = $data;
}
/**
* Устанавливает ID пользователя
*
* @param int $data
*/
public function setUserId($data)
{
$this->_aData['user'] = $data;
}
/**
* Возвращает статус дружбы для конкретного пользователя
*
* @param int $data Статус
* @param int $sUserId ID пользователя
* @return bool
*/
public function setStatusByUserId($data, $sUserId)
{
if ($sUserId == $this->getUserFrom()) {
$this->setStatusFrom($data);
return true;
}
if ($sUserId == $this->getUserTo()) {
$this->setStatusTo($data);
return true;
}
return false;
}
}