Unique Licence Code based on user_id

  • Gary Bartlett
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 9 months ago #136263 by Gary Bartlett
Unique Licence Code based on user_id was created by Gary Bartlett
G'Day Folks,

I would like to provide my users with a unique licence code that appears in a designated place on each page and is based on the user_id.

The primary purpose is to generate a user-specific IP Licence Number that they can disseminate various things under.

'Anyone have any ideas on how best to achieve this? I use K2 and Regular Labs' Sourcerer - and will combine it with the current date in user local time.

(I guess I'm really looking for a way - probably using a PHP - to access the logged in user's user_id at page presentation time)

Thanks very much!

Gary

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

  • Gary Bartlett
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 9 months ago #136265 by Gary Bartlett
Replied by Gary Bartlett on topic Unique Licence Code based on user_id
I'm making some progress: membershipprodoc.joomservices.com/develo...umentation/api-basic

Now I need how to implement it!

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

  • Gary Bartlett
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 9 months ago - 3 years 9 months ago #136267 by Gary Bartlett
Replied by Gary Bartlett on topic Unique Licence Code based on user_id
I'm running with the following for the moment:
Code:
{source}<?php $user = JFactory::getUser(); echo "This user's name is {$user->name}, email is {$user->email}, id is {$user->id} and username is {$user->username}"; ?>{/source}
(But I'm still keen to figure out how to use the MP Basic API!
Last edit: 3 years 9 months ago by Gary Bartlett. Reason: Formatting

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

More
3 years 9 months ago #136268 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Unique Licence Code based on user_id
Hello Gary

Membership Pro API is used for different purpose (for external application like mobile app or code from external website to access to Membership Pro data, so it's not related here)

Back to your issue, the code you are using sourcer is correct (to get user id and username... of the current logged in user). What else you are looking for?

And honestly, I don't see this has anything to do with Membership Pro

Tuan

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

  • Gary Bartlett
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 9 months ago - 3 years 9 months ago #136285 by Gary Bartlett
Replied by Gary Bartlett on topic Unique Licence Code based on user_id
Thanks, Tuan!

I realise now that I was trying to get the MP membership ID not the Joomla user id!

I would also like to get the current user's MP subscription plan names and plan Ids.

Can you help me with that?

Thanks

Gary
Last edit: 3 years 9 months ago by Gary Bartlett. Reason: Greater clarity

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

More
3 years 9 months ago - 3 years 9 months ago #136290 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Unique Licence Code based on user_id
Hello

Please try the code below:
Code:
<?php $user = JFactory::getUser(); $db = JFactory::getDbo(); $query = $db->getQuery(true) ->select('a.*, b.title AS plan_title') ->from('#__osmembership_subscribers AS a') ->innerJoin('#__osmembership_plans AS b ON a.plan_id = b.id') ->where('user_id = ' . $user->id) ->where('(a.published >= 1 OR payment_method LIKE "os_offline%")'); $db->setQuery($query); $rows = $db->loadObjectList(); if (count($rows)) { $membershipId = 0; $planIds = []; $planTitles = []; foreach ($rows as $row) { if ($row->membership_id > 0) { $membershipId = $row->membership_id; } $planIds[] = $row->plan_id; $planTitles[] = $row->plan_title; echo 'Membership ID:' . $membershipId; print_r($planIds); print_r($planTitles); } }
Last edit: 3 years 9 months ago by Tuan Pham Ngoc.

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

  • Gary Bartlett
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 9 months ago #136304 by Gary Bartlett
Replied by Gary Bartlett on topic Unique Licence Code based on user_id
Thanks, Tuan - works a treat. Exactly what I wanted. So simple, in hindsight. You're a legend, Mate!

For anyone else needing this in future, I made two small changes to get it to work perfectly:
Code:
-> where('(b.published >= 1 OR payment_method LIKE "os_offline%")');
instead of
Code:
where('(published >= 1 OR payment_method LIKE "os_offline%")');
..because both tables have a published field.

2. the addition of the PHP closing tag
Code:
?>

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

More
3 years 9 months ago #136311 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Unique Licence Code based on user_id
Actually, it should be a.published instead of b.published

For additional PHP closing tag, I don't know how sourcer parse the code, but normally, the closing tag is not needed in PHP file (it's optional)

Regards,

Tuan

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

  • Gary Bartlett
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 8 months ago #136691 by Gary Bartlett
Replied by Gary Bartlett on topic Unique Licence Code based on user_id
Thanks, Tuan - just seen this now!

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

More
3 years 8 months ago #136698 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Unique Licence Code based on user_id
OK Gary.

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