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) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Can't Get Participant ID/Contact ID?
Pages: [1]

Author Topic: Can't Get Participant ID/Contact ID?  (Read 1148 times)

zesgar

  • I post occasionally
  • **
  • Posts: 107
  • Karma: 2
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5
Can't Get Participant ID/Contact ID?
March 14, 2011, 03:45:08 pm
I have the following code which is not working.  I am trying to add a participant in an event to a group and also add a relationship. 
Code: [Select]
$participantIDs = $form->getVar( '_participantId' );

$sql = "
SELECT contact_id
FROM   civicrm_participant
WHERE  id =  '$participantIDs'
";
require_once 'CRM/Core/DAO.php';
$dao = CRM_Core_DAO::executeQuery( $sql );
while ( $dao->fetch( ) ) {
$submitterID = $dao->contact_id;
add_to_group(2,$submitterID);
add_relationship($submitterID,$contact2['contact_id'],1);
}

here is my full code, it successfully adds the second contact and adds them to their group and adds the participant to the event.
Code: [Select]
<?php

/*
 * When Contribution Confirm form is submitted
 * 
 * When the contribution page is submitted we want to add a parent contact 
 * we add them to groups and register the camper for the event. 
 * Then we create a relationship between the parent and camper.
 */

function joomla_civicrm_postProcess ( $class, &$form ) {

if ( ! 
is_a($form, 'CRM_Event_Form_Registration_Register') ) {
return;
}

//CRM_Core_Error::debug( $form );


require_once 'CRM/Core/Config.php';
$config =& CRM_Core_Config::singleton( );

require_once 
"api/v2/Contact.php";
require_once 
"api/v2/Relationship.php";
require_once 
"api/v2/GroupContact.php";




$params = $form->controller->exportValues( $form->getName( ) );



// get contact of the submitter - it doesn't show up in the $form if it's an anon user
/* $indivParams = array ( 
'email' => $params['email-5'],
'contact_type' => 'Individual',
);
$indivResult = civicrm_contact_search( $indivParams );

if ( civicrm_error ($indivResult )) { return $indivResult['error_message']; } 
else {

foreach ($indivResult as $indiv) {
foreach ($indiv as $ind) {
$submitterID = $indiv['contact_id'];
}
}
} */






// create contacts for parent
$contactParams2 = array(
                    
'first_name'    => $params['custom_5'],
                    
'last_name'     => $params['custom_6'],
                    
'email'         => $params['custom_7'],
'contact_sub_type' => 'Parent',
                    
'contact_type'  => 'Individual',
                    
'dupe_check'    => True,
                    );
$contact2 = &civicrm_contact_create( $contactParams2 ); // returns contact id, is_error

$homePhone = array('phone'         => $params['custom_8'],
                           
'phone_type_id' => 1,
                           
'location_type_id' => 1
                           
);
$mobilePhone = array('phone'         => $params['custom_5'],
                           
'phone_type_id' => 2,
                           
'location_type_id' => 1
                           
);
 $address = array( 1 => array( 'location_type_id'       => 1,
                                      
'is_primary'             => 1,
                                      
'city'                   => $params['city-1'],
                                      
'state_province'         => $params['state_province-1'],
                                      
'street_address'         => $params['street_address-1'],
                                      
'postal_code_suffix'     => $params['postal_code-1'],
                                      
'country_id'             => 1228
                                     
)
                        );
 
  // Put them in an array and then add to $params array
        
$phones = array( $homePhone, $mobilePhone);
        
$paramsContact = array('version'    => '3.0',
                        
'contact_id' => $contact2['contact_id'],
                        
'phone'      => $phones,
                        
'address'    => $address
                        
);
        require_once 
'api/v2/Location.php';
        
$newLocation =& civicrm_location_add($paramsContact);
        if( 
civicrm_error( $newLocation ) ) {
            echo 
'Error occured while creating Location';
        } else {
            echo 
'Location Created';
        }

print_r($contact2['contact_id']);
print_r($submitterID);
if ( civicrm_error ( $contact2)) { return $contact2['error_message']; }


// add parent to parents group
add_to_group(1,$contact2['contact_id']);




$partID = $params['_participantId'];
$participantIDs = $form->getVar( '_participantId' );

       




 
$sql = "
SELECT contact_id
FROM   civicrm_participant
WHERE  id =  '
$participantIDs'
"
;


require_once 'CRM/Core/DAO.php';
        
$dao = CRM_Core_DAO::executeQuery( $sql );
while ( $dao->fetch( ) ) {
$submitterID = $dao->contact_id;
add_to_group(2,$submitterID);
add_relationship($submitterID,$contact2['contact_id'],1);
}

// add camper to the camper group
//add_to_group(2,$submitterID);

//CRM_Core_Error::debug($form);
/*
if ($params['is_online_registration'] == 0) {
$contactbID = $relatedOrgID;
$reltype = 4; // DOC company membership
} else {
// if no org was set we still want to create a relationship
$contactbID = $submitterID;
$reltype = 1; // child
}
*/






// we want to set the default relationships for each contact as set above
// add_relationship($submitterID,$contact2['contact_id'],1);








} //end associated_members_civicrm_postProcess()

function add_to_group($groupID, $contactID) {

$groupParams = array(
                    
'contact_id' => $contactID,
                    
'group_id'     => $groupID
                    
);
$groupResult = civicrm_group_contact_add( $groupParams );
print_r($groupResult);
print_r($groupID);
print_r($contactID);
}

function 
add_relationship($contactaID,$contactbID,$relationshipType) {

$relationshipParams = array(
                    
'contact_id_a'         => $contactaID,
                    
'contact_id_b'         => $contactbID,
                    
'relationship_type_id' => $relationshipType,
                    
'is_active'            => 1
                    
);
$relationshipCreate = &civicrm_relationship_create( $relationshipParams );
if ( civicrm_error ( $relationshipCreate )) { 
return $relationshipCreate['error_message']; 
}
}
?>
« Last Edit: March 16, 2011, 07:01:07 am by zesgar »

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Can't Get Participant ID/Contact ID?
March 18, 2011, 04:28:58 am
Hi,

Why don't you use the api to fetch the participant ?

$participant = civicrm_api ("Participant","get",array (id => $participantid)).

that's on the 3.4, but backporting is trivial

Eileen, can you confirm that's just

- copying the api/v3
- copying api/api.php

?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

zesgar

  • I post occasionally
  • **
  • Posts: 107
  • Karma: 2
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5
Re: Can't Get Participant ID/Contact ID?
March 18, 2011, 10:10:51 am
Right now I am using 3.3.5.  So I don't think I will have access to that api call. Any other ideas?

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Can't Get Participant ID/Contact ID?
March 18, 2011, 12:29:03 pm
If you download from the alpha or svn trunk and copy api/api.php and api/v3/* to your install you do ;)

I think there is an api v2 that would be civicrm_participant_get (or civicrm_participant_find or _search)

X+

-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Can't Get Participant ID/Contact ID?

This forum was archived on 2017-11-26.