You are here

function certificate_certificate_map in Certificate 3.x

Same name and namespace in other branches
  1. 8.3 certificate.module \certificate_certificate_map()
  2. 6.2 certificate.module \certificate_certificate_map()
  3. 7.3 certificate.module \certificate_certificate_map()
  4. 7.2 certificate.module \certificate_certificate_map()

Implements hook_certificate_map().

Return the key of the mapping to use.

Return value

string Key of matched mapping.

File

./certificate.module, line 743
Certificate module.

Code

function certificate_certificate_map($node, $user, $map_type, $options) {
  if ($map_type == 'rules') {
    foreach ($options as $key) {
      global $_certificate_award;
      $_certificate_award = FALSE;
      rules_invoke_component($key, $node, $user);
      if ($_certificate_award) {
        $valid[] = $key;
      }
    }
    return $valid;
  }
  if ($map_type == 'profile') {
    $profiles = module_exists('profile2') ? profile2_load_by_user($user) : array();
    $profiles['user'] = entity_load_single('user', $user->uid);
    $groupings = variable_get('certificate_field_grouping', array());
    foreach ($options as $key) {
      if (!empty($groupings[$key])) {
        foreach ($groupings[$key] as $field_name => $accepted_values) {
          foreach ($profiles as $profile) {
            if (!empty($profile->{$field_name}[LANGUAGE_NONE])) {
              foreach ($profile->{$field_name}[LANGUAGE_NONE] as $item) {
                if (in_array($item['value'], $accepted_values)) {
                  $valid[] = $key;
                }
              }
            }
          }
        }
      }
    }
    return $valid;
  }
  if ($map_type == 'manual') {
    if (isset($options[0]) && $options[0] == 'manual') {
      return 'manual';
    }
  }
}