public function AddTopic(TopicEntity_Topic $oTopic)
public function AddTopic(TopicEntity_Topic $oTopic,$needId=null)
public function AddTopic(TopicEntity_Topic $oTopic) {
$sql = "INSERT INTO ".DB_TABLE_TOPIC."
(blog_id,
user_id,
topic_type,
topic_title,
topic_tags,
topic_date_add,
topic_user_ip,
topic_publish,
topic_publish_draft,
topic_publish_index,
topic_cut_text,
topic_forbid_comment,
topic_text_hash
)
VALUES(?d, ?d, ?, ?, ?, ?, ?, ?d, ?d, ?d, ?, ?, ?)
";
if ($iId=$this->oDb->query($sql,$oTopic->getBlogId(),$oTopic->getUserId(),$oTopic->getType(),$oTopic->getTitle(),
$oTopic->getTags(),$oTopic->getDateAdd(),$oTopic->getUserIp(),$oTopic->getPublish(),$oTopic->getPublishDraft(),$oTopic->getPublishIndex(),$oTopic->getCutText(),$oTopic->getForbidComment(),$oTopic->getTextHash()))
{
$oTopic->setId($iId);
$this->AddTopicContent($oTopic);
return $iId;
}
return false;
}
public function AddTopic(TopicEntity_Topic $oTopic,$needId=null) {
if($needId==null)
{
$sql = "INSERT INTO ".DB_TABLE_TOPIC."
(blog_id,
user_id,
topic_type,
topic_title,
topic_tags,
topic_date_add,
topic_user_ip,
topic_publish,
topic_publish_draft,
topic_publish_index,
topic_cut_text,
topic_forbid_comment,
topic_text_hash
)
VALUES(?d, ?d, ?, ?, ?, ?, ?, ?d, ?d, ?d, ?, ?, ?)
";
if ($iId=$this->oDb->query($sql,$oTopic->getBlogId(),$oTopic->getUserId(),$oTopic->getType(),$oTopic->getTitle(),
$oTopic->getTags(),$oTopic->getDateAdd(),$oTopic->getUserIp(),$oTopic->getPublish(),$oTopic->getPublishDraft(),$oTopic->getPublishIndex(),$oTopic->getCutText(),$oTopic->getForbidComment(),$oTopic->getTextHash()))
{
$oTopic->setId($iId);
$this->AddTopicContent($oTopic);
return $iId;
}
}else
{
$sql="select count(*) as cnt from ".DB_TABLE_TOPIC." where topic_id='".$needId."'";
$aRow=$this->oDb->query($sql);
//echo $needId;
//print_r($aRow);
if($aRow[0]['cnt']>0)
{
return false;
}
$sql = "INSERT INTO ".DB_TABLE_TOPIC."
(blog_id,
user_id,
topic_type,
topic_title,
topic_tags,
topic_date_add,
topic_user_ip,
topic_publish,
topic_publish_draft,
topic_publish_index,
topic_cut_text,
topic_forbid_comment,
topic_text_hash,
topic_id
)
VALUES(?d, ?d, ?, ?, ?, ?, ?, ?d, ?d, ?d, ?, ?, ?,?d)
";
if ($iId=$this->oDb->query($sql,$oTopic->getBlogId(),$oTopic->getUserId(),$oTopic->getType(),$oTopic->getTitle(),
$oTopic->getTags(),$oTopic->getDateAdd(),$oTopic->getUserIp(),$oTopic->getPublish(),$oTopic->getPublishDraft(),$oTopic->getPublishIndex(),$oTopic->getCutText(),$oTopic->getForbidComment(),$oTopic->getTextHash(),$needId))
{
$oTopic->setId($needId);
$this->AddTopicContent($oTopic);
return $needId;
}
}
return false;
}
if ($sId=$this->oMapperTopic->AddTopic($oTopic)) {
if ($sId=$this->oMapperTopic->AddTopic($oTopic,$needId)) {
Source: https://habr.com/ru/post/78699/
All Articles