Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Table Categories -> Nested

Table Categories -> Nested 25 Apr 2012 17:46 #2141

  • dorac
  • dorac's Avatar
  • Offline
  • New Member
  • Posts: 2
  • Karma: 0
Hi guys,

Before I ask for help, just like to say I tried the tutorials on how to make a 2.5 component, WOW.... HECTIC!! J-Cook is really amazing in its simplicity!! Really something that I look forward to once I learn how to use it properly!

Alright, I have a table, Categories, with two fields, Name and Parent Id, its like a foreign key, but internally in its own table based on the category's id.

So parent categories will have parent ids of 0 while subcategories would have their parents id.

I've done some browsing through the forum and all I found was id is hidden, and foreign id is for linking two separate tables to one another.

Any advice on how I can accomplish this?

Thanks!! :oops:
Last Edit: 27 Apr 2012 07:48 by admin.
The administrator has disabled public write access.

Re: Table Categories -> Parent Id? 25 Apr 2012 18:50 #2142

  • admin
  • admin's Avatar
  • Online
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
The ID is not hidden, if you drag the table node, you get the ID. It was hidden because of a little bug, but now it is working nice.

The work you try to accomplish is possible but be careful, after few left joins, it starts to not be clean at all.
To manage hierarchical trees, you need a nested structure, as the com_categories way of doing.

parent_id + left + right + level + Very clever management = Good optimized Nested system.

The nested system is one of the big dev on the roadmap for 2012.
In localhost it works already but not stable and not unified with others wizards (grouping, publish)
Lot of others jobs are on the way, while Nested is quite finished and not ready for the moment.

I do all my possible.

If you want to do such job, it is possible I think
It is complicated, but others users can catch the idea.


TODO :

Create fields :
parent_id + lft + rgt + level (+ alias) in your table

and then rewrite in your table file (php) to HERIT of NESTED table file
jimport('joomla.database.tablenested');		//Include nested system

class JTableXxxx extends JTableNested		//HERE extends NestedSystem
{
	..
}


ajust your models and table files taking example of the com_category model, and you will get it working nice.

The job is done when parent_id, lft, rgt and level keeps coherence for whatever operation (add, delete, move)

When you will done this quite painful job, you will understand the power of auto generating it !!!
Coding is now a piece of cake
Last Edit: 25 Apr 2012 18:57 by admin.
The administrator has disabled public write access.
The following user(s) said Thank You: dorac

Re: Table Categories -> Nested 26 Apr 2012 10:45 #2146

  • dorac
  • dorac's Avatar
  • Offline
  • New Member
  • Posts: 2
  • Karma: 0
Aha! Thanks! Also a great thanks for such a speedy response!! :woohoo:

I understand most of what you are saying and looked at the joomla category table to see what you mean. What I don't understand is why there is a left, right and level. I tried googling about it and don't really find any reason to its method and logic. Sorry i'm not too clued up on how everything works.

The big picture:

Pretty much what I am trying to accomplish is a simplistic catalog even if its just a front-end. I have a database with products and categories.

Tables:

Products - id, parent_id, category_id, code, name, description

Category - id, parent_id, name

I don't understand what that left, right, level fields on categories are meant to do :unsure:

Also, i'm trying to Subscribe ;) but I click checkout but doesn't open any window nor is any window blocked on my browser, i'm using Firefox 12. Any advice? Many thanks!!!
The administrator has disabled public write access.

Re: Table Categories -> Nested 26 Apr 2012 13:38 #2147

  • admin
  • admin's Avatar
  • Online
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
I don't understand what that left, right, level fields on categories are meant to do

Maybe I didn't understand you...
Are the categories hierarchical ?
I mean, do you have a parent_id key pointing to the same id table ?

If you try to build infinite levels of such categories, read this to understand :
en.wikipedia.org/wiki/Nested_set_model



About subscribing, did you checked if the popup window is under ?
Does your browser accept pop-up ?

