1

好吧,在这里我再次尝试从头开始编写代码,但我无法完全正确......我要做的就是检索用户所在的组 id(不包括注册用户),然后在以下语句:如果检索到的 group_id 是 10,则返回指定的消息,否则从检索到的 group_id 中删除用户并将它们放入 group_id 10。这是我到目前为止所拥有的,但我认为我在 dbal 的某个地方出错了。 .. 至于用户组添加/删除功能,我不确定我是否正确使用它们...我还包含了 functions_user.php 但不确定我是否真的需要或者我是否正确放置了它。好吧,这就是我所拥有的,有什么帮助吗?

    $integer = 2;

    $sql = 'SELECT group_id FROM ' . USER_GROUP_TABLE . '
            WHERE user_id = ' . (int) $user->data['user_id'] . "
            AND group_id != '" . (int) $integer . "'";
    $result = $db->sql_query($sql);

    if ($result == 10)
    {
       $message = sprintf($user->lang['CANNOT_USE_TRAVEL_ITEM'], $this->data['name']);
    }
    else
    {
       include($phpbb_root_path . 'includes/functions_user.' . $phpEx);

       $userid = $user->data['user_id'];

       group_user_add((10), array($user_id));
       group_user_del(($result), array($user_id));

       $message = sprintf($user->lang['TRAVEL_ITEM_NOW_USE'], $this->data['name']);
    }
4

1 回答 1

1

Alright, I got it working... here is the code. Used the group_memberships function to both eliminate the SQL query as well as providing the correct boolean result to the group_user_add and group_user_del functions.

    global $user, $shop, $db, $phpEx, $phpbb_root_path;

    $this->remove_item();

    include($phpbb_root_path . 'includes/functions_user.' . $phpEx);

    if (group_memberships(10,$user->data['user_id'],true))
    {
       $message = sprintf($user->lang['CANNOT_USE_TRAVEL_ITEM'], $this->data['name']);
    }
    else
    {
       $groups = group_memberships(false,$user->data['user_id']);
       foreach ($groups as $grouprec)
       {
               $groupid = $grouprec['group_id'];
       }

       group_user_add((10), array($user->data['user_id']));
       group_user_del(($groupid), array($user->data['user_id']));

       $message = sprintf($user->lang['TRAVEL_ITEM_NOW_USE'], $this->data['name']);
    }

    return $message;
于 2012-06-17T01:05:51.100 回答