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

CRM_Utils_Array::asColumns() - Add helper to rotate a matrix (from rows to columns) #20788

Merged
merged 1 commit into from
Jul 7, 2021

Conversation

totten
Copy link
Member

@totten totten commented Jul 6, 2021

Overview

Add a helper function, asColumns(), which rotates an array-matrix -- converting from a row-orientation to a column-orientation.

Before

Helper does not exist.

After

Helper exists.

Technical Details

Suppose you have this data:

$alphabetByLetter = [
          // English column     // Greek column
  'a' => ['english' => 'eh',    'greek' => 'alpha'],
  'b' => ['english' => 'bee',   'greek' => 'beta' ],
];
// Assert: $rows['b']['greek'] == 'beta'

Then you rotate it, getting the data in columnar form:

$alphabetByLang = CRM_Utils_Array::asColumns($alphabetByLetter);

The resulting data is shaped like:

$alphabetByLang = [
                // "A" column      // "B" column
  'english' => ['a' =>'eh',        'b' => 'bee' ],
  'greek'   => ['a' =>'alpha',     'b' => 'beta'],
];
// Assert: $rows['greek']['b'] == 'beta'

@civibot
Copy link

civibot bot commented Jul 6, 2021

(Standard links)

@civibot civibot bot added the master label Jul 6, 2021
@totten totten added the has-test label Jul 6, 2021
@eileenmcnaughton
Copy link
Contributor

Stream of consciousness thoughts on merging this from chat

==tldr = merge-ready - give @colemanw a chance to input / say 'but x function already does that'

image

@eileenmcnaughton eileenmcnaughton added the merge ready PR will be merged after a few days if there are no objections label Jul 6, 2021
@totten totten changed the title CRM_Utils_Array - Add helper to rotate an array (from rows to columns) CRM_Utils_Array::asColumns() - Add helper to rotate an array (from rows to columns) Jul 6, 2021
@totten totten changed the title CRM_Utils_Array::asColumns() - Add helper to rotate an array (from rows to columns) CRM_Utils_Array::asColumns() - Add helper to rotate a matrix (from rows to columns) Jul 6, 2021
@colemanw colemanw merged commit 0110c3f into civicrm:master Jul 7, 2021
@colemanw
Copy link
Member

colemanw commented Jul 7, 2021

Useful function with a test - good to merge IMO.

@eileenmcnaughton raised the question about what internal functions of CiviCRM we are obligated to maintain as a shared library for use by extensions. I agree we could be much more clear about that, but it doesn't have to block this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-test master merge ready PR will be merged after a few days if there are no objections
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants