Restrict SOBI2 access based on CB Plans

9 years 6 months ago #156351 by RoCoART
Hi there.
I'm trying to find a way to restrict access to SOBI2 adds, based on subscription plans.
Basically I have 2 plans: free and paid.
The SOBI2 adds are listed on the main page in a V-card format.
I would like to give access to the details view of the adds only to those who paid the subscription.
So I have to extract the proper info from CB, add it to the V-card and that should solve the problem. I found a solution on SOBI forum but I'm stuck.
To extract data from from CB I used this:
function Load_CBfield($fieldname) {
  $database =& $config->getDb();
  $user =& JFactory::getUser();
  $userId = $user->get( 'id' );
  $sql = "SELECT ($fieldname) FROM #__comprofiler WHERE id= {$userId}";
  $database->setQuery( $sql );
  echo $database->loadResult();
and tried to use this:
$type = Load_CBfield("cb_membership");
if ($type == "paid") echo $title;
else echo $mySobi->title;
where I wanted to be the link that give access based on the plans I have.
But I get a Fatal error and nothing else. I'm not a php developer so I don't have a clue on how to solve this.
Could anyone help on this?
Thank you


Please Log in to join the conversation.

9 years 6 months ago #156814 by krileon
Replied by krileon on topic Re: Restrict SOBI2 access based on CB Plans
Please see the below tutorials on how to properly retrieve CB information. Direct database usage is not recommend, it ignores configuration and privacy settings (if using CB Privacy for instance).

Load CB API Externally:

Prepare $user Object:

Obtain User Field:

If you do not want to do this then please see the below fixing to your function.
function Load_CBfield( $field ) {
  $database	=&	$config->getDb();
  $user		=&	JFactory::getUser();
  $user_id	=	$user->get( 'id' );
  $sql		=	"SELECT `" . $field . "` FROM `#__comprofiler` WHERE `id` = " . (int) $user_id;
  $database->setQuery( $sql );
  return $database->loadResult();

I did not test the above. To debug ensure you have debug mode enabled and maximum error reporting set within Joomla global configuration. If new to PHP please see the below tutorial to get started in learning.

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.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.408 seconds

Facebook Twitter LinkedIn