/**
  * {@inheritdoc}
  *
  * Return the basic entity field query for messages, with additional filter
  * that matches only messages accessible by the current user.
  */
 public function getEntityFieldQuery()
 {
     $query = parent::getEntityFieldQuery();
     // Add condition to match only messages accessible by the current user.
     // Find the list of valid OGs for current user
     $account = $this->getAccount();
     $wrapper = entity_metadata_wrapper('user', $account);
     $gids = $wrapper->og_user_node->value(array('identifier' => TRUE));
     if (!$gids) {
         // User is not a member in any group.
         throw new \RestfulUnauthorizedException('Current user is not related to any account. No messages to show.');
     }
     // Filter to match only messages from these OGs
     $query->fieldCondition('field_meter_account', 'target_id', $gids, 'IN');
     return $query;
 }
 /**
  * Overrides RestfulEntityBase::getQueryForList().
  *
  * Add dates filter.
  */
 public function getEntityFieldQuery()
 {
     $request = $this->getRequest();
     $query = parent::getEntityFieldQuery();
     if (empty($request['from_date'])) {
         throw new \RestfulBadRequestException('Missing from_date parameter.');
     }
     if (!self::validDate($request['from_date'])) {
         throw new \RestfulBadRequestException('Wrong from_date format. Expecting yyyy-mm-dd.');
     }
     $query->propertyCondition('date', $request['from_date'], '>=');
     if (empty($request['until_date'])) {
         throw new \RestfulBadRequestException('Missing until_date parameter.');
     }
     if (!self::validDate($request['until_date'])) {
         throw new \RestfulBadRequestException('Wrong until_date format. Expecting yyyy-mm-dd.');
     }
     $query->propertyCondition('date', $request['until_date'], '<=');
     return $query;
 }