<commit_before><?php


/**
 * OG selection handler.
 */
class RedhenGroupSelectionHandler implements EntityReference_SelectionHandler {

  protected function __construct($field, $instance) {
    $this->field = $field;
    $this->instance = $instance;
  }

  /**
   * Factory function: create a new instance of this handler for a given field.
   *
   * @param $field
   *   A field datastructure.
   * @return EntityReferenceHandler
   */
  public static function getInstance($field, $instance) {
    return new RedhenGroupSelectionHandler($field, $instance);
  }

  /**
   * Return a list of referencable entities.
   */
  public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
    $entities = array();
    foreach ($this->getContactGroups() as $org_id => $org) {
      $entities[$org_id] = $this->getLabel($org);
    }

    return $entities;
  }

  protected function getContactGroups() {
    $orgs = array();
    $org_types = redhen_org_get_types();
    $valid_org_types = array();
    foreach ($org_types as $org_type) {
      if (isset($org_type->group) && $org_type->group && $org_type->redhen_state = REDHEN_STATE_ACTIVE) {
        if (isset($org_type->group_settings['content_types'])) {
          if (in_array($this->instance['bundle'], $org_type->group_settings['content_types'])) {
            $valid_org_types[] = $org_type->name;
          }
        }
      }
    }

    global $user;
    if ($contact = redhen_contact_user_contact($user)) {
      $relations = redhen_relation_relations($contact, 'redhen_affiliation');
      foreach ($relations as $relation_id => $orgs) {
        foreach ($orgs as $org) {
          if (in_array($org->type, $valid_org_types)) {
            $orgs[$org->org_id] = $org;
          }
        }
      }
    }

    return $orgs;
  }

  /**
   * Count entities that are referencable by a given field.
   */
  public function countReferencableEntities($match = NULL, $match_operator = 'CONTAINS') {
    return count($this->getContactGroups());
  }<commit_msg>Refactor getReferencableEntities to use new API calls<commit_after><?php


/**
 * OG selection handler.
 */
class RedhenGroupSelectionHandler implements EntityReference_SelectionHandler {

  protected function __construct($field, $instance) {
    $this->field = $field;
    $this->instance = $instance;
  }

  /**
   * Factory function: create a new instance of this handler for a given field.
   *
   * @param $field
   *   A field datastructure.
   * @return EntityReferenceHandler
   */
  public static function getInstance($field, $instance) {
    return new RedhenGroupSelectionHandler($field, $instance);
  }

  /**
   * Return a list of referencable entities.
   */
  public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
    $entities = array();
    foreach ($this->getContactGroups() as $org_id => $org) {
      $entities[$org_id] = $this->getLabel($org);
    }

    return $entities;
  }

  protected function getContactGroups() {
    global $user;
    return redhen_org_group_contact_groups($user, FALSE, $this->instance['bundle']);
  }

  /**
   * Count entities that are referencable by a given field.
   */
  public function countReferencableEntities($match = NULL, $match_operator = 'CONTAINS') {
    return count($this->getContactGroups());
  }
{'fraction_non_alphanumeric': 0.13231780167264037, 'fraction_numerical': 0.0005973715651135006, 'mean_word_length': 3.338082901554404, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '20418', 'n_tokens_mistral': 1025, 'n_tokens_neox': 1015, 'n_words': 238}