Skip to Content Skip to Menu

[SOLVED] Checking field value from php in a module

  • fribse2011
  • fribse2011
  • OFFLINE
  • Posts: 921
  • Thanks: 79
  • Karma: 8
9 years 9 months ago - 9 years 9 months ago #256688 by fribse2011
I would like to display one module for one field value, an another module for a different value.
Advanced Module Manager can check via php, but I have no idea what the code looks like, can you help out?

Best regards
Fribse

Frømandsklubben Nikon, www.nikondyk.dk
We're a volunteer driven diving club in Ishøj, Denmark.
Har du brug for en dykkerklub der rummer alle, så kom ned til os.
Last edit: 9 years 9 months ago by fribse2011.

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

  • fribse2011
  • fribse2011
  • OFFLINE
  • Posts: 921
  • Thanks: 79
  • Karma: 8
9 years 9 months ago #256692 by fribse2011
Replied by fribse2011 on topic Checking field value from php in a module
Ahaaa, I found some code on the forum

Establishing the user object:
Code:
<?php global $_CB_framework, $mainframe; if ( defined( 'JPATH_ADMINISTRATOR' ) ) { if ( ! file_exists( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ) ) { echo 'CB not installed!'; return; } include_once( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ); } else { if ( ! file_exists( $mainframe->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/plugin.foundation.php' ) ) { echo 'CB not installed!'; return; } include_once( $mainframe->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/plugin.foundation.php' ); } $user =& CBuser::getUserDataInstance( $_CB_framework->myId() );

Is that still correct code?

Then to get a field would be something like
Code:
$user->cb_cell

Is that correct?

Oh, and it's in a component of course I need to check this, but it's going to display one module or another.

Best regards
Fribse

Frømandsklubben Nikon, www.nikondyk.dk
We're a volunteer driven diving club in Ishøj, Denmark.
Har du brug for en dykkerklub der rummer alle, så kom ned til os.

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

  • fribse2011
  • fribse2011
  • OFFLINE
  • Posts: 921
  • Thanks: 79
  • Karma: 8
9 years 9 months ago - 9 years 9 months ago #256693 by fribse2011
Replied by fribse2011 on topic Checking field value from php in a module
I guess it could be even simpler for the user object
Code:
Global $_CB_framework; $user =& CBuser::getUserDataInstance( $_CB_framework->myId() );

Then
Code:
$rykker = $user -> cb_rykker; return ( $rykker == '1' );

cb_rykker is a single checkmark.

Would that be correct?

Best regards
Fribse

Frømandsklubben Nikon, www.nikondyk.dk
We're a volunteer driven diving club in Ishøj, Denmark.
Har du brug for en dykkerklub der rummer alle, så kom ned til os.
Last edit: 9 years 9 months ago by fribse2011.

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

  • fribse2011
  • fribse2011
  • OFFLINE
  • Posts: 921
  • Thanks: 79
  • Karma: 8
9 years 9 months ago #256695 by fribse2011
Replied by fribse2011 on topic Checking field value from php in a module
Code:
Global $_CB_framework; $user =& CBuser::getUserDataInstance( $_CB_framework->myId() ); return ( $user -> cb_rykker == '1' );

This works it seems, I hope it's done 'correctly'.

Best regards
Fribse

Frømandsklubben Nikon, www.nikondyk.dk
We're a volunteer driven diving club in Ishøj, Denmark.
Har du brug for en dykkerklub der rummer alle, så kom ned til os.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48479
  • Thanks: 8283
  • Karma: 1443
9 years 9 months ago #256754 by krileon
Replied by krileon on topic Checking field value from php in a module
If you're using CB 2.x you'd do the below to shorten it a bit.

File Attachment:

File Name: cb_2_api_u...ject.txt
File Size:0 KB


When possible I recommend always using get/set if it's available. In case of CB 2.x all our table classes can use get/set properly.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
Attachments:
The following user(s) said Thank You: fribse2011

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

  • fribse2011
  • fribse2011
  • OFFLINE
  • Posts: 921
  • Thanks: 79
  • Karma: 8
9 years 9 months ago #256869 by fribse2011
Replied by fribse2011 on topic Checking field value from php in a module
And even shorter :-)
Of course I could even skip the error checking, but it's nice to have it anyways. It doesn't seem to use that much extra ram or take extra time to load the page, so I'm very happy with this solution, thankyou!
It actually also worked, so quite a few clubmembers has paid their overdue fees :evil:

Best regards
Fribse

Frømandsklubben Nikon, www.nikondyk.dk
We're a volunteer driven diving club in Ishøj, Denmark.
Har du brug for en dykkerklub der rummer alle, så kom ned til os.
Attachments:

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

Moderators: beatnantkrileon
Powered by Kunena Forum