ArticleTopic::AddTopicToArticle PHP Method

AddTopicToArticle() public static method

Link a topic to an article.
public static AddTopicToArticle ( integer $p_topicId, integer $p_articleNumber ) : void
$p_topicId integer
$p_articleNumber integer
return void
    public static function AddTopicToArticle($p_topicId, $p_articleNumber)
    {
        global $g_ado_db;
        $queryStr = 'INSERT IGNORE INTO ArticleTopics(NrArticle, TopicId)' . ' VALUES(' . $p_articleNumber . ', ' . $p_topicId . ')';
        $g_ado_db->Execute($queryStr);
    }

Usage Example

Example #1
0
// 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);
    }
}

?>

<script type="text/javascript">
<?php if (!is_null($f_topic_ids)) { ?>
try {
    parent.$.fancybox.reload = true;
    parent.$.fancybox.message = '<?php putGS('Topics updated.'); ?>';
} catch (e) {}
<?php } ?>
parent.$.fancybox.close();
</script>