Skip to content
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

hook_civicrm_alterReportVar is not working #577

Open
fajlay opened this issue Jan 25, 2024 · 8 comments
Open

hook_civicrm_alterReportVar is not working #577

fajlay opened this issue Jan 25, 2024 · 8 comments

Comments

@fajlay
Copy link

fajlay commented Jan 25, 2024

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';

  $from = $var->getVar('_from');
  $from .= ' LEFT JOIN civicrm_financial_trxn card_type 
           ON (contribution.trxn_id = card_type.trxn_id) 
           LEFT JOIN civicrm_option_value card_type_label 
           ON (card_type.card_type_id = card_type_label.value AND card_type_label.option_group_id = 9)';
  $var->setVar('_from', $from);
}

}
}

@eileenmcnaughton
Copy link
Owner

@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

@fajlay
Copy link
Author

fajlay commented Jan 25, 2024

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/

@eileenmcnaughton
Copy link
Owner

ouch - I might update that!

@seamuslee001
Copy link
Collaborator

@eileenmcnaughton I will just say that getVar() has been used in some JMA extensions to add or modify things like the from etc

@eileenmcnaughton
Copy link
Owner

@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

@adevapp
Copy link

adevapp commented Feb 7, 2024

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.

@adevapp
Copy link

adevapp commented Feb 7, 2024

Built with Search Kit and looks amazing! Turned into a dashlet/report. Thank you @eileenmcnaughton for the suggestion.

@eileenmcnaughton
Copy link
Owner

@devappsoftware thanks for the feedback - & hopefully it will be the first of many search kit dashlets for you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants