donglei3370 2012-06-19 10:18
浏览 23
已采纳

如何在joomla 2.5中创建joomla用户组

I am working on my component in joomla 2.5 and i need to create user groups dynamically through my code.

As i know in 2.5 joomla is using nested sets for maintaining hierarchical structure so it may affect the whole table when we insert any new entry.

Does joomla provide any function that can be directly used to create user group ? something in which we can specify the parent group and new group will be created under it.

  • 写回答

2条回答 默认 最新

  • dongmangji0950 2012-07-17 09:47
    关注

    I solved it myself

    In my case i need to insert the child groups just under a particular group (mentioned as $parent_id in the code below)

    // get max right from all the child under parent id
        $child_query = "SELECT max(`rgt`) FROM `#__usergroups` WHERE `id` = ".$parent_id;
    $db->setQuery($child_query);
    $max_rgt = $db->loadResult();
    
    
    // calculate left and rgt for new entry
    $new_lft = $max_rgt;
    $new_rgt = $max_rgt + 1;
    
    // update lft and rgt of all entries having lft , rgt greater than max_rgt
    $upd1 = "UPDATE `#__usergroups` SET `lft` = `lft` + 2 WHERE `lft` > ".$max_rgt;
    $upd2 = "UPDATE `#__usergroups` SET `rgt` = `rgt` + 2 WHERE `rgt` >= ".$max_rgt;
    
    
    // insert new  child
    $insert = "INSERT INTO `#__usergroups`(`parent_id`,`lft`,`rgt`,`title`) VALUES(".$matrix_parent.",".$new_lft.",".$new_rgt.",'".$title."')";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向