Add user to moodle after subscription on PayPlans

  • Leandro
  • Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 4 months ago #1 by Leandro
Hi Chris and Antonio!

I´m trying to make some changes in the payplans plugin, to allow users registration only after subscription.

I´ve already wrote few words like two weeks ago about this (enrol user based on joomla group (that would be great!!!)), but since that I´ve changed from akeebasubscription to payplans after Chris alert that akeebascription was in EOL...

I´ve installed the payplans and made some changes in the joomdle plugin and I want to share and ask some help....

These are the changes that I´ve made...

Turned off "Auto create Moodle users" on joomdle configuration component.

On /var/www/plugins/payplans/joomdle3/joomdle3/app/joomdle.php

Line +/- 53
Code:
// if subscription is active if($newStatus == PayplansStatus::SUBSCRIPTION_ACTIVE){ $this->_enrol_user($userid, $courses, $subid); //added.. $this->_addmoodle_login($userid); return true; }

Added the following lines on the end of the file
Code:
protected function _addmoodle_login($userid) { require_once(JPATH_ADMINISTRATOR.'/components/com_joomdle/helpers/content.php'); $user = JFactory::getUser($userid); JoomdleHelperContent::add_moodle_users ($user); return true; }
Now, when the users get activated by one plan using joomdle plugin it gets registered on the moodle too.

But, I´m having two problems...

1) It´s give me an “XML-RPC Error (404): Unknown error”, but the user get registered on moodle…

2) The name and email the data that should be transferred to moodle register doesn´t work.

Can you guy’s help me to finish or give some instructions to finish it?

I´m not a developer, but I believe that shouldn’t be too hard… :)

Thanks in advanced for you time,
Leandro

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

More
12 years 4 months ago #2 by Antonio Durán
Replied by Antonio Durán on topic Add user to moodle after subscription on PayPlans
Hi.

I don't think you need that, if I understand it correctly.

Joomdle will create a Moodle user when you try to enrol him into a course if he is not created yet.

From Joomdle enrol function in moodle:
Code:
.... /* Create the user before if it is not created yet */ $conditions = array ('username' => $username); $user = $DB->get_record('user',$conditions); if (!$user) $this->create_joomdle_user ($username); .....

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

  • Leandro
  • Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 4 months ago - 12 years 4 months ago #3 by Leandro
Hi Antonio,

So I believe that I´m doing something wrong… I created the plan in payplans, installed the joomdle app, assigned a course, left the "Auto create Moodle users" off, but when I bought the subscription the user didn´t get registered on moodle… so this is why I made the change in your php…


Yesterday late at night I found a way that works, or at last seems to..
Code:
protected function _addmoodle_login($userid) { require_once(JPATH_ADMINISTRATOR.'/components/com_joomdle/helpers/content.php'); $user = JFactory::getUser($userid); JoomdleHelperContent::call_method ('create_joomdle_user', $user->username); return true; }

But if It should be automatically registered do you have any clue what I´m doing wrong?


I tried again, but no luck…

The plugin seems to work, when I make the subscription active and the user exists on moodle, it get enrolled, when I change to expired, the courses are removed from user, but if the user didn’t exists on moodle, It doens´t get registered on moodle and when I manually register It, he is not enrolled in any course…

I looked at your script and yes… the lines that you mention are there.. but I do not understand why it´s not working if the user is not registered on moodle…

The changes that I made seems to work.. but I´m not sure if I need it since yours already have this function inside and probably is something that I´m doing in the wrong way….
Last edit: 12 years 4 months ago by Leandro. Reason: more tests executed...

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

More
12 years 3 months ago #4 by Antonio Durán
Replied by Antonio Durán on topic Add user to moodle after subscription on PayPlans
Hi,

I just tested, and user was not automatically registered. I thought it would happen, as this is working fine in normal shop integration, but it did not.

I reviewed the code, and it turns out the problem is that we are using different enrol functions: here we use multiple_enrol function from Joomdle web services in Moodle (moodle/auth/joomdle/auth.php)
That function had this:
Code:
if (!$user) return;
So, if a user did not exist, it did nothing.

I have changed this to:
Code:
if (!$user) $this->create_joomdle_user ($username); $user = $DB->get_record('user',$conditions);

And not it is working fine on my local tests. I will include that change for next release.

Thanks for the feedback!

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

  • Leandro
  • Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 3 months ago #5 by Leandro
Hi Antonio!

I´ve made the changes and now seems to be working flawless.

Thanks again for you time,
Leandro

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

More
12 years 3 months ago #6 by Antonio Durán
Great, thanks for the feedback.

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

  • Leandro
  • Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 3 months ago - 12 years 3 months ago #7 by Leandro
You are welcome!
Last edit: 12 years 3 months ago by Leandro.

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