/** * Get the entity ID. * * @param $entity_type * 'node', 'user', etc. * @param $title * Title of the entity. * @param $bundle * Optional; The bundle of the entity. * * @return mixed * The entity ID (in case of $return). */ public static function getEntityID($entity_type, $title, $bundle = NULL) { $query = new EntityFieldQuery(); $query->entityCondition('entity_type', $entity_type); if ($entity_type == 'node') { $query->propertyCondition('title', $title); } else { if ($entity_type == 'file') { $query->propertyCondition('filename', $title); } } if ($bundle) { $query->entityCondition('bundle', $bundle); } $result = $query->execute(); // Currently only support file and node. if ($entity_type == 'node') { $identifier = 'nid'; } else { if ($entity_type == 'file') { $identifier = 'fid'; } } if (empty($result[$entity_type])) { return NULL; } return reset($result[$entity_type])->{$identifier}; }
public function actionList() { $sels = new Sels(); $easyNewsall = array(); $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'clue')->propertyOrderBy('nid', 'DESC')->propertyCondition('status', 1)->range(0, 20); if (isset($_POST['lastnewsid'])) { $query->propertyCondition('nid', $_POST['lastnewsid'], '<'); } $result = $query->execute(); if (isset($result['node'])) { $news_items_nids = array_keys($result['node']); $news = node_load_multiple($news_items_nids); } foreach ($news as $new) { $easyNews['id'] = $new->nid; $easyNews['title'] = $new->title; $easyNews['img1'] = str_replace("public://", BigImg, $new->field_tux['und'][0]['uri']); array_push($easyNewsall, $easyNews); } $sels->articles = $easyNewsall; $jsonObj = CJSON::encode($sels); /* if(isset($key)) $cache->set($key,$jsonObj,0,new CDbCacheDependency('select max(id) from tbl_dblogs')); */ echo $jsonObj; }
/** * Build an EntityFieldQuery to get referencable entities. * Almost the same as EntityReference_SelectionHandler_Generic::buildEntityFieldQuery, * but the bundles are dynamic. */ protected function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS') { $query = new EntityFieldQuery(); $query->entityCondition('entity_type', $this->field['settings']['target_type']); $node_types = project_node_types_by_behavior($this->field['settings']['handler_settings']['behavior']); if (!empty($node_types)) { $query->entityCondition('bundle', $node_types, 'IN'); } if (isset($match)) { $entity_info = entity_get_info($this->field['settings']['target_type']); if (isset($entity_info['entity keys']['label'])) { $query->propertyCondition($entity_info['entity keys']['label'], $match, $match_operator); } } // Add a generic entity access tag to the query. $query->addTag($this->field['settings']['target_type'] . '_access'); $query->addTag('entityreference'); $query->addMetaData('field', $this->field); $query->addMetaData('entityreference_selection_handler', $this); // Add the sort option. if (!empty($this->field['settings']['handler_settings']['sort'])) { $sort_settings = $this->field['settings']['handler_settings']['sort']; if ($sort_settings['type'] == 'property') { $query->propertyOrderBy($sort_settings['property'], $sort_settings['direction']); } elseif ($sort_settings['type'] == 'field') { list($field, $column) = explode(':', $sort_settings['field'], 2); $query->fieldOrderBy($field, $column, $sort_settings['direction']); } } return $query; }
/** * Returns the user's billing cycle with the provided start time. * * If an existing billing cycle matches the expected start and end, it will * be returned. Otherwise, a new one will be created. * * @param $uid * The uid of the user. * @param $start * The unix timestamp when the billing cycle needs to start. * @param $save * Whether to save the created billing cycle entity. * Passing FALSE allows an unsaved billing cycle entity to be returned * for estimation purposes. * * @return * A cl_billing_cycle entity. */ public function getBillingCycle($uid, $start = REQUEST_TIME, $save = TRUE) { // Make the billing cycle exactly 30 days long, so that it can be divided // predictably for prorating. // The 1 is substracted to make sure that the billing cycle ends 1s before // the next one starts $end = $start + 2592000 - 1; // Try to find an existing billing cycle matching our parameters. $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'cl_billing_cycle')->entityCondition('bundle', $this->name)->propertyCondition('status', 1)->propertyCondition('uid', $uid); if ($start != REQUEST_TIME) { // In case of a custom start, make sure to match the exact billing cycle. // Ensures that new orders get the previous billing cycle created at the // start of testing, while getNextBillingCycle returns the expected result. $query->propertyCondition('start', $start); } $result = $query->execute(); if ($result) { $billing_cycle_id = key($result['cl_billing_cycle']); $billing_cycle = entity_load_single('cl_billing_cycle', $billing_cycle_id); } else { // No existing billing cycle found. Create a new one. $billing_cycle = entity_create('cl_billing_cycle', array('type' => $this->name)); $billing_cycle->uid = $uid; $billing_cycle->start = $start; $billing_cycle->end = $end; $billing_cycle->status = 1; if ($save) { $billing_cycle->save(); } } return $billing_cycle; }
/** * Displays the bean. */ public function view($bean, $content, $view_mode = 'default', $langcode = NULL) { // Retrieve the terms from the loaded entity. $active_entity = bean_tax_active_entity_array(); // Check for cached content on this block. $cache_name = 'bean_tax:listing:' . $bean->delta . ':' . $active_entity['type'] . ':' . $active_entity['ids'][0]; if ($cache = cache_get($cache_name)) { $content = $cache->data; } else { // We need to make sure that the bean is configured correctly. if ($active_entity['type'] != 'bean' && !empty($bean->filters['vocabulary']) && (isset($active_entity['terms']) && count($active_entity['terms']))) { // Reformat vocabulary list from machine names to vocabulary vids. $vids = array(); foreach ($bean->filters['vocabulary'] as $vm) { $query = new EntityFieldQuery(); $result = $query->entityCondition('entity_type', 'taxonomy_vocabulary'); $query->propertyCondition('machine_name', $vm); global $language; if ($language->language != NULL && db_field_exists('taxonomy_vocabulary', 'language')) { $query->propertyCondition('language', $language->language); } $result = $query->execute(); foreach ($result['taxonomy_vocabulary'] as $vocabulary) { $vids[$vocabulary->vid] = $vocabulary->vid; } } $i = 0; $content['terms'] = array(); // Parse terms from correct vocabularies, limit list to X results. foreach ($active_entity['terms'] as $term) { $term = entity_load_single('taxonomy_term', $term->tid); if (in_array($term->vid, $vids) && $i < $bean->settings['records_shown']) { $content['terms'][$term->tid] = entity_view('taxonomy_term', array($term->tid => $term), $bean->settings['term_view_mode']); $i++; } } cache_set($cache_name, $content, 'cache', time() + 60 * $bean->settings['cache_duration']); } elseif (isset($active_entity['type']) && $active_entity['type'] == 'bean' && $bean->bid === $active_entity['object']->bid) { $content['#markup'] = ''; } elseif ($bean->settings['hide_empty'] || !$active_entity['object']) { return; } else { $content['#markup'] = t('No terms.'); } } return $content; }
private function scanReports () { $this->affected = array(); $query = new \EntityFieldQuery(); $query->entityCondition('entity_type', 'node'); $query->propertyCondition('type', NODE_TYPE_REPORT); $query->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT'); $result = $query->execute(); $reportNids = isset($result['node']) ? array_keys($result['node']) : NULL; $reportNodes = node_load_multiple($reportNids); foreach ( $reportNodes as $node ) { $datasetName = get_node_field_value($node,'field_report_dataset_sysnames'); if ( empty($datasetName) ) { $patient = array( 'info' => array( 'reportNodeId' => $node->nid, 'reportTitle' => $node->title, 'published' => $node->status, 'type' => $node->type, 'datasetName' => $datasetName ), 'notes' => 'Dataset field is empty.' ); $this->attachTreatment($patient); $this->affected[] = $patient; continue; } // lookup dataset $datasourceQuery = new \EntityFieldQuery(); $datasourceQuery->entityCondition('entity_type', 'node'); $datasourceQuery->propertyCondition('type', NODE_TYPE_DATASET); $datasourceQuery->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT'); $datasourceQuery->fieldCondition('field_dataset_sysname', 'value', $datasetName); $datasourceQuery->fieldCondition('field_dataset_datasource', 'value', get_node_field_value($node,'field_report_datasource')); $datasourceEntities = $datasourceQuery->execute(); $datasource_nids = isset($datasourceEntities['node']) ? array_keys($datasourceEntities['node']) : NULL; if (count($datasource_nids) != 1) { $patient = array( 'info' => array( 'reportNodeId' => $node->nid, 'reportTitle' => $node->title, 'published' => $node->status, 'type' => $node->type, 'datasetName' => $datasetName ), 'notes' => 'Dataset does not exist.' ); $this->attachTreatment($patient); $this->affected[] = $patient; continue; } } }
private function scanReportConfigs () { $this->affected = array(); $query = new \EntityFieldQuery(); $query->entityCondition('entity_type', 'node'); $query->propertyCondition('type', NODE_TYPE_REPORT); $query->propertyCondition('status', NODE_PUBLISHED); $query->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT'); $result = $query->execute(); $reportNids = isset($result['node']) ? array_keys($result['node']) : NULL; $reportNodes = node_load_multiple($reportNids); foreach ( $reportNodes as $node ) { \LogHelper::log_info(t('Inspecting report @nid', array('@nid' => $node->nid))); $reportConfigText = get_node_field_value($node, 'field_report_conf', 0, 'value', FALSE); $reportConfig = isset($reportConfigText) ? json_decode($reportConfigText) : NULL; if (!isset($reportConfig)) { \LogHelper::log_info('Report configuration is EMPTY'); continue; } // loop through filters if (!empty($reportConfig->model->filters)) { foreach ($reportConfig->model->filters as $key => $value) { $result = $this->detectInvalidFilter($value); if ($result) { $patient = array( 'info' => array( 'reportNodeId' => $node->nid, 'reportTitle' => $node->title, 'filter' => $value, 'published' => $node->status, 'configPath' => 'model/filters' ), 'notes' => $result ); $this->attachTreatment($patient); $this->affected[] = $patient; } } } } }
/** * @inheritdoc */ public static function Query($id = NULL) { $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node')->propertyCondition('type', array_keys(vsite_vsite_og_node_type_info()), 'IN'); if ($id) { $query->propertyCondition('nid', $id, '>='); } return $query; }
/** * Find entity ID by title. */ private function getEntityId($title, $entity_type = 'node', $bundle = NULL) { $query = new EntityFieldQuery(); $query->entityCondition('entity_type', $entity_type); if ($bundle) { $query->entityCondition('bundle', $bundle); } $result = $query->propertyCondition('title', $title)->range(0, 1)->execute(); return !empty($result[$entity_type]) ? key($result[$entity_type]) : FALSE; }
function prepare_entity_query_4_node_type($nodeType, $publishedOnly = PUBLISHED_ONLY) { $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node')->propertyCondition('type', $nodeType); if ($publishedOnly) { $query->propertyCondition('status', NODE_PUBLISHED); } // Neutralize the 'entity_field_access' query tag added by field_sql_storage_field_storage_query(). // The result cannot depend on the access grants of the current user. $query->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT'); return $query; }
/** * Check if the provided scope exists in storage. * * @param $scope * A space-separated string of scopes. * @param $client_id * The requesting client. * * @return * TRUE if it exists, FALSE otherwise. */ function scopeExists($scope, $client_id = null) { $scope = explode(' ', trim($scope)); // Get all scope entities that match the provided scope. // Compare the difference. $query = new \EntityFieldQuery(); $query->entityCondition('entity_type', 'oauth2_server_scope'); $query->propertyCondition('server', $this->server->name); $query->propertyCondition('name', $scope); $query->addTag('oauth2_server_scope_access'); $query->addMetaData('oauth2_server', $this->server); $results = $query->execute(); if ($results) { $scope_ids = array_keys($results['oauth2_server_scope']); $loaded_scopes = entity_load('oauth2_server_scope', $scope_ids); $found_scope = array(); foreach ($loaded_scopes as $loaded_scope) { $found_scope[] = $loaded_scope->name; } return count(array_diff($scope, $found_scope)) == 0; } }
/** * Build an EntityFieldQuery to get referencable entities. */ public function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS') { $query = new EntityFieldQuery(); $query->entityCondition('entity_type', $this->field['settings']['target_type']); if (!empty($this->field['settings']['handler_settings']['target_bundles'])) { $query->entityCondition('bundle', $this->field['settings']['handler_settings']['target_bundles'], 'IN'); } if (isset($match)) { $query->propertyCondition('title', $match, $match_operator); } // Add an access tag to the query. $query->addTag('harmony_access'); $query->addTag('entityreference'); $query->addMetaData('field', $this->field); $query->addMetaData('entityreference_selection_handler', $this); // Adding the 'harmony_thread_access' tag is sadly insufficient for threads: core // requires us to also know about the concept of 'published' and // 'unpublished'. We need to do that as long as there are no access control // modules in use on the site. As long as one access control module is there, // it is supposed to handle this check. if ((!user_access('bypass harmony forum access control') || !user_access('administer forum content')) && !count(module_implements('harmony_thread_grants'))) { $query->propertyCondition('status', HARMONY_PUBLISHED); $query->propertyCondition('locked', HARMONY_NOT_LOCKED); } // Add the sort option. if (!empty($this->field['settings']['handler_settings']['sort'])) { $sort_settings = $this->field['settings']['handler_settings']['sort']; if ($sort_settings['type'] == 'property') { $query->propertyOrderBy($sort_settings['property'], $sort_settings['direction']); } elseif ($sort_settings['type'] == 'field') { list($field, $column) = explode(':', $sort_settings['field'], 2); $query->fieldOrderBy($field, $column, $sort_settings['direction']); } } return $query; }
function findAgent($json) { $json_array = drupal_json_decode($json); if (!isset($json_array['mbox']) && !isset($json_array['mbox_sha1sum']) && !isset($json_array['openid']) && (!isset($json_array['account']) && !isset($json_array['account']['homePage']) && !isset($json_array['account']['name']))) { return 0; } $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'tincan_agent'); if (isset($json_array['objectType'])) { switch ($json_array['objectType']) { case 'Agent': $query->propertyCondition('object_type', 'Agent'); break; case 'Group': $query->propertyCondition('object_type', 'Group'); break; } } else { $query->propertyCondition('object_type', 'Agent'); } if (isset($json_array['mbox'])) { $query->propertyCondition('mbox', $json_array['mbox']); } if (isset($json_array['mbox_sha1sum'])) { $query->propertyCondition('mbox_sha1sum', $json_array['mbox_sha1sum']); } if (isset($json_array['openid'])) { $query->propertyCondition('openid', $json_array['openid']); } if (isset($json_array['account'])) { if (isset($json_array['account']['homePage'])) { $query->propertyCondition('account_home_page', $json_array['account']['homePage']); } if (isset($json_array['account']['name'])) { $query->propertyCondition('account_name', $json_array['account']['name']); } } $result = $query->execute(); if (isset($result['tincan_agent'])) { foreach ($result['tincan_agent'] as $key => $agent) { return $key; } } else { return 0; } }
public function actionList() { if (isset($_POST['uid'])) { $tids = user_load($_POST['uid'])->field__danwei; } else { $tids = array(); $tids['und'][0]['tid'] = '62'; } //var_dump($tids); $sels = new Sels(); $easyNewsall = array(); $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'sup')->propertyOrderBy('nid', 'DESC')->propertyCondition('status', 1)->range(0, 20); if (isset($_POST['lastnewsid'])) { $query->propertyCondition('nid', $_POST['lastnewsid'], '<'); } $result = $query->execute(); if (isset($result['node'])) { $news_items_nids = array_keys($result['node']); $news = node_load_multiple($news_items_nids); foreach ($news as $new) { //$power=false; //echo '标题:'.$new->title.'<br>'; //var_dump($new->field__danwei['und']); //var_dump($tids['und']); foreach ($tids['und'] as $tid) { //echo '$tid:'.$tid.'<br>'; if (in_array($tid, $new->field__danwei['und'])) { //$power=true; $easyNews['id'] = $new->nid; $easyNews['title'] = $new->title; $easyNews['img1'] = str_replace("public://", BigImg, $new->field_tux['und'][0]['uri']); $easyNews['label'] = $new->field_biaoqian['und'][0]['value']; array_push($easyNewsall, $easyNews); break; } } } } $sels->articles = $easyNewsall; $jsonObj = CJSON::encode($sels); echo $jsonObj; }
/** * Returns the default scope for the provided server. * * Invoked by OAuth2_Scope_Drupal. * If no hook implementation returns a default scope for the current server, * then the one from $server->settings['default_scope'] is used. * * This hook runs on "authorize" and "token" requests and has access to the * client_id in $_GET (for "authorize") or via * oauth2_server_get_client_credentials() (for "token"). * Note that client_id in this case corresponds to $client->client_key. * * @return * An array of default scopes (their machine names). */ function hook_oauth2_server_default_scope($server) { // For the "test" server, grant the user any scope he has access to. if ($server->name == 'test') { $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'oauth2_server_scope'); $query->propertyCondition('server', $server->name); $query->addTag('oauth2_server_scope_access'); $query->addMetaData('oauth2_server', $server); $results = $query->execute(); if ($results) { $scope_ids = array_keys($results['oauth2_server_scope']); $scopes = entity_load('oauth2_server_scope', $scope_ids); $default_scopes = array(); foreach ($scopes as $scope) { $default_scopes[] = $scope->name; } return $default_scopes; } } }
/** * Fetch entity IDs that have a certain label. * * @param string $entity_type * The entity type of $entity. * @param string $label * The label of the entity to load. * @param string $bundle * An optional bundle to restrict the results to. * @param object $query * An optional EntityFieldQuery object to use to perform the query. * * @return array * An array of matching entity IDs. * * @throws Exception */ public static function queryIdsByLabel($entity_type, $label, $bundle = NULL, $query = NULL) { $info = entity_get_info($entity_type); if (empty($info['entity keys']['label'])) { throw new Exception("Unable to load entities of type {$entity_type} by label."); } if (!isset($query)) { $query = new EntityFieldQuery(); $query->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT'); } $query->entityCondition('entity_type', $entity_type); if (isset($bundle)) { $query->entityCondition('bundle', $bundle); } $query->propertyCondition($info['entity keys']['label'], $label); $results = $query->execute(); if (!empty($results[$entity_type])) { return array_keys($results[$entity_type]); } else { return array(); } }
protected function _getEntities() { $options = $this->getOptions(); $query = new EntityFieldQuery(); $query->entityCondition('entity_type', $options['entity-type']); if (!empty($options['sort-field'])) { if (strpos($options['sort-field'], ':') === FALSE) { $query->propertyOrderBy($options['sort-field'], strtoupper($options['sort-order'])); } else { $sort_field = explode(':', $options['sort-field']); $query->fieldOrderBy($sort_field[0], $sort_field[1], strtoupper($options['sort-order'])); } } if (!empty($options['bundle'])) { $query->propertyCondition('type', $options['bundle']); } $query->range(0, $options['limit']); $results = $query->execute(); if (empty($results[$options['entity-type']])) { return array(); } return entity_load($options['entity-type'], array_keys($results[$options['entity-type']])); }
/** * Filter the query for list. * * @param \EntityFieldQuery $query * The query object. * * @throws \RestfulBadRequestException * * @see \RestfulEntityBase::getQueryForList */ protected function queryForListFilter(\EntityFieldQuery $query) { $public_fields = $this->getPublicFields(); foreach ($this->parseRequestForListFilter() as $filter) { // Determine if filtering is by field or property. if (!$property_name = $public_fields[$filter['public_field']]['property']) { throw new \RestfulBadRequestException('The current filter selection does not map to any entity property or Field API field.'); } if (field_info_field($property_name)) { if (in_array(strtoupper($filter['operator'][0]), array('IN', 'BETWEEN'))) { $query->fieldCondition($public_fields[$filter['public_field']]['property'], $public_fields[$filter['public_field']]['column'], $filter['value'], $filter['operator'][0]); continue; } for ($index = 0; $index < count($filter['value']); $index++) { $query->fieldCondition($public_fields[$filter['public_field']]['property'], $public_fields[$filter['public_field']]['column'], $filter['value'][$index], $filter['operator'][$index]); } } else { if (in_array(strtoupper($filter['operator'][0]), array('IN', 'BETWEEN'))) { $query->propertyCondition($property_name, $filter['value'], $filter['operator'][0]); continue; } $column = $this->getColumnFromProperty($property_name); for ($index = 0; $index < count($filter['value']); $index++) { $query->propertyCondition($column, $filter['value'][$index], $filter['operator'][$index]); } } } }
public function setValue($wrapper, $fieldLabel, $rawValue) { $subField = FALSE; if (strpos($fieldLabel, ':') !== FALSE) { $fieldStrings = explode(':', $fieldLabel); $fieldLabel = $fieldStrings[0]; $subField = $fieldStrings[1]; } foreach ($wrapper->getPropertyInfo() as $key => $wrapper_property) { if ($fieldLabel == $wrapper_property['label']) { $fieldMachineName = $key; $fieldInfo = isset($wrapper_property['field']) && $wrapper_property['field'] ? field_info_field($fieldMachineName) : array(); if (empty($fieldInfo)) { switch ($wrapper_property['type']) { case 'boolean': $value = filter_var($rawValue, FILTER_VALIDATE_BOOLEAN); break; case 'date': if (!is_numeric($rawValue)) { $rawValue = strtotime($rawValue); } default: $value = $rawValue; } } elseif ($fieldInfo = field_info_field($fieldMachineName)) { // @todo add condition for each field type. switch ($fieldInfo['type']) { case 'entityreference': $relatedEntityType = $fieldInfo['settings']['target_type']; $targetBundles = $fieldInfo['settings']['handler_settings']['target_bundles']; $query = new \EntityFieldQuery(); $query->entityCondition('entity_type', $relatedEntityType); // Adding special conditions. if (count($targetBundles) > 1) { $relatedBundles = array_keys($targetBundles); $query->entityCondition('bundle', $relatedBundles, 'IN'); } else { $relatedBundles = reset($targetBundles); $query->entityCondition('bundle', $relatedBundles); } if ($relatedEntityType == 'node') { $query->propertyCondition('title', $rawValue); } if ($relatedEntityType == 'taxonomy_term' || $relatedEntityType == 'user') { $query->propertyCondition('name', $rawValue); } $results = $query->execute(); if (empty($results)) { throw new \Exception("Entity that you want relate doesn't exist."); } $value = array_keys($results[$relatedEntityType]); if (count($value) == 1) { $value = array_pop($value); } break; case 'image': try { $fieldInstance = field_info_instance($wrapper->type(), $fieldMachineName, $wrapper->getBundle()); $fieldDirectory = 'public://' . $fieldInstance['settings']['file_directory']; $image = file_get_contents($rawValue); $pathinfo = pathinfo($rawValue); $filename = $pathinfo['basename']; file_prepare_directory($fieldDirectory, FILE_CREATE_DIRECTORY); $value = (array) file_save_data($image, $fieldDirectory . '/' . $filename, FILE_EXISTS_RENAME); if ($fieldInfo['cardinality'] > 1 || $fieldInfo['cardinality'] == FIELD_CARDINALITY_UNLIMITED) { $value = array($value); } } catch (Exception $e) { throw new \Exception("File {$rawValue} coundn't be saved."); } break; default: $value = $rawValue; break; } } } } if (empty($fieldMachineName)) { throw new \Exception("Entity property {$fieldLabel} doesn't exist."); } if ($subField) { $wrapper->{$fieldMachineName}->{$subField} = $value; } else { $wrapper->{$fieldMachineName} = $value; } $wrapper->save(); }
private function findActivity($json_array) { watchdog('findActivity', 'Query:<pre>%d</pre>', array('%d' => print_r($json_array, 1)), WATCHDOG_DEBUG); $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'tincan_activity'); if (isset($json_array['id'])) { $query->propertyCondition('activity_id', $json_array['id']); } $result = $query->execute(); if (isset($result['tincan_activity'])) { foreach ($result['tincan_activity'] as $key => $activity) { return $key; } } else { return 0; } }
function check_if_article_exists($id) { //Queries the brafton_id table and checks for the id $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node'); $query->fieldCondition('field_brafton_id', 'value', $id, '='); $query->propertyCondition('status', 1); //checks for published nodes $result = $query->execute(); if (empty($result)) { $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node'); $query->fieldCondition('field_brafton_id', 'value', $id, '='); $query->propertyCondition('status', 0); //checks for unpublished nodes $result = $query->execute(); debug($result); } //debug($result); return $result; }
/** * Extract tids by term name and vocabulari id * * @param mixed $name * A string or an array of strings * @param int|string $voc * (optionally) Vocabulary id/name * * @return mixed * Fetched tids */ public static function getTaxonomyIdByName($name, $voc = 0) { if (!is_numeric($voc)) { // Get vid from name. $voc = self::getVidFromName($voc); } // Get tids. $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'taxonomy_term'); $query->propertyCondition('name', $name); if ($voc) { $query->propertyCondition('vid', $voc); } $query = $query->execute(); if (empty($query)) { return NULL; } else { return array_keys($query['taxonomy_term']); } }
public function actionZhome() { if (!isset($_POST['specialid'])) { $basic = new basic(); $basic->error_code = 1; $basic->error_msg = "no enough input parameter"; $jsonObj = CJSON::encode($basic); echo $jsonObj; die(0); } else { $tid = $_POST['specialid']; } $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node')->fieldCondition('field_myspecial', 'tid', $tid)->fieldCondition('field_show', 'value', 1)->propertyCondition('status', 1)->propertyOrderBy('sticky', 'DESC')->propertyOrderBy('vid', 'DESC')->range(0, 20); if (isset($_POST['lastnewsid'])) { //只返回新闻列表,有lastnewsid $query->propertyCondition('nid', $_POST['lastnewsid'], '<'); } $result = $query->execute(); $newslists = array(); if (isset($result['node'])) { $news_items_nids = array_keys($result['node']); $nodes = node_load_multiple($news_items_nids); foreach ($nodes as $node) { if ($node->type == 'multi') { $multi_news['newstype'] = 2; //多图 $multi_news['newstitle'] = $node->title; $multi_news['newsid'] = $node->nid; $pics = array(); $field_tups = $node->field_tup['und']; foreach ($field_tups as $field_tup) { $pic = new pic(); $pic->pic = $field_tup['uri']; $pic->pic = str_replace("public://", BigImg, $pic->pic); array_push($pics, $pic); } $multi_news['newspics'] = $pics; array_push($newslists, $multi_news); } else { if ($node->type == '_url') { $url_news['newstype'] = 3; //url链接新闻 $url_news['newstitle'] = $node->title; $url_news['newsid'] = $node->nid; $url_news['newsicon'] = $node->field_tux['und'][0]['uri']; $url_news['newsicon'] = str_replace("public://", BigImg, $url_news['newsicon']); $url_news['newslink'] = $node->field_link['und'][0]['value']; array_push($newslists, $url_news); } else { $normal_news['newstype'] = 1; //普通新闻 $normal_news['newstitle'] = $node->title; $normal_news['newsid'] = $node->nid; $field_image = $node->field_image; $normal_news['newsicon'] = $field_image['und'][0]['uri']; $normal_news['newsicon'] = str_replace("public://", ThumbnailImg, $normal_news['newsicon']); $field_fubiaoti = $node->field_fubiaoti; $normal_news['newssubtitle'] = $field_fubiaoti['und'][0]['value']; $normal_news['newslabel'] = $node->field_label['und'][0]['value']; $normal_news['comment_count'] = $node->comment_count; array_push($newslists, $normal_news); } } } } if (isset($_POST['lastnewsid'])) { $easyhome['error_code'] = 0; $easyhome['newslist'] = $newslists; $jsonObj = CJSON::encode($easyhome); echo $jsonObj; die(0); } else { //首页轮播图 $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node')->propertyCondition('status', 1)->fieldCondition('field_myspecial', 'tid', $tid)->propertyCondition('promote', 1, '=')->propertyOrderBy('vid', 'DESC')->range(0, 5); $result = $query->execute(); if (isset($result['node'])) { $news_items_nids = array_keys($result['node']); $topnodes = node_load_multiple($news_items_nids); } $topbanners = array(); foreach ($topnodes as $key => $node) { $topbanner = new topbanner(); if ($node->type == 'multi') { $topbanner->toptype = 2; } else { if ($node->type == '_url') { $topbanner->toptype = 3; $topbanner->toplink = $node->field_link['und'][0]['value']; } else { $topbanner->toptype = 1; } } $topbanner->topimag = $node->field_image['und'][0]['uri']; //多图也有缩略图属性 $topbanner->topimag = str_replace("public://", BigImg, $topbanner->topimag); $topbanner->toptitle = $node->title; $topbanner->topid = $node->nid; array_push($topbanners, $topbanner); } $homepage['error_code'] = 0; $homepage['topbanner'] = $topbanners; $homepage['newslist'] = $newslists; $jsonObj = CJSON::encode($homepage); echo $jsonObj; } }
echo $row['field_image_title']; ?> </h2> </div> </div> <?php } elseif (strtolower($row['field_template']->name) == 'blog') { ?> <?php $type = "article"; $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node')->propertyCondition('type', $type)->propertyCondition('status', 1)->propertyOrderBy('created', 'DESC'); if ($_GET['blog_filter'] == '2') { $query->propertyCondition('promote', 1); } $entities = $query->execute(); $articles = node_load_multiple(array_keys($entities['node'])); ?> <div class="pure-g grid-blog"> <?php foreach ($articles as $nid => $article) { ?> <?php $tid = $article->field_category['und'][0]['tid']; if ($tid == 33) { //sweat
/** * Filter files by vsite */ protected function queryForListFilter(EntityFieldQuery $query) { if ($this->request['vsite']) { if ($vsite = vsite_get_vsite($this->request['vsite'])) { $query->fieldCondition(OG_AUDIENCE_FIELD, 'target_id', $this->request['vsite']); } else { throw new RestfulBadRequestException(t('No vsite with the id @id', array('@id' => $this->request['vsite']))); } } // Make getting private files explicit // Private files currently require PIN authentication before they can even be access checked if (!isset($this->request['private'])) { $query->propertyCondition('uri', 'private://%', 'NOT LIKE'); } elseif ($this->request['private'] == 'only') { $query->propertyCondition('uri', 'private://%', 'LIKE'); } }
/** * Displays the bean. */ public function view($bean, $content, $view_mode = 'default', $langcode = NULL) { // We need to make sure that the bean is configured correctly. if (!empty($bean->filters['vocabulary']) && !empty($bean->settings['bundle_types'])) { // Define an array of all taxonomy terms in the defined vocabularies. $possible_tid = array(); foreach ($bean->filters['vocabulary'] as $vm) { $query = new EntityFieldQuery(); $result = $query->entityCondition('entity_type', 'taxonomy_vocabulary')->propertyCondition('machine_name', $vm)->execute(); foreach ($result['taxonomy_vocabulary'] as $vocabulary) { $vid = $vocabulary->vid; } $tree = taxonomy_get_tree($vid); foreach ($tree as $term) { $possible_tid[$term->tid] = $term->tid; } } // Compare possible terms to those attached to the menu object or current // user depending on 'related' settings. $active_entity = bean_tax_active_entity_array($bean->settings['related']); if (isset($active_entity['terms'])) { $valid_tid = array(); foreach ($active_entity['terms'] as $term) { if (isset($possible_tid[$term->tid])) { $valid_tid[$term->tid] = $term->tid; } } // Store Entity type. $type = $bean->settings['entity_type']; // Entity field query for entities of the defined bundle. $aggregate = array(); foreach ($bean->settings['bundle_types'] as $bundle) { $query = new EntityFieldQuery(); $query->entityCondition('entity_type', $type); $query->entityCondition('bundle', $bundle); $query->propertyOrderBy('created', 'DESC'); if ($type == 'node') { $query->propertyCondition('status', 1); } // Additional conditions for node based translations. global $language; if ($language->language != NULL && $type == 'node') { $query->propertyCondition('language', $language->language); $query->propertyCondition('tnid', 0, "<>"); } $results[$bundle] = $query->execute(); // For nodes using field based translation. if ($language->language != NULL && $type == 'node') { $query = new EntityFieldQuery(); $query->entityCondition('entity_type', $type); $query->entityCondition('bundle', $bundle); $query->propertyOrderBy('created', 'DESC'); $query->propertyCondition('tnid', 0); $query->propertyCondition('status', 1); $field_translated = $query->execute(); // Reassign the result array or merge arrays if necessary if (empty($results[$bundle][$type]) && !empty($field_translated[$type])) { $results[$bundle][$type] = $field_translated[$type]; } elseif (!empty($results[$bundle][$type]) && !empty($field_translated[$type])) { $combined = $results[$bundle][$type] + $field_translated[$type]; ksort($combined); $results[$bundle][$type] = $combined; } } // Store the results in an aggregated array of entities. if (isset($results[$bundle][$bean->settings['entity_type']])) { foreach ($results[$bundle][$bean->settings['entity_type']] as $id => $result) { $aggregate[$bean->settings['entity_type']][$id] = $result; } } } // Create a taxonomy related "score" for each result's matching terms. $result = array(); $unmatching = array(); if (isset($aggregate[$bean->settings['entity_type']])) { foreach ($aggregate[$bean->settings['entity_type']] as $key => $value) { $entity_terms = bean_tax_get_entity_terms($bean->settings['entity_type'], $key); $score = 0; // The actual scoring to determine valid taxonomy term matching. foreach ($entity_terms as $term) { if (isset($valid_tid[$term->tid])) { $score++; } } $item['id'] = $key; $item['score'] = $score; // A score of 1 or greater adds to the array of matching entities. if ($score != 0) { $result[] = $item; } elseif ($score == 0 && $bean->settings['unmatch_add']) { $result[] = $item; } } } // Calculate an overall score. $all = 0; foreach ($result as $item) { $all = $item['score'] + $all; } // If overall score is none, do sort. if ($all != 0) { // Invoke comparison function to determine highest ranked results. usort($result, "bean_tax_cmp"); } } // Remove active page from results. if (!empty($result)) { foreach ($result as $key => $entity) { $active_page = bean_tax_active_entity_array('page'); if (isset($active_page['ids']) && $active_page['ids'][0] == $entity['id'] && $active_page['type'] == $bean->settings['entity_type']) { unset($result[$key]); } } } // Related entities initially set to none. if (empty($result)) { // Hide block when result is empty and 'hide_empty' option is checked. if ($bean->settings['hide_empty'] || !$active_entity['object']) { return; } // There are no related nodes. Set Empty array for theme output. $content['#markup'] = t('No Results'); } elseif (isset($active_entity['type']) && $active_entity['type'] == 'bean' && $bean->bid === $active_entity['object']->bid) { $content['#markup'] = ''; } else { // Start counting results at index of 0. $i = 0; // Set and index for actual results shown. $shown = 0; // Set markup index as empty. $content['#markup'] = ''; // Load and render the related entities. foreach ($result as $entity) { if (isset($entity['id']) && $shown < $bean->filters['records_shown'] && $i >= $bean->filters['offset_results']) { $entity = entity_load_single($bean->settings['entity_type'], $entity['id']); $entity_view = entity_view($bean->settings['entity_type'], array($entity), $bean->settings['entity_view_mode']); $content['#markup'] .= drupal_render($entity_view); $shown++; } // Count continues along... $i++; } } } if (!empty($bean->more_link['text']) && !empty($bean->more_link['path'])) { // Invoke the theme function to show the additional information "more link" $content['#markup'] .= theme('bean_tax_more_link', array('text' => $bean->more_link['text'], 'path' => $bean->more_link['path'])); } return $content; }
/** * As seen in commerce_services: filtering. * * Adds property and field conditions to an index EntityFieldQuery. * * @param \EntityFieldQuery $query * The EntityFieldQuery object being built for the index query. * @param string $entity_type * Machine-name of the entity type of the index query. * @param array $filter * An associative array of property names, single column field names, or * multi-column field column names with their values to use to filter the * result set of the index request. * @param array $filter_op * An associative array of field and property names with the operators to * use when applying their filter conditions to the index request query. */ public static function indexQueryFilter(\EntityFieldQuery $query, $entity_type, array $filter, array $filter_op) { // Loop over each filter field to add them as property or field conditions // on the query object. This function assumes the $filter and $filter_op // arrays contain matching keys to set the correct operator to the filter // fields. foreach ($filter as $filter_field => $filter_value) { // Determine the corresponding operator for this filter field, defaulting // to = in case of an erroneous request. $operator = '='; if (!empty($filter_op[$filter_field])) { $operator = $filter_op[$filter_field]; } // If operator is IN, try to turn the filter into an array. if ($operator == 'IN') { $filter_value = explode(',', $filter_value); } // If the current filter field is a property, use a property condition. $properties = self::entityTypeProperties($entity_type); if (in_array($filter_field, array_keys($properties), TRUE)) { $query->propertyCondition($properties[$filter_field], $filter_value, $operator); } else { // Look for the field name among the entity type's field list. foreach (self::entityTypeFields($entity_type) as $field_name => $field_type) { // If the filter field begins with a field name, then either the // filter field is the field name or is a column of the field. if (strpos($filter_field, $field_name) === 0) { $field_info = field_info_field($field_name); // If field is list_boolean, convert true => 1 and false => 0. if ($field_info['type'] == 'list_boolean') { if ($filter_value === 'true') { $filter_value = 1; } if ($filter_value === 'false') { $filter_value = 0; } } // If it is the field name and the field type has a single column // schema, add the field condition to the index query. if ($field_name == $filter_field && count($field_info['columns']) == 1) { $column = key($field_info['columns']); $query->fieldCondition($field_name, $column, $filter_value, $operator); break; } else { // Otherwise if the filter field contains a valid column // specification for the field type, add the field condition to // the index query. $column = substr($filter_field, strlen($field_name) + 1); if (in_array($column, array_keys($field_info['columns']))) { $query->fieldCondition($field_name, $column, $filter_value, $operator); break; } } } } } } }
/** * Build an EntityFieldQuery to get referencable entities. */ protected function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS') { $query = new EntityFieldQuery(); global $user; $query->entityCondition('entity_type', 'commerce_store'); if (!user_access('add products to any store')) { $query->fieldCondition('cmp_m_store', 'target_id', $user->uid); } if (isset($match)) { $entity_info = entity_get_info('commerce_store'); if (isset($entity_info['entity keys']['label'])) { $query->propertyCondition($entity_info['entity keys']['label'], $match, $match_operator); } } // Add a generic entity access tag to the query. $query->addTag($this->field['settings']['target_type'] . '_access'); $query->addTag('entityreference'); $query->addMetaData('field', $this->field); $query->addMetaData('entityreference_selection_handler', $this); return $query; }
/** * Entity field query for entities of the defined bundle. */ private function getAggregate($bean) { $type = $bean->settings['entity_type']; foreach ($bean->settings['bundle_types'] as $bundle) { $query = new EntityFieldQuery(); $query->entityCondition('entity_type', $type); $query->entityCondition('bundle', $bundle); $query->propertyOrderBy('created', 'DESC'); if ($type == 'node') { $query->propertyCondition('status', 1); } // Additional conditions for node based translations. global $language; if ($language->language != NULL && $type == 'node') { $query->propertyCondition('language', $language->language); $query->propertyCondition('tnid', 0, "<>"); } $results[$bundle] = $query->execute(); // For nodes using field based translation. if ($language->language != NULL && $type == 'node') { $query = new EntityFieldQuery(); $query->entityCondition('entity_type', $type); $query->entityCondition('bundle', $bundle); $query->propertyOrderBy('created', 'DESC'); $query->propertyCondition('tnid', 0); $query->propertyCondition('status', 1); $field_translated = $query->execute(); // Reassign the result array or merge arrays if necessary if (empty($results[$bundle][$type]) && !empty($field_translated)) { $results[$bundle][$type] = $field_translated[$type]; } elseif (!empty($results[$bundle][$type]) && !empty($field_translated[$type])) { $combined = $results[$bundle][$type] + $field_translated[$type]; ksort($combined); $results[$bundle][$type] = $combined; } } } // Store the results in an aggregated array of entities. $aggregate = array(); if (isset($results[$bundle][$bean->settings['entity_type']])) { foreach ($results[$bundle][$bean->settings['entity_type']] as $id => $result) { $aggregate[$bean->settings['entity_type']][$id] = $result; } } return $aggregate; }
public function load(AbstractMetaModel $metamodel, array $filters = NULL) { $environment_metamodel = data_controller_get_environment_metamodel(); LogHelper::log_notice(t('Loading Meta Model from GovDashboard Content Types ...')); $loaderName = $this->getName(); $datasetQuery = new EntityFieldQuery(); $datasetQuery->entityCondition('entity_type', 'node'); $datasetQuery->propertyCondition('type', NODE_TYPE_DATASET); $datasetQuery->propertyCondition('status', NODE_PUBLISHED); $datasetQuery->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT'); // applying filters. Note that we have custom mapping for filter properties $datasetFilters = isset($filters['DatasetMetaData']) ? $filters['DatasetMetaData'] : NULL; if (isset($datasetFilters)) { foreach ($datasetFilters as $propertyName => $filterValues) { switch ($propertyName) { case 'datasourceName': $selectedDataSourceNames = FALSE; // checking if any of the data sources are actually data marts foreach ($filterValues as $datasourceName) { $datasource = $environment_metamodel->findDataSource($datasourceName); if (isset($datasource->nid)) { $selectedDataSourceNames[] = $datasourceName; } } if (isset($selectedDataSourceNames)) { $datasetQuery->fieldCondition('field_dataset_datasource', 'value', $selectedDataSourceNames); } else { // there is no selected datamarts for this request return; } break; default: throw new UnsupportedOperationException(t( 'Unsupported mapping for the property for filtering during dataset loading: %propertyName', array('%propertyName' => $propertyName))); } } } $datasetEntities = $datasetQuery->execute(); $dataset_nids = isset($datasetEntities['node']) ? array_keys($datasetEntities['node']) : NULL; if (!isset($dataset_nids)) { return; } $datasetNodes = node_load_multiple($dataset_nids); // loading columns for selected datasets $columnNodes = gd_column_get_columns_4_dataset($dataset_nids, LOAD_ENTITY, INCLUDE_UNPUBLISHED); // grouping nodes in context of dataset $datasetsColumnNodes = $this->groupNodesByDataset($columnNodes, 'field_column_dataset'); // preparing dataset & cubes $processedDatasetCount = 0; foreach ($datasetNodes as $datasetNode) { $dataset_nid = $datasetNode->nid; $datasourceName = get_node_field_value($datasetNode, 'field_dataset_datasource'); $datasource = isset($datasourceName) ? $environment_metamodel->findDataSource($datasourceName) : NULL; if (!isset($datasource)) { // the data mart could be unpublished or ... continue; } $datasetColumnNodes = isset($datasetsColumnNodes[$dataset_nid]) ? $datasetsColumnNodes[$dataset_nid] : NULL; // preparing dataset $dataset = GD_DatasetMetaModelLoaderHelper::prepareDataset($metamodel, $datasetNode, $datasetColumnNodes, $datasource); // assigning a loader which created the dataset $dataset->loaderName = $loaderName; $processedDatasetCount++; } LogHelper::log_info(t('Processed @datasetCount dataset node(s)', array('@datasetCount' => $processedDatasetCount))); }