how to rebuild user groups tree?

256 views
Skip to first unread message

fornandakishore

unread,
Nov 11, 2013, 12:48:11 AM11/11/13
to joomla-de...@googlegroups.com
Hello to all,

I have created custom component and on it I have 3 custom user groups. I have successfully inserted the user groups on the installation time but my question how to rebuild that user groups tree.

As that table contains lft and rgt fields, I got confused what values do I need to provide here.

I guess I need to call the rebuild tree, correct ? if yes, where is it and how to use it?

Please let me  know the solution. And my version is J3.x

Regards 
Nanda K.
PHP / Joomla Developer as a Freelancer
Sr. Developer at Hudda Infotech

Mark Dexter

unread,
Nov 11, 2013, 10:10:16 AM11/11/13
to Joomla! General Development
Are you using SQL or PHP to insert the user groups? It's much easier if you use PHP. If you use the store() method from JTableUsergroup it does all of the lft & rgt stuff for you. I think you just need to make sure you have the parent_id set. Alternatively, I think you could use SQL to do inserts (making sure you have the parent_id set correctly) and then use the rebuild() method to fix up the lft/rgt values. 

Good luck. Mark


--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/groups/opt_out.

fornandakishore

unread,
Nov 11, 2013, 12:24:13 PM11/11/13
to joomla-de...@googlegroups.com
Thanks for your reply Mark,

I am using the mysql to insert the groups as I have written the code in install.compname.php file and its not allowing the $db. And the Parent id for these groups is 'Registered' and there I have written the code to fetch the id of that group and will pass that where ever required. 

I have copied the core rebuild function from usergroups.php and placed in my installer file but here my question is what would be the lft value as it is the param to that function. I am passing the lft value as 1 and it messed up all the groups :(

How this lft, rgt process will calcuate/execute. Please explain in details if possible as this same concept also be there on categories, so I would like to know more about this.

Thanks in Advance.


Regards 
Nanda K.
PHP / Joomla Developer as a Freelancer
Sr. Developer at Hudda Infotech


Mark Dexter

unread,
Nov 11, 2013, 3:06:57 PM11/11/13
to Joomla! General Development
I believe you can run rebuild() with no arguments and it will rebuild the entire table -- which I think is what you want. Good luck. Mark

Adam Rifat

unread,
Nov 12, 2013, 5:08:24 AM11/12/13
to joomla-de...@googlegroups.com
I do this on a table with over 30000 rows.

You can insert a load of records into the table without lft and rgt, as long as you make sure tha parent_id is set (as Mark said). You can then call rebuild() and it calculates all the lft and rgt values for you so when you look at the list view everything is nested correctly.

It does work... ;-)
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.

To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.

To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.

Luis Aguilar

unread,
Aug 24, 2016, 5:25:40 PM8/24/16
to Joomla! General Development
Confirmed as Adam Rifat and Mark Dexter said, you can insert x number of rows into the usergroups table and then call the rebuild() method from the class JTableUsergroup, we did it from outside the framework as an independent routine, here's the code, though we haven't tried inserting all the records and then do a single call to rebuild(), we suppose must be the same.

Cheers.

<?php
define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
define('ABSOLUTE_PATH', dirname(__FILE__));
define('RELATIVE_PATH', 'modules');
define('JPATH_BASE', str_replace(RELATIVE_PATH, "", ABSOLUTE_PATH));
require_once ( JPATH_BASE . DS . 'includes' . DS . 'defines.php' );
require_once ( JPATH_BASE . DS . 'includes' . DS . 'framework.php' );
//require_once ( JPATH_BASE . DS . 'modules' . DS . 'mod_formTitular'.DS.'helper.php');
//jimport( 'joomla.application.module.helper' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();

function insert_group(){

$db = JFactory::getDbo();

$query = "INSERT INTO #__usergroups (parent_id, title) VALUES (0, 'Some group name example here.')";
$db->setQuery($query);
$db->query();

$errno=$db->getErrorNum();
if($errno==0){
$JTUserGroup = new JTableUsergroup($db);
echo $JTUserGroup->rebuild();
echo "SUCCESS INSERTING ROWS";
}
else{ echo "FAILED TO INSERT ROWS"; }

}
insert_group();
?>
Reply all
Reply to author
Forward
0 new messages