Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Help with a jReviews recipe?

Help with a jReviews recipe?

I'm on Joomla 2.5 (Joomla SEF is on).

On the detailed listing display of a given jReviews listing, I need to have that listing queried and I want to test for a value in a jr custom field. If that criteria matches, I'd like to display a custom module in sidebar-a (an RT template).

So, if jr_promo = 'yes' then display module #184.

Can you help me with this?

Thanks!
Teresa

BeTheDance
Beginner Modder
ranks
useravatar
Offline
9 Posts
Administrator has disabled public posting

Re: Help with a jReviews recipe?

Ok, this is going to require 2 things:

1 - detecting when you are on a JReviews listing, and extracting the id number from that
2 - writing the query to get the value stored in the jr_promo field in the database.

Now, for (1), could you please add a blank MetaMod in module manager, set it to display on all pages, then turn on MetaMod's advanced debug mode and visit a jReviews listing? Then write back with the output from the MetaMod, which should have enough info in it to work out how to detect being on a jReviews page, and which variable has the id number of the jReview in it.

(2) is going to look something like this, once we have (1) in place:

$query = "sel" . "ect jr_promo from #_" . "_jreviews_content where contentid = " . (int)$contentid;
$db->setQuery($query);
if ($db->loadResult() == 'yes') return 184;


Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: Help with a jReviews recipe?

Here it is:

Page Identification
The PHP code below may be used to help MetaMod to identify the exact page that you are viewing. For help using this feature, please click here.
if (
$option == 'com_content'
and $view == 'article'
and $id == 77
and JRequest::getVar('catid') == 31 /*!*/
and $Itemid == '319'
and JRequest::getVar('url') == NULL /*!*/
) return XXX; /* replace XXX with the module ID or position to display */
Note: lines starting with "and" and ending with /*!*/ contain rules that may be optional. You may wish to leave them out.
MetaMod debug info:
Module ID: 188
$option: com_content
$view: article
$id: 77
$Itemid: 319
$timezone: America/Indiana/Indianapolis
$language: en-us
$language_code: en
$language_region: us
Including modules: None

BeTheDance
Beginner Modder
ranks
useravatar
Offline
9 Posts
Administrator has disabled public posting

Re: Help with a jReviews recipe?

Ok, that's great, thanks. jReviews is dealing with completely normal Joomla articles.

So try the following:

if ($core_genius->check("pagetype = article")) {
  $query = "sel" . "ect jr_promo from #_" . "_jreviews_content where contentid = " . (int)$id;
  $db->setQuery($query);
  if ($db->loadResult() == 'yes') return 184;
}


Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: Help with a jReviews recipe?

Awesome! Worked. So, how would I change it a bit for a LIKE condition? I couldn't get that to work.

Thanks so much.
Cheers,
Teresa

BeTheDance
Beginner Modder
ranks
useravatar
Offline
9 Posts
Administrator has disabled public posting

Re: Help with a jReviews recipe?

What's a "like" condition? Is that something that users can do in jReviews? If so, it's probably a column in the database... might pay to check the columns in the _jreviews_content table and see if it's there, and what the column name is.

Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: Help with a jReviews recipe?

smile I just mean SQL, for example, jr_customfield LIKE '%stars%' rather than a pure ==

I have a lot of multi-option fields where the value I'm looking for I can't test with an equal condition. I need a 'contains' or a 'like' type of test.

Thanks much!

BeTheDance
Beginner Modder
ranks
useravatar
Offline
9 Posts
Administrator has disabled public posting

Re: Help with a jReviews recipe?

Yes, this would work:

jr_customfield LIKE '%stars%'

The syntax used is that of MySQL. See http://dev.mysql.com/doc/refman/5.0/en/ … tions.html

"%" matches 0 or more of any character. "_" matches exactly 1 character.

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: Help with a jReviews recipe?

So, by way of example, in the same case as above, if try to change the comparison per below:

FROM THIS:

if ($core_genius->check("pagetype = article")) { $query = "select jr_tastingclubwinery from #__jreviews_content where contentid = " . (int)$id; $db->setQuery($query); if ($db->loadResult() == '*yes*') return 174; }

TO THIS:

if ($core_genius->check("pagetype = article")) { $query = "select jr_tastingclubwinery from #__jreviews_content where contentid = " . (int)$id; $db->setQuery($query); if ($db->loadResult() like '%*yes*%') return 174; }

It doesn't work.

I need to figure out how to get the syntax right so that I can compare the field. Not sure how the $db->loadResult() is really working.

Actually, if you could explain this syntax to me in English: -> I would be very grateful. I've never been sure of how to really read that. I'm a self-taught, learn by trying kind of gal. It just eludes me. Probably sounds pretty dumb.

Thanks!

BeTheDance
Beginner Modder
ranks
useravatar
Offline
9 Posts
Administrator has disabled public posting

Re: Help with a jReviews recipe?

No, not dumb - we all had to learn it once!

The "like" syntax goes inside the SQL query. PHP doesn't do "like" but there *are* some PHP ways to achieve the same thing.

So let's do it with PHP.

if ($core_genius->check("pagetype = article")) {
  $query = "sel" . "ect jr_tastingclubwinery from #_" . "_jreviews_content where contentid = " . (int)$id;
  $db->setQuery($query);
  $res = $db->loadResult();
  if ( strpos($res, 'yes') !== false) return 184;
}


Ok, so how does this work?
strpos returns the position of the 2nd string ("yes") within the first string (what comes out of the database). If the 2nd string is not found in the 1st string, then it returns "false". Now, because 0 and false are treated almost the same in php, you have to do a === or !== to detect if the result is EXACTLY false or not. So if it was 0, it won't get confused into thinking that's the same as false. Sorry if that's confusing, I'm typing faster than my brain is working.

So the strpos method is a simple way of testing if a string contains a certain substring.

If you want it to be case insensitive, use "stripos" instead of "strpos".

For more complex string matching you can use something called Regular Expressions (regex) using a function called preg_match. That starts to look similar to the LIKE syntax (though it's different) and is far more powerful than strpos can achieve. But we'll only go there if we need to...

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5933
Posts this week:
3
User Info:
 
Total Users:
4412
Newest User:
doyal54741
Members Online:
1
Guests Online:
142

Online: 
doyal54741

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked