Category Implementation - Nested Categories #260

Closed
opened 2018-04-08 23:31:05 +00:00 by mwweb · 2 comments
mwweb commented 2018-04-08 23:31:05 +00:00 (Migrated from github.com)

Steps to reproduce the issue

Create a category in, as an example, Sermon Distributor, then add some child categories. Such as:
Sunday Class

  • Class 1
  • Class 2

Now, add a sermon to Class 1 and Class 2. On the frontend of your website, it you display items from the category for Class 1 or Class 2 categories, then it should the item in that category. However, if you select the parent, Sunday Class, nothing displays, since there is nothing in "Sunday Class".

Expected result

If you selected a parent category it would load all items in the parent category, as well as all child categories. Basically, everything between lft and rgt. com_categories has various categories, but the way Joomla implemented it, the lft and rgt columns contain the range to encompass that. For example, Sunday Class id=71, Class 1 id=72, and Class 2 id=73.

However, in the database, lft on Sunday Class is 73, rgt=78. Class 1 is 74 and 75, and Class 2 is 76 and 77.

An explanation of the process that Joomla implemented can be understood here: https://www.sitepoint.com/hierarchical-data-database-2/

Basically, in part, it is the implementation of /libraries/src/Table/Nested.php

com_content is an example of how Joomla implemented this feature to show items from a parent category, as well as child categories.

Actual result

JCB only displays items from the selected category, not parent and child categories.

System information (as much as possible)

  • OS Name & Version: Ubuntu 14.04
  • MySql Version: 10.1.28-MariaDB-1~trusty
  • Apache Version: Apache/2.4.29 (Ubuntu)
  • PHP Version: PHP 7.1.11-1+ubuntu14.04.1+deb.sury.org+1
  • Joomla Version: 3.8.6
  • JCB Version: 2.7.0
  • Browser: Firefox 58.0.2

Additional comments

### Steps to reproduce the issue Create a category in, as an example, Sermon Distributor, then add some child categories. Such as: Sunday Class - Class 1 - Class 2 Now, add a sermon to Class 1 and Class 2. On the frontend of your website, it you display items from the category for Class 1 or Class 2 categories, then it should the item in that category. However, if you select the parent, Sunday Class, nothing displays, since there is nothing in "Sunday Class". ### Expected result If you selected a parent category it would load all items in the parent category, as well as all child categories. Basically, everything between lft and rgt. com_categories has various categories, but the way Joomla implemented it, the lft and rgt columns contain the range to encompass that. For example, Sunday Class id=71, Class 1 id=72, and Class 2 id=73. However, in the database, lft on Sunday Class is 73, rgt=78. Class 1 is 74 and 75, and Class 2 is 76 and 77. An explanation of the process that Joomla implemented can be understood here: https://www.sitepoint.com/hierarchical-data-database-2/ Basically, in part, it is the implementation of /libraries/src/Table/Nested.php com_content is an example of how Joomla implemented this feature to show items from a parent category, as well as child categories. ### Actual result JCB only displays items from the selected category, not parent and child categories. ### System information (as much as possible) - OS Name & Version: Ubuntu 14.04 - MySql Version: 10.1.28-MariaDB-1~trusty - Apache Version: Apache/2.4.29 (Ubuntu) - PHP Version: PHP 7.1.11-1+ubuntu14.04.1+deb.sury.org+1 - Joomla Version: 3.8.6 - JCB Version: 2.7.0 - Browser: Firefox 58.0.2 ### Additional comments

Since the whole front-end query is build by you, via a dynamic get. Dealing with child categories is really up to each developer.

Sermon Distributor does not deal with it in the same way that you are expecting, but you can set it up by combining a getItem (main-get) and a getCustoms. Since the dynamic get can load multiple queries on one page. One main-get and many custom gets...

I should at some point make a tutorial of some of the advanced combinations that can be done.

But for now the short answer is, that kind of query can be build, but you will have to combine a few queries with the Tweak->Filter->FunctionVar and Tweak->Set Global to make the connection between queries.

In the getCustoms(getChildren) query at Tweak->Filter->FunctionVar

The State Key could be something like $this->a_parent and the Table Key would then be a.parent_id in the getCustoms(getChildren) query.

In the the main getItem query at Tweak->Set Global

The name must then be parent and the Table Key/As Name must be id and the AS is a and the type is this

You will then get the children of the parent on the same page, yes it will be in a different object, but could easy link echo them based on parent ID.

Hope this helps. The query combination features of JCB is absolutely mind blowing, but yes not always obvious.

Since the whole front-end query is build by you, via a dynamic get. Dealing with child categories is really up to each developer. Sermon Distributor does not deal with it in the same way that you are expecting, but you can set it up by combining a getItem (main-get) and a getCustoms. Since the dynamic get can load multiple queries on one page. One main-get and many custom gets... I should at some point make a tutorial of some of the advanced combinations that can be done. But for now the short answer is, that kind of query can be build, but you will have to combine a few queries with the `Tweak->Filter->FunctionVar` and `Tweak->Set Global` to make the connection between queries. > In the getCustoms(getChildren) query at `Tweak->Filter->FunctionVar` The `State Key` could be something like `$this->a_parent` and the `Table Key` would then be `a.parent_id` in the getCustoms(getChildren) query. > In the the main getItem query at `Tweak->Set Global` The `name` must then be `parent` and the `Table Key/As Name` must be `id` and the `AS` is `a` and the `type` is `this` You will then get the children of the parent on the same page, yes it will be in a different object, but could easy link echo them based on parent ID. Hope this helps. The query combination features of JCB is absolutely mind blowing, but yes not always obvious.

Let me know if you have any further questions on this.

Let me know if you have any further questions on this.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#260
No description provided.