2010-10-10 70 views
0

我想在論壇主題列表頁面上顯示訂閱/取消訂閱鏈接,以及列表中的每個主題。我都在$主題變量mytheme_preprocess_forum_topic_list()的訂閱鏈接的信息:Drupal通知模塊 - 如何獲取訂閱ID(SID)?

foreach ($variables['topics'] as $id => $topic) { 

假設我想打電話給notifications_get_link()來獲得退訂鏈接,我怎麼能獲得訂閱ID(SID )爲主題節點的任何現有訂閱?

我想我應該調用notifications_user_get_subscriptions(),但文檔有點薄。一個例子會很棒。

回答

0

我的解決辦法找到了完全符合一個訂閱當前節點(如果存在),並組成要麼是提供給該模板的susbcribe或退訂鏈接:

// find subscription 
$subs = notifications_user_get_subscriptions(
     $user->uid, 
     'node', 
     $topic->nid, 
     $topic,  
     FALSE); 

// compose link 
$destination = "?destination=forum/idea-exchange"; 
if ($subs) { 
    foreach ($subs as $key => $sub) { 
     $link = notifications_get_link('unsubscribe', array(
       'sid' => $sub->sid, 
       'confirm' => FALSE)); 
     $variables['topics'][$id]->subscribe_link = 
     '<a class="unsubscribe" href="/'.$link['href']. 
       $destination.'">'.t('Stop tracking this topic').'</a>'; 
     break; 
    } 
} 
else { 
    $link = notifications_get_link(
     'subscribe', 
     array('uid' => $user->uid, 
       'type' => 'thread', 
       'fields' => array('nid' => $topic->nid), 
       'confirm' => FALSE)); 
    $variables['topics'][$id]->subscribe_link = 
     '<a class="subscribe" href="/'. 
     $link['href'].$destination.'">'.t('Track this topic').'</a>'; 
} 

我結束了使用CCK計算字段此這樣我可以將它包含在View中。有關更多上下文,請參閱this