Forum
Welcome, Guest
Username: Password: Remember me
If you are looking for support for any nZambi Ex extensions, please try to provide as much information as you can. For example, at the very least include your Joomla! version and the version of Kunena you are extending . In most cases posting a link to your site would also be helpful.

TOPIC: modification to specify a topic ID or category ID

modification to specify a topic ID or category ID 1 year 5 months ago #414

  • gariti
  • gariti's Avatar
  • OFFLINE
  • New Member
  • Posts: 3
  • Karma: 1
I am running Kunena 2.0.3 and would like to have a corresponding topic created for each of my K2 items (K2 v2.6) and have it displayed as a module on the K2 item page.

Your module works well, however rather than choose a category in the module settings, can the module work to receive a topic or category id via a php parameter and display the latest posts that way?

example: K2 item has an extra field created - "Forum id " which can be manually assigned a topic ID example "7"

your module would parse the extra field content as the topic ID to display in the module on that page.

does this sound possible?

thanks in advance!!
The administrator has disabled public write access.

modification to specify a topic ID or category ID 1 year 5 months ago #415

  • Aaron
  • Aaron's Avatar
  • OFFLINE
  • Administrator
  • Posts: 133
  • Thank you received: 8
  • Karma: 4
gariti,
Thanks for taking the time to try my extension and to post your idea here...
Yes, this sounds like something that will be possible!
However, though I have used K2 a fair bit in the past, I have moved all but one of the site I administer away from it and back to the J! core content system, so we will need to walk through this together...
Let me see if I understand the idea;

You have a K2 article called Example.
There is a Forum Category called Article Discussions.
In Article Discussions there is a Topic called Discuss Example Article.

You have a menu item pointing to the Example Article and on that page you'd like a module in the sidebar that is showing the latest posts to the topic Discuss Example Article.

How did I do so far? :silly:

How many of these article/topics do you expect to have? A few? Dozens? Hundreds? If you expect to have a number that is manageable, the easiest way I can see right now to make this happen with the existing module would be for me to add a topicId parameter in the module configuration and allow to you set the data source to Recent Posts and confine it to a Single Topic. You would then create a new module instance for each article, add the topic id there, and assign this module to only the one Example Article page....
Get it?

Other than that, I can see this probably needing a plugin to parse the Extra Fields of the K2 article for a specified field, in your example 'Forum id', add the topicId to the user state (or set a url var) and then have the module check for this variable...

Let me know if I am on target here... I do have to say though that I am very busy with a few other projects right now... But lets just see where this goes.
.:Aaron:.
nZambi Ex
Want to help?
Remember to visit the JED to vote for and review my extensions! IT ONLY TAKES A MOMENT and I appreciate it!
Please consider making a Donation if you find these extensions useful.
The administrator has disabled public write access.

modification to specify a topic ID or category ID 1 year 5 months ago #416

  • gariti
  • gariti's Avatar
  • OFFLINE
  • New Member
  • Posts: 3
  • Karma: 1
Hi Aaron,

Yes the scenario you have described above is exactly what I am looking for.

Currently I am calling the extra fields within the item.php file using the following:
<!-- Call to prepare extra fields --> 
    <?php  
    //convertArray to use ids as key
    $extrafields = array();
    foreach($this->item->extra_fields as $item)
    {    
    $extrafields[$item->id] = $item->value;
    }   
    ?>
and then where i want to display the extra field content I put:
<?php echo $extrafields[XXX]; ?>
//where XXX is the Field ID

through some trial and error I have been able to display the extra field within your module as text "the Topic ID is 12345" by using sessions:

item.php:
<?php  
    //convertArray to use ids as key
    $extrafields = array();
    foreach($this->item->extra_fields as $item)
    {    
    $extrafields[$item->id] = $item->value;
    }   
    ?>

    <?php  
    //convertArray to use ids as key
    $extrafieldslabel = array();
    foreach($this->item->extra_fields as $label)
    {    
    $extrafieldslabel[$label->id] = $label->name;
    }   
    ?>
