ArticleTopic::RemoveTopicFromArticle PHP Method

RemoveTopicFromArticle() public static method

Unlink a topic from an article.
public static RemoveTopicFromArticle ( integer $p_topicId, integer $p_articleNumber ) : void
$p_topicId integer
$p_articleNumber integer
return void
    public static function RemoveTopicFromArticle($p_topicId, $p_articleNumber)
    {
        global $g_ado_db;
        $queryStr = "DELETE FROM ArticleTopics WHERE NrArticle={$p_articleNumber} AND TopicId={$p_topicId}";
        $g_ado_db->Execute($queryStr);
    }

Usage Example

Example #1
0
$articleTopics = ArticleTopic::GetArticleTopics($f_article_number);

if (!Input::IsValid()) {
	camp_html_display_error(getGS('Invalid input: $1', Input::GetErrorString()), null, true);
	exit;
}

if (!$g_user->hasPermission('AttachTopicToArticle')) {
	camp_html_display_error(getGS("You do not have the right to detach topics from articles."), null, true);
	exit;
}

// delete
foreach ($articleTopics as $topic) {
    if (!in_array($topic->getTopicId(), $f_topic_ids)) {
        ArticleTopic::RemoveTopicFromArticle($topic->getTopicId(), $f_article_number);
    } else {
        unset($f_topic_ids[array_search($topic->getTopicId(), $f_topic_ids)]);
    }
}

// insert rest
foreach ($f_topic_ids as $topicIdString) {
    // Verify topic exists
    $tmpTopic = new Topic($topicIdString);
    if ($tmpTopic->exists()) {
        ArticleTopic::AddTopicToArticle($topicIdString, $f_article_number);
    }
}

?>
All Usage Examples Of ArticleTopic::RemoveTopicFromArticle