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

Towards CRM-20037 edit template to be more flexible. #10295

Merged
merged 1 commit into from
May 4, 2017

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented May 3, 2017

This commit changes the way the Selector.tpl is structured to be 'driven' by the array,
meaning that if people alter the order, or the array, their changes are more easily reflected in the tpl.

I've kind of ignored the soft credit fields but this does set a direction for setting them in
and not having special handling in the tpl - ie. replace {if $softCreditColumns}

with columnHeader wrangling


@eileenmcnaughton eileenmcnaughton force-pushed the tpl branch 4 times, most recently from 7ff7cf9 to 5455c6d Compare May 3, 2017 11:27
@eileenmcnaughton
Copy link
Contributor Author

@monishdeb I think this simplifies the changes required & allows the hook to re-order. It's probably worth adding weight - e,.g just before returning from getColumnHeaders

foreach (array_keys($columnHeaders) as $key) {
$columnHeaders[$key]['weight'] = $key *10;
}

and then reordering after the hook. Would be easier for hook users. Hook docs would need updating

@monishdeb
Copy link
Member

@eileenmcnaughton thanks for the improvement. Makes sense to introduce weight attribute in columnHeaders , can you update the PR with

foreach (array_keys($columnHeaders) as $key) {
   $columnHeaders[$key]['weight'] = $key *10;
}

This commit changes the way the Selector.tpl is structured to be 'driven' by the  array,
meaning that if people alter the order, or the array, their changes are more easily reflected in the tpl.

I've kind of ignored the soft credit fields but this does set a direction for setting them in
 and not having special handling in the tpl - ie. replace {if }
with columnHeader wrangling
@eileenmcnaughton
Copy link
Contributor Author

@monishdeb see if you can make that work

@monishdeb
Copy link
Member

monishdeb commented May 4, 2017

The patch works for me, this is how the hook definition is adjusted

function hook_civicrm_searchColumns($contextName, &$columnHeaders, &$rows, $form) {
  if ($contextName == 'contribution') {
    foreach ($columnHeaders as $index => $column) {
      if ($column['field_name'] == 'total_amount') {
        $weight = $column['weight']+1;
        $columnHeaders[$weight] = array(
          'name' => ts('Balance Due'),
          'field_name' => 'balance_due',
          'weight' => $weight,
        );
        break;
      }
    }

    foreach ($rows as $key => $row) {
      $balanceDue = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType(
        $row['contribution_id'],
        'contribution',
        FALSE,
        $row['total_amount']
      );
      $rows[$key]['balance_due'] = sprintf("<b>%s</b>", CRM_Utils_Money::format($balanceDue));
    }
  }
}

@monishdeb monishdeb merged commit c0ad3c1 into civicrm:master May 4, 2017
@eileenmcnaughton eileenmcnaughton deleted the tpl branch May 5, 2017 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants