/**
  * 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;
 }
Example #2
0
 /**
  * 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;
 }
  /**
   * 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;
  }
 /**
  * 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());
 }
Example #5
0
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);
        }
    }
}
 /**
  * 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;
 }
 /**
  * {@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);
 }
Example #8
0
/**
 * 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)]);
            }
        }
    }
}
 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;
 }
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.';
    }
}
/**
 * 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();
}
/**
 * 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());
    }
}
Example #13
0
 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);
 }
 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;
 }
/**
 * 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;
}
    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;
            }
        }
    }
Example #17
0
 /**
  * @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;
 }
 public function getEntityFieldQuery()
 {
     if (variable_get('spectrum_development_mode', true)) {
         $this->validateQuery();
     }
     $query = new EntityFieldQuery();
     $query->entityCondition('entity_type', $this->entityType);
     if (!empty($this->bundle)) {
         $query->entityCondition('bundle', $this->bundle);
     }
     foreach ($this->conditions as $condition) {
         $condition->addQueryCondition($query);
     }
     foreach ($this->orders as $order) {
         $order->addQueryOrder($query);
     }
     return $query;
 }
Example #19
0
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;
}
Example #20
0
 /**
  * @param scalar $puid is permanent unique id value and
  */
 public function drupalUserFromPuid($puid)
 {
     $query = new EntityFieldQuery();
     $query->entityCondition('entity_type', 'user')->fieldCondition('ldap_user_puid_sid', 'value', $this->sid, '=')->fieldCondition('ldap_user_puid', 'value', $puid, '=')->fieldCondition('ldap_user_puid_property', 'value', $this->unique_persistent_attr, '=')->addMetaData('account', user_load(1));
     // run the query as user 1
     $result = $query->execute();
     if (isset($result['user'])) {
         $user = entity_load('user', array_keys($result['user']));
     }
 }
function wyc_get_uid_by_wycnumber($no)
{
    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'user')->fieldCondition('field_wyc_number', 'value', $no);
    $result = $query->execute();
    if (!empty($result['user'])) {
        return key($result['user']);
    }
    return 0;
}
/**
 * Obtenir la dernière actualité épinglée
 */
function actualite_get_single_sticky()
{
    $node = NULL;
    $query = new EntityFieldQuery();
    $entities = $query->entityCondition('entity_type', 'node')->propertyCondition('type', 'actualites')->propertyCondition('status', 1)->propertyCondition('sticky', 1)->propertyOrderBy('created', 'DESC')->range(0, 1)->execute();
    if (!empty($entities['node'])) {
        $nids = array_keys($entities['node']);
        $node = node_load(reset($nids));
    }
    return $node;
}
/**
 *
 */
function _query_products_nids()
{
    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'node')->entityCondition('bundle', array('card', 'software', 'chassis'))->propertyCondition('status', 1);
    $result = $query->execute();
    $nids = NULL;
    if (isset($result['node'])) {
        $nids = array_keys($result['node']);
    }
    return $nids;
}
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;
}
Example #25
0
 public static function get_nid_from_data($id_label)
 {
     $result = array();
     $query = new EntityFieldQuery();
     $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'listino_base')->propertyCondition('status', 1)->fieldCondition('field_lb_classe_servizio', 'value', ucfirst($id_label))->addMetaData('account', user_load(1));
     $qryres = $query->execute();
     if (isset($qryres['node'])) {
         $items_nids = array_keys($qryres['node']);
         $result = $items_nids[0];
     }
     return $result;
 }
Example #26
0
function get_nodes_by_reference($bundle, $field, $nid, $view_mode)
{
    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'node')->entityCondition('bundle', $bundle)->propertyCondition('status', NODE_PUBLISHED)->fieldCondition($field, 'target_id', $nid, '=')->addMetaData('account', user_load(1));
    $result = $query->execute();
    if (isset($result['node'])) {
        $nids = array_keys($result['node']);
        $nodes = entity_load('node', $nids);
        return node_view_multiple($nodes, $view_mode);
    }
    return FALSE;
}
 /**
  * {@inheritdoc}
  *
  * Override RestfulEntityBase::createEntity() to test if meter already exists,
  * to allow update existing nodes in stead of creating a copy.
  */
 public function createEntity()
 {
     $query = new EntityFieldQuery();
     $result = $query->entityCondition('entity_type', 'node')->propertyCondition('type', 'iec_meter')->fieldCondition('field_contract_id', 'value', $this->request['contract'])->fieldCondition('field_meter_code', 'value', $this->request['meter_code'])->fieldCondition('field_meter_serial', 'value', $this->request['meter_serial'])->range(0, 1)->execute();
     if (!empty($result['node'])) {
         // Node exists, update it.
         $id = key($result['node']);
         return parent::updateEntity($id);
     }
     // New node.
     return parent::createEntity();
 }
 /**
  * Get the meters list of the account.
  */
 function getMeters(\EntityMetadataWrapper $wrapper)
 {
     $nid = $wrapper->getIdentifier();
     $query = new EntityFieldQuery();
     $result = $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'iec_meter')->propertyCondition('status', NODE_PUBLISHED)->fieldCondition(OG_AUDIENCE_FIELD, 'target_id', $nid)->propertyOrderBy('nid')->execute();
     if (empty($result['node'])) {
         return;
     }
     $nids = array_keys($result['node']);
     $handler = restful_get_restful_handler('iec_meters');
     return $handler->get(implode(',', $nids));
 }
function entity_reference_users($nid)
{
    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'user');
    $result = $query->execute();
    foreach ($result['user'] as $doctors) {
        $doctor = user_load($doctors->uid);
        if ($doctor->field_speciality['und'][0]['target_id'] == $nid) {
            $doctor_arr[$doctors->uid] = array('name' => $doctor->name, 'designation' => $doctor->field_designation['und'][0]['value'], 'profile_link' => $doctor->field_view_profile_link['und'][0]['value']);
        }
    }
    return $doctor_arr;
}
/**
 * @return array,
 */
function _node_title_search($title = NULL, $brand_tid = NULL, $depend_chassis)
{
    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'node')->entityCondition('bundle', array('card', 'chassis', 'software'))->propertyCondition('title', $title)->propertyCondition('status', NODE_PUBLISHED);
    $result = $query->execute();
    $nid_array = NULL;
    if (isset($result['node'])) {
        if (count($result['node']) > 0) {
            $nid_array = array_keys($result['node']);
        }
    }
    return $nid_array;
}