Dear Tomasso:
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.