- Posts: 5
COMMUNITY FORUM
blog calendar doesn't pull from children categories
- andrew sobol
-
Topic Author
- Offline
- New Member
the calendar has no links on it when it's set to pull from the main category, when it's set to pull from the child category, it does link the dates to posts ... any ideas?
TIA
Please Log in or Create an account to join the conversation.
- fjesteban
-
- Offline
- New Member
- Posts: 18
I've modified the code to change this behaviour. It's accomplished by altering the SQL query generated for the task 'calendar' in the itemlist model file
I can contribute this changes if the author consider it interesting.
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Moderator
- Posts: 8743
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- fjesteban
-
- Offline
- New Member
- Posts: 18
Anyway, it's very easy to add a parameter to the tool and change the model file so the user can choose the behaviour of his/her interest. My offer was in this way.
Lefteris Kavadas said:Hi. Indeed the calendar doesn't fetch items from children categories. But this is not a bug. This is how it was designed to work.
Please Log in or Create an account to join the conversation.
- Juan Pablo Campa
-
- Offline
- New Member
- Posts: 12
Un saludo y gracias de antemano.
Francisco José Esteban Risueño said:I agree: this is not a bug but a design decission.Anyway, it's very easy to add a parameter to the tool and change the model file so the user can choose the behaviour of his/her interest. My offer was in this way.Lefteris Kavadas said:Hi. Indeed the calendar doesn't fetch items from children categories. But this is not a bug. This is how it was designed to work.
Please Log in or Create an account to join the conversation.
- fjesteban
-
- Offline
- New Member
- Posts: 18
Thanks for you interest. I answer to you in English, so others can read it.
I've generated a modified version of this great tool that accomplish this task and some others:
- Fix the bug that prevent deleting attachments from the front-end item editor.
- Add an component view that show a category as a list of linkable tittle/attachment grouped by subcategory (I call it "Press dossier"). I've also modified the calendar module with a parameter that choose to show a day/month in this way.
- Add a "Save & New" button to the front-end item editor
I'm also planning a modified calendar module with two new links in order to forward/rewind a whole year at a time.
I'll send to you the modified files tomorrow (I'm not at work now). Once again if the author or someone else is interested in this development, I can contribute it.
Juan Pablo Campa said:Hola Francisco José, he visto tus respuestas y agradecería tu ayuda. Estoy desarrollando una web en la que quiero mostrar en el calendario diferentes categorías hijas de una categoría principal. Como tu comentas mas arriba has llegado a hacerlo. No soy ningún experto en PHP ni MySql pero te agradecería que arrojaras algo de luz sobre mi problema. Mi correo de empresa es This email address is being protected from spambots. You need JavaScript enabled to view it..
Un saludo y gracias de antemano.
Francisco José Esteban Risueño said:I agree: this is not a bug but a design decission.Anyway, it's very easy to add a parameter to the tool and change the model file so the user can choose the behaviour of his/her interest. My offer was in this way.Lefteris Kavadas said:Hi. Indeed the calendar doesn't fetch items from children categories. But this is not a bug. This is how it was designed to work.
Please Log in or Create an account to join the conversation.
- Juan Pablo Campa
-
- Offline
- New Member
- Posts: 12
Thanks.
Please Log in or Create an account to join the conversation.
- litogeno
-
- Offline
- New Member
- Posts: 6
I would be very interesting in the modified files of your calendar. congratulations for your job.
Thanks
Please Log in or Create an account to join the conversation.
- fjesteban
-
- Offline
- New Member
- Posts: 18
consigna.uco.es/shared/b52d8dc3-6049-46fc-823a-e9b8b00dd104
Note for the author: If this redistribution is not acceptable for you, let me know and I'll suspend it inmediately
litogeno said:Hi Francisco I would be very interesting in the modified files of your calendar. congratulations for your job. Thanks
Please Log in or Create an account to join the conversation.
- litogeno
-
- Offline
- New Member
- Posts: 6
Please Log in or Create an account to join the conversation.
- CallMeLaNN
-
- Offline
- New Member
- Posts: 2
I cannot download the link. click continue and do nothing.
Is this full K2 package or patch file?
Francisco José Esteban Risueño said:I've just upload the mod to my university site, so you (and anyone who's interested) can get it. Feel free to download at:
consigna.uco.es/shared/b52d8dc3-6049-46fc-823a-e9b8b00dd104
Note for the author: If this redistribution is not acceptable for you, let me know and I'll suspend it inmediately
litogeno said:Hi Francisco I would be very interesting in the modified files of your calendar. congratulations for your job. Thanks
Please Log in or Create an account to join the conversation.
- fjesteban
-
- Offline
- New Member
- Posts: 18
Sorry for the inconvenience. It seems that we've a problem with our file exchange service. I will probably be fixed on Monday.
The zip includes full modified versions of the K2 files. Just unzip it in your server, replacing the old ones, adjust the parameters in the K2 tool and you're done.
Regards from Spain.
CallMeLaNN said:Hi,
I cannot download the link. click continue and do nothing.
Is this full K2 package or patch file?
Francisco José Esteban Risueño said:I've just upload the mod to my university site, so you (and anyone who's interested) can get it. Feel free to download at: consigna.uco.es/shared/b52d8dc3-6049-46fc-823a-e9b8b00dd104
Note for the author: If this redistribution is not acceptable for you, let me know and I'll suspend it inmediately
litogeno said:Hi Francisco I would be very interesting in the modified files of your calendar. congratulations for your job. Thanks
Please Log in or Create an account to join the conversation.
- Ian
-
- Offline
- New Member
- Posts: 16
The use of a drop-down menu is easier for newbies but it would make the module more flexible where ever a category is shown you can make the decision of one or many - probably easier to do with category id number.
Please Log in or Create an account to join the conversation.
- Tommaso Vogel
-
- Offline
- New Member
- Posts: 8
P.S. I am not a programmer, therefore I would be grateful if you could outline the exact code that needs to be implemented. Thanks.
Francisco José Esteban Risueño said:
I think the calendar only get items from the category itself you select, not including her children.I've modified the code to change this behaviour. It's accomplished by altering the SQL query generated for the task 'calendar' in the itemlist model fileI can contribute this changes if the author consider it interesting.
Please Log in or Create an account to join the conversation.
- fjesteban
-
- Offline
- New Member
- Posts: 18
Dear Tommaso:
I've not tested the hack with the latest version of K2, but I think it should be compatible: I've only made a minor change in the code. Anyway, you can test it yourself. Here's the detailed procedure:
1.- Backup your file <jomla_root>/components/com_k2/models/itemlist.php
2.- Edit the above file. Search for the first occurrence of the string "case 'date'". In my version it's at line 119
3.- The code to construct the category based query is 10 lines further. This is the original code:
if (JRequest::getInt('catid')) { $catid = JRequest::getInt('catid'); $query .= " AND i.catid={$catid}"; }
4. And this is it should be like to include subcategories:
if (JRequest::getInt('catid')) { $catid = JRequest::getInt('catid'); $categories = K2ModelItemlist::getCategoryChilds($catid); $categories[] = $catid; $categories = @array_unique($categories); $sql = @implode(',', $categories); $query .= " AND c.id IN ({$sql})"; }
That's all. Please ask again if it doesn't work for you.
Regards from Spain
Please Log in or Create an account to join the conversation.
- Tommaso Vogel
-
- Offline
- New Member
- Posts: 8
thank you very much for your reply. Unfortunatelly it doesn't work for me. But I must admit that it looks weird. The code in my version looks exactly the same as the one you have (even the lines). Therefore I was prettty sure it would have worked. I tryed but actually it does nothing. No errors, nothing at all. It just keeps on behaving as if I didn't apply the patch. Quite strange indeed! There must be something missing. Any ideas?
thanks
Please Log in or Create an account to join the conversation.
- fjesteban
-
- Offline
- New Member
- Posts: 18
I've checked the rest of my code and there's no other change related to this feature, so I agree: It should have worked for you too.
May you please check your options in the module parameters? In the Calendar Settings, you should choose a category in the field "category filter" and, in order to test the functionality, there should be some item in this category's subcategories to be displayed in the date selected within the calendar.
Yo can also check the URL generated when a day is clicked in the calendar: it should contain the words "itemlist" and "date"; if not, there's been some change in the calendar module since the version I use, so the hack is no longer usable.
Regards.
Please Log in or Create an account to join the conversation.
- Tommaso Vogel
-
- Offline
- New Member
- Posts: 8
I've checked a few things. I have articles in the parent category as well as in the child categories. The URL is: index.php?option=com_k2&view=itemlist&task=date&year=2011&month=4&day=28&catid=5&Itemid=1
I now realised that it is actually working but with one problem. Basically it is retrieving articles from the child categories only if in that same date there is also at least one article from the parent category. In my case this is a big problem because I will actually never have articles in the parent category as it is used purelly as an empty container (Parent category: Events, and the child categories actually contain the differente events).
I hope this can be solved somehow.
Thank you very much for your help!
Regards
Please Log in or Create an account to join the conversation.
- fjesteban
-
- Offline
- New Member
- Posts: 18
Your last post give me the cue: The URL is probably working right (you can test it by altering the date manually in it), but the date in the calendar is marked as linkable only if there are items in the parent category. You need an additional hack to fix it. Sorry for not giving it at first.
Here's the procedure:
1.- backup your <joomla_root>/modules/mod_k2_tools/helper.php
2.- Search for the class "MyCalendar". In my version it's at line 550
3.- The fuction getDateLink (lines 554 to 587 in my version) looks originally like this:
function getDateLink($day, $month, $year) {
$user = &JFactory::getUser();
$aid = $user->get('aid');
$db = &JFactory::getDBO();
$jnow = &JFactory::getDate();
$now = $jnow->toMySQL();
$nullDate = $db->getNullDate();
$query = "SELECT COUNT(*) FROM #__k2_items WHERE YEAR(created)={$year} AND MONTH(created)={$month} AND DAY(created)={$day} AND published=1 AND ( publish_up = ".$db->Quote($nullDate)." OR publish_up <= ".$db->Quote($now)." ) AND ( publish_down = ".$db->Quote($nullDate)." OR publish_down >= ".$db->Quote($now)." ) AND trash=0 AND access<={$aid} AND EXISTS(SELECT * FROM #__k2_categories WHERE id= #__k2_items.catid AND published=1 AND trash=0 AND access<={$aid})";
$catid = $this->category;
if ($catid > 0)
$query .= " AND catid={$catid}";
$db->setQuery($query);
$result = $db->loadResult();
if ($db->getErrorNum()) {
echo $db->stderr();
return false;
}
if ($result > 0) {
$itemID = JRequest::getInt('Itemid');
if ($catid > 0)
return JRoute::_('index.php?option=com_k2&view=itemlist&task=date&year='.$year.'&month='.$month.'&day='.$day.'&catid='.$catid.'&Itemid='.$itemID);
else
return JRoute::_('index.php?option=com_k2&view=itemlist&task=date&year='.$year.'&month='.$month.'&day='.$day.'&Itemid='.$itemID);
} else {
return false;
}
}
4.- And it should be replaced (the entire function) by the following code segment (it adds also the ability to resolve the whole month view with only one query to the database, so it renders 31 times faster) :
var $days_with_data = null;
function getMonthView($month, $year) {
$user = &JFactory::getUser();
$aid = $user->get('aid');
$db = &JFactory::getDBO();
$jnow = &JFactory::getDate();
$now = $jnow->toMySQL();
$nullDate = $db->getNullDate();
$query = "SELECT DISTINCT DAY(created) AS myday FROM #__k2_items WHERE YEAR(created)={$year} AND MONTH(created)={$month} AND published=1 AND ( publish_up = ".$db->Quote($nullDate)." OR publish_up <= ".$db->Quote($now)." ) AND ( publish_down = ".$db->Quote($nullDate)." OR publish_down >= ".$db->Quote($now)." ) AND trash=0 AND access<={$aid} AND EXISTS(SELECT * FROM #__k2_categories WHERE id= #__k2_items.catid AND published=1 AND trash=0 AND access<={$aid})";
$catid = $this->category;
if ($catid > 0) {
$categories = modK2ToolsHelper::getCategoryChildren($catid);
$categories[] = $catid;
$categories = @array_unique($categories);
$sql = @implode(',', $categories);
$query .= " AND catid IN ({$sql})";
}
$db->setQuery($query);
$this->days_with_data = $db->loadObjectList();
if ($db->getErrorNum()) {
echo $db->stderr();
}
return parent::getMonthView($month,$year);
}
function getDateLink($day, $month, $year) {
static $array = array();
$itemID = JRequest::getInt('Itemid');
foreach ($this->days_with_data as $day_with_data) {
array_push($array, $day_with_data->myday);
if ($day == $day_with_data->myday) {
$route='index.php?option=com_k2&view=itemlist&task=date&year={$year}&month={$month}&day={$day}";
if($this->category>0)
$route.="&catid={$this->category}";
return JRoute::_($route.'&Itemid='.$itemID);
} //if
} //foreach
return false;
}
And that's all. After this changes, your calendar should show the correct links, and it's also expected to appear faster (you can test it clicking on previous/next month). I've slightly modified the code before posting it to eliminate other hacks in my site. Please report back any problem you get.
Regards.
Please Log in or Create an account to join the conversation.
- Tommaso Vogel
-
- Offline
- New Member
- Posts: 8
Muchas gracias!
You saved my life! I was getting a bit concerned as I need to go live in a couple of weeks with this site and I still need to do a lot of stuff. I jumped into Joomla & K2 with little experience but this was actually the biggest issue for me as I am not a programmer. The rest is just configuration, templating and content. I will send you the link as soon as I go live.
all the best from Italy
Please Log in or Create an account to join the conversation.