本文整理汇总了PHP中EntityFieldQuery类的典型用法代码示例。如果您正苦于以下问题:PHP EntityFieldQuery类的具体用法?PHP EntityFieldQuery怎么用?PHP EntityFieldQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EntityFieldQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createOrUpdateWorkSession
/**
* Create a new session or update an open session.
*/
public function createOrUpdateWorkSession()
{
$request = $this->getRequest();
$account = $this->getAccount();
if (!user_access('timewatch punch')) {
throw new RestfulForbiddenException('No punch access.');
}
if (empty($request['pincode'])) {
throw new \RestfulBadRequestException('Pincode is required');
}
$uid = timewatch_session_get_uid_by_pincode($request['pincode']);
if (!$uid) {
throw new \RestfulBadRequestException('Wrong pincode');
}
$employee_account = user_load($uid);
// Find an existing session with no end date.
$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'work_session')->propertyCondition('status', NODE_PUBLISHED)->fieldCondition('field_employee', 'target_id', $uid)->fieldCondition('field_session_date', 'value2', NULL)->range(0, 1)->execute();
if (empty($result['node'])) {
// When there's no open session, create a new one.
$values = array('type' => 'work_session', 'uid' => $account->uid, 'status' => NODE_PUBLISHED, 'title' => format_string('@date - @user', array('@date' => date('d/m/y'), '@user' => $employee_account->name)));
$node = entity_create('node', $values);
$wrapper = entity_metadata_wrapper('node', $node);
$wrapper->field_employee->set($uid);
$wrapper->field_session_date->value->set(REQUEST_TIME);
} else {
// Otherwise set the end date of the open session.
$wrapper = entity_metadata_wrapper('node', key($result['node']));
$wrapper->field_session_date->value2->set(REQUEST_TIME);
}
$wrapper->save();
return $this->viewEntity($wrapper->getIdentifier());
}
示例2: quatro_preprocess_page
function quatro_preprocess_page(&$vars)
{
// Set the page title for the "Verein" Panels Page
if (arg(0) == 'verein' && is_numeric(arg(1))) {
//dpm($vars);
$nid = arg(1);
// Search for the "Mannschaft" Node matching the argument
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'mannschaft')->propertyCondition('status', NODE_PUBLISHED)->propertyCondition('nid', $nid, '=')->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT');
$result = $query->execute();
// Set the page title to the Node Title of the "Mannschaft" Node
if (isset($result['node'])) {
$node_ids = array_keys($result['node']);
$node_id = $node_ids[0];
$node = node_load($node_id);
drupal_set_title($node->title);
}
}
// Set the page title for the "Spieler" Panels Page
if (arg(0) == 'spieler' && is_numeric(arg(1))) {
//dpm($vars);
$nid = arg(1);
// Search for the ticket matching the Rabattcode
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'spieler')->propertyCondition('status', NODE_PUBLISHED)->propertyCondition('nid', $nid, '=')->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT');
$result = $query->execute();
// If a ticket was found, set the price field to the ticket price
if (isset($result['node'])) {
$node_ids = array_keys($result['node']);
$node_id = $node_ids[0];
$node = node_load($node_id);
drupal_set_title($node->title);
}
}
}
示例3: insert_door_to_drupal
function insert_door_to_drupal($door_id)
{
// set HTTP_HOST or drupal will refuse to bootstrap
$_SERVER['HTTP_HOST'] = 'zl-apps';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
include_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$door = new Door();
$door_detail = $door->read(null, $door_id);
$door_nid = null;
$query = new EntityFieldQuery();
$entities = $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'doors')->propertyCondition('status', 1)->fieldCondition('field_door_id', 'value', $door_detail['Door']['id'], '=')->execute();
foreach ($entities['node'] as $nid => $value) {
$door_nid = $nid;
break;
// no need to loop more even if there is multiple (it is supposed to be unique
}
$node = null;
if (is_null($door_nid)) {
$node = new stdClass();
$node->language = LANGUAGE_NONE;
} else {
$node = node_load($door_nid);
}
$node->type = 'doors';
node_object_prepare($node);
$node->title = $door_detail['Door']['door_style'];
$node->field_door_id[$node->language][0]['value'] = $door_detail['Door']['id'];
$node->sell_price = 0;
$node->model = $door_detail['Door']['door_style'];
$node->shippable = 1;
$path = 'door/' . $node->title;
$node->path = array('alias' => $path);
node_save($node);
}
示例4: getBillingCycle
/**
* 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;
}
示例5: generateRefreshToken
/**
* Create a refresh token for the current user
*
* It will delete all the existing refresh tokens for that same user as well.
*
* @param int $uid
* The user ID.
*
* @return \RestfulTokenAuth
* The token entity.
*/
private function generateRefreshToken($uid) {
// Check if there are other refresh tokens for the user.
$query = new \EntityFieldQuery();
$results = $query
->entityCondition('entity_type', 'restful_token_auth')
->entityCondition('bundle', 'refresh_token')
->propertyCondition('uid', $uid)
->execute();
if (!empty($results['restful_token_auth'])) {
// Delete the tokens.
entity_delete_multiple('restful_token_auth', array_keys($results['restful_token_auth']));
}
// Create a new refresh token.
$values = array(
'uid' => $uid,
'type' => 'refresh_token',
'created' => REQUEST_TIME,
'name' => t('Refresh token for: @uid', array(
'@uid' => $uid,
)),
'token' => drupal_random_key(),
);
$refresh_token = $this->create($values);
$this->save($refresh_token);
return $refresh_token;
}
示例6: load_data
public function load_data($ar_data = null)
{
$result = array();
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'sito_parcheggio')->propertyCondition('status', 1)->addMetaData('account', user_load(1));
$qryres = $query->execute();
if (isset($qryres['node'])) {
$items_nids = array_keys($qryres['node']);
$items = entity_load('node', $items_nids);
$first = true;
foreach ($items as $nodo => $elem) {
if ($first) {
$result[0]['codice'] = 0;
$result[0]['descrizione'] = 'Selezionare un parcheggio';
$first = false;
}
$result[$nodo]['codice'] = $elem->field_sp_codice[LANGUAGE_NONE][0]['value'];
$result[$nodo]['descrizione'] = $elem->title;
$result[$nodo]['indirizzo']['indirizzo'] = $elem->field_sp_indirizzo[LANGUAGE_NONE][0]['thoroughfare'];
$result[$nodo]['indirizzo']['cap'] = $elem->field_sp_indirizzo[LANGUAGE_NONE][0]['postal_code'];
$result[$nodo]['indirizzo']['localita'] = $elem->field_sp_indirizzo[LANGUAGE_NONE][0]['locality'];
$result[$nodo]['indirizzo']['provincia'] = $elem->field_sp_indirizzo[LANGUAGE_NONE][0]['administrative_area'];
}
}
$this->ar_lista = $result;
}
示例7: community_features_user_feed
function community_features_user_feed()
{
$uid = $GLOBALS['user']->uid;
$flags = flag_get_user_flags('user', null, $uid);
//dpm($flags);
//unset($flags['cf_follow_user']);
if (isset($flags['cf_follow_user'])) {
//dpm($flags['cf_follow_user']);
foreach ($flags['cf_follow_user'] as $flag) {
//dpm($flag);
$author_uid = $flag->entity_id;
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'cm_show')->propertyCondition('status', 1)->propertyCondition('uid', $author_uid)->propertyOrderBy('created', 'DESC')->fieldCondition('field_show_vod', 'fid', 'NULL', '!=')->pager(5);
//->range(0, 100);
$result = $query->execute();
if (isset($result['node'])) {
$nids = array_keys($result['node']);
$nodes = entity_load('node', $nids);
foreach ($nodes as $node) {
$items[$node->nid] = array('node' => $node);
}
}
}
$build['pager'] = array('#theme' => 'pager', '#weight' => 5);
//dpm($items);
// Send data to TPL.
return theme('cf_user_feed_all', array('content' => isset($items) ? $items : '', 'pager' => $build['pager']));
} else {
return '<br/> You are currently not following any users. Please follow some users and their videos will appear here.';
}
}
示例8: queryLoad
protected function queryLoad($ids)
{
$multifields = multifield_get_fields();
foreach (array_keys($multifields) as $field_name) {
$query = new EntityFieldQuery();
if ($ids) {
$query->fieldCondition($field_name, 'id', $ids, 'IN');
} else {
$query->fieldCondition($field_name, 'id', 0, '>');
}
if ($results = $query->execute()) {
$pseudo_entities = array();
$field = field_info_field($field_name);
foreach ($results as $entity_type => $entities) {
// Simply doing an entity load on the entities with multifield values
// will cause the cacheSet() from multifield_field_load() to get
// invoked.
$entities = entity_load($entity_type, array_keys($entities));
foreach ($entities as $entity) {
if ($items = field_get_items($entity_type, $entity, $field_name)) {
foreach ($items as $item) {
$pseudo_entities[$item['id']] = _multifield_field_item_to_entity($field['type'], $item);
}
}
}
}
$this->cacheSet($pseudo_entities);
}
}
return array_intersect_key($this->entityCache, drupal_map_assoc($ids, $ids));
}
示例9: PROFILE_install
/**
* Implements hook_install().
*/
function PROFILE_install()
{
global $base_url;
$server_name = 'oauth2';
$client_key = 'client1';
$client_secret = md5(uniqid(rand(), TRUE));
$redirect_uri = $base_url . '/oauth2/authorized';
// Delete the client if already exists.
$query = new EntityFieldQuery();
$clients = $query->entityCondition('entity_type', 'oauth2_server_client')->propertyCondition('server', $server_name)->propertyCondition('client_key', $client_key)->execute();
if (isset($clients['oauth2_server_client'])) {
$cids = array_keys($clients['oauth2_server_client']);
foreach ($cids as $cid) {
entity_delete('oauth2_server_client', $cid);
}
}
// Register a client on the oauth2 server.
$client = entity_create('oauth2_server_client', array());
$client->server = $server_name;
$client->label = 'Test OAuth2 Client';
$client->client_key = $client_key;
$client->client_secret = $client_secret;
$client->redirect_uri = $redirect_uri;
$client->automatic_authorization = TRUE;
$client->save();
}
示例10: loadConvenzioneFromTarga
private function loadConvenzioneFromTarga($ar_data)
{
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'parkauto')->propertyCondition('status', 1)->fieldCondition('field_p_targa_auto_cliente', 'value', trim($ar_data['rc_targa_auto_cliente']), '=')->fieldCondition('field_p_sito_parking', 'nid', trim($ar_data['sito']))->range(0, 1)->addMetaData('account', user_load(1));
$qryres = $query->execute();
return $qryres;
}
示例11: hook_get_group_content_ids_alter
/**
* Allows overriding of the selected entity list for cloning.
*
* @param $ids
* An array of entity ids currently selected.
* @return
* An array of entity ids after processing.
*/
function hook_get_group_content_ids_alter(&$ids)
{
// array of content types to remove from cloning
$content_types = array('cle_submission');
// pull out nodes for testing as this could have other entities
foreach ($ids as $key => $id) {
if ($id['entity_type'] == 'node') {
$id_key[$key] = $id['etid'];
}
}
// Don't allow submissions to be cloned
$query = new EntityFieldQuery();
// select all nodes
$query->entityCondition('entity_type', 'node')->entityCondition('bundle', $content_types, 'IN')->propertyCondition('nid', $id_key, 'IN')->addMetaData('account', user_load(1));
$result = $query->execute();
// verify that we have results
if (isset($result['node'])) {
// test the node array against the nodes in the clone array
foreach ($result['node'] as $node) {
// if the node selected is in the array, remove it from the ids
if (in_array($node->nid, $id_key)) {
unset($ids[array_search($node->nid, $id_key)]);
}
}
}
}
示例12: whaleocalypse_preprocess_field
/**
* Add the comic strip name right above the body field.
*/
function whaleocalypse_preprocess_field(&$vars)
{
if (isset($vars['element']['#bundle']) && $vars['element']['#bundle'] == 'comic' && isset($vars['element']['#field_name']) && $vars['element']['#field_name'] == 'body') {
$vars['label'] = $vars['element']['#object']->title;
}
//Add the transcript expand js if the field is populated
if ($vars['element']['#field_name'] == 'field_transcript') {
drupal_add_js(drupal_get_path('theme', 'whaleocalypse') . '/js/expand-transcript.js', array('scope' => 'footer', 'type' => 'file'));
}
//Create the custom "story arc" functionality
if (isset($vars['element']['#field_name']) && $vars['element']['#field_name'] == 'field_story_arc') {
$tid = $vars['element']['#object']->field_story_arc[LANGUAGE_NONE][0]['tid'];
$nid = $vars['element']['#object']->nid;
$story_arc_count = new EntityFieldQuery();
$vars['story_arc_count'] = $story_arc_count->entityCondition('entity_type', 'node')->entityCondition('bundle', 'comic')->fieldCondition('field_story_arc', 'tid', $tid, '=')->count()->execute();
$story_arc_position = new EntityFieldQuery();
$story_arc_position = $story_arc_position->entityCondition('entity_type', 'node')->entityCondition('bundle', 'comic')->fieldCondition('field_story_arc', 'tid', $tid, '=')->propertyOrderBy('created', 'ASC')->execute();
$vars['story_arc_position'] = array_search($nid, array_keys($story_arc_position['node'])) + 1;
}
//Add the author URL if it is set.
if (isset($vars['element']['#field_name']) && $vars['element']['#field_name'] == 'field_contributing_author') {
if (isset($vars['element']['#object']->field_contributing_author_url[LANGUAGE_NONE][0])) {
$vars['items'][0]['#markup'] = l($vars['items'][0]['#markup'], $vars['element']['#object']->field_contributing_author_url[LANGUAGE_NONE][0]['value'], array("attributes" => array("target" => "_blank")));
}
$vars['call_to_action'] = 'You can ' . l('write your own whaleocalypse too.', 'node/169', array());
}
}
示例13: authenticate
/**
* {@inheritdoc}
*/
public function authenticate(RequestInterface $request)
{
// Access token may be on the request, or in the headers.
if (!($token = $this->extractToken($request))) {
return NULL;
}
// Check if there is a token that has not expired yet.
$query = new \EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'restful_token_auth')->entityCondition('bundle', 'access_token')->propertyCondition('token', $token)->range(0, 1)->execute();
if (empty($result['restful_token_auth'])) {
// No token exists.
return NULL;
}
$id = key($result['restful_token_auth']);
$auth_token = entity_load_single('restful_token_auth', $id);
if (!empty($auth_token->expire) && $auth_token->expire < REQUEST_TIME) {
// Token is expired.
if (variable_get('restful_token_auth_delete_expired_tokens', TRUE)) {
// Token has expired, so we can delete this token.
$auth_token->delete();
}
return NULL;
}
return user_load($auth_token->uid);
}
示例14: hook_commerce_product_can_delete
/**
* Lets modules prevent the deletion of a particular product.
*
* Before a product can be deleted, other modules are given the chance to say
* whether or not the action should be allowed. Modules implementing this hook
* can check for reference data or any other reason to prevent a product from
* being deleted and return FALSE to prevent the action.
*
* This is an API level hook, so implementations should not display any messages
* to the user (although logging to the watchdog is fine).
*
* @param $product
* The product to be deleted.
*
* @return
* TRUE or FALSE indicating whether or not the given product can be deleted.
*
* @see commerce_product_reference_commerce_product_can_delete()
*/
function hook_commerce_product_can_delete($product)
{
// Use EntityFieldQuery to look for line items referencing this product and do
// not allow the delete to occur if one exists.
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'commerce_line_item', '=')->entityCondition('bundle', 'product', '=')->fieldCondition('product', 'product_id', $product->product_id, '=')->count();
return $query->execute() > 0 ? FALSE : TRUE;
}
示例15: portfolino_get_articles
function portfolino_get_articles()
{
$query = new EntityFieldQuery();
$i = 50;
$result = $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'article')->range(0, $i)->execute();
$nids = array_keys($result['node']);
$nodes = entity_load('node', $nids);
return $nodes;
}