-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes to Membership Renewal for issue CRM-20571 #10822
Conversation
Can one of the admins verify this patch? |
test this please |
(that last comment was to jenkins - to run our CI tests) |
Jenkins ok to test |
// Get the Join Date from Membership info as it is not available in the Renew form | ||
$joinDate = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'join_date'); | ||
// Save its value in a hidden field | ||
$this->addElement('hidden', 'join_date', $joinDate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amsharma9 Instead of creating a hidden field and storing values, can we not check the join_date
in formRule()
itself using membership id?
You can pass $this
to addFormRule() in order to get membership id. Something like -
$this->addFormRule(array('CRM_Member_Form_MembershipRenewal', 'formRule'), $this);
and then add params to formRule()
function
public static function formRule($params, $files, $self) {
You should get membership id in $self->_id
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is what I wanted to do. Just to inform you I am new to CiviCRM. I asked on Stackexchange but nobody gave a hint about how to get a field from Membership form in Membership Renewal form. I saw similar code in Membership.php but didn't understand it fully and couldn't find the documentation. Didn't understand from where $self
appeared. Can you point me to the documentation. I can then make that change. Is there some place where I can find explanation of each parameter of each function in CiviCRM, probably with some examples. The best documentation I could find was QuickForm Reference which just mentioned how formRule()
works and the only argument which can be accessed in it is $values
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idt, there is a doc which explain "each parameter of each function in CiviCRM" as you mention. Just pinging @eileenmcnaughton if she might have seen any. What I found is https://docs.civicrm.org/dev/en/master/core/architecture/#form which explains these basic form function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jitendrapurohit I will make the change you suggested, will check out some examples, let me try. Your explanation helped to understand how $self
appeared. I edited my reply to give you the link to my query on Stackexchange - I wanted to know how to access $this->_id
in formFule()
. If $self
works in formRule()
if we pass $this
as you suggested then we have a better solution right away. This should work in formRule()
:
$joinDate = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $self->_id, 'join_date')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do this validation using addRule()
in buildQuickForm()
itself. I didn't find any documentation on what kind of complex parameters can addRule()
take. Is there a way to compare two dates in addRule()
. The best complexity I saw is below. What options other than objectExists
are available, is there any documentation about that.
$this->addRule('trxn_id', ts('Transaction ID already exists in Database.'),
'objectExists', array('CRM_Contribute_DAO_Contribution', $this->_id, 'trxn_id')
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jitendrapurohit I made the changes as you suggested and checked. It works without issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you have a good explanation and accepted answer from Andrew. Not sure if they could be done directly in buildForm() within a single line, but the current code looks fine and more straightforward to me. But if you want to try, I think you can do something like - https://pear.php.net/manual/en/package.html.html-quickform.html-quickform.addrule.php ?
For options accepted by addRule()
, these are the registered rules within quickform https://pear.php.net/manual/en/package.html.html-quickform.html-quickform.getregisteredrules.php. You can directly see the list of them at https://github.com/civicrm/civicrm-packages/blob/master/HTML/QuickForm.php#L75-L89.
Also civicrm registers some rules explicitly available on all forms - see https://github.com/civicrm/civicrm-core/blob/master/CRM/Core/Form.php#L288. So you can use any of them.
@jitendrapurohit looks OK to me now - what do you think? |
looks good to me too @eileenmcnaughton. I'll test this and update soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eileenmcnaughton Tested and confirmed the working. I think this is good to merge.
Fantastic @jitendrapurohit @amsharma9 - your virtual 'first time committer mug' has just appeared on your desk :-) |
Overview
Modifications required to compare join_date with renewal date before allowing the renewal to be accepted.
Before
Any renewal date can be specified and if it is before the join_date then the form gives error.
After
If the renewal date is before the join_date then the form reports an error indicating it must be after join_date, i.e. date of membership start.
Technical Details
Explained it in inline comments
// CRM-20571
Get the Join Date from Membership info as it is not available in the Renew form
Save its value in a hidden field
// CRM-20571: Check if the renewal date is not before Join Date, if it is then add to 'errors' array
The fields in Renewal form come into this routine in $params array. 'renewal_date' is already in the form and we added 'join_date' as a hidden field in the buildForm routine with member join date value
We process both the dates before comparison using CRM utils so that they are in same date format
Comments