Commit a9532559 authored by Michael McAndrew's avatar Michael McAndrew

adding new civicrm providers module to do things that views could not

parent d68943f7
name = CiviCRM providers list
description = Enables us to create nice badges for providers via a CiviCRM custom field (views was not powerful enough for us to do this)
package = custom modules
core = 7.x
//this module populates a custom field whenever a service provider becomes a partner or active contributor
//At the moment, it is set to run whenever a group or membership is created or edited.
//The reason we do this is because we need something we can add to a view, since it (IMHO) is impossible to do the view calculation in the view itself
function civicrm_providers_civicrm_post($op, $objectName, $objectId, $ObjectRef){
if(!in_array($op, array('edit', 'create', 'delete'))){
if($objectName = 'Membership'){
if($objectName = 'ContactGroup' AND $objectId = 131){
foreach($ObjectRef as $contact);
}//$objectref is an array of contacts that are going to be added to the group, it seems...
function civicrm_providers_update_provider($contact_id){
//check that the contact is a service provider contact subtype
$params = array('version' => 3, 'contact_id' => $contact_id);
$contact=civicrm_api('Contact', 'getsingle', $params);
if(!is_array($contact['contact_sub_type']) OR !in_array('Service_provider', $contact['contact_sub_type'])){
//find out if they are in the active contributors group. NOTE: this criteria is likely to change as we get more sophisticated about how we classify active contributors
$params = array('version' => 3, 'contact_id' => $contact_id);
$groups=civicrm_api('GroupContact', 'get', $params);
foreach($groups['values'] as $group){
//find out if they members and what type of members they are
$params = array('version' => 3, 'contact_id' => $contact_id);
$membership=civicrm_api('Membership', 'getsingle', $params);
if(in_array($membership['status_id'], array(1,2,3,5))){
$badges[]=str_replace(' ', '-', strtolower($membership['membership_name'])); //1=new, 2=current, 3=grace, 5=pending
$updateParams = array('version' => 3, 'contact_id' => $contact_id, 'custom_160' => json_encode($badges));
$result=civicrm_api('contact', 'update', $updateParams);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment