【问题标题】:How to grant user User Points after adding comment once?添加评论后如何授予用户用户积分?
【发布时间】:2013-10-11 09:27:50
【问题描述】:

当用户在节点上添加评论时,我创建了一个规则来授予用户用户积分。但是,我只想给他们一次这些积分。这意味着:他们在同一个节点上第二次或第三次反应时不会获得更多积分,但在另一个节点上发表评论后仍然会获得积分。

我该怎么做?

【问题讨论】:

    标签: drupal-7 comments userpoints


    【解决方案1】:

    规则必须具有: 事件:保存评论之前

    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;
    }
    }
    

    【讨论】:

      【解决方案2】:

      我使用标志模块解决了我的问题:我创建了名为“已在此节点上评论”和“第一反应”* 的标志以及名为“已在节点上评论”的规则。这些是我的规则设置:

      事件:保存新评论后

      条件:

      • 内容的类型参数:内容:[comment:node],内容类型: 文章
      • NOT 节点被标记参数:标志:在此节点上评论,节点: [comment:node],代查用户:[comment:author]

      动作:

      • Grant指向一个用户参数:用户:[comment:author], 积分:2,积分类别:反应,实体:[comment:node], 描述:新反应,操作:添加, 显示:false,中等:自动批准
      • 标记节点参数:标记:评论节点,节点: [comment:node],代表其标记的用户:[comment:author],跳过 权限检查:假
      • 标记评论:参数:标记:第一反应,评论:[comment], 代表其标记的用户:[comment:author],跳过权限 检查:假

      因此,每次用户第一次向某个节点添加评论时,该节点都会被标记为“在某个节点上评论”,反应被标记为“第一反应”并且添加评论的用户是奖励2分。

      **我在related question.*中使用“第一条评论”标志。*

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-04-15
        • 1970-01-01
        • 1970-01-01
        • 2019-05-21
        • 2012-01-22
        • 1970-01-01
        • 2012-10-19
        相关资源
        最近更新 更多