Emma PHP :: Search Functions

The search functions are used to create, update, and delete searches. You can also retrieve lists of members that meet the search criteria.

Create a new search definition in Emma.

Each search criterion is specified as an array with several values. The actual number of values depends on the filter type in question:

  • Filter type - and, or, not, group, opened, clicked
  • Operator
  • Value

Figuring out your search criteria can be a bit tricky. In the example provided below, we've created a search that includes any member belonging to at least one of the groups listed, with an email preference (custom field) either not set (undefined), or set to 'Weekly' or 'Not Specified'. The example gives you one example of an array you need to pass to createSearch().

Another good way to get your hands dirty constructing criteria is to create representative samples of searches using the Emma web interface, and then using listSearches() and/or getSearchDetail() to see how they're structured in Emma. You can also refer to Emma's API documentation for create_search, just keep in mind that their internal representation of the criteria is a JSON array.

Arguments: 

  • array $criteria - The criteria that define the search.
  • string $search_name - The name for your new search.

Use:


require_once('../../MyEmmaPHP.php');

try {

	$me = new MyEmmaPHP();
   
	$name = 'PeopleSoft Users with Weekly Emails Set';
	
	$criteria = 
	  array(
		"and",
		array(	
			"or",
			array("group", "in", "General: Marketing Contacts Only - PeopleSoft"),
			array("group", "in", "SIG: PeopleSoft Compensation & Benefits"),
			array("group", "in", "Product: PeopleSoft"),
			array("group", "in", "Interest: Absence Management")
		),
		array(	
			"or",
			array("member_field:wildcard_1355694", "undefined"),
			array("member_field:wildcard_1355694", "contains", "Weekly"),
			array("member_field:wildcard_1355694", "contains", "Not Specified")
		)
	  );

    $retval = $me->createSearch($criteria, $name);
    
	print_r($retval);
        
    
} catch ( Exception $e ) {
    echo $e->getMessage() . "\n\n";
}



Wrapper for: create_search

Delete a single search in Emma.

Arguments: 

  • int $search_id - The ID of the search you want to delete.

Use:


require_once('../../MyEmmaPHP.php');

try {

	$me = new MyEmmaPHP();
   
	$search_id = 19200;
	
    $retval = $me->deleteSearch($search_id);
    
	if ($retval) {
		echo "Search deleted successfully.\n";
	} else {
		echo "Search not deleted.\n";
	}
        
    
} catch ( Exception $e ) {
    echo $e->getMessage() . "\n\n";
}



Wrapper for: delete_search

Retrieve details for a single search in Emma.

Arguments: 

  • int $search_id - The search ID you want to retrieve the details for.
  • bool $deleted - (Optional) Retrieve search details even if the search is marked as deleted. Defaults to false.

Use:


require_once('../../MyEmmaPHP.php');

try {

	$me = new MyEmmaPHP();
   
    $retval = $me->getSearchDetail(16128);
    
	print_r($retval);
        
    
} catch ( Exception $e ) {
    echo $e->getMessage() . "\n\n";
}



Wrapper for: get_search_detail

Retrieve a list of members matching a defined search in Emma.

Arguments: 

  • int $search_id - The search ID for which you wish to retrieve the list of matching members.

Use:


require_once('../../MyEmmaPHP.php');

try {

	$me = new MyEmmaPHP();
   
    $retval = $me->getSearchMembers(19200);
   
	print_r($retval);
        
    
} catch ( Exception $e ) {
    echo $e->getMessage() . "\n\n";
}

Wrapper for: get_search_members

Retrieve a list of all the searches in an account in Emma.

Arguments: 

  • bool $deleted - (Optional) Retrieve searches marked as deleted. Defaults to false.

Use:


require_once('../../MyEmmaPHP.php');

try {

	$me = new MyEmmaPHP();
   
    $retval = $me->listSearches();
   
	print_r($retval);
        
    
} catch ( Exception $e ) {
    echo $e->getMessage() . "\n\n";
}



Wrapper for: list_searches

Update a search definition in Emma.

Arguments: 

  • int $search_id - The ID for the search you want to update.
  • array $criteria - The criteria that define the search. (See createSearch() for details.)
  • string $search_name - The updated name for your search.

Both $criteria and $search_name are optional, but you need to supply at least one of them to update. If you do not wish to update the search criteria, pass null as the argument.

Use:


require_once('../../MyEmmaPHP.php');

try {

	$me = new MyEmmaPHP();
   
	$search_id = 19200;
	
	$name = 'PeopleSoft Members with Weekly Email Pref';
	
	$criteria = 
	  array(
		"and",
		array(	
			"or",
			array("group", "in", "General: Marketing Contacts Only - PeopleSoft"),
			array("group", "in", "SIG: PeopleSoft Compensation & Benefits"),
			array("group", "in", "Product: PeopleSoft"),
			array("group", "in", "Interest: Absence Management")
		),
		array(	
			"or",
			array("member_field:wildcard_1355694", "undefined"),
			array("member_field:wildcard_1355694", "contains", "Weekly"),
			array("member_field:wildcard_1355694", "contains", "Not Specified")
		)
	  );

    $retval = $me->updateSearch($search_id, $criteria, $name);
    
	if ($retval) {
		echo "Search updated successfully.\n";
	} else {
		echo "Search not updated.\n";
	}
        
    
} catch ( Exception $e ) {
    echo $e->getMessage() . "\n\n";
}



Wrapper for: update_search

Keep in Touch

Contact Us

Buzz

Loading...

People talking about '@synergycode':