Please tell me if you still have problems, and contact me privatly for this.
But it is strange that you cannot, I never encoured problems with this.
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Table Categories -> Nested 05 Oct 2012 19:17 #4284

  • dyvel
  • dyvel's Avatar
  • Offline
  • Elite Member
  • Posts: 200
  • Thank you received: 11
  • Karma: 10
Hi

I would like to bring up this old topic, as I'm wondering what the status of nested categories in Cook?
It's a feature I specially looking forward to get my hands dirty with :-)

Thanks
The administrator has disabled public write access.

Re: Table Categories -> Nested 14 Oct 2012 14:11 #4478

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi @admin,

Just wondering how far away nested functionality is? Just read that wiki link and am about to dig in to the code to test it out on one of my tables...

Any advice on mod'ing the item view?

many thanks,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: Table Categories -> Nested 15 Dec 2012 13:22 #6102

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi @admin,

Will this nested feature be arriving in the new, highly anticipated V2.0?

Thanks,

Gez
//************** ADD *****************//

I'm trying to follow this tutorial on the joomla docs however, things start to get a little confusing past the first couple of steps.

To be precise, I have done the following:
  1. Added
    jimport('joomla.database.tablenested');		//Include nested system
    to my table class, commenting out the cimport(...)
  2. Changed the table class to:
    class NestedtestTableCategory extends JTableNested
  3. After my constructor, I've added in the check/set for the root function:
    public function addRoot()
      {
      $db = JFactory::getDbo();
      $sql = 'INSERT INTO #__nestedtest_categories'
    	  . ' SET parent_id = 0'
    	  . ', lft = 0'
    	  . ', rgt = 1'
    	  . ', level = 0'
    	  . ', title = '.$db->quote( 'root' )
    	  . ', alias = '.$db->quote( 'root' )
    	  . ', access = 1'
    	  . ', path = '.$db->quote( '' )
    	  ;
             $db->setQuery( $sql );
             $db->query();
            return $db->insertid();
    }
  4. But, where it goes on to explain calling this getRoot method and beyond, it does not precise where they should be called from. $rootId =
    $table->getRootId();[/li]
    if ($rootId === false) {
        $rootId = $table->addRoot();
    }
Furthermore, it goes on to describe lots of other methods to update, add, retrieve a node but with no reference as to where or how they should be added...

I wonder, would it be possible to point me in the right direction please.

Also, at the first step of the example, just before extenting JTableNested, it refers to adding the line;
$table = JTable::getInstance( 'nestedsets', 'Table' );
where I am replacing this with my table name 'categories' however, I'm getting the error Table class TableCategory not found in file..

Any help on this would be massively appreciated as I need to implement this to replace a 2 tiered Sction->Category approach as well as for a messages and replies to messages part of a component.

Many thanks,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
Last Edit: 15 Dec 2012 13:58 by JoomGuy. Reason: ADD
The administrator has disabled public write access.

Re: Table Categories -> Nested 15 Dec 2012 13:55 #6108

  • admin
  • admin's Avatar
  • Online
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
No, not for the moment, sorry.

Same than languages, it is not a big deal, but I prefer going slowly for the same obvious reasons that is is creating complex SQL queries.
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Table Categories -> Nested 15 Dec 2012 13:59 #6110

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Thanks for the update @admin!

I just wonder if you could point me in the right direction... Please see previous edited post.

Many thanks,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: Table Categories -> Nested 22 Dec 2012 14:40 #6235

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Bloody hell this is a tricky operation :sick: :huh:
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: Table Categories -> Nested 26 Dec 2012 09:37 #6278

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Has anyone actually achieved this integration?

Any experience to share?

Thanks,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: Table Categories -> Nested 26 Dec 2012 21:06 #6283

  • admin
  • admin's Avatar
  • Online
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
$table = JTable::getInstance( 'nestedsets', 'Table' );
Is wrong.


Let's say :
'Nestedtest' is the name of your component
'Category' is the name of your Nested table

You define 'NestedtestTable' as the common root class name for tables.

So you define :
class NestedtestTableCategory extends JTableNested
OK

