Joomla Subcategories Project

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Locked
orware
Joomla! Explorer
Joomla! Explorer
Posts: 255
Joined: Mon Jul 10, 2006 8:16 pm
Location: CA
Contact:

Joomla Subcategories Project

Post by orware » Fri Jun 06, 2008 6:08 pm

OK, I was thinking yesterday that it's about time we gots ourselves a working subcategory system for Joomla 1.5 :-).

I've begun development of the various patches to the Joomla core files that will be required to make this work.

First, I didn't check too much on the forums beforehand, but I was browsing around this morning and I found some other forum topics that have also discussed this:

http://forum.joomla.org/viewtopic.php?t=47415
http://forum.joomla.org/viewtopic.php?f ... a&start=90

While I was sitting there thinking yesterday I noticed that all of the pieces already exist somewhere else in Joomla for the most part.

In order to implement subcategories for Joomla 1.5 there are a few things that need to be figured out:
1. Get Category Manager to List Subcategories Properly
2. Get Category Manager to Show List of Possible Parent Categories (dependent on Section Chosen) when Adding/Editing a Category
3. Get Article Manager to Correctly Display Parent/Child Categories when Adding/Editing an Article.
4. Apply the above changes to the frontend version of com_content
5. Modify my ArtCats Module to support Subcategories

As a side-effect it looks like this would also allow the Web Links component to have subcategories as well (since it shares the same table where Article Categories are stored) with a small change.

So far I am pretty sure that I am complete with #1, and I have a simple implementation of #2 (where you can just enter in the parent category ID into a text box, rather than having a list of categories to choose available).

In order to get #1 going, I borrowed code/concepts from com_menus because in Joomla menu items have always had the capability of being nested.

The main files I borrowed from com_menus were:
JOOMLA/administrator/components/com_menus/models/list/list.php
JOOMLA/administrator/components/com_menus/views/list/view.php
JOOMLA/administrator/components/com_menus/views/list/tmpl/default.php

I took a few features from a few functions in the files above and modified com_categories:
JOOMLA/administrator/components/com_categories/admin.categories.html.php
JOOMLA/administrator/components/com_categories/admin.categories.php

In order to make one function work correctly I modified one Joomla Library file:
JOOMLA/libraries/joomla/html/html/menu.php

By copying the treerecurse function, renaming it categorytreerecurse and modifying some of the parameters so that the function would return correct results for data coming from categories (the original one is tailored for operating on data coming the menu table). There could be a better way of putting this function in (I wanted to add it to content.php in the html folder above but when I tried to call it from the code it didn't work out so for the sake of speed I just added it to menu.php (that might be the most appropriate place for it I don't know).

In order to make everything a little more user friendly I also modified the administrator language file for com_categories:
JOOMLA/administrator/language/en-GB/en-GB.com_categories.ini

I added these two lines:
EDIT CATEGORY=Click to Edit this Category
PARENT CATEGORY=Parent Category

While putting what I have so far together the trickiest moments were figuring out that treerecurse was tailored for the menus table ("So that's why it wasn't working!") and getting filtering to work correctly for subcategories (still haven't figured out exactly what I did with the SQL query but it's working now).

I'm going to upload what I have so far to this thread. I've arranged the folders so that all you have to do is copy and paste the folders into the root of your site and the appropriate files will get overwritten. I'm a bit disorganized at the moment, but I have double-checked the patch files on a second site so there shouldn't be any trouble (but just be careful that if you are going to test the subcategories...make sure to use an id for the parent category that exists or else you might get a category that magically doesn't show up).

I'll be posting more on here as I continue working through the implementation.
You do not have the required permissions to view the files attached to this post.

orware
Joomla! Explorer
Joomla! Explorer
Posts: 255
Joined: Mon Jul 10, 2006 8:16 pm
Location: CA
Contact:

Re: Joomla Subcategories Project

Post by orware » Mon Jun 09, 2008 4:46 pm

OK, I began writing a post on Saturday, which would have been version 0.2 of the patches, but as I was creating screenshots for demonstration purposes I noticed some bugs in the display of the move up/move down icons so I went back to fix these issues and at the same time I went and implemented move/copy categories for subcategories too.

The two main issues for com_categories occurred at the extremities: The first occurs for the last category at the end of a section and the first category at the beginning of the next section, and the second occurs for the last category in a section when a child is present.

The first issue is a com_categories only problem since unlike com_menus where you are always guaranteed to only be looking at the menu items from only one menu, in com_categories you do not have the same guarantee because you are viewing categories from all of the sections on your site. So you have an issue towards the ending of one section and the beginning of another.

The second issues is viewable in both com_categories and com_menus because it is related the subcategories/submenuitems at the end of a section/menu. Joomla doesn't correctly show the move up icon for the last item because it has a child so it doesn't consider the real last item to be the last (it shows both the move up/down icons). For com_categories this introduced another issue when viewing all of the categories because for top level categories with no parents top level categories considered all of the categories in the other sections to be their siblings too (so rather than having a section sibling count for top level categories you'd have a total top level category count).

In order to implement these changes I needed to make a few more slight modifications to:
JOOMLA/libraries/joomla/html/html/menu.php

The first was to treerecurse, I added a new list variable named siblings using the two lines of code after the children list variable is added:

Code: Select all

$siblings = count( @$children[$pt] );
				$list[$id]->siblings = $siblings;
The second was to categorytreerecurse (which I added to support subcategories in my previous post), I added the new siblings list variable, but I also had to add a check for top level categories and then only count the top level categories with the same section id:

Code: Select all

				// Added check for $pt = 0 so that siblings
				// would be correct when viewing all sections
				if ($pt == 0){
					$count = 0;
					foreach ($children[$pt] as $top) 
					{
						if ($s == $top->section){
							$count++;
						}
					}
					$siblings = $count;
				} else {
					$siblings = count( @$children[$pt] );
				}
				$list[$id]->siblings = $siblings;
In addition to the modifications above, I needed to add additional condition checking code to the following two files:
JOOMLA/administrator/components/com_categories/admin.categories.html.php
JOOMLA/administrator/components/com_menus/views/list/tmpl/default.php

It's quite a bit of code (I added some variables just to make it a little easier to comprehend for anybody reading it). As far as I know I've covered just about all of the possibilities, but if any other conditions are found please let me know as I'd like to know :-).

In addition to the fixes above, I also mentioned that I had implemented copying/moving of categories/subcategories (I haven't checked out deletion just yet) and I believe this is working pretty good as well.

Also, when adding a new category I did add a select list that allows you to choose the category you'd like to use as a parent. If you have in mind that you want to create a subcategory item, please make sure to set the filter to the section you are going to be adding the subcategory item to first. The reason for this is that if you are viewing all of the categories then that means no specific section is set in URL so when you go to create a new category the section id variable is going to be null and no records are going to be returned to choose from for the parent category. It's easy to see, but hard to explain in words, just try creating a new category when viewing all categories and then try creating a new category after setting the section filter to only show categories from a specific section and you'll see the difference.

The next items on the to-do list are:
1. Implement categories/subcategories deletion using com_menus as an example
2. If possible, implement dynamic section/category menu when adding a new category (this would fix the issue above, but the current implementation is still "good enough").
3. Get Article Manager to Correctly Display Parent/Child Categories when Adding/Editing an Article.
4. Apply the #3 to Frontend version of the article manager.
5. Add Batch Category Add Feature (ala jxtended)
6. Add Batch Change Parent Feature (ala jxtended)
7. Modify ArtCats to support Subcategories.

Well, I hope someone will be brave enough to try this on (non-production) site and let me know what they think and what their experiences are
You do not have the required permissions to view the files attached to this post.

orware
Joomla! Explorer
Joomla! Explorer
Posts: 255
Joined: Mon Jul 10, 2006 8:16 pm
Location: CA
Contact:

Re: Joomla Subcategories Project

Post by orware » Mon Jun 09, 2008 4:47 pm

Just to let you know, version 0.3 of the patches is squeezed inbetween the two images above (it looks like it would be easy to miss that to me). Also, I wanted to add an additional screenshot of the Categories view with section filter applied:
You do not have the required permissions to view the files attached to this post.

orware
Joomla! Explorer
Joomla! Explorer
Posts: 255
Joined: Mon Jul 10, 2006 8:16 pm
Location: CA
Contact:

Re: Joomla Subcategories Project

Post by orware » Mon Jun 09, 2008 5:11 pm

Just as a sidenote something has been bugging me when menuitems/categories are moved to a different menu/section.

In the new section the ordering is correct (added to the end of the list), but there is a gap now in the old section.

I don't see it as being a huge issue, since when you add a new category to the section the JTable::reorder method will be called which will reorder everything and make sure the gaps are removed, but to me it seems like it'd be nice if the old section could be reordered after the move.

I'll look into it and see if there is anything I can do, but since this is also how com_menus functions I'm not sure if it's that big of a deal or not.

OlivierMiR
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Thu Feb 07, 2008 1:40 pm

Re: Joomla Subcategories Project

Post by OlivierMiR » Tue Jun 10, 2008 10:13 am

Hi, Thanks for developing this.

Will this provide multi-categories functionality? Where one article can belong to several sub-categories?

orware
Joomla! Explorer
Joomla! Explorer
Posts: 255
Joined: Mon Jul 10, 2006 8:16 pm
Location: CA
Contact:

Re: Joomla Subcategories Project

Post by orware » Tue Jun 10, 2008 2:06 pm

Thanks for the reply OlivierMiR!

Nope, I figured since the current Joomla database schema for categories does not have the correct fields to implement the multi-categories functionality so I'm just keeping it to strictly allowing for subcategories.

If you are looking for something that provides multi-categories functionality right now, I'd recommend taking a look at the jxtended components :-).

OlivierMiR
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Thu Feb 07, 2008 1:40 pm

Re: Joomla Subcategories Project

Post by OlivierMiR » Tue Jun 10, 2008 3:28 pm

I'm looking for a free solution.

If you have any idea to help development of a free multi-categories system please check these threads. Any help would be really appreciated.

http://forum.joomla.org/viewtopic.php?f=477&t=289368
http://forum.joomla.org/viewtopic.php?f=231&t=292175

orware
Joomla! Explorer
Joomla! Explorer
Posts: 255
Joined: Mon Jul 10, 2006 8:16 pm
Location: CA
Contact:

Re: Joomla Subcategories Project

Post by orware » Wed Jun 11, 2008 2:02 am

Well, the reason I mention jxtended is because all 4 developers there are Joomla core developers so there stuff is pretty high-quality, and since it's GPL, you're able to re-use the software on as many sites as you'd like, so it might not be that expensive of a solution if you're going to be needing the capabilities over multiple sites.

The reason why I'd like subcategories myself is just for the extra levels of hierarchy, which for me is needed much more than the multi-categories functionality (but I understand that it's something that other people would want which is why I pointed you to them). It's up to you of course :-).

I'll check out those links you posted!

OlivierMiR
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Thu Feb 07, 2008 1:40 pm

Re: Joomla Subcategories Project

Post by OlivierMiR » Wed Jun 11, 2008 8:56 am

Nested sub-categories

FYI, the Magazine jxtended extension has feature:
Unlimited depth category system
jxtended contact

And also FYI, I posted the following using the "contact" jxtended form.
Hello,

Some strange things on your website:
- Even after having added a product to the Shopping Cart, it appears empty. I guess it's because cookies are disabled here, but why no error message appears saying that? This is not user-friendly!
- Searching for "credits" on your search tool does not yield any result. However, the word "credits" appears in all your product pages.
- Sending a message (through this "contact" form) does not yield a "Thank you for your e-mail" message when cookies are disabled. Clicking "send" just made my message disappear, with no error messages or anything! And my message was lost, #@{[#@|[! (Luckily I had pasted it into the clipboard before sending.) With cookies activated, however, it works. Please make it so the user does not loose his message when something apparently goes wrong when sending, and let him know what happens!

Question:
- How does the "credit" system work? How much cost a credit? What if I just want to buy a product and not go on paying for all my life?

Thank you for your attention.
Note about jxtended

I forgot to mention it in the message: I really think extensions such as multi-categories or multi-depth-categories should be free for non-commercial use (i.e., for non-profits organisations). One of the good things about Joomla! is that it allows little, no money, organisations (such as non-profits or even a simple group of friends) to develop good web sites. And such extension is really a must-have, IMHO, for any good web site.

User avatar
carsten888
Joomla! Ace
Joomla! Ace
Posts: 1224
Joined: Sat Feb 11, 2006 8:32 am
Contact:

Re: Joomla Subcategories Project

Post by carsten888 » Wed Jul 30, 2008 11:50 am

Mod note by dam-man:
Please, do not promote your own website or extentions here. This is not allowed by the forum rules: http://forum.joomla.org/viewtopic.php?f=8&t=65 you can promote your site and components at the extentions site, but not here!

Thank You!
http://www.pages-and-items.com my extensions:
User-Private-Page, Redirect-on-Login, Admin-Help-Pages, Dynamic-Menu-Links, Admin-Menu-Manager, plugin load module in article, plugin pure css tooltip and more...

rapidhelp
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Fri Aug 01, 2008 12:43 am

Re: Joomla Subcategories Project

Post by rapidhelp » Fri Aug 01, 2008 12:56 am

thanks for development that :)

orware
Joomla! Explorer
Joomla! Explorer
Posts: 255
Joined: Mon Jul 10, 2006 8:16 pm
Location: CA
Contact:

Re: Joomla Subcategories Project

Post by orware » Fri Aug 01, 2008 1:53 am

@rapidhelp
Were you referring to my project or carsten888s project?

I have some more updates coming soon for mine :-).

liquidice
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Mon Aug 04, 2008 5:46 am

Re: Joomla Subcategories Project

Post by liquidice » Mon Aug 04, 2008 7:13 pm

Hey thanks for this orware! I applied the 0.3 patch on my server and the back end looks wonderful. Everything is falling into place except for the up/down arrows which I don't really bother me to much. However I noticed on the front end that I still see all catagories listed under the section as if I never had a subcategories structure.

I am as noob as you can get with web sites but can do most of what is needed if the function is there. Anyway my question on this is "Is this function only for the backend or is it suppose to reflect your subcategory structure on the frontend as well?" If it is suppose to then I have nubbed something up and will work on it.

Thanks again for you time and effort in this function.

orware
Joomla! Explorer
Joomla! Explorer
Posts: 255
Joined: Mon Jul 10, 2006 8:16 pm
Location: CA
Contact:

Re: Joomla Subcategories Project

Post by orware » Mon Aug 04, 2008 10:18 pm

Hi liquidice, nope you haven't messed anything up, I haven't gotten to applying the subcategories to the frontend area (you are talking about when you add/edit categories in the frontend I believe). I also want to see if there is a way I can get the breadcrumbs to reflect the subcategories (that feature would still interpret the category structure as it normally would) I don't know if that's a problem or not yet.

I have an update actually to the subcategories (were you applying it to Joomla 1.5.4 or 1.5.5 by any chance?) project and it provides a few updates to 0.3 (though it's been a few weeks and I technically don't remember what I improved exactly, I need to go back and review). If you are using 1.5.4 or 1.5.5 the updated one I'll be uploading will allow you to take advantage of the new content triggers introduced in 1.5.4 (well, actually any new extensions that use them).

I'll post back tomorrow with the update (the updated files are at work at the moment).

Thanks for trying it out :-).

liquidice
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Mon Aug 04, 2008 5:46 am

Re: Joomla Subcategories Project

Post by liquidice » Tue Aug 05, 2008 3:15 am

You caught my noobness. When I said Frontend I ment what the user sees when they click on a menu and view the section that has the categories in it. All my categories show up under the section even if they are sub-menus. Really sorry for the lack of terms.

Anyway I am more than happy to test anything out for you. I have a site that I am working on and it is version 1.5.5. I am not in any BIG rush to get it up as I am learning in the process. The template is in place and ran into a big wall with the 3 levels.

I don't know much about programming but I will offer to try anything you put up. :D

Thanks again

User avatar
webrp
Joomla! Guru
Joomla! Guru
Posts: 853
Joined: Sat Oct 28, 2006 9:10 pm
Location: Lisbon, Portugal

