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.

 

how to make operator "does contain" and "does not contain" ?

Re: how to make operator "does contain" and "does not contain" ?

hello Stephen

sorry to come again with my problem but I still unable to display/hide the module according to my wish. I probably make some confusion with all test and code and the fact the forum "strip out" part of code was not helpful. However I made again many test and I can absolutely confirm all test described below. For avoid any "strip out" I made a screenshot of used code and the image is available here:

http://img13.imageshack.us/img13/4000/e … il1381.png

******************************
When I try with CODE A:
*******************************


- Test 1

Email field does NOT contain "gmail"
Checkbox field cb_googlespam is NOT checked

Module display in debug mode this:

The e-mail address does not contain 'gmail'
googlespam box was not checked

The visual result is module 120 is not displayed

- Test 2

Email field CONTAIN "gmail"
Checkbox field cb_googlespam is NOT checked

Module display in debug mode this:

The e-mail address does not contain 'gmail'
googlespam box was not checked

The visual result is module 120 is not displayed

- Test 3

Email field CONTAIN "gmail"
Checkbox field cb_googlespam IS CHECKED

Module display in debug mode this:

The e-mail address does not contain 'gmail'
googlespam box was checked

The visual result is module 120 is not displayed

- Test 4

Email field does NOT contain "gmail"
Checkbox field cb_googlespam IS CHECKED

Module display in debug mode this:

The e-mail address does not contain 'gmail'
googlespam box was checked

The visual result is module 120 is not displayed


So in practice with the CODE A the module 120 is never displayed....


*************************
When I try with CODE B:
**************************

- Test 5

Email field does NOT contain "gmail"
Checkbox field cb_googlespam IS CHECKED

The visual result is module 120 is not displayed

- Test 6

Email field CONTAIN "gmail"
Checkbox field cb_googlespam IS CHECKED

The visual result is module 120 is not displayed

- Test 7

Email field CONTAIN "gmail"
Checkbox field cb_googlespam is NOT checked

The visual result is module 120 IS DISPLAYED

- Test 8

Email field does NOT contain "gmail"
Checkbox field cb_googlespam is NOT checked


The visual result is module 120 IS DISPLAYED


So in practice here all is well except in test 8 where normally the module must not be displayed because email field DOES NOT CONTAIN "gmail" and Checkbox field cb_googlespam is NOT checked.

If you can tell me how to solve the problem about test 8/CODE B and how to hide the module in that case (without of course change anything about other test/situation who work normally) it will beautiful.

Hope you can help..

Many many thank for your time.

dotcom22
Junior Modder
ranks
useravatar
Offline
21 Posts
Administrator has disabled public posting

Re: how to make operator "does contain" and "does not contain" ?

Hi dotcom22,

the reason why the module was never displayed with CODE A is that we never put in the lines to return the module id. The point was simply that it would indicate the results of the two variables, so you could see that the right data was there.

What I see is that the $contains variable is not coming up with the right answer. Somehow, it always thinks that the e-mail address does not contain "gmail", even when it does contain it.

My guess is that there's no field called email in the database table # __comprofiler. On my test site there isn't. If that's a field that you have added yourself, I think the field would be called cb_email instead.

If that was the case (if you have added an email field to CB) then change this line:

$email = strtolower($row->email);

to this:

$email = strtolower($row->cb_email);

If you have NOT added your own e-mail field, and you're just using the standard Joomla e-mail field, then change the line to this:

$email = strtolower($user->email);



Try making that change in both recipes, and see what happens. Hopefully in CODE A you'll see that the $contains variable is reporting the address correctly.

I think my original logic may need some alterations too, as you suggested...

instead of this:

  if (strpos($email, 'gmail') !== false) return 120; // rule 1
  // now we already know that email does not contain "gmail"...
  if ($gmail == 0) return 120; // rule 2.

try this:

  $contains = (strpos($email, 'gmail') !== false);
  if (!$contains and $gmail == 0) return; // show no module
  if ($contains) return 120;
  // now we already know that email does not contain "gmail"...
  if ($gmail == 0) return 120;

I so hope I got it this time!

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
3329 Posts
User info in posts
Administrator has disabled public posting

Re: how to make operator "does contain" and "does not contain" ?

hey Stephen

many thank for your reply...

Damned I'm sorry but no luck... :-(

I use the default email field and this field name is really "email" and not "cb_email". I take a look for be sure inside the database and I can confirm this point..

So I tried to change variable by putting in both code A and B this:

  $email = strtolower($user->email);

...but no change and the email field seem really to not be recognized. Maybe the variable is not the right one for that field...

I see in my database the email field is not part of "comprofiler" table but is a "users" table...so maybe is required to make another query in the recipe for email field ?

I made some search on CB forum and I found this:

http://www.allmysocials.com/index.php?o … ser-object

For the less I understand some more code must maybe added in the recipe.

I'm sorry if what I say have no sens...unfortunately I'm not a coder and PHP is a nightmare for me even if I start to understand few things. But maybe this can give you some clue...

1000 thank

dotcom22
Junior Modder
ranks
useravatar
Offline
21 Posts
Administrator has disabled public posting

Re: how to make operator "does contain" and "does not contain" ?

Hi again,

wow, this is much more difficult to get right than I thought. You know what, it would be much quicker if I could just be logged in to your site and try out the different options until I find out what's going on. Would you be ok with that? I'll send you a PM with my e-mail address.

We'll get there!

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
3329 Posts
User info in posts
Administrator has disabled public posting

Re: how to make operator "does contain" and "does not contain" ?

Ok, now I've got the full picture and as far as I can see, this is working properly.

Code:

$user_id = $db->getEscaped((int)($user->id));

if ($user_id > 0) {
   $query = "select c.cb_googlespam, u.email from #__comprofiler c left join #__users u on c.user_id = u.id where c.user_id = '$user_id';";
  $db->setQuery( $query );
  $row     = $db->loadObject();

  $gspam = $row->cb_googlespam;
  $email = strtolower($row->email);
  $contains = (strpos($email, 'gmail') !== false);

  // show module if it's a gmail address and box is not checked.
  if ($contains and !$gspam) return 120;

}

Here's what was going on in the PHP:

1 - the actual rule is quite simple. It's just a single condition: the module is only to display when the user has a gmail address AND they have not checked the checkbox. I guess the checkbox will be labelled with something like "Yes, I've added this site to my list of approved senders in gmail". We were getting all confused earlier with various conditions etc.

2 - here was the hard part: the # __comprofiler table does not contain the e-mail address. Officially, the # __users table contains the e-mail address. And the e-mail address is supposed to be available in the $user object. However, it appears that CommunityBuilder does not update the $user object when it changes an e-mail address. $user still held the old address! Therefore, I had to get it direct from the database. I just added it to the SQL statement above so that it gets the value of the checkbox from one table, and the e-mail address from the other table.

I tested this out by changing my e-mail address to and from a gmail address, and I tested this with the checkbox on and off. As far as I can see this now works properly - can you please check it too?

And, I'd advise putting some more info on the page about what the "google spam" checkbox actually does.

Thanks for letting me have access to the site - it was definitely much easier to diagnose that way!

Best regards,
Stephen

Edited By: metamodguy
21-Oct-11 10:51:26

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
3329 Posts
User info in posts
Administrator has disabled public posting

Re: how to make operator "does contain" and "does not contain" ?

You rock stephen !!!! Many thank for help .-) :-)

This time all seem to be fine and also with the CB conditional email field who display the checkbox only if "gmail" is detected...

I'm so happy to have find this trick because is really annoying to get problem with Gmail... Is the only viable solution for warn users...

Thank also for your advice concerning the checkbox. I already make in my production site a "tooltip" for explain for what is the checkbox...

In some month I will need to upgrade my joomla from 1.5 to 1.7 and I will consider buy your pro version...

All the best

cheers

dotcom22
Junior Modder
ranks
useravatar
Offline
21 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1688
Total Polls:
6
Total Posts:
5939
Dormant:
User Info:
 
Total Users:
6886
Newest User:
shafn31a2
Members Online:
1
Guests Online:
130

Online: 
shafn31a2

Forum Legend:

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