2009-09-07 18 views

回答

2

如何實現這在很大程度上取決於NODE_TYPE的創建方式。 假設你有一個NODE_TYPE模塊,你可以做這樣的事情落實hook_validate

function NODE_TYPE_validate($node, &$form) { 
    if (NODE_TYPE_reached_post_limit()) { 
    form_set_error('form_name', t('You have reached your post limit')); 
    } 
} 

function NODE_TYPE_reached_post_limit() { 
    global $user; 
    //Write code to do the following: 
    //-> Check which group $user belongs to 
    //-> Create query to see how many posts $user has made 
    //-> Return true if $user has reached the limit 
} 

如果您沒有訪問該創建NODE_TYPE您可以創建一個新的模塊並實現hook_nodeapi模塊:

function yournewmodule_nodeapi(&$node, $op) { 
    switch ($op) { 
    case 'validate': 
     if ($node->type == "NODE_TYPE" && yournewmodule_reached_post_limit()) { 
     form_set_error('form_name', t('You have reached your post limit')); 
     } 
     break; 
    } 
} 

function yournewmodule_reached_post_limit() { 
    global $user; 
    //Write code to do the following: 
    //-> Check which group $user belongs to 
    //-> Create query to see how many posts $user has made 
    //-> Return true if $user has reached the limit 
} 

我不是100%確定validate最好的掛鉤來實現,但它肯定是一個選項。

+0

這可能是比我所做的更好的解決方案。我使用了另一個稱爲user_quota的模塊,它可以工作,但現在每次節點被刪除時,我都必須增加該人的配額。 – coderama 2009-09-09 10:18:23

相關問題