ModuleBlog_MapperBlog
Package | modules.blog |
---|---|
Inheritance | class ModuleBlog_MapperBlog » Mapper » LsObject |
Since | 1.0 |
Source Code | /classes/modules/blog/mapper/Blog.mapper.class.php |
Protected Properties
Property | Type | Description | Defined By |
---|---|---|---|
oDb | DbSimple_Generic_Database | Объект подключения к базе данных | Mapper |
Public Methods
Method | Description | Defined By |
---|---|---|
AddBlog() | Добавляет блог в БД | ModuleBlog_MapperBlog |
AddRelationBlogUser() | Добавляет свзяь пользователя с блогом в БД | ModuleBlog_MapperBlog |
DeleteBlog() | Удаление блога из базы данных | ModuleBlog_MapperBlog |
DeleteBlogUsersByBlogId() | Удалить пользователей блога по идентификатору блога | ModuleBlog_MapperBlog |
DeleteRelationBlogUser() | Удаляет отношение пользователя с блогом | ModuleBlog_MapperBlog |
GetBlogByTitle() | Получает блог по названию | ModuleBlog_MapperBlog |
GetBlogByUrl() | Получает блог по URL | ModuleBlog_MapperBlog |
GetBlogUsers() | Получает список отношений пользователей с блогами | ModuleBlog_MapperBlog |
GetBlogUsersByArrayBlog() | Получает список отношений пользователя к блогам | ModuleBlog_MapperBlog |
GetBlogs() | Возвращает список всех не персональных блогов | ModuleBlog_MapperBlog |
GetBlogsByArrayId() | Получает список блогов по ID | ModuleBlog_MapperBlog |
GetBlogsByFilter() | Получает список блогов по фильтру | ModuleBlog_MapperBlog |
GetBlogsByOwnerId() | Получить список блогов по хозяину | ModuleBlog_MapperBlog |
GetBlogsRating() | Возвращает список не персональных блогов с сортировкой по рейтингу | ModuleBlog_MapperBlog |
GetBlogsRatingJoin() | Получает список блогов в которых состоит пользователь | ModuleBlog_MapperBlog |
GetBlogsRatingSelf() | Получает список блогов, которые создал пользователь | ModuleBlog_MapperBlog |
GetCloseBlogs() | Возвращает полный список закрытых блогов | ModuleBlog_MapperBlog |
GetPersonalBlogByUserId() | Получает ID персонального блога пользователя | ModuleBlog_MapperBlog |
RecalculateCountTopic() | Пересчитывает число топиков в блогах | ModuleBlog_MapperBlog |
UpdateBlog() | Обновляет блог в БД | ModuleBlog_MapperBlog |
UpdateRelationBlogUser() | Обновляет отношение пользователя с блогом | ModuleBlog_MapperBlog |
__construct() | Передаем коннект к БД | Mapper |
Method Details
public int|bool AddBlog(ModuleBlog_EntityBlog $oBlog)
| ||
$oBlog | ModuleBlog_EntityBlog | Объект блога |
{return} | int|bool |
public function AddBlog(ModuleBlog_EntityBlog $oBlog) {
$sql = "INSERT INTO ".Config::Get('db.table.blog')."
(user_owner_id,
blog_title,
blog_description,
blog_type,
blog_date_add,
blog_limit_rating_topic,
blog_url,
blog_avatar
)
VALUES(?d, ?, ?, ?, ?, ?, ?, ?)
";
if ($iId=$this->oDb->query($sql,$oBlog->getOwnerId(),$oBlog->getTitle(),$oBlog->getDescription(),$oBlog->getType(),$oBlog->getDateAdd(),$oBlog->getLimitRatingTopic(),$oBlog->getUrl(),$oBlog->getAvatar())) {
return $iId;
}
return false;
}
Добавляет блог в БД
public bool AddRelationBlogUser(ModuleBlog_EntityBlogUser $oBlogUser)
| ||
$oBlogUser | ModuleBlog_EntityBlogUser | Объект отношения пользователя с блогом |
{return} | bool |
public function AddRelationBlogUser(ModuleBlog_EntityBlogUser $oBlogUser) {
$sql = "INSERT INTO ".Config::Get('db.table.blog_user')."
(blog_id,
user_id,
user_role
)
VALUES(?d, ?d, ?d)
";
if ($this->oDb->query($sql,$oBlogUser->getBlogId(),$oBlogUser->getUserId(),$oBlogUser->getUserRole())===0) {
return true;
}
return false;
}
Добавляет свзяь пользователя с блогом в БД
public bool DeleteBlog(int $iBlogId)
| ||
$iBlogId | int | ID блога |
{return} | bool |
public function DeleteBlog($iBlogId) {
$sql = "
DELETE FROM ".Config::Get('db.table.blog')."
WHERE blog_id = ?d
";
if ($this->oDb->query($sql,$iBlogId)) {
return true;
}
return false;
}
Удаление блога из базы данных
public bool DeleteBlogUsersByBlogId(int $iBlogId)
| ||
$iBlogId | int | ID блога |
{return} | bool |
public function DeleteBlogUsersByBlogId($iBlogId) {
$sql = "
DELETE FROM ".Config::Get('db.table.blog_user')."
WHERE blog_id = ?d
";
if ($this->oDb->query($sql,$iBlogId)) {
return true;
}
return false;
}
Удалить пользователей блога по идентификатору блога
public bool DeleteRelationBlogUser(ModuleBlog_EntityBlogUser $oBlogUser)
| ||
$oBlogUser | ModuleBlog_EntityBlogUser | Объект отношения пользователя с блогом |
{return} | bool |
public function DeleteRelationBlogUser(ModuleBlog_EntityBlogUser $oBlogUser) {
$sql = "DELETE FROM ".Config::Get('db.table.blog_user')."
WHERE
blog_id = ?d
AND
user_id = ?d
";
if ($this->oDb->query($sql,$oBlogUser->getBlogId(),$oBlogUser->getUserId())) {
return true;
}
return false;
}
Удаляет отношение пользователя с блогом
public ModuleBlog_EntityBlog|null GetBlogByTitle(string $sTitle)
| ||
$sTitle | string | Нащвание блога |
{return} | ModuleBlog_EntityBlog|null |
public function GetBlogByTitle($sTitle) {
$sql = "SELECT blog_id FROM ".Config::Get('db.table.blog')." WHERE blog_title = ? ";
if ($aRow=$this->oDb->selectRow($sql,$sTitle)) {
return $aRow['blog_id'];
}
return null;
}
Получает блог по названию
public ModuleBlog_EntityBlog|null GetBlogByUrl(string $sUrl)
| ||
$sUrl | string | URL блога |
{return} | ModuleBlog_EntityBlog|null |
public function GetBlogByUrl($sUrl) {
$sql = "SELECT
b.blog_id
FROM
".Config::Get('db.table.blog')." as b
WHERE
b.blog_url = ?
";
if ($aRow=$this->oDb->selectRow($sql,$sUrl)) {
return $aRow['blog_id'];
}
return null;
}
Получает блог по URL
public array GetBlogUsers(array $aFilter, int &$iCount=NULL, int $iCurrPage=NULL, int $iPerPage=NULL)
| ||
$aFilter | array | Фильтр поиска отношений |
$iCount | int | Возвращает общее количество элементов |
$iCurrPage | int | Номер текущейс страницы |
$iPerPage | int | Количество элементов на одну страницу |
{return} | array |
public function GetBlogUsers($aFilter,&$iCount=null,$iCurrPage=null,$iPerPage=null) {
$sWhere=' 1=1 ';
if (isset($aFilter['blog_id'])) {
$sWhere.=" AND bu.blog_id = ".(int)$aFilter['blog_id'];
}
if (isset($aFilter['user_id'])) {
$sWhere.=" AND bu.user_id = ".(int)$aFilter['user_id'];
}
if (isset($aFilter['user_role'])) {
if(!is_array($aFilter['user_role'])) {
$aFilter['user_role']=array($aFilter['user_role']);
}
$sWhere.=" AND bu.user_role IN ('".join("', '",$aFilter['user_role'])."')";
} else {
$sWhere.=" AND bu.user_role>".ModuleBlog::BLOG_USER_ROLE_GUEST;
}
$sql = "SELECT
bu.*
FROM
".Config::Get('db.table.blog_user')." as bu
WHERE
".$sWhere." ";
if (is_null($iCurrPage)) {
$aRows=$this->oDb->select($sql);
} else {
$sql.=" LIMIT ?d, ?d ";
$aRows=$this->oDb->selectPage($iCount,$sql,($iCurrPage-1)*$iPerPage, $iPerPage);
}
$aBlogUsers=array();
if ($aRows) {
foreach ($aRows as $aUser) {
$aBlogUsers[]=Engine::GetEntity('Blog_BlogUser',$aUser);
}
}
return $aBlogUsers;
}
Получает список отношений пользователей с блогами
public array GetBlogUsersByArrayBlog(array $aArrayId, int $sUserId)
| ||
$aArrayId | array | Список ID блогов |
$sUserId | int | ID блогов |
{return} | array |
public function GetBlogUsersByArrayBlog($aArrayId,$sUserId) {
if (!is_array($aArrayId) or count($aArrayId)==0) {
return array();
}
$sql = "SELECT
bu.*
FROM
".Config::Get('db.table.blog_user')." as bu
WHERE
bu.blog_id IN(?a)
AND
bu.user_id = ?d ";
$aBlogUsers=array();
if ($aRows=$this->oDb->select($sql,$aArrayId,$sUserId)) {
foreach ($aRows as $aUser) {
$aBlogUsers[]=Engine::GetEntity('Blog_BlogUser',$aUser);
}
}
return $aBlogUsers;
}
Получает список отношений пользователя к блогам
public array GetBlogs()
| ||
{return} | array |
public function GetBlogs() {
$sql = "SELECT
b.blog_id
FROM
".Config::Get('db.table.blog')." as b
WHERE
b.blog_type<>'personal'
";
$aBlogs=array();
if ($aRows=$this->oDb->select($sql)) {
foreach ($aRows as $aBlog) {
$aBlogs[]=$aBlog['blog_id'];
}
}
return $aBlogs;
}
Возвращает список всех не персональных блогов
public array GetBlogsByArrayId(array $aArrayId, array|null $aOrder=NULL)
| ||
$aArrayId | array | Список ID блогов |
$aOrder | array|null | Сортировка блогов |
{return} | array |
public function GetBlogsByArrayId($aArrayId,$aOrder=null) {
if (!is_array($aArrayId) or count($aArrayId)==0) {
return array();
}
if (!is_array($aOrder)) $aOrder=array($aOrder);
$sOrder='';
foreach ($aOrder as $key=>$value) {
$value=(string)$value;
if (!in_array($key,array('blog_id','blog_title','blog_type','blog_rating','blog_count_user','blog_date_add'))) {
unset($aOrder[$key]);
} elseif (in_array($value,array('asc','desc'))) {
$sOrder.=" {$key} {$value},";
}
}
$sOrder=trim($sOrder,',');
$sql = "SELECT
*
FROM
".Config::Get('db.table.blog')."
WHERE
blog_id IN(?a)
ORDER BY
{ FIELD(blog_id,?a) } ";
if ($sOrder!='') $sql.=$sOrder;
$aBlogs=array();
if ($aRows=$this->oDb->select($sql,$aArrayId,$sOrder=='' ? $aArrayId : DBSIMPLE_SKIP)) {
foreach ($aRows as $aBlog) {
$aBlogs[]=Engine::GetEntity('Blog',$aBlog);
}
}
return $aBlogs;
}
Получает список блогов по ID
public array GetBlogsByFilter(array $aFilter, array $aOrder, int &$iCount, int $iCurrPage, int $iPerPage)
| ||
$aFilter | array | Фильтр выборки |
$aOrder | array | Сортировка |
$iCount | int | Возвращает общее количество элментов |
$iCurrPage | int | Номер текущей страницы |
$iPerPage | int | Количество элементов на одну страницу |
{return} | array |
public function GetBlogsByFilter($aFilter,$aOrder,&$iCount,$iCurrPage,$iPerPage) {
$aOrderAllow=array('blog_id','blog_title','blog_rating','blog_count_user','blog_count_topic');
$sOrder='';
foreach ($aOrder as $key=>$value) {
if (!in_array($key,$aOrderAllow)) {
unset($aOrder[$key]);
} elseif (in_array($value,array('asc','desc'))) {
$sOrder.=" {$key} {$value},";
}
}
$sOrder=trim($sOrder,',');
if ($sOrder=='') {
$sOrder=' blog_id desc ';
}
if (isset($aFilter['exclude_type']) and !is_array($aFilter['exclude_type'])) {
$aFilter['exclude_type']=array($aFilter['exclude_type']);
}
if (isset($aFilter['type']) and !is_array($aFilter['type'])) {
$aFilter['type']=array($aFilter['type']);
}
$sql = "SELECT
blog_id
FROM
".Config::Get('db.table.blog')."
WHERE
1 = 1
{ AND blog_id = ?d }
{ AND user_owner_id = ?d }
{ AND blog_type IN (?a) }
{ AND blog_type not IN (?a) }
{ AND blog_url = ? }
{ AND blog_title LIKE ? }
ORDER by {$sOrder}
LIMIT ?d, ?d ;
";
$aResult=array();
if ($aRows=$this->oDb->selectPage($iCount,$sql,
isset($aFilter['id']) ? $aFilter['id'] : DBSIMPLE_SKIP,
isset($aFilter['user_owner_id']) ? $aFilter['user_owner_id'] : DBSIMPLE_SKIP,
(isset($aFilter['type']) and count($aFilter['type']) ) ? $aFilter['type'] : DBSIMPLE_SKIP,
(isset($aFilter['exclude_type']) and count($aFilter['exclude_type']) ) ? $aFilter['exclude_type'] : DBSIMPLE_SKIP,
isset($aFilter['url']) ? $aFilter['url'] : DBSIMPLE_SKIP,
isset($aFilter['title']) ? $aFilter['title'] : DBSIMPLE_SKIP,
($iCurrPage-1)*$iPerPage, $iPerPage
)) {
foreach ($aRows as $aRow) {
$aResult[]=$aRow['blog_id'];
}
}
return $aResult;
}
Получает список блогов по фильтру
public array GetBlogsByOwnerId(int $sUserId)
| ||
$sUserId | int | ID пользователя |
{return} | array |
public function GetBlogsByOwnerId($sUserId) {
$sql = "SELECT
b.blog_id
FROM
".Config::Get('db.table.blog')." as b
WHERE
b.user_owner_id = ?
AND
b.blog_type<>'personal'
";
$aBlogs=array();
if ($aRows=$this->oDb->select($sql,$sUserId)) {
foreach ($aRows as $aBlog) {
$aBlogs[]=$aBlog['blog_id'];
}
}
return $aBlogs;
}
Получить список блогов по хозяину
public array GetBlogsRating(int &$iCount, int $iCurrPage, int $iPerPage)
| ||
$iCount | int | Возвращает общее количество элементов |
$iCurrPage | int | Номер текущей страницы |
$iPerPage | int | Количество элементов на одну страницу |
{return} | array |
public function GetBlogsRating(&$iCount,$iCurrPage,$iPerPage) {
$sql = "SELECT
b.blog_id
FROM
".Config::Get('db.table.blog')." as b
WHERE
b.blog_type<>'personal'
ORDER by b.blog_rating desc
LIMIT ?d, ?d ";
$aReturn=array();
if ($aRows=$this->oDb->selectPage($iCount,$sql,($iCurrPage-1)*$iPerPage, $iPerPage)) {
foreach ($aRows as $aRow) {
$aReturn[]=$aRow['blog_id'];
}
}
return $aReturn;
}
Возвращает список не персональных блогов с сортировкой по рейтингу
public array GetBlogsRatingJoin(int $sUserId, int $iLimit)
| ||
$sUserId | int | ID пользователя |
$iLimit | int | Ограничение на выборку элементов |
{return} | array |
public function GetBlogsRatingJoin($sUserId,$iLimit) {
$sql = "SELECT
b.*
FROM
".Config::Get('db.table.blog_user')." as bu,
".Config::Get('db.table.blog')." as b
WHERE
bu.user_id = ?d
AND
bu.blog_id = b.blog_id
AND
b.blog_type<>'personal'
ORDER by b.blog_rating desc
LIMIT 0, ?d
;
";
$aReturn=array();
if ($aRows=$this->oDb->select($sql,$sUserId,$iLimit)) {
foreach ($aRows as $aRow) {
$aReturn[]=Engine::GetEntity('Blog',$aRow);
}
}
return $aReturn;
}
Получает список блогов в которых состоит пользователь
public array GetBlogsRatingSelf(int $sUserId, int $iLimit)
| ||
$sUserId | int | ID пользователя |
$iLimit | int | Ограничение на выборку элементов |
{return} | array |
public function GetBlogsRatingSelf($sUserId,$iLimit) {
$sql = "SELECT
b.*
FROM
".Config::Get('db.table.blog')." as b
WHERE
b.user_owner_id = ?d
AND
b.blog_type<>'personal'
ORDER by b.blog_rating desc
LIMIT 0, ?d
;";
$aReturn=array();
if ($aRows=$this->oDb->select($sql,$sUserId,$iLimit)) {
foreach ($aRows as $aRow) {
$aReturn[]=Engine::GetEntity('Blog',$aRow);
}
}
return $aReturn;
}
Получает список блогов, которые создал пользователь
public array GetCloseBlogs()
| ||
{return} | array |
public function GetCloseBlogs() {
$sql = "SELECT b.blog_id
FROM ".Config::Get('db.table.blog')." as b
WHERE b.blog_type='close'
;";
$aReturn=array();
if ($aRows=$this->oDb->select($sql)) {
foreach ($aRows as $aRow) {
$aReturn[]=$aRow['blog_id'];
}
}
return $aReturn;
}
Возвращает полный список закрытых блогов
public int|null GetPersonalBlogByUserId(int $sUserId)
| ||
$sUserId | int | ID пользователя |
{return} | int|null |
public function GetPersonalBlogByUserId($sUserId) {
$sql = "SELECT blog_id FROM ".Config::Get('db.table.blog')." WHERE user_owner_id = ?d and blog_type='personal'";
if ($aRow=$this->oDb->selectRow($sql,$sUserId)) {
return $aRow['blog_id'];
}
return null;
}
Получает ID персонального блога пользователя
public bool RecalculateCountTopic(int|null $iBlogId=NULL)
| ||
$iBlogId | int|null | ID блога |
{return} | bool |
public function RecalculateCountTopic($iBlogId=null) {
$sql = "
UPDATE ".Config::Get('db.table.blog')." b
SET b.blog_count_topic = (
SELECT count(*)
FROM ".Config::Get('db.table.topic')." t
WHERE
t.blog_id = b.blog_id
AND
t.topic_publish = 1
)
WHERE 1=1
{ and b.blog_id = ?d }
";
if ($this->oDb->query($sql,is_null($iBlogId) ? DBSIMPLE_SKIP : $iBlogId)) {
return true;
}
return false;
}
Пересчитывает число топиков в блогах
public bool UpdateBlog(ModuleBlog_EntityBlog $oBlog)
| ||
$oBlog | ModuleBlog_EntityBlog | Объект блога |
{return} | bool |
public function UpdateBlog(ModuleBlog_EntityBlog $oBlog) {
$sql = "UPDATE ".Config::Get('db.table.blog')."
SET
blog_title= ?,
blog_description= ?,
blog_type= ?,
blog_date_edit= ?,
blog_rating= ?f,
blog_count_vote = ?d,
blog_count_user= ?d,
blog_count_topic= ?d,
blog_limit_rating_topic= ?f ,
blog_url= ?,
blog_avatar= ?
WHERE
blog_id = ?d
";
if ($this->oDb->query($sql,$oBlog->getTitle(),$oBlog->getDescription(),$oBlog->getType(),$oBlog->getDateEdit(),$oBlog->getRating(),$oBlog->getCountVote(),$oBlog->getCountUser(),$oBlog->getCountTopic(),$oBlog->getLimitRatingTopic(),$oBlog->getUrl(),$oBlog->getAvatar(),$oBlog->getId())) {
return true;
}
return false;
}
Обновляет блог в БД
public bool UpdateRelationBlogUser(ModuleBlog_EntityBlogUser $oBlogUser)
| ||
$oBlogUser | ModuleBlog_EntityBlogUser | Объект отношения пользователя с блогом |
{return} | bool |
public function UpdateRelationBlogUser(ModuleBlog_EntityBlogUser $oBlogUser) {
$sql = "UPDATE ".Config::Get('db.table.blog_user')."
SET
user_role = ?d
WHERE
blog_id = ?d
AND
user_id = ?d
";
if ($this->oDb->query($sql,$oBlogUser->getUserRole(),$oBlogUser->getBlogId(),$oBlogUser->getUserId())) {
return true;
}
return false;
}
Обновляет отношение пользователя с блогом