コード例 #1
0
 /**
  * Overrides OgSelectionHandler::buildEntityFieldQuery().
  */
 public function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS')
 {
     $group_type = $this->field['settings']['target_type'];
     // See if the Entity allows for non-member postings
     $user_access = FALSE;
     $event = NULL;
     if ($this->entity && isset($this->entity->og_group_ref[LANGUAGE_NONE][0]['target_id'])) {
         $event = $this->entity->og_group_ref[LANGUAGE_NONE][0]['target_id'];
     } elseif (module_exists('og_context') && isset($_SESSION)) {
         $event = isset($_SESSION['og_context']) ? $_SESSION['og_context'] : og_context('node');
         $event = isset($event['gid']) ? $event['gid'] : NULL;
     }
     if ($event) {
         $user_access = og_user_access('node', $event, "create " . $this->instance['bundle'] . " content") || og_user_access('node', $event, "update own " . $this->instance['bundle'] . " content") || og_user_access('node', $event, "edit any " . $this->instance['bundle'] . " content");
     }
     if (empty($this->instance['field_mode']) || $group_type != 'node' || user_is_anonymous() || !$user_access) {
         return parent::buildEntityFieldQuery($match, $match_operator);
     }
     $handler = EntityReference_SelectionHandler_Generic::getInstance($this->field, $this->instance, $this->entity_type, $this->entity);
     $query = $handler->buildEntityFieldQuery($match, $match_operator);
     // Show only the entities that are active groups.
     $query->fieldCondition(OG_GROUP_FIELD, 'value', 1);
     // Add this property to make sure we will have the {node} table later on in
     // OgCommonsSelectionHandler::entityFieldQueryAlter().
     $query->propertyCondition('nid', 0, '>');
     $query->addMetaData('entityreference_selection_handler', $this);
     // FIXME: http://drupal.org/node/1325628
     unset($query->tags['node_access']);
     $query->addTag('entity_field_access');
     $query->addTag('og');
     return $query;
 }
コード例 #2
0
  /**
   * Overrides OgSelectionHandler::buildEntityFieldQuery().
   *
   * This is an example of "subgroups" (but without getting into the logic of
   * sub-grouping).
   * The idea here is to show we can set "My groups" and "Other groups" to
   * reference different groups by different
   * logic. In this example, all group nodes below node ID 5, will appear under
   * "My groups", and the rest will appear under "Other groups",
   * for administrators.
   */
  public function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS') {
    $query = parent::buildEntityFieldQuery($match, $match_operator);
    if (!empty($_GET[OG_AUDIENCE_FIELD])) {
      $gid = $_GET[OG_AUDIENCE_FIELD];
      $query->fieldCondition(OG_AUDIENCE_FIELD, 'target_id', $gid, '=');
    }
    else {
      if (isset($this->entity) && isset($this->entity->{OG_AUDIENCE_FIELD})) {
        $field = $this->entity->{OG_AUDIENCE_FIELD};
        $gid = $field[LANGUAGE_NONE][0]['target_id'];
        $query->fieldCondition(OG_AUDIENCE_FIELD, 'target_id', $gid, '=');
      }
    }

    return $query;
  }
