ArticleTopic::GetArticleTopics PHP Method

GetArticleTopics() public static method

Get the topics for the given article.
public static GetArticleTopics ( integer $p_articleNumber, boolean $p_countOnly = false ) : mixed
$p_articleNumber integer Retrieve the topics for this article.
$p_countOnly boolean Only get the number of topics attached to the article.
return mixed Return an array or an int.
    public static function GetArticleTopics($p_articleNumber, $p_countOnly = false)
    {
        global $g_ado_db;
        $selectStr = "*";
        if ($p_countOnly) {
            $selectStr = "COUNT(*)";
        }
        $queryStr = "SELECT {$selectStr} FROM ArticleTopics " . " WHERE NrArticle = {$p_articleNumber}" . ' ORDER BY TopicId';
        if ($p_countOnly) {
            return $g_ado_db->GetOne($queryStr);
        } else {
            $rows = $g_ado_db->GetAll($queryStr);
            $topics = array();
            $em = \Zend_Registry::get('container')->getService('em');
            foreach ($rows as $row) {
                $topics[] = $em->getReference('Newscoop\\NewscoopBundle\\Entity\\Topic', $row['TopicId']);
            }
            return $topics;
        }
    }

Usage Example

Example #1
0
require_once($GLOBALS['g_campsiteDir']."/$ADMIN_DIR/articles/topics/topic_common.php");
require_once($GLOBALS['g_campsiteDir'].'/classes/Topic.php');
require_once($GLOBALS['g_campsiteDir'].'/classes/Log.php');
require_once($GLOBALS['g_campsiteDir'].'/classes/DbObjectArray.php');
require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleTopic.php');

if (!SecurityToken::isValid()) {
    camp_html_display_error(getGS('Invalid security token!'));
    exit;
}

$f_language_selected = Input::Get('f_language_selected', 'int', 0);
$f_article_number = Input::Get('f_article_number', 'int', 0);
$f_topic_ids = Input::Get('f_topic_ids', 'array', array(), true);
$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);
All Usage Examples Of ArticleTopic::GetArticleTopics