Build a system to wrap EntityFieldQuery and provide base property and bundle field specific methods for adding conditions.

Comments

  • zengenuity committed 84f8c17 on 7.x-1.x
    #2354747 - Initial build of the query wrapper. Supports entity types,...
zengenuity’s picture

Committed build of the query wrapper system supporting querying by entity type. Enable the new Wrappers Delight Query submodule to use it. I still need to add the code to generate bundle-specific query wrappers. The entity query wrappers can be used like this:

<?php
$results = WdNodeWrapperQuery::find()
            ->byAuthor(1)
            ->execute();

$user_node_links = array();
foreach ($results as $record) {
  $user_node_links[] = l($record->getTitle(), 'node/' . $record->getNid());
}
?>

The query wrapper supports chaining and overriding the operator, so you can also do something like this:

<?php
$results = WdNodeWrapperQuery::find()
            ->byAuthor(1)
            ->byTitle('%Test%', 'LIKE')
            ->execute();
?>

It supports order and range modifiers. I still need to add property and field specific orderby methods, but you can call the generic ones at this point:

<?php
$results = WdNodeWrapperQuery::find()
            ->byAuthor(1)
            ->orderByProperty('title', 'DESC')
            ->range(0, 10)
            ->execute();
?>

It supports fields and their value columns using dot syntax:

<?php
$results = WdCommerceLineItemWrapperQuery::find()
            ->byUnitPrice(10000, 'USD', '>')
            ->orderByField('commerce_unit_price.amount', 'DESC')
            ->execute();
?>

  • zengenuity committed b5b4d2b on 7.x-1.x
    #2354747 - Added the ability to generate bundle-specific WrapperQuery...
zengenuity’s picture

Wrappers Delight Query module now supports bundle-specific queries with fields. So, you can now do something like:

<?php
$results = ArticleNodeWrapperQuery::find()
  ->bySomeCustomField($value)
  ->byAnotherCustomField($value2)
  ->execute();
?>

Results will be of type ArticleNodeWrapper in this case. So, something like this should work:

<?php
foreach ($results as $record) {
  $output .= $record->getTitle();
  $output .= $record->getImageHtml('medium');
}
?>

Still need some code cleanup and tests.

  • zengenuity committed c4602e2 on 7.x-1.x
    #2354747 - Refactor of submodules and query system complete. Tests, docs...
zengenuity’s picture

Status: Active » Fixed

Query system is built. When the Wrappers Delight Query module is enabled, the drush wrap command will generate both an entity wrapper and a query wrapper class for each bundle. The query wrappers work as described above, with the addition that they now support orderBy() methods. So, something like this should work:

<?php
$results = ArticleNodeWrapperQuery::find()
            ->byAuthor(1)
            ->orderByCreatedTime('DESC')
            ->range(0, 10)
            ->execute();
?>

It supports fields and their value columns using dot syntax:

<?php
$results = WdCommerceLineItemWrapperQuery::find()
            ->byUnitPrice(10000, 'USD', '>')
            ->orderByField('commerce_unit_price.amount', 'DESC')
            ->execute();

?>

The drush command will also generate custom orderByXXXXX() methods for every field in your entity bundle. It works with field types that have a "value" column, file types ("fid"), and entityreferences ("target_id"). Everything else will likely need some hand tuning.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

fox_01’s picture

is it possible to add a query tag like?

$query = new EntityFieldQuery();
  return $query
    ->fieldCondition($field)
    ->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT')
    ->execute();
zengenuity’s picture

I've added an addTag() method to the WdWrapperQuery class that will pass a tag down to the query inside.