Keyword

Content Module Filter Problem

More
14 years 11 months ago #73634 by Lefteris
Replied by Lefteris on topic Content Module Filter Problem
Hi. Thanks for posting this mod but i think that it will break in PHP 4. We have implemented a little different patch for this. You can always view the latest source from the Joomlaworks svn repository on google code.

Colin Salomons said:You have to edit function getCategoryChilds in components/com_k2/models/itemlist.php. The problem is that static array. Here is what I replaced it with:
function getCategoryChilds($catid, &$array=array()) {

$user = &JFactory::getUser();
$aid = $user->get('aid');
$db = &JFactory::getDBO();
$query = "SELECT * FROM #__k2_categories WHERE parent={$catid} AND published=1 AND trash=0 AND access<={$aid} ORDER BY ordering ";
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row) {
array_push($array, $row->id);
if (K2ModelItemlist::hasChilds($row->id)) {
K2ModelItemlist::getCategoryChilds($row->id, $array);
}

}
return $array;
}

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • John Comeskey
  • John Comeskey's Avatar Topic Author
  • Offline
  • Junior Member
More
14 years 11 months ago #73635 by John Comeskey
Replied by John Comeskey on topic Content Module Filter Problem
Lefteris,

It would be better if you would either post the correct code here or release an updated version of the entire module.

Lefteris Kavadas said:Hi. Thanks for posting this mod but i think that it will break in PHP 4. We have implemented a little different patch for this. You can always view the latest source from the Joomlaworks svn repository on google code.
Colin Salomons said:You have to edit function getCategoryChilds in components/com_k2/models/itemlist.php. The problem is that static array. Here is what I replaced it with: function getCategoryChilds($catid, &$array=array()) {

$user = &JFactory::getUser();
$aid = $user->get('aid');
$db = &JFactory::getDBO();
$query = "SELECT * FROM #__k2_categories WHERE parent={$catid} AND published=1 AND trash=0 AND access<={$aid} ORDER BY ordering ";
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row) {
array_push($array, $row->id);
if (K2ModelItemlist::hasChilds($row->id)) {
K2ModelItemlist::getCategoryChilds($row->id, $array);
}

}
return $array;
}

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

More
14 years 11 months ago #73636 by Colin Salomons
Replied by Colin Salomons on topic Content Module Filter Problem
You are probably right that it will break in PHP4. But after looking at the SVN repository I noticed that the second parameter is used when you only want to clear the array, thus you have to change all the occurrences where the function is called. You should make it default to true and when you make the recursive call throw in false.

Lefteris Kavadas said:Hi. Thanks for posting this mod but i think that it will break in PHP 4. We have implemented a little different patch for this. You can always view the latest source from the Joomlaworks svn repository on google code.
Colin Salomons said:You have to edit function getCategoryChilds in components/com_k2/models/itemlist.php. The problem is that static array. Here is what I replaced it with: function getCategoryChilds($catid, &$array=array()) {

$user = &JFactory::getUser();
$aid = $user->get('aid');
$db = &JFactory::getDBO();
$query = "SELECT * FROM #__k2_categories WHERE parent={$catid} AND published=1 AND trash=0 AND access<={$aid} ORDER BY ordering ";
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row) {
array_push($array, $row->id);
if (K2ModelItemlist::hasChilds($row->id)) {
K2ModelItemlist::getCategoryChilds($row->id, $array);
}

}
return $array;
}

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

More
14 years 10 months ago #73637 by Kenneth Crowder
Replied by Kenneth Crowder on topic Content Module Filter Problem
Thanks Colin!

I came here to post my fix to this issue, but realized your fix is much cleaner. +5 points for you!

Colin Salomons said:You have to edit function getCategoryChilds in components/com_k2/models/itemlist.php. The problem is that static array. Here is what I replaced it with:
function getCategoryChilds($catid, &$array=array()) {

$user = &JFactory::getUser();
$aid = $user->get('aid');
$db = &JFactory::getDBO();
$query = "SELECT * FROM #__k2_categories WHERE parent={$catid} AND published=1 AND trash=0 AND access<={$aid} ORDER BY ordering ";
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row) {
array_push($array, $row->id);
if (K2ModelItemlist::hasChilds($row->id)) {
K2ModelItemlist::getCategoryChilds($row->id, $array);
}

}
return $array;
}

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


Powered by Kunena Forum