Skip to content

Instantly share code, notes, and snippets.

@jbartek
jbartek / sugarquery-having.php
Created April 21, 2014 12:54
SugarQuery - Having
<?php
$query = new SugarQuery();
$query->from(BeanFactory::getBean('Accounts'));
$query->join('contacts', array('alias' => 'industryContacts'));
$query->join('opportunities', array('relatedJoin' => 'industryContacts', 'alias' => 'contactsOpportunities'));
$query->select()->setCountQuery();
$query->where()->equals('contactsOpportunities.sales_stage', 'closed');
$havingCondition = new SugarQuery_Builder_Condition($query);
$havingCondition->setField('contactsOpportunities.amount')->setOperator('>')->setValues('1000');
$query->having($havingCondition);
@jbartek
jbartek / sugarquery-groupby.php
Created April 18, 2014 20:37
SugarQuery - GroupBy
<?php
$query = new SugarQuery();
$query->from(BeanFactory::getBean('Accounts'));
$query->join('contacts', array('alias' => 'industryContacts'));
$query->join('opportunities', array('relatedJoin' => 'industryContacts', 'alias' => 'contactsOpportunities'));
$query->select()->setCountQuery();
$query->where()->equals('contactsOpportunities.sales_stage', 'closed');
$query->groupBy('accounts.industry');
$results = $query->execute();
@jbartek
jbartek / sugarquery-orderby.php
Created April 18, 2014 20:07
SugarQuery - OrderBy
<?php
$query = new SugarQuery();
$query->from(BeanFactory::getBean('Accounts'));
$query->join('contacts', array('alias' => 'industryContacts'));
$query->join('opportunities', array('relatedJoin' => 'industryContacts', 'alias' => 'contactsOpportunities'));
$query->select(array(array('industryContacts.first_name', 'fname'), array('industryContacts.last_name', 'lname'), 'contactsOpportunities.name'));
$query->where()->equals('industryAccounts.industry','Media');
$query->where()->equals('contactsOpportunities.sales_stage', 'closed');
$query->orderBy('industryContacts.name', 'DESC');
$results = $query->execute();
@jbartek
jbartek / sugarquery-aliasing.php
Last active August 29, 2015 14:00
SugarQuery - Aliasing
<?php
$query = new SugarQuery();
$query->from(BeanFactory::getBean('Accounts'));
$query->join('contacts', array('alias' => 'industryContacts'));
$query->join('opportunities', array('relatedJoin' => 'industryContacts', 'alias' => 'contactsOpportunities'));
$query->select(array(array('industryAccounts.first_name', 'fname'), array('industryContacts.last_name', 'lname'), 'contactsOpportunities.name'));
$query->where()->equals('industryAccounts.industry','Media');
$query->where()->equals('contactsOpportunities.sales_stage', 'closed');
$results = $query->execute();
@jbartek
jbartek / sugarquery-n-deep-joins.php
Last active August 29, 2015 14:00
SugarQuery - Select all contacts that have closed opportunities on accounts of type industry
<?php
$query = new SugarQuery();
$query->from(BeanFactory::getBean('Accounts'));
$contacts = $query->join('contacts')->joinName();
$opp = $query->join('opportunities', array('relatedJoin' => $contacts))->joinName();
$query->select(array("$contacts.full_name", "$opp.name"));
$query->where()->equals('industry','media');
$query->where()->equals("$opp.sales_stage", 'closed');
$results = $query->execute();
@jbartek
jbartek / sugarquery-acconts-contacts.php
Last active August 29, 2015 14:00
SugarQuery - Select Accounts joining Contacts
<?php
$query = new SugarQuery();
$query->from(BeanFactory::getBean('Accounts'));
$contacts = $query->join('contacts')->joinName();
$query->select(array("$contacts.full_name"));
$query->where()->equals('industry','Media');
$results = $query->execute();
@jbartek
jbartek / sugarquery-accounts.php
Last active August 29, 2015 14:00
SugarQuery - Select Accounts with account_type = 'Industry'
<?php
$query = new SugarQuery();
$query->select(array('id','name'));
$query->from(BeanFactory::getBean('Accounts'));
$query->where()->equals('industry','Media');
$results = $query->execute();
@jbartek
jbartek / elastic-help.json
Created October 15, 2012 21:34
elastic-help
INDEXES:
{"Accounts":{"properties":{"name":{"boost":3,"type":"string"},"phone_fax":{"boost":1,"type":"string"},"phone_office":{"boost":1,"type":"string"},"phone_alternate":{"boost":1,"type":"string"},"email1":{"boost":3,"index":"not_analyzed","type":"string"},"doc_owner":{"boost":1,"type":"string","index":"not_analyzed"},"user_favorites":{"boost":1,"type":"array","index":"not_analyzed"}}}}
{"Calls":{"properties":{"name":{"boost":"1","type":"string"},"description":{"boost":"3","type":"string"},"doc_owner":{"boost":1,"type":"string","index":"not_analyzed"},"user_favorites":{"boost":1,"type":"array","index":"not_analyzed"}}}}
{"Cases":{"properties":{"name":{"boost":3,"type":"string"},"case_number":{"boost":3,"type":"string"},"doc_owner":{"boost":1,"type":"string","index":"not_analyzed"},"user_favorites":{"boost":1,"type":"array","index":"not_analyzed"}}}}
RECORDS:
{
_index: 5b04e75a7a93007a0bbdbb4a4764804f
@jbartek
jbartek / not_analyzed.php
Created September 10, 2012 16:46
Gist of not analyzed field
$properties['doc_owner'] = array(
'boost' => 1,
'type' => 'string',
'index' => 'not_analyzed'
);
@jbartek
jbartek / meetings.json
Created August 30, 2012 19:10
JSON Query Example with Ranges
{"Meetings":{"properties":{"name":{"type":"string"},"date_start":{"type":"date","index":"not_analyzed"},"date_end":{"type":"date","index":"not_analyzed"},"doc_owner":{"boost":1,"type":"string","index":"not_analyzed"}}}}
{"index":{"_index":"40f6c8db6e0db0a0665860ce8a683fc4","_type":"Meetings","_id":"827cf1c8-c4c4-ebe2-b285-503fa0a76a21"}}
{"name":"Review needs","date_start":"2013-02-18T12:00:00+0100","date_end":"2013-02-18T13:00:00+0100","module":"Meetings","team_set_id":"West","doc_owner":"seed_max_id"}
{"index":{"_index":"40f6c8db6e0db0a0665860ce8a683fc4","_type":"Meetings","_id":"93b48de6-5a3d-5dee-c2f8-503fa02576e5"}}
{"name":"Discuss pricing","date_start":"2013-02-21T10:00:00+0100","date_end":"2013-02-21T11:45:00+0100","module":"Meetings","team_set_id":"East","doc_owner":"seed_chris_id"}
{"index":{"_index":"40f6c8db6e0db0a0665860ce8a683fc4","_type":"Meetings","_id":"9ed7fec4-1196-ea64-78fb-503fa0cb7606"}}
{"name":"Discuss pricing","date_start":"2013-02-21T13:15:00+0100","date_end":"2013-02-21T16:00:00+01