Community Documentation

PartyQuery - Querying a Party-based CRM

Last updated September 21, 2012. Created by rlmumford on September 21, 2012.
Log in to edit this page.

Party collects information from multiple entities and SQL tables so writing queries for this data can be difficult. For this reason Party provides a Select Query Extender (see http://drupal.org/node/508796) to help developers write queries.

To make use of the Party Query Extender start a select query on the party table as usual then call the extend() method with 'PartyQuery' as the argument.

<?php
$query
= db_select('party', 'party');
$query = $query->extend('PartyQuery');
?>

Alternatively, Party also provides a helper function to automate these two steps:

<?php
$query
= party_query();
?>

The party query extender provides a number of helpful methods to filter a query by fields and properties on attached entities as shown in the example below. In this example we get all of the party id's of parties that

  • Have the organization hat
  • Are older than 18
  • AND have an active user account

<?php
$party_ids
= party_query()
  ->
fieldCondition('party', 'party_hat', 'hat_name', 'organization')
  ->
fieldCondition('profile2_main', 'field_age', 'value'18, '>')
  ->
propertyCondition('user', 'status', 1)
  ->
fetchPids();
?>

Method List

The query extender provides a number of helpful methods for querying a Party CRM. These are listed below.

fieldCondition

Set a simple field condition on an attached entity or the party entity.

<?php
public function fieldCondition($data_set, $field, $column, $value, $operator = NULL, $field_delta = NULL, $data_set_delta = NULL, $type = 'INNER')
?>

propertyCondition

Set a simple property condition on an attached entity.

<?php
public function propertyCondition($data_set, $column, $value, $operator = NULL, $delta = NULL, $type = 'INNER')
?>

joinField

Create a join to an field on an attached entity.

<?php
public function joinField($data_set, $field, $alias = NULL, $field_delta = NULL, $data_set_delta = NULL, $type = 'INNER')
?>

joinAttachedEntity

Create a join to an attached entity table.

<?php
public function joinAttachedEntity($data_set, $alias = NULL, $delta = NULL, $type = 'INNER')
?>

fetchPids

Execute the query and return an array of party ids that satisfy the conditions.

<?php
 
public function fetchPids() 
?>

Page status

About this page

Drupal version
Drupal 7.x
Audience
Programmers
Level
Intermediate

Site Building Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here