2009-05-10 10:50:39 +03:00
|
|
|
<?php
|
2008-09-21 09:36:57 +03:00
|
|
|
/*-------------------------------------------------------
|
|
|
|
*
|
|
|
|
* LiveStreet Engine Social Networking
|
|
|
|
* Copyright © 2008 Mzhelskiy Maxim
|
|
|
|
*
|
|
|
|
*--------------------------------------------------------
|
|
|
|
*
|
|
|
|
* Official site: www.livestreet.ru
|
|
|
|
* Contact e-mail: rus.engine@gmail.com
|
|
|
|
*
|
|
|
|
* GNU General Public License, version 2:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
*
|
|
|
|
---------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Mapper_Blog extends Mapper {
|
|
|
|
protected $oUserCurrent=null;
|
|
|
|
|
|
|
|
public function SetUserCurrent($oUserCurrent) {
|
|
|
|
$this->oUserCurrent=$oUserCurrent;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function AddBlog(BlogEntity_Blog $oBlog) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "INSERT INTO ".Config::Get('db.table.blog')."
|
2008-09-21 09:36:57 +03:00
|
|
|
(user_owner_id,
|
|
|
|
blog_title,
|
|
|
|
blog_description,
|
|
|
|
blog_type,
|
|
|
|
blog_date_add,
|
|
|
|
blog_limit_rating_topic,
|
2008-10-25 23:31:29 +03:00
|
|
|
blog_url,
|
2009-10-13 11:39:30 +03:00
|
|
|
blog_avatar
|
2008-09-21 09:36:57 +03:00
|
|
|
)
|
2009-10-13 11:39:30 +03:00
|
|
|
VALUES(?d, ?, ?, ?, ?, ?, ?, ?)
|
2008-09-21 09:36:57 +03:00
|
|
|
";
|
2009-10-13 11:39:30 +03:00
|
|
|
if ($iId=$this->oDb->query($sql,$oBlog->getOwnerId(),$oBlog->getTitle(),$oBlog->getDescription(),$oBlog->getType(),$oBlog->getDateAdd(),$oBlog->getLimitRatingTopic(),$oBlog->getUrl(),$oBlog->getAvatar())) {
|
2008-09-21 09:36:57 +03:00
|
|
|
return $iId;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function UpdateBlog(BlogEntity_Blog $oBlog) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "UPDATE ".Config::Get('db.table.blog')."
|
2008-09-21 09:36:57 +03:00
|
|
|
SET
|
|
|
|
blog_title= ?,
|
|
|
|
blog_description= ?,
|
|
|
|
blog_type= ?,
|
|
|
|
blog_date_edit= ?,
|
|
|
|
blog_rating= ?f,
|
|
|
|
blog_count_vote = ?d,
|
|
|
|
blog_count_user= ?d,
|
|
|
|
blog_limit_rating_topic= ?f ,
|
2008-10-25 23:31:29 +03:00
|
|
|
blog_url= ?,
|
2009-10-13 11:39:30 +03:00
|
|
|
blog_avatar= ?
|
2008-09-21 09:36:57 +03:00
|
|
|
WHERE
|
|
|
|
blog_id = ?d
|
|
|
|
";
|
2009-10-13 11:39:30 +03:00
|
|
|
if ($this->oDb->query($sql,$oBlog->getTitle(),$oBlog->getDescription(),$oBlog->getType(),$oBlog->getDateEdit(),$oBlog->getRating(),$oBlog->getCountVote(),$oBlog->getCountUser(),$oBlog->getLimitRatingTopic(),$oBlog->getUrl(),$oBlog->getAvatar(),$oBlog->getId())) {
|
2008-09-21 09:36:57 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-05-29 18:32:37 +03:00
|
|
|
public function GetBlogsByArrayId($aArrayId) {
|
|
|
|
if (!is_array($aArrayId) or count($aArrayId)==0) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "SELECT
|
|
|
|
b.*
|
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.blog')." as b
|
2009-05-29 18:32:37 +03:00
|
|
|
WHERE
|
|
|
|
b.blog_id IN(?a)
|
|
|
|
ORDER BY FIELD(b.blog_id,?a) ";
|
|
|
|
$aBlogs=array();
|
|
|
|
if ($aRows=$this->oDb->select($sql,$aArrayId,$aArrayId)) {
|
|
|
|
foreach ($aRows as $aBlog) {
|
2009-09-08 15:02:51 +03:00
|
|
|
$aBlogs[]=Engine::GetEntity('Blog',$aBlog);
|
2009-05-29 18:32:37 +03:00
|
|
|
}
|
2009-09-18 23:36:07 +03:00
|
|
|
}
|
2009-05-29 18:32:37 +03:00
|
|
|
return $aBlogs;
|
|
|
|
}
|
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
public function AddRelationBlogUser(BlogEntity_BlogUser $oBlogUser) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "INSERT INTO ".Config::Get('db.table.blog_user')."
|
2008-09-21 09:36:57 +03:00
|
|
|
(blog_id,
|
2009-09-17 21:54:55 +03:00
|
|
|
user_id,
|
|
|
|
user_role
|
2008-09-21 09:36:57 +03:00
|
|
|
)
|
2009-09-17 21:54:55 +03:00
|
|
|
VALUES(?d, ?d, ?d)
|
2008-09-21 09:36:57 +03:00
|
|
|
";
|
2009-09-17 21:54:55 +03:00
|
|
|
if ($this->oDb->query($sql,$oBlogUser->getBlogId(),$oBlogUser->getUserId(),$oBlogUser->getUserRole())===0) {
|
2008-09-21 09:36:57 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function DeleteRelationBlogUser(BlogEntity_BlogUser $oBlogUser) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "DELETE FROM ".Config::Get('db.table.blog_user')."
|
2008-09-21 09:36:57 +03:00
|
|
|
WHERE
|
|
|
|
blog_id = ?d
|
|
|
|
AND
|
|
|
|
user_id = ?d
|
|
|
|
";
|
|
|
|
if ($this->oDb->query($sql,$oBlogUser->getBlogId(),$oBlogUser->getUserId())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-10-16 23:26:53 +03:00
|
|
|
public function UpdateRelationBlogUser(BlogEntity_BlogUser $oBlogUser) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "UPDATE ".Config::Get('db.table.blog_user')."
|
2008-10-16 23:26:53 +03:00
|
|
|
SET
|
2009-09-17 21:54:55 +03:00
|
|
|
user_role = ?d
|
2008-10-16 23:26:53 +03:00
|
|
|
WHERE
|
|
|
|
blog_id = ?d
|
|
|
|
AND
|
|
|
|
user_id = ?d
|
|
|
|
";
|
2009-09-17 21:54:55 +03:00
|
|
|
if ($this->oDb->query($sql,$oBlogUser->getUserRole(),$oBlogUser->getBlogId(),$oBlogUser->getUserId())) {
|
2008-10-16 23:26:53 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
|
2009-06-07 20:20:58 +03:00
|
|
|
public function GetBlogUsers($aFilter) {
|
2008-09-21 09:36:57 +03:00
|
|
|
$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'];
|
|
|
|
}
|
2009-09-17 21:54:55 +03:00
|
|
|
if (isset($aFilter['user_role'])) {
|
2009-09-22 00:08:00 +03:00
|
|
|
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>".LsBlog::BLOG_USER_ROLE_GUEST;
|
2009-09-17 21:54:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "SELECT
|
2009-06-02 22:29:05 +03:00
|
|
|
bu.*
|
2008-09-21 09:36:57 +03:00
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.blog_user')." as bu
|
2008-09-21 09:36:57 +03:00
|
|
|
WHERE
|
2009-06-02 22:29:05 +03:00
|
|
|
".$sWhere."
|
2009-09-17 21:54:55 +03:00
|
|
|
;
|
2008-09-21 09:36:57 +03:00
|
|
|
";
|
|
|
|
$aBlogUsers=array();
|
|
|
|
if ($aRows=$this->oDb->select($sql)) {
|
|
|
|
foreach ($aRows as $aUser) {
|
2009-09-29 01:31:49 +03:00
|
|
|
$aBlogUsers[]=Engine::GetEntity('Blog_BlogUser',$aUser);
|
2008-09-21 09:36:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aBlogUsers;
|
|
|
|
}
|
2009-09-18 23:36:07 +03:00
|
|
|
|
2009-06-07 20:20:58 +03:00
|
|
|
public function GetBlogUsersByArrayBlog($aArrayId,$sUserId) {
|
2009-06-02 22:29:05 +03:00
|
|
|
if (!is_array($aArrayId) or count($aArrayId)==0) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "SELECT
|
|
|
|
bu.*
|
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.blog_user')." as bu
|
2009-06-02 22:29:05 +03:00
|
|
|
WHERE
|
|
|
|
bu.user_id = ?d
|
|
|
|
AND
|
|
|
|
bu.blog_id IN(?a) ";
|
|
|
|
$aBlogUsers=array();
|
|
|
|
if ($aRows=$this->oDb->select($sql,$sUserId,$aArrayId)) {
|
|
|
|
foreach ($aRows as $aUser) {
|
2009-09-08 15:02:51 +03:00
|
|
|
$aBlogUsers[]=Engine::GetEntity('Blog_BlogUser',$aUser);
|
2009-06-02 22:29:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aBlogUsers;
|
|
|
|
}
|
|
|
|
|
2009-06-07 20:20:58 +03:00
|
|
|
|
2008-10-04 00:07:32 +03:00
|
|
|
public function GetPersonalBlogByUserId($sUserId) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "SELECT blog_id FROM ".Config::Get('db.table.blog')." WHERE user_owner_id = ?d and blog_type='personal'";
|
2008-10-04 00:07:32 +03:00
|
|
|
if ($aRow=$this->oDb->selectRow($sql,$sUserId)) {
|
2009-06-20 16:54:24 +03:00
|
|
|
return $aRow['blog_id'];
|
2008-09-21 09:36:57 +03:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2009-06-20 16:54:24 +03:00
|
|
|
|
2008-10-16 18:40:57 +03:00
|
|
|
public function GetBlogByTitle($sTitle) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "SELECT blog_id FROM ".Config::Get('db.table.blog')." WHERE blog_title = ? ";
|
2008-10-16 18:40:57 +03:00
|
|
|
if ($aRow=$this->oDb->selectRow($sql,$sTitle)) {
|
2009-06-24 00:35:20 +03:00
|
|
|
return $aRow['blog_id'];
|
2008-10-16 18:40:57 +03:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
|
2009-06-02 22:29:05 +03:00
|
|
|
|
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
|
2009-06-07 20:20:58 +03:00
|
|
|
public function GetBlogByUrl($sUrl) {
|
2008-09-21 09:36:57 +03:00
|
|
|
$sql = "SELECT
|
2009-06-07 20:20:58 +03:00
|
|
|
b.blog_id
|
2008-09-21 09:36:57 +03:00
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.blog')." as b
|
2008-09-21 09:36:57 +03:00
|
|
|
WHERE
|
2009-06-07 20:20:58 +03:00
|
|
|
b.blog_url = ?
|
2008-09-21 09:36:57 +03:00
|
|
|
";
|
2009-06-07 20:20:58 +03:00
|
|
|
if ($aRow=$this->oDb->selectRow($sql,$sUrl)) {
|
|
|
|
return $aRow['blog_id'];
|
2008-09-21 09:36:57 +03:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function GetBlogsByOwnerId($sUserId) {
|
|
|
|
$sql = "SELECT
|
2009-06-13 14:32:06 +03:00
|
|
|
b.blog_id
|
2008-09-21 09:36:57 +03:00
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.blog')." as b
|
2008-09-21 09:36:57 +03:00
|
|
|
WHERE
|
|
|
|
b.user_owner_id = ?
|
|
|
|
AND
|
|
|
|
b.blog_type<>'personal'
|
|
|
|
";
|
|
|
|
$aBlogs=array();
|
|
|
|
if ($aRows=$this->oDb->select($sql,$sUserId)) {
|
|
|
|
foreach ($aRows as $aBlog) {
|
2009-06-13 14:32:06 +03:00
|
|
|
$aBlogs[]=$aBlog['blog_id'];
|
2008-09-21 09:36:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aBlogs;
|
|
|
|
}
|
|
|
|
|
2008-10-04 00:07:32 +03:00
|
|
|
public function GetBlogs() {
|
|
|
|
$sql = "SELECT
|
2009-06-15 00:15:11 +03:00
|
|
|
b.blog_id
|
2008-10-04 00:07:32 +03:00
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.blog')." as b
|
2008-10-04 00:07:32 +03:00
|
|
|
WHERE
|
|
|
|
b.blog_type<>'personal'
|
|
|
|
";
|
|
|
|
$aBlogs=array();
|
|
|
|
if ($aRows=$this->oDb->select($sql)) {
|
|
|
|
foreach ($aRows as $aBlog) {
|
2009-06-15 00:15:11 +03:00
|
|
|
$aBlogs[]=$aBlog['blog_id'];
|
2008-10-04 00:07:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aBlogs;
|
|
|
|
}
|
2009-06-28 17:04:44 +03:00
|
|
|
|
2009-06-09 18:55:10 +03:00
|
|
|
public function GetBlogsRating(&$iCount,$iCurrPage,$iPerPage) {
|
2008-09-21 09:36:57 +03:00
|
|
|
$sql = "SELECT
|
2009-06-09 18:55:10 +03:00
|
|
|
b.blog_id
|
2008-09-21 09:36:57 +03:00
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.blog')." as b
|
2008-11-03 22:37:38 +02:00
|
|
|
WHERE
|
2009-09-18 23:36:07 +03:00
|
|
|
b.blog_type<>'personal'
|
2008-09-21 09:36:57 +03:00
|
|
|
ORDER by b.blog_rating desc
|
2009-06-09 18:55:10 +03:00
|
|
|
LIMIT ?d, ?d ";
|
2008-09-21 09:36:57 +03:00
|
|
|
$aReturn=array();
|
2009-06-09 18:55:10 +03:00
|
|
|
if ($aRows=$this->oDb->selectPage($iCount,$sql,($iCurrPage-1)*$iPerPage, $iPerPage)) {
|
2008-09-21 09:36:57 +03:00
|
|
|
foreach ($aRows as $aRow) {
|
2009-06-09 18:55:10 +03:00
|
|
|
$aReturn[]=$aRow['blog_id'];
|
2008-09-21 09:36:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aReturn;
|
|
|
|
}
|
|
|
|
|
2009-02-06 23:24:30 +02:00
|
|
|
public function GetBlogsRatingJoin($sUserId,$iLimit) {
|
|
|
|
$sql = "SELECT
|
|
|
|
b.*
|
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.blog_user')." as bu,
|
|
|
|
".Config::Get('db.table.blog')." as b
|
2009-02-06 23:24:30 +02:00
|
|
|
WHERE
|
|
|
|
bu.user_id = ?d
|
|
|
|
AND
|
|
|
|
bu.blog_id = b.blog_id
|
|
|
|
AND
|
2009-09-19 17:48:28 +03:00
|
|
|
b.blog_type<>'personal'
|
2009-02-06 23:24:30 +02:00
|
|
|
ORDER by b.blog_rating desc
|
|
|
|
LIMIT 0, ?d
|
|
|
|
;
|
|
|
|
";
|
|
|
|
$aReturn=array();
|
|
|
|
if ($aRows=$this->oDb->select($sql,$sUserId,$iLimit)) {
|
|
|
|
foreach ($aRows as $aRow) {
|
2009-09-08 15:02:51 +03:00
|
|
|
$aReturn[]=Engine::GetEntity('Blog',$aRow);
|
2009-02-06 23:24:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function GetBlogsRatingSelf($sUserId,$iLimit) {
|
|
|
|
$sql = "SELECT
|
|
|
|
b.*
|
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.blog')." as b
|
2009-02-06 23:24:30 +02:00
|
|
|
WHERE
|
|
|
|
b.user_owner_id = ?d
|
|
|
|
AND
|
|
|
|
b.blog_type<>'personal'
|
|
|
|
ORDER by b.blog_rating desc
|
|
|
|
LIMIT 0, ?d
|
2009-09-19 17:48:28 +03:00
|
|
|
;";
|
2009-02-06 23:24:30 +02:00
|
|
|
$aReturn=array();
|
|
|
|
if ($aRows=$this->oDb->select($sql,$sUserId,$iLimit)) {
|
|
|
|
foreach ($aRows as $aRow) {
|
2009-09-08 15:02:51 +03:00
|
|
|
$aReturn[]=Engine::GetEntity('Blog',$aRow);
|
2009-02-06 23:24:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aReturn;
|
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
|
2009-09-19 17:48:28 +03:00
|
|
|
public function GetCloseBlogs() {
|
2009-09-22 00:08:00 +03:00
|
|
|
$sql = "SELECT b.blog_id
|
2009-09-19 17:48:28 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
}
|
|
|
|
?>
|