You are here

function certificate_certificate_map in Certificate 6.2

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

Implementation of hook_certificate_map().

Return the key of the mapping to use.

Return value

string Key of matched mapping.

File

./certificate.module, line 709
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_rule_set($key, array(
        'node' => $node,
        'user' => $user,
      ));
      if ($_certificate_award) {
        return $key;
      }
    }
  }
  if ($map_type == 'content_profile') {
    $content_profile = content_profile_load('profile', $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 ($content_profile->{$field_name} as $item) {
            if (in_array($item['value'], $accepted_values)) {
              return $key;
            }
          }
        }
      }
    }
  }
  if ($map_type == 'manual') {
    if (isset($options[0]) && $options[0] == 'manual') {
      return 'manual';
    }
  }
}