コード例 #3
0
 /**
  * Overrides OgSelectionHandler::buildEntityFieldQuery().
  */
 public function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS')
 {
     $group_type = $this->field['settings']['target_type'];
     if (empty($this->instance['field_mode']) || $group_type != 'node' || user_is_anonymous()) {
         return parent::buildEntityFieldQuery($match, $match_operator);
     }
     $handler = EntityReference_SelectionHandler_Generic::getInstance($this->field, $this->instance, $this->entity_type, $this->entity);
     $query = $handler->buildEntityFieldQuery($match, $match_operator);
     // Show only the entities that are active groups.
     $query->fieldCondition(OG_GROUP_FIELD, 'value', 1);
     $query->fieldCondition('field_og_subscribe_settings', 'value', 'anyone');
     // Add this property to make sure we will have the {node} table later on in
     // OgCommonsSelectionHandler::entityFieldQueryAlter().
     $query->propertyCondition('nid', 0, '>');
     $query->addMetaData('entityreference_selection_handler', $this);
     // FIXME: http://drupal.org/node/1325628
     unset($query->tags['node_access']);
     $query->addTag('entity_field_access');
     $query->addTag('og');
     return $query;
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS')
 {
     parent::buildEntityFieldQuery();
     global $user;
     $handler = EntityReference_SelectionHandler_Generic::getInstance($this->field, $this->instance, $this->entity_type, $this->entity);
     $query = $handler->buildEntityFieldQuery($match, $match_operator);
     // FIXME: http://drupal.org/node/1325628
     unset($query->tags['node_access']);
     // FIXME: drupal.org/node/1413108
     unset($query->tags['entityreference']);
     $query->addTag('entity_field_access');
     $query->addTag('og');
     $group_type = $this->field['settings']['target_type'];
     $entity_info = entity_get_info($group_type);
     if (!field_info_field(OG_GROUP_FIELD)) {
         // There are no groups, so falsify query.
         $query->propertyCondition($entity_info['entity keys']['id'], -1, '=');
         return $query;
     }
     // Show only the entities that are active groups.
     $query->fieldCondition(OG_GROUP_FIELD, 'value', 1, '=');
     $account = user_load($user->uid);
     if (user_access('administer site configuration', $account)) {
         // Site administrator can choose also groups he is not member of.
         $query->fieldCondition('c4m_og_status', 'value', array('deleted'), 'NOT IN');
         return $query;
     }
     $user_groups = og_get_groups_by_user(NULL, $group_type);
     $user_groups = $user_groups ? $user_groups : array();
     if ($user_groups) {
         $query->propertyCondition($entity_info['entity keys']['id'], $user_groups, 'IN');
     } else {
         // User doesn't have permission to select any group so falsify this
         // query.
         $query->propertyCondition($entity_info['entity keys']['id'], -1, '=');
     }
     $unallowed_values = array('requested', 'archived', 'rejected', 'deleted');
     $query->fieldCondition('c4m_og_status', 'value', $unallowed_values, 'NOT IN');
     return $query;
 }
コード例 #5
0
 /**
  * Overrides OgSelectionHandler::buildEntityFieldQuery().
  */
 public function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS')
 {
     $group_type = $this->field['settings']['target_type'];
     // See if the Entity allows for non-member postings
     $event_entity_types = cod_events_get_group_content_entity_types();
     if (empty($this->instance['field_mode']) || $group_type != 'node' || user_is_anonymous() || isset($this->instance['bundle']) && !(isset($event_entity_types['node'][$this->instance['bundle']]['non_member']) && user_access("create " . $this->instance['bundle'] . " content"))) {
         return parent::buildEntityFieldQuery($match, $match_operator);
     }
     $handler = EntityReference_SelectionHandler_Generic::getInstance($this->field, $this->instance, $this->entity_type, $this->entity);
     $query = $handler->buildEntityFieldQuery($match, $match_operator);
     // Show only the entities that are active groups.
     $query->fieldCondition(OG_GROUP_FIELD, 'value', 1);
     // Add this property to make sure we will have the {node} table later on in
     // OgCommonsSelectionHandler::entityFieldQueryAlter().
     $query->propertyCondition('nid', 0, '>');
     $query->addMetaData('entityreference_selection_handler', $this);
     // FIXME: http://drupal.org/node/1325628
     unset($query->tags['node_access']);
     $query->addTag('entity_field_access');
     $query->addTag('og');
     return $query;
 }
コード例 #6
0
 /**
  * Overrides OgSelectionHandler::buildEntityFieldQuery().
  *
  * This is an example of "subgroups" (but without getting into the logic of
  * sub-grouping).
  * The idea here is to show we can set "My groups" and "Other groups" to
  * reference different groups by different
  * logic. In this example, all group nodes below node ID 5, will appear under
  * "My groups", and the rest will appear under "Other groups",
  * for administrators.
  */
 public function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS')
 {
     $group_type = $this->field['settings']['target_type'];
     if (empty($this->instance['field_mode']) || $group_type != 'node') {
         return parent::buildEntityFieldQuery($match, $match_operator);
     }
     $field_mode = $this->instance['field_mode'];
     $handler = EntityReference_SelectionHandler_Generic::getInstance($this->field, $this->instance, $this->entity_type, $this->entity);
     $query = $handler->buildEntityFieldQuery($match, $match_operator);
     // Show only the entities that are active groups.
     $query->fieldCondition(OG_GROUP_FIELD, 'value', 1, '=');
     if ($field_mode == 'default') {
         $query->propertyCondition('nid', '5', '<=');
     } else {
         $query->propertyCondition('nid', '5', '>');
     }
     // FIXME: http://drupal.org/node/1325628
     unset($query->tags['node_access']);
     // FIXME: drupal.org/node/1413108
     unset($query->tags['entityreference']);
     $query->addTag('entity_field_access');
     $query->addTag('og');
     return $query;
 }