And :
$table = JTable::getInstance( 'Category', 'NestedtestTable' );
Coding is now a piece of cake
Last Edit: 26 Dec 2012 21:06 by admin.
The administrator has disabled public write access.
The following user(s) said Thank You: JoomGuy

Re: Table Categories -> Nested 28 Dec 2012 12:08 #6294

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi Jocelyn,

Thanks! That was a silly mistake on my part but I had already tried that too.

Just to clarify, I've tried importing the JTableNested into my Categories table class like;
// no direct access
defined('_JEXEC') or die('Restricted access');

//cimport('classes.jtablenested');
jimport('joomla.database.tablenested');

/**
* Nestedtest Table class
*
* @package	Nestedtest
* @subpackage	Category
*/
class NestedtestTableCategory extends JTableNested
{
	/**
	* Constructor
	*
	* @access	public
	* @param	object	&$db	Database connector object
	* @return	void
	**/

	public function __construct(&$db)
	{
		parent::__construct('#__nestedtest_categories', 'id', $db);
	}
	
	public function addRoot()
	{
	    $db = JFactory::getDbo();
	    $sql = 'INSERT INTO #__nestedtest_categories'
	        . ' SET parent_id = 0'
	        . ', lft = 0'
	        . ', rgt = 1'
	        . ', level = 0'
	        . ', title = '.$db->quote( 'root' )	
	        . ', alias = '.$db->quote( 'root' )
	        . ', access = 1'
	        . ', path = '.$db->quote( '' )
	        ;
	    $db->setQuery( $sql );
	    $db->query();

	    return $db->insertid();
	}
	
	public function store()
	{
		$rootId = $table->getRootId();
		if ($rootId === false) {
		    $rootId = $table->addRoot();
		}
		parent::store();
	}

}
AND I've also tried Copying the classes/jtable.php file and rename it as jtablenested.php then tried to extend this in my Category table class like;
NestedtestTableCategory extends NestedtestTableNested
But, no matter what, I always get the error on Save - Save failed with the following error: Invalid parent ID.

Now, I understand what the JTableNested does and lft, rgt, etc but, I really don't understand how to call this functionality into my categories table.

Please could you provide an example of this?

many thanks,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: Table Categories -> Nested 14 Apr 2013 15:17 #7046

  • dieda1821
  • dieda1821's Avatar
  • Offline
  • Senior Member
  • Posts: 53
  • Thank you received: 2
  • Karma: 4
Hi Gez,

Did you manage to have the nested table working?

I am going to try to implement it in my component and I was wondering: could it be that instead of renaming the jtable.php file one should copy the tablenested.php from libraries/joomla/database into the component class folder?

Elena
The administrator has disabled public write access.

Re: Table Categories -> Nested 16 Apr 2013 09:04 #7050

  • dieda1821
  • dieda1821's Avatar
  • Offline
  • Senior Member
  • Posts: 53
  • Thank you received: 2
  • Karma: 4
Hi, on a second (fresher) thought, what I suggested is not necessary, anyhow I think I've found the way to start with TableNested. This is what I have achieved so far (PLEASE feel free to contribute). Assume that Component is your component name and that Category is your nested table.

1) Copy classes/jtable.php and rename it jtablenested.php. Inside the file change this:
1A) Add this line at the beginning (after "defined...")
jimport('joomla.database.tablenested');

1B) Change the line
class ComponentTable extends JTable

into
class ComponentTableNested extends JTableNested

2) Inside tables/category.php change the line
class ComponentTableCategory extends ComponentTable

into
class ComponentTableCategory extends ComponentTableNested

I think that here one could/should also add, e.g. the AddRoot function (not tested yet).

3) Inside models/category.php add the following test line inside the prepareTable function:
$table->setLocation( $table->parent_id, 'first-child' );

Now, assumed that you have created your root element by hand, directly in the database, along with a couple of test entries, you will notice that when creating in a component a new element and saving, the setLocation function works and all the lft-rgt-level-path, values are updated correctly preserving the integrity of the nested tree.

As I said, it's just a starting point. If one has gone more further...please share :-) I will post my step forward.

Thanks

Elena
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Time to create page: 0.235 seconds

Get Started