【发布时间】:2013-10-11 09:27:50
【问题描述】:
当用户在节点上添加评论时,我创建了一个规则来授予用户用户积分。但是,我只想给他们一次这些积分。这意味着:他们在同一个节点上第二次或第三次反应时不会获得更多积分,但在另一个节点上发表评论后仍然会获得积分。
我该怎么做?
【问题讨论】:
标签: drupal-7 comments userpoints
当用户在节点上添加评论时,我创建了一个规则来授予用户用户积分。但是,我只想给他们一次这些积分。这意味着:他们在同一个节点上第二次或第三次反应时不会获得更多积分,但在另一个节点上发表评论后仍然会获得积分。
我该怎么做?
【问题讨论】:
标签: drupal-7 comments userpoints
规则必须具有: 事件:保存评论之前
Conditions: this code
global $user;
$node =array();
$query = db_select('comment', 'c');
$query->fields('c', array('nid'));
$query->condition('c.uid', $user->uid);
$result = $query->execute();
while ($res = $result->fetchAll()) {
foreach ($res AS $re) {
$node[] = $re->nid;
}
}
if(!in_array($comment->nid, $node)){
return TRUE;
}
操作:授予用户用户积分
==============================
条件:执行自定义PHP代码 或创建自定义条件
/**
* Implements hook_rules_condition_info().
*/
function MYMODULE_rules_condition_info() {
$conditions = array();
$conditions['MYCONDITION'] = array(
'label' => t('lable'),
'parameter' => array(
'user' => array(
'type' => 'user',
'label' => t('User'),
),
),
'group' => t('Custom'),
'callbacks' => array(
'execute' => 'MYMODULE_rules_condition_MYCONDITION',
),
);
return $conditions;
}
function MYMODULE_rules_condition_MYCONDITION($user) {
$node =array();
$query = db_select('comment', 'c');
$query->fields('c', array('nid'));
$query->condition('c.uid', $user->uid);
$result = $query->execute();
while ($res = $result->fetchAll()) {
foreach ($res AS $re) {
$node[] = $re->nid;
}
}
if(!in_array($comment->nid, $node)){
return TRUE;
}
}
【讨论】:
我使用标志模块解决了我的问题:我创建了名为“已在此节点上评论”和“第一反应”* 的标志以及名为“已在节点上评论”的规则。这些是我的规则设置:
事件:保存新评论后
条件:
[comment:node],内容类型:
文章[comment:node],代查用户:[comment:author]
动作:
[comment:author],
积分:2,积分类别:反应,实体:[comment:node],
描述:新反应,操作:添加,
显示:false,中等:自动批准[comment:node],代表其标记的用户:[comment:author],跳过
权限检查:假[comment],
代表其标记的用户:[comment:author],跳过权限
检查:假因此,每次用户第一次向某个节点添加评论时,该节点都会被标记为“在某个节点上评论”,反应被标记为“第一反应”并且添加评论的用户是奖励2分。
**我在related question.*中使用“第一条评论”标志。*
【讨论】: