Skip to content

Commit

Permalink
Merge pull request #1237 from necyberteam/md-dev
Browse files Browse the repository at this point in the history
Md dev
  • Loading branch information
a-pasquale authored Sep 9, 2024
2 parents e7c87aa + 8195a37 commit 62ed254
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions web/modules/custom/campuschampions/campuschampions.module
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ function campuschampions_views_data_export_row_alter(&$row, ResultRow $result, V

$cc = (string) $row['field_carnegie_code'];

$row['field_carnegie_code'] = t('Users Carnegie Code is not valid.');
$row['field_carnegie_code'] = t('');
$row['field_carnegie_code_location'] = '';
$row['field_carnegie_code_classification'] = '';
$row['field_carnegie_code_msi'] = '';
Expand All @@ -275,23 +275,33 @@ function campuschampions_views_data_export_row_alter(&$row, ResultRow $result, V
if (empty($cc)) {
$mail = strip_tags((string) $row['mail']);
$user = user_load_by_mail($mail);
$carnegie_code = NULL;

$institution = $user->get('field_institution')->getValue();
// Try to get the ACCESS Organization first.
$org = $user->get('field_access_organization')->getValue();
if (!empty($org)) {

if (empty($institution)) {
return;
$org = Node::load($org[0]['target_id']);
$carnegie_code = $org->get('field_carnegie_code')->getValue();
}
else {
// If there isn't an ACCESS organization, try the institution field.
$institution = $user->get('field_institution')->getValue();
if (empty($institution)) {
return;
}

// Try to find by institution name.
$query = \Drupal::database()
->select('carnegie_codes', 'cc')
->fields('cc', ['UNITID']);
$query->condition($query->orConditionGroup()
->condition('NAME', $institution[0]['value'], '=')
->condition('NAME', $institution[0]['value'] . '%', 'LIKE')
);
$carnegie_code = $query->execute()
->fetchField();
// Try to find by institution name.
$query = \Drupal::database()
->select('carnegie_codes', 'cc')
->fields('cc', ['UNITID']);
$query->condition($query->orConditionGroup()
->condition('NAME', $institution[0]['value'], '=')
->condition('NAME', $institution[0]['value'] . '%', 'LIKE')
);
$carnegie_code = $query->execute()
->fetchField();
}

if (!$carnegie_code) {
return;
Expand Down

0 comments on commit 62ed254

Please sign in to comment.