Re: Joomla Subcategories Project

Post by webrp » Tue Aug 05, 2008 4:03 am

If you make this work, it will be a major improvement on joomla. Sub categories could become very usefull, to a lot of users I guess. I will twist my fingers on your project!

liquidice
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Mon Aug 04, 2008 5:46 am

Re: Joomla Subcategories Project

Post by liquidice » Wed Aug 06, 2008 12:09 am

Not sure if this is a bug or not but, You can not delete the Parent category first. If you delete the parent category first then you are stuck with the children being listed and no way to delete them in the backend until you delete the section.

Now this may go back to my initial issue with the parent category and sub-category listing on the same page in the section. However I think the same idea will happen weather or not the display is working. I tried to read through the code but really just to unfamilar with it to really know what is going on. Anyway thought I would report what I have found so far in the topic. Oh BTW here is some info about the site.

joomla ver. 1.5.5
template JA_purity ver 1.2.0
PHP 5.0

orware
Joomla! Explorer
Joomla! Explorer
Posts: 255
Joined: Mon Jul 10, 2006 8:16 pm
Location: CA
Contact:

Re: Joomla Subcategories Project

Post by orware » Wed Aug 06, 2008 1:49 am

I think I may have fixed the delete issues in this version (I tell you exactly what I changed in this revision, but I know the last things I had been working on were to make sure that what you described didn't happen). There's still quite a bit I need to do, but let me know how it goes and any ideas you might have!
You do not have the required permissions to view the files attached to this post.

liquidice
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Mon Aug 04, 2008 5:46 am

Re: Joomla Subcategories Project

Post by liquidice » Wed Aug 06, 2008 5:55 pm

orware

I am happy to report that the delete problem is cleared up with the 0.5 patch. When deleting the parent cat the children are also deleted. Even so in the database. Where as before the children were still left in the database even after the section was deleted and clearing them from the admin view. So good work.

Well since I was in the SQL database I decided to look around a bit and see how things were put together (data wise). I did notice something.

1. Menu in the DB table has:
a. Parent
b. Sublevel

Looking at some of the examples I made out of the submenus I see that the Parent is set in the submenus as the ID of the parent menu. Not that it is new news. However I did notice that each of my submenus had a 1 in the sublevel. Now this my increase if I put sub-sub-menu in place. (I'll have to check that)

Now with the category I see:
a. Parent ID

That is all I see in the database table for the categories. Now going off a limb here but I was thinking that if code is being moved from say menu to category to "borrow" the sub feature, then you would want the database structure to be almost the same as well. Not that you need to steal the exact naming convention but I think that would just be extra work being that it is a different table. No sublevel field.

Well I could have just wasted everyones time by reading what I posted about the DBs but trying to start somewhere to lend a helping hand.

orware
Joomla! Explorer
Joomla! Explorer
Posts: 255
Joined: Mon Jul 10, 2006 8:16 pm
Location: CA
Contact:

Re: Joomla Subcategories Project

Post by orware » Wed Aug 06, 2008 8:07 pm

Thanks liquidice!

I had noticed the same thing with the sublevel field, but I hadn't been able to figure out how it was being used by the code last time I was working on it so I didn't worry about it at the time. Maybe if you or I figure out what it's usage is in the code it might make it more clear whether or not it'd be a good idea to add the field in the categories table as well.

I'll keep my out to see what I can find out about it :-).

anderius
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Sun Aug 24, 2008 4:58 pm

Re: Joomla Subcategories Project

Post by anderius » Mon Aug 25, 2008 6:58 pm

Hey,
I'm very happy about this mod. Thanks for it. :) :D
I've found an "Bug" but my English is very bad, so i con not tell it here. :'( :(
If you can German or Russian I can tell it you.

orware
Joomla! Explorer
Joomla! Explorer
Posts: 255
Joined: Mon Jul 10, 2006 8:16 pm
Location: CA
Contact:

Re: Joomla Subcategories Project

Post by orware » Mon Aug 25, 2008 7:13 pm

Maybe you can say filename? And describe problem in your own language?

I can try to figure it out from that,

Thank you!

anderius
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Sun Aug 24, 2008 4:58 pm

Re: Joomla Subcategories Project

Post by anderius » Mon Aug 25, 2008 7:35 pm

Ok, I'll try it.
When I want to greate a new subcategory, I must select the Category. But there is no category to select.(In Parent Category).
So I must Greate a Category and then I must edit it. There I can make it to a Subcategory.


I hope you understood me.
You do not have the required permissions to view the files attached to this post.

orware
Joomla! Explorer
Joomla! Explorer
Posts: 255
Joined: Mon Jul 10, 2006 8:16 pm
Location: CA
Contact:

Re: Joomla Subcategories Project

Post by orware » Mon Aug 25, 2008 8:03 pm

I think perhaps you do not have any categories created yet?

You can only create subcategories of other categories so you do need to create some parent categories (normal 1 level Joomla Categories) before anything will show up in the Parent Category area.

For Joomla you have this hierarchy: Sections->Categories->Articles.

I am adding this capability: Sections->Categories->Subcategories->Articles.

Hopefully this will help you!

anderius
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Sun Aug 24, 2008 4:58 pm

Re: Joomla Subcategories Project

Post by anderius » Mon Aug 25, 2008 8:14 pm

I'm working with joomla for 3 month. Ive got many Categories.
I made the Subcategories "Test" and "Test2" with the way i wrote in my last answer.
But when I want to make a new Subkategory there are no Parent Categories in the list. So I must greate my subcategoty al a standart Joomla Category and then, when I'm edit it, there are some Categories in "Parent category" and i can select them to make a Subcategory
You do not have the required permissions to view the files attached to this post.

orware
Joomla! Explorer
Joomla! Explorer
Posts: 255
Joined: Mon Jul 10, 2006 8:16 pm
Location: CA
Contact:

Re: Joomla Subcategories Project

Post by orware » Mon Aug 25, 2008 8:48 pm

ok, I understand what you mean now. I have not worked on this project for a little while now so I do not have a test environment setup where I can go verify the problem but I'm pretty sure I will be able to see the problem for myself when I try again.

I will try to get this fixed the next time I am able to work on this (which should be soon).

foxfirediego
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Wed Aug 27, 2008 5:47 pm

Re: Joomla Subcategories Project

Post by foxfirediego » Wed Aug 27, 2008 5:53 pm

Hi orware, I'm going to test your patch and let you know if it works fine at 1.5.6!
Keep it up!
thanks

orware
Joomla! Explorer
Joomla! Explorer
Posts: 255
Joined: Mon Jul 10, 2006 8:16 pm
Location: CA
Contact:

Re: Joomla Subcategories Project

Post by orware » Thu Aug 28, 2008 12:51 am

Thanks foxfire!

There's a whole list of new things I'd like to add to it but at the moment I've been kept away from working on this and other small projects for Joomla so anytime I get a message here it brings some extra encouragement to continue working on it.

fievetal
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Thu Aug 28, 2008 12:02 pm

Re: Joomla Subcategories Project

Post by fievetal » Fri Aug 29, 2008 8:41 am

Hi,
As you need some encouragement to continuing working on this project I am posting this message.
I think, this module is exactly what a lot of people need. I am one of them. :) 8)

Continue
I will implement it on one of our corporate site !

Best regards

foxfirediego
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Wed Aug 27, 2008 5:47 pm

Re: Joomla Subcategories Project

Post by foxfirediego » Fri Aug 29, 2008 4:33 pm

Hi orware, it's my pleasure to be one of the users of this project, but I don't know why didn't work with 1.5.6, gonna test again when I get back home... Oh well, keep up this work, like fievetal said, a lot of people need it!
thanks


Locked

Return to “Joomla! 1.5 Coding”