//add topic ID extra field to session
<?php
session_start();
$_SESSION['topicID'] = $extrafields[41];
?>

then add this to your default.php:
//add topic ID extra field to variable

<?php 
session_start();
$topicID = $_SESSION['topicID'];
?>
// then echo the stored variable
<div id="topicID"> topic ID is <?php echo $topicID; ?></div>

This seems to do the job of getting the ID into your module, however now i am stuck as to where I can put this variable to return the correct forum information.

Thanks so much for your help and for taking the time to look at this so far.

Greg
The administrator has disabled public write access.

modification to specify a topic ID or category ID 1 year 5 months ago #417

  • Aaron
  • Aaron's Avatar
  • OFFLINE
  • Administrator
  • Posts: 133
  • Thank you received: 8
  • Karma: 4
Hi Greg...
OK... I see you have done some research already... this makes me more eager to jump in and help... I just went ahead and installed K2 on one of my development sites and looked over your ideas.
If you want to use the user session... id go with
// untested but I'm confident
JFactory::getApplication()->setUserState( "zKunenaLatest.topicID", $extrafields[41] );
However... I would hesitate to use the session as it may be persistent and cause grief on other pages.
Let me test a couple ideas I have...
.:Aaron:.
nZambi Ex
Want to help?
Remember to visit the JED to vote for and review my extensions! IT ONLY TAKES A MOMENT and I appreciate it!
Please consider making a Donation if you find these extensions useful.
The administrator has disabled public write access.

modification to specify a topic ID or category ID 1 year 5 months ago #418

  • Aaron
  • Aaron's Avatar
  • OFFLINE
  • Administrator
  • Posts: 133
  • Thank you received: 8
  • Karma: 4
OK... I think I have something that will work for you....
First though, I need to make sure... You are running mod_zkunenalatest_2(beta) on Joomla! 2.5 , Kunena 2.0.3 , K2 2.6... right?

OK. I set up my K2 extra fields with a field called Topic Id and an alias of topicid. It is a text field with default = 0 . This can be left for articles that don't yet have a topic.
First, edit the K2 item.php in the template you are using. I use the code below, right near the beginning of the file (after defined('_JEXEC') )
defined('_JEXEC') or die();

if (count($this->item->extra_fields)) {
	
	foreach ($this->item->extra_fields as $k=>$extraField) {
		// I have and extra field with alias 'topicid' and default value of 0
		if ($extraField->alias == 'topicid' && (int)$extraField->value > 0 ) {
			// I'll look for this variable in the module
			JRequest::setVar('k2topicid' , $extraField->value );
			// unset the extrafield to allow you to use other extra
			// fields in your article if you like without showing this one.
			unset($this->item->extra_fields[$k] );
		}
	}
}
Next, backup the file site/modules/mod_zkunenalatest/helper.php and replace it with the file attached here.

Attachment mod_zkunenalatest-gariti.zip not found


Enable the mod on pages with K2 Articles that have the topicid set and give it a try... Good Luck!
.:Aaron:.
nZambi Ex
Want to help?
Remember to visit the JED to vote for and review my extensions! IT ONLY TAKES A MOMENT and I appreciate it!
Please consider making a Donation if you find these extensions useful.
The administrator has disabled public write access.

modification to specify a topic ID or category ID 1 year 5 months ago #419

  • gariti
  • gariti's Avatar
  • OFFLINE
  • New Member
  • Posts: 3
  • Karma: 1
Hi Aaron,

this worked perfectly!!

I made a slight modification to comment out the "else" portion of the "function getItems($params)" in the helper.php as I need it to show nothing if the topic id is the default 0.

Thank you so much for your doing this, I'll be making a donation for your effort.

Greg
The administrator has disabled public write access.
Moderators: Aaron
Time to create page: 0.242 seconds