×
Kunena 5.2 Beta 1 Released (24 Sep 2020)

The Kunena team is thrilled to announce the first public beta release of Kunena 5.2, a native Joomla extension for Joomla 3.9. This is a development release and should be only be used for testing; this version is not recommended for live websites at this stage.

The purpose of this release is to encourage testing by downloading, installing and identifying any problems or shortcomings that people may discover. K 5.2.0 B1 is stable and we are aware that people will discover defects. We encourage you to use the forum to report defects, as soon as they are discovered, so that the development team can work through the problems before the release of K 5.1 as a stable product. Reporting defects does not mean that the problems can or will be fixed. The Kunena team is looking forward to hearing your feedback on how well we have achieved our design goals.

× Please note: The Kunena project team takes NO responsibility for maintaining nor supporting anything in this category.

Solved Customize categories WHERE clause

More
6 years 10 months ago - 6 years 10 months ago #1 by jcsoft
Hello!

I'm using Kunena 3.0.3 with Joomla 2.5

I would like to customize the categories query to display only some categories depending on languages (i'll use specific aliases for this)

Where to find the WHERE clause to edit?
Which .php file to look for?

Thanx!
Last edit: 6 years 10 months ago by jcsoft.

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

More
6 years 10 months ago #2 by Matias
Unfortunately there isn't just one query which you can change, this would affect many different places. Kunena doesn't currently have full language support.

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

More
6 years 10 months ago - 6 years 10 months ago #3 by jcsoft
Thank you very much for your answer, Matias!

Meanwhile i put some printf() and print_r() around to try to understand how it works, and finally achieved it by myself, well, kunena is a very clean code! :)

!!!This hack works for Kunena 3.0.3 and Joomla 2.5!
Other versions not tested!!!


All data i need is in the class KunenaViewCategory.
i just needed to modify this file:

/components/com_kunena/views/category/view.html.php

The function i hacked is displayList() to remove some categories from the list.

I manage the category aliases by placing the lang-code before the name to be able to distinguish them, as i didn't find any lang field for categories.
So, for example, website alias became both en-website, fr-website, it-website etc.
This way i just need to hide the categories that doesn't begin with the current lang-code.

Here's the code:
function displayList($tpl = null) {
		$this->Itemid = $this->get ( 'Itemid' );
		$this->category = $this->get ( 'Category' );
		if ($this->category->id && ! $this->category->authorise('read')) {
			$this->setError($this->category->getError());
		}
		$this->message_ordering = $this->me->getMessageOrdering();
		$this->categories = $this->get ( 'Categories' );
		$this->pending = $this->get ( 'UnapprovedCount' );
		$this->moderators = $this->get ( 'Moderators' );
		$this->sections = isset($this->categories[0]) ? $this->categories[0] : array();
 
		if ($this->category->isSection()) {
// TODO: turn this on:
/*			if ($this->me->isAdmin($this->category)) {
				$url = "index.php?option=com_kunena&view=category&layout=manage&catid={$this->category->id}";
				$this->category_manage = $this->getButton($url, 'manage', 'category', 'moderation');
			}*/
		}
		if ($this->me->exists()) {
			$this->markAllReadURL = KunenaRoute::_();
		}
 
		$errors = $this->getErrors();
		if ($errors) {
			$this->displayNoAccess($errors);
			return;
		}
/*******************************************************************************************/
// here i add some code to hack category list, i need to display current language categories only!
// i manage categories by placing the lang-code [en, fr, ...] before the category name itself (like en-website-category, fr-website-category, ...)
 
	//retrieve lang code
	$jcsoft_language = &JFactory::getLanguage();
	$jcsoft_lang_code_array = explode('-',$jcsoft_language->getTag());
	$jcsoft_lang_code = $jcsoft_lang_code_array[0];
 
	//check if there are categories in other languages and unset them
	foreach ($this->categories as $jc_idx => $jc_main_cat) {
		foreach($jc_main_cat as $jc_inner_idx => $jc_cat) {
			$jc_cat_explo = explode("-", $jc_cat->alias);
			$jc_cat_lang = $jc_cat_explo[0];
			if($jcsoft_lang_code==$jc_cat_lang) {
				// this is what i need! -do nothing-
			} else {
				// don't want these categories, remove from array
				unset($this->categories[$jc_idx][$jc_inner_idx]);
			}
		}
	}
 
	// finally check if there are some empty main categories (the parents of the removed ones) and unset them
	foreach($this->categories as $jc_idx => $jc_main_cat) {
		if(empty($jc_main_cat)) {
			unset($this->categories[$jc_idx]);
			unset($this->sections[$jc_idx]);
		}
	}
 
// that's it, now it can be displayed
/*******************************************************************************************/
 
		$this->_prepareDocument('list');
 
		$this->display ($tpl);
	}

-EDIT-
A similar hack could be extended to the other objects and functions (category/views.html.php#displayDefault(), topic/..., search/...) to make language categories indipendent, but this way if, for exampe, a -fr- user searches for an item, he will not see the results from non-fr- categories.

Hope it helps.

... i love php!
Last edit: 6 years 10 months ago by jcsoft.
The following user(s) said Thank You: Matias, Jiminimonka

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

More
6 years 10 months ago #4 by Matias
Didn't think of that. :)

Thanks for saying that Kunena is easy to modify -- Kunena 3.1 will be even easier and you can do much more inside the template.

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

  • Not Allowed: to create new topic.
  • Not Allowed: to reply.
  • Not Allowed: to edit your message.
Time to create page: 0.103 seconds