2013-03-01 31 views
1

所以我有一個非常具體的情況,我的用戶有X(無限)節點由他們創作......但他們只允許有6個節點一次發佈。Drupal 7限制發佈的節點每用戶

我搜索了一會兒,發現http://www.badzilla.co.uk/Drupal-7--Node-Limit-Publish-Module,它工作得很好,除了這限制了特定內容類型的已發佈節點的總數。

我需要這個確切的功能,除了w /對每個用戶的附加限制......因此,每個用戶只能有6個節點發布一次,而不是整個Drupal站點只有X總數一次發佈的特定內容類型。

希望這是有道理的......無論從上面的URL的代碼/模塊是正確的工作,只是我需要迎合它檢查每個用戶的基礎上!我對模塊編碼或其他任何東西都不太瞭解,所以如果有人能夠在如何修改該網站上的模塊代碼方面有所幫助,那就太棒了! TIA

+0

我的第一反應是做出檢查上發佈檢查多少節點有用戶爲作者...漂亮的新的Drupal的規則,雖然 – Ken 2013-03-01 19:42:51

回答

0

Node Limit是你後一...

節點限制模塊允許管理員限制角色或用戶可以創建一個特定類型的節點的數量。例如,如果網站具有可以創建「廣告」節點的「廣告商」角色,則節點限制管理員可以將該角色中的所有用戶限制爲特定數量的節點。他也可能會按用戶限制用戶。

+0

節點限制是不太什麼,我一直在尋找,我是試圖在我的描述中非常具體,我需要它來限制PUBLISHED節點,而不是CREATED/EXISTING節點。 「節點限制」模塊只針對創建節點進行檢查,我不想限制節點的創建。 – savingstrangers 2013-03-04 15:43:44

2

對於誰在我同樣的問題,需要運行限制特定內容類型發佈時間節點的數量的,任何人,我的一個朋友改變了上面鏈接Badzilla模塊,和調整它爲以下。感謝Badzilla提供模塊的基礎,以及我的好友們調整它以檢查基於用戶而不是整個站點範圍內的已發佈節點。

<?php 

/* 
* File   : node_limit_publish.module 
* Title  : Limits the number of concurrently published node types dependent upon admin configurable limits 
* Sponsor  : Hangar Seven Digital 
* Author  : Badzilla www.badzilla.co.uk @badzillacouk 
* 
* This work is copyright Badzilla under the GPL licence terms and conditions 
* 
*/ 






/** 
* Implementation of hook_menu(). 
* 
*/ 
function node_limit_publish_menu() { 

    $items = array(); 

    $items['admin/config/content/node_limit_publish'] = array(
     'title' => 'Limit Number of Published Nodes per Node Type', 
     'description' => t('Zero represents an unlimited amount of published nodes'), 
     'page callback' => 'drupal_get_form', 
     'page arguments' => array('node_limit_publish_admin_settings'), 
     'access arguments' => array('administer node_limit_publish'), 
     'type' => MENU_NORMAL_ITEM, 
    ); 

    return $items; 
} 






function node_limit_publish_admin_settings() { 

    $form = array(); 

    if (is_array($types = node_type_get_types())) { 

     $form['title'] = array(
      '#markup' => t('Zero represents an unlimited amount of published nodes'), 
     ); 

     foreach($types as $key => $value) 
      $form['node_limit_publish_'.$key] = array(
       '#type' => 'textfield', 
       '#description' => $key, 
       '#size' => 4, 
       '#maxlength' => 10, 
       '#element_validate' => array('node_limit_publish_is_numeric'), 
       '#default_value' => variable_get('node_limit_publish_'.$key, 0),     
      ); 
    } 

    return system_settings_form($form); 
} 




function node_limit_publish_is_numeric($element, &$form_state, $form) { 

    if (!is_numeric($element['#value'])) 
     form_error($element, t('This field must be numeric')); 
} 





/** 
* Implementation of hook_presave(). 
* 
*/ 
function node_limit_publish_node_presave($node) { 
    global $user; 

    // Get the limit on this type 
    if (($limit = variable_get('node_limit_publish_'.$node->type, 0)) and $node->status == 1) { 
     // now check whether we have reached our maximum 
     $query = db_select('node') 
      ->condition('type', $node->type) 
      ->condition('status', 1) 
         ->condition('uid', $user->uid); 
     if (isset($node->nid)) 
      $query->condition('nid', $node->nid, '!='); 
     $count = $query->countQuery() 
      ->execute() 
      ->fetchField(); 
     if ($count >= $limit) { 
      $node->status = 0; 
      // use %type for dynamic node type 
      drupal_set_message(t('Sorry, the maximum of this node are active already. You must first disable another!', array('%type' => $node->type)), 'warning'); 
     } 
    } 
}