Frontend display of category name in event properties

  • Tuan Pham Ngoc
  • Away
  • Administrator
  • Administrator
More
5 years 11 months ago #113574 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Frontend display of category name in event properties
Thanks to James. He's always helpful :)

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

More
5 years 11 months ago #113581 by James Riley
And to Tuan for fixing my mistakes, and correcting my errors! (and for putting up with them!)

James Riley .: EventBooking user since 2014 ::: JoomDonation user since 2016 :.
.: grfx & web design / IT / AV @ St. Therese Institute of Faith and Mission, Bruno, SK, Canada :.

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

  • Christoph
  • Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 10 months ago #113817 by Christoph
Hi, unfortunately it is me again regarding this matter. This is the code which works pretty well in events_properties.php:
Code:
<?php $catTopicIDs=array(3,4,26,27,28,29,30,42 /* add other "topic" IDs */ ); $catTopic = ''; $catLanguageIDs=array(33,32,34,35,36,37,38,39,40,41 /* add other "langauge" IDs */ ); $catLanguage = ''; $catGradeIDs=array(11,12,13,14,15,16,17,18,19,20,21,22,23,24,25 /* add other "grade" IDs */ ); $catGrade = ''; $catDayIDs=array(6,7,8,9,10 /* add other "day" IDs */ ); $catDay = ''; // etc foreach($item->categories as $category) { // check if $category contains one of the Category Topics ids if (in_array($category->id,$catTopicIDs)) { if ($catTopic) { $catTopic .= ', '; // add a comma if there is already previous data added to this variable } $categories = []; $categoryUrl = JRoute::_(EventbookingHelperRoute::getCategoryRoute($category->id, $Itemid)); $categories[] = '<a href="' . $categoryUrl . '">' . $category->name . '</a>'; $catTopic .= implode(',' , $categories); } // check if $category contains one of the Category Langauage ids if (in_array($category->id,$catLanguageIDs)) { if ($catLanguage) { $catLanguage .= ', '; } // add a comma if there is already previous data added to this variable $categories = []; $categoryUrl = JRoute::_(EventbookingHelperRoute::getCategoryRoute($category->id, $Itemid)); $categories[] = '<a href="' . $categoryUrl . '">' . $category->name . '</a>'; $catLanguage .= implode(',' , $categories); } // etc etc etc for the rest of the "sub-groups" if (in_array($category->id,$catGradeIDs)) { if ($catGrade) { $catGrade .= ', '; } // add a comma if there is already previous data added to this variable $categories = []; $categoryUrl = JRoute::_(EventbookingHelperRoute::getCategoryRoute($category->id, $Itemid)); $categories[] = '<a href="' . $categoryUrl . '">' . $category->name . '</a>'; $catGrade .= implode(',' , $categories); } if (in_array($category->id,$catDayIDs)) { if ($catDay) { $catDay .= ', '; } // add a comma if there is already previous data added to this variable $categories = []; $categoryUrl = JRoute::_(EventbookingHelperRoute::getCategoryRoute($category->id, $Itemid)); $categories[] = '<a href="' . $categoryUrl . '">' . $category->name . '</a>'; $catDay .= implode(',' , $categories); } } ?>

However, adding that code to events_table.php to display the categories in the list or table view keeps the table empty.

<?php echo $catDay ?> or even <?php echo $category ?> delivers no results in events_table.php too. Is the category object not known in that file?

Thank you,
Chris

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

  • Tuan Pham Ngoc
  • Away
  • Administrator
  • Administrator
More
5 years 10 months ago #113823 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Frontend display of category name in event properties
Hi Chris

I think you will have to debug the code yourself. $item->categories is available in that layout, you can try to add var_dump($item->categories); and you will see the value of it

Try to check the code to see what's wrong, you should be able to figure it out. Please note that the code you wrote above, must he placed inside for ($i = 0, $n = count($items); $i < $n; $i++) block, it could not be placed outside for, maybe that's your problem

Regards,

Tuan
The following user(s) said Thank You: Christoph

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

  • Christoph
  • Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 10 months ago #113834 by Christoph
Thank you very much Tuan! I got it now

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

  • Tuan Pham Ngoc
  • Away
  • Administrator
  • Administrator
More
5 years 10 months ago #113847 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Frontend display of category name in event properties
OK, great

Tuan

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

  • Christoph
  • Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 10 months ago #113903 by Christoph
Hello,

In event table and properties view the category works well and I'm happy that a similar feature is now available through the 3.5.1 update. Kudos to EB developer team and community!

I'm trying to understand how the category object gets loaded into the different views. Currently I'm working on to get the category values also displayed in the views of the shopping cart overlay (cart/mini.php) and the shopping card page (cart/default.php).

I started with copying the code into mini.php and default.php into the ($i = 0, $n = count($items); $i < $n; $i++) block, but the difference there is the block is like this: ($i = 0 , $n = count($this->items) ; $i < $n; $i++)

and - surprise - it doesn't work :-/

I tried to debug the problem for hours. Still getting NULL only if I call the values with

var_dump($categories) ;
var_dump($category) ;
var_dump($item->categories) ;
var_dump($item->category) ;
var_dump($this->categories) ;
var_dump($this->category) ;
var_dump($this->item->categories) ;
or var_dump($this->item->category) ;

That's the code which works in event table and event properties view but not for the shopping cart table:
cart/mini.php and cart/default.php
Code:
$catGradeIDs=array(11,12,13,14,15,16,17,18,19,20,21,22,23,24,25); $catGrade = ''; foreach($item->categories as $category) { if (in_array($category->id,$catGradeIDs)) { if ($catGrade) { $catGrade .= ', '; } // add a comma if there is already previous data added to this variable $categories = []; $categoryUrl = JRoute::_(EventbookingHelperRoute::getCategoryRoute($category->id, $Itemid)); $categories[] = '<a href="' . $categoryUrl . '">' . $category->name . '</a>'; $catGrade .= implode(',' , $categories); } }

Please help to guide me to the correct direction.

Thank you,
Chris

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

  • Tuan Pham Ngoc
  • Away
  • Administrator
  • Administrator
More
5 years 10 months ago #113925 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Frontend display of category name in event properties
Hi Chris

No surprise at all. Different views has different data (we just load the data needed for the view, not loading extra data when it's not needed for slowing down the page)

In the mini.php and default.php, you only have $eventId data from $item->id variable.

Base on that, you will need to query database to get categories of that event. See the code in preProcessEventData method, file components/com_eventbooking/helper/data.php , line 539 to 554 to see the code to query the database and get categories of an event

Hope it helps

Tuan

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

  • Christoph
  • Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 10 months ago #113986 by Christoph
Hi Tuan,

thank you for all the help I really appreciate! Unfortunately I cannot get it done myself. I can only look into professional code and get clues myself, copy it, tinker around and hope for the best ;-)
rather than code it myself. Still have to learn a lot about php...

Kind regards,
Chris

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

  • Tuan Pham Ngoc
  • Away
  • Administrator
  • Administrator
More
5 years 10 months ago #113994 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Frontend display of category name in event properties
Yes, maybe hire someone who understand Joomla / PHP programming better to do it for you. Sometime, it's not easy to do the modification if you don't have much experience with Joomla/PHP programming

Tuan

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

Moderators: Tuan Pham Ngoc