Guest
10 Apr 2013 17:26

Hi there :)

I am new to cobalt (and to joomla altogether, by the way). I have been looking ccks for joomla the last few weeks, and finally landed here. None of them seem really capable of achieving a simple feature like this.

I am building a site with info about courses of many kinds, and all I need is to be able to list them grouped by categories, so it looks something like this:

CATEGORY1

Course1 X hours Y Price

Course2 X hours Y Price

CATEGORY2

Course1 X hours Y Price

Course2 X hours Y Price

CATEGORY3

Course1 X hours Y Price

Course2 X hours Y Price

I can list all of them this way, but that's no good for me:

Course1 X hours Y Price categoryfoo

Course2 X hours Y Price categorybar

.........

Before wasting more hours on this, is this possible at all with cobalt or am I wasting my time?

Thanks beforehand for your help :)

Last Modified: 02 Mar 2014

Tags Cobalt 9


Sergey
Total posts: 13,748
11 Apr 2013 05:15

it is possible but there is no parameters for that. But you can do it in custom template. It is a very small PHP code to reorder article by categories and then display in groups. But article list page have to display all articles in current category without page navigation.

You can set default article per page = 1000 and hide page limiter in any article list template.


pepperstreet VIP
Total posts: 3,837
11 Apr 2013 12:42

@Jesús J. Guerrero Botella

Since you mentioned you are new to Joomla... you might also have a look at the CMS Drupal. Especially on its extension called "Views". AFAIK, it can sort and display records this way. Its all about configuration and parameters. But... its complex!

As far as Joomla is concerned, Cobalt CCK is the most powerful extension in this area. There is nothing like "Views" in the Joomla world. So, you have to look into Cobalt configuration and template features. This might include some PHP tweaks as Sergey already noted.


pepperstreet VIP
Total posts: 3,837
06 Jun 2013 18:08

now we come to grouping by category, then we want to group by user or type or who knows what :) I mean if we add grouping it should be complex solution to enable any kind of grouping and even on paged lists.

Any news on this?

BTW, my older C7 topic about grouping


Guest
11 Jun 2013 05:23

I've mostly been able to achieve this (in an ugly and hacky way, of course, but anyway...).

I have a little problem though. I can't seem to be able to make Cobalt display more than 20 articles in the list.

Following your advice above I have been able to disable the pager, and in the category config, I go to the general parameters tab, I scroll down to record list, choose my template (the one I edited), click the button to the right to set its parameters, and there I scroll down to "default records per page" and set it to 1000.

However the page still doesn't display more (nor less) than 20 articles. If I go to the admin pagel there are 31 of them right now, so that's not the problem. The three options above that one are off (show title index, pagination and pagination limit box).

Any idea what the problem could be? :)


Sergey
Total posts: 13,748
12 Jun 2013 01:09

However the page still doesn't display more (nor less) than 20 articles. If I go to the admin pagel there are 31 of them right now, so that's not the problem. The three options above that one are off (show title index, pagination and pagination limit box).

This was the bug in Cobalt. It is fixed in next update. The list limit reset to last opened section.


Guest
13 Jun 2013 05:03

Thanks, :)


Guest
30 Jul 2013 04:02

As I said above, I mostly got this working. However, I need now a way to discriminate between categories and subcategories, so that I can give a different formating via css.

Right now, I order the array by using the usort php function in my custom template php file, which is called default_list_my_table.php. It seems that categories and subcategories appear the same in the array, or that's my understanding, correct?

This is what I did to the default list php file (I know it's not rocket science but it worked until now ). The concept is quite simple. I just read the categories array, and go comparing the string in each iteration. If it's the same string that there was in the previous round then I don't do anything. If the string is new I print the header with a random string name so I can format it easily using css. But I have no idea how can I (well, can I at all?) discriminate nested categories to format it differently.

PHP is certainly not my mother tongue :lol:


--- default_list_default.php 2013-07-30 10:47:12.268055807 +0200 +++ default_list_my_table.php 2013-07-30 10:47:12.227055805 +0200 @@ -40,8 +40,48 @@ right: 0; } </style> + + <?php + + function cmp( $a, $b ) + { + $foo = strcmp($a->categories_links[0],$b->categories_links[0]); + if( $foo == 0 ) + { + $bar = strcmp($a->title,$b->title); + if ( $bar == 0 ) + { + return 0; + } + elseif( $bar < 0 ) + { + return -1; + } + else + { + return 1; + } + } + return ( strcmp( $a->categories_links[0], $b->categories_links[0]) < 0 ) ? -1 : 1; + } + $prevstring = "foobarmoocow"; + usort($this->items,'cmp'); + + //print(gettype($this->section->categories)); + //print($this->section->categories); + //foreach ($this->section->categories AS $cat): + // print($cat); + //endforeach; + + //print(gettype($this->items)); + //print_r($this->items['categories']); + ?> + <table class="table table-striped"> <thead> + + + <tr> <?php if($params->get('tmpl_core.item_title')):?> <th><?php echo JText::_('CTITLE');?></th> @@ -141,6 +181,17 @@ </thead> <tbody> <?php foreach ($this->items AS $item):?> + + <?php + $thisstring = implode(', ', $item->categories_links); + //print $thisstring.",".$prevstring; + if(strcmp($thisstring, $prevstring) != 0) { + $prevstring = $thisstring; + //print " prevstring set to $prevstring "; + print '<tr class="special_for_maria"><td colspan="4"><h4>' . $prevstring . '</h4></td></tr>'; + } + ?> + <tr class="<?php if($item->featured) {

Sergey
Total posts: 13,748
31 Jul 2013 00:53

This example looks like summary from git. I cannot say for sure as I do тещ see all code but only part of it.


Sergey
Total posts: 13,748
01 Aug 2013 01:53

$this->section->categories - contain number of categories in section. This is rather to be used to check if section has any category at all.

I guess I know the answer, but I have to ask anyway :p Isn't there any magic option that you can turn on that will convert $item->categories_links in an array with more indexes, being each index one step in teh categories/sub-categories tree? That way it would be a breeze to sort this out... :=)

Unfortunately no. To get category path, you need to run much more complicated query than simply category name. We cannot do it due to performance issues.

In js_res_categories table there is path column. You may use it as a label. In this case you will not see separate link for each category but at least you will see full path where this category is located.

But if you want to get path

SELECT cat.*

FROM #__js_res_categories AS node,

        #__js_res_categories AS parent

WHERE node.lft BETWEEN parent.lft AND parent.rgt

        AND node.id = '10'

ORDER BY node.lft;

And then you can create url like

Url::records($this->section, $category)


Guest
01 Aug 2013 03:16

I see, thank you. I'll keep this in mind in the future.

For this concrete case, I have a working solution for now, though, as said, it involves formatting the titles of subcategories in a special way (then stripping the cruft away before printing...). It seems to work well enough for my concrete case, though I highly doubt this would be useful for anyone else.

Powered by Cobalt