CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Rules - load contact action & condition -has no user id
Pages: [1]

Author Topic: Rules - load contact action & condition -has no user id  (Read 763 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Rules - load contact action & condition -has no user id
August 10, 2011, 05:42:08 am
I started work on extending rules integration to allow you to load an a contact & check if user ID exists for participants but have abandoned this in favour of another approach. Posting code here in case someone wants to pick it up & test it / implement it.

Code would allow you to have a rule

- When participant record is created
- IF participant has no USER ID
- THEN LOAD the contact for that participant
- THEN carry out contact action (e.g. send an email, add to group etc) or use contact details for another action

Code: [Select]
Index: drupal/modules/civicrm_rules/civicrm_rules.rules.inc
===================================================================
--- drupal/modules/civicrm_rules/civicrm_rules.rules.inc (revision 35654)
+++ drupal/modules/civicrm_rules/civicrm_rules.rules.inc (working copy)
@@ -237,7 +237,7 @@
                     'module' => 'CiviCRM Mailing',
                     )
               
-              );
+              ) + civicrm_rules_entities_action_info();
 }
 
 
@@ -419,6 +419,12 @@
                                     'savable' => FALSE,
                                     'identifiable' => TRUE,
                                     ),
+                'civicrm_mailing' => array(
+                                    'label' => t('Mailing'),
+                                    'class' => 'rules_data_type_mailing',
+                                    'savable' => FALSE,
+                                    'identifiable' => TRUE,
+                                    ),
                  )+ civicrm_rules_entities_data_type_info();
                 
 
@@ -449,6 +455,16 @@
     }
 }
 
+class rules_data_type_civicrm_mailing extends rules_data_type {
+    function load($id) {
+        return _civicrm_rules_load_mailing( $id );
+    }
+   
+    function get_identifier() {
+        $mailing = $this->get();
+        return $mailing->id;
+    }
+}
 class rules_data_type_civicrm_event extends rules_data_type {
     function load($id) {
 
Index: drupal/modules/civicrm_rules/civicrm_rules_civicrm_contact.eval.inc
===================================================================
--- drupal/modules/civicrm_rules/civicrm_rules_civicrm_contact.eval.inc (revision 35654)
+++ drupal/modules/civicrm_rules/civicrm_rules_civicrm_contact.eval.inc (working copy)
@@ -38,3 +38,12 @@
     }
 }
 
+/**
+ * Handler to get the user. This will work if $entityobj->contact_id is defined
+ * e.g. for participant object, contribution object
+ */
+function civicrm_rules_condition_contact_hasuserid(&$entityobj,&$settings) {
+    require_once 'api/api.php';
+    $contactcount = civicrm_api('UFMatch','getcount',array('version' => 3,'contact_id' => $entityobj->contact_id, 'sequential' =>1));
+    return $contactcount > 0 ? true: false;
+}
Index: drupal/modules/civicrm_rules/civicrm_rules_civicrm_participant.eval.inc
===================================================================
--- drupal/modules/civicrm_rules/civicrm_rules_civicrm_participant.eval.inc (revision 35654)
+++ drupal/modules/civicrm_rules/civicrm_rules_civicrm_participant.eval.inc (working copy)
@@ -73,3 +73,10 @@
 
                                                     );
 }
+
+
+function civicrm_rules_action_civicrm_participant_loadrelatedcontact(&$entityobj,&$settings){
+  $contact = new rules_data_type_contact;
+  return $contact->load($entityobj->contact_id); 
+ 
+}
\ No newline at end of file
Index: drupal/modules/civicrm_rules/civicrm_rules_entities.rules.inc
===================================================================
--- drupal/modules/civicrm_rules/civicrm_rules_entities.rules.inc (revision 35654)
+++ drupal/modules/civicrm_rules/civicrm_rules_entities.rules.inc (working copy)
@@ -4,6 +4,29 @@
 module_load_include('inc', 'civicrm_rules', 'civicrm_rules_civicrm_event.eval');
 module_load_include('inc', 'civicrm_rules', 'civicrm_rules_civicrm_participant.eval');
 module_load_include('inc', 'civicrm_rules', 'civicrm_rules_civicrm_contact.eval');
+
+
+function civicrm_rules_entities_action_info(){
+   
+    return array($events['rules_action_civicrm_participant_loadrelatedcontact'] = array(
+                                                              'label'     => t( "Load Related Contact" ),
+                                                              'module'  => t('CiviCRM Participant'),
+                                        'description' => 'Load relevant contact',
+                                                              'arguments' => array(
+                                                              'civicrm_participant' => array(
+                                                                 'label' => 'Relevant Contact', 
+                                                                   'type' => "civicrm_participant" )),
+              'new variables' => array(
+        'registrant' => array(
+            'type' => 'contact',
+            'label' => t('Registering Contact'),
+                                                                 ),
+                                                                ),));     
+   
+}
+
+
+
 /*
  * Declare post functions for valid post entities. This declares 5 actions for each enabled object
  * Enabled objects are defined through the 'civicrm_rules_post_entities' drupal variable
@@ -67,8 +90,13 @@
                  'civicrm_rules_condition_event_type' => array(
                                                                'label' => t('Event Type'),
                                                                'arguments' =>  civicrm_rules_entities_conditions(  t( 'Created Event' ),'civicrm_event' ),
-                                                               'module' => 'CiviCRM event',
+                                                               'module' => 'CiviCRM Event',
                                                                ),
+                'civicrm_rules_condition_contact_hasuserid' => array(
+                                                               'label' => t('Contact Has User ID'),
+                                                               'arguments' =>  civicrm_rules_entities_conditions(  t( 'Relevant Contact' ),'civicrm_participant' ),
+                                                               'module' => 'CiviCRM Contact',
+                                                               ),
                  );
 }
 /**
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Rules - load contact action & condition -has no user id

This forum was archived on 2017-11-26.