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

报告相同问题?