Open fajlay opened 7 months ago
@fajlay calling getVar()
is probably best avoided because it is a way to interact with a property on a class that wasn't intended for external interaction
I guess there are few different ways to do what you are trying to do but the first question is - could it be done with SearchKit? From my point of view I'm not aware of anything this extension does that search kit doesn't do better these days
Thanks for your reply. The official CiviCRM guide suggested using getVar() to alter report output. So I was just following the official approach. https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterReportVar/
ouch - I might update that!
@eileenmcnaughton I will just say that getVar() has been used in some JMA extensions to add or modify things like the from etc
@seamuslee001 yeah - it has a lot of legacy uses - but it is basically used to access things that are not supported for external access - so it is totally liable to break at any time
Yes, find the columns do not appear in the report. Example below. The code executes and freezes with a var_dump, but doesn't seem to work with the hook.
function eventidlink_civicrm_alterReportVar($varType, &$var, $reportForm) {
$class = get_class($reportForm);
if (in_array($class, ['CRM_Extendedreport_Form_Report_Event_ParticipantExtended']) && $varType == 'rows') {
$var['civicrm_contact']['filters']['civicrm_contact_civicrm_contact_contact_id'] = [
'name' => 'current_user',
'title' => ts('Limit To Current User'),
'type' => CRM_Utils_Type::T_INT,
'operatorType' => CRM_Report_Form::OP_SELECT,
'options' => ['0' => ts('No'), '1' => ts('Yes')],
];
}
Might look at search kit.
Built with Search Kit and looks amazing! Turned into a dashlet/report. Thank you @eileenmcnaughton for the suggestion.
@devappsoftware thanks for the feedback - & hopefully it will be the first of many search kit dashlets for you!
I am trying to alter a report to show an extra column. Before updating the extension it worked fine. But after updating, it is not working anymore. Following is my code. The error shows "Call to a member function getVar() on string in ..."
I also noticed that $var->_select value is empty and $var->_columnHeaders, $var->getVar(), $var->setVar() are not working anymore. Any thoughts?
function extname_civicrm_alterReportVar($varType, &$var, $reportForm) { $instanceValue = $reportForm->getVar('_instanceValues');
if (!empty($instanceValue) && in_array($instanceValue['report_id'], array('price/lineitem',))) { if ($varType == 'sql') { $var->_columnHeaders['civicrm_card_name'] = array( 'title' => 'Credit Card Type', 'type' => 2, ); $var->_select .= ' , GROUP_CONCAT(DISTINCT (card_type.card_type_id)) as civicrm_credit_card_type , GROUP_CONCAT(DISTINCT (card_type_label.name)) as civicrm_card_name';
} }