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条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