Keyword

Calendar to include sub categories

  • stephanie
  • stephanie's Avatar Topic Author
  • Offline
  • New Member
More
7 years 4 months ago #161807 by stephanie
Calendar to include sub categories was created by stephanie
Hi

Need some help on doing the Calendar module to load the sub categories of the selected category.

Here's what I have;
c13117.sgvps.net/~handlebar/index.php?option=com_k2&view=latest&layout=latest&Itemid=264

As you can see on the calendar module, items are loaded on their respective dates, I have modified the helper.php under calendar function to load such but my problem is the link within the date, it will only load the selected category and not the sub categoreis items. The only problem now is the datelink to load all the items under the subcategories of main category set on the Calendar module K2 tools.


Any help will be highly appreciated!

Regards,
Steph

Please Log in or Create an account to join the conversation.

More
7 years 4 months ago #161808 by esedic
Replied by esedic on topic Calendar to include sub categories
You have to remove category id from calendar link in modules/mod_k2_tools/helper.php .
In function getDateLink() change
return JRoute::_(K2HelperRoute::getDateRoute($year, $month, $day, $catid));
to
return JRoute::_(K2HelperRoute::getDateRoute($year, $month, $day));

Compare results:
c13117.sgvps.net/~handlebar/index.php?option=com_k2&view=itemlist&task=date&year=2017&month=5&day=10&catid=4&Itemid=264
and
c13117.sgvps.net/~handlebar/index.php?option=com_k2&view=itemlist&task=date&year=2017&month=5&day=10&Itemid=264

Remember this is a hack and you will loose changes if you update K2.

Regards

Please Log in or Create an account to join the conversation.

  • stephanie
  • stephanie's Avatar Topic Author
  • Offline
  • New Member
More
7 years 4 months ago #161825 by stephanie
Replied by stephanie on topic Calendar to include sub categories
Hi


Thank you for your reply, I have two parent categories (Sports and Bands), under each parent category there are subcategories such as Jazz, Pop etc for Bands and for Sports we have Basketball etc.

Under Bands page (c13117.sgvps.net/~handlebar/index.php?option=com_k2&view=latest&layout=latest&Itemid=264), the calendar should only load items from subcategories under Bands, so by removing the catid, Calendar results will also load items from Sports, What we need is to separate each parent category on the calendar, any help on how to accomplish such?

Thank you very much

Regards,

Please Log in or Create an account to join the conversation.

More
7 years 4 months ago #161827 by esedic
Replied by esedic on topic Calendar to include sub categories
I've solved it like this:
In mod_k2_tools.xml I've added attribute "multiple to" calendarCategory field.
From
<field name="calendarCategory" type="categories" label="K2_CATEGORY_FILTER" description="" default=""/>
to
<field name="calendarCategory" type="categories" label="K2_CATEGORY_FILTER" description="" default="" multiple ="true"/>

Then in helper.php in function getDateLink() I've changed this:
$catid = $this->category;
if ($catid > 0)
$query .= " AND catid={$catid}";
to this:
$catid = rtrim(implode(',', $this->category), ',');
if ($catid > 0)
$query .= " AND catid IN({$catid})";

That means that I've manually selected included categories in the module administration - but I still had to remove category id from the url.
Probably this could be done much smoother (there is a function for getting child category ids in same helper.php), but it's a quick solution and it's working for me, also I don't have a problem with manually selecting all the categories which have events.

Please Log in or Create an account to join the conversation.

More
7 years 4 months ago #161829 by esedic
Replied by esedic on topic Calendar to include sub categories
Update with simpler solution:

in beginning block of the file helper.php after
require_once (dirname(__FILE__).DS.'includes'.DS.'calendarClass.php');
add this:
require_once (JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'models'.DS.'itemlist.php');

Than in function getDateLink() change this:
$catid = $this->category;
if ($catid > 0)
$query .= " AND catid={$catid}";
to this:
$catids = K2ModelItemlist::getCategoryTree($this->category);
$catid = implode(',', $catids);

if ($catid > 0)
	$query .= " AND catid IN({$catid})";

This way you don't have to change xml file and you need to only select parent category in category field.
You still have to remove category id from url.

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum