id]); return civicrm_api3_create_success($participant, $params, 'participant', 'create', $participantBAO); } /** * Create a default participant line item */ function _civicrm_api3_participant_createlineitem(&$params, $participant){ $sql = " SELECT ps.id AS setID, pf.id AS priceFieldID, pfv.id AS priceFieldValueID FROM civicrm_price_set_entity cpse LEFT JOIN civicrm_price_set ps ON cpse.price_set_id = ps.id AND cpse.entity_id = {$params['event_id']} AND cpse.entity_table = 'civicrm_event' LEFT JOIN civicrm_price_field pf ON pf.`price_set_id` = ps.id LEFT JOIN civicrm_price_field_value pfv ON pfv.price_field_id = pf.id and pfv.label = '{$params['fee_level']}' where ps.id is not null "; $dao = CRM_Core_DAO::executeQuery($sql); if ($dao->fetch()) { $amount = CRM_Utils_Array::value('fee_amount', $params, 0); $lineItemparams = array( 'price_field_id' => $dao->priceFieldID, 'price_field_value_id' => $dao->priceFieldValueID, 'entity_table' => 'civicrm_participant', 'entity_id' => $participant->id, 'label' => $params['fee_level'], 'qty' => 1, 'participant_count' => 0, 'unit_price' => $amount, 'line_total' => $amount, 'version' => 3, ); civicrm_api('line_item', 'create', $lineItemparams); } } /** * Adjust Metadata for Create action * * The metadata is used for setting defaults, documentation & validation * @param array $params array or parameters determined by getfields */ function _civicrm_api3_participant_create_spec(&$params) { $params['status_id']['api.default'] = "1"; $params['register_date']['api.default'] = "now"; $params['event_id']['api.required'] = 1; $params['contact_id']['api.required'] = 1; // These are for the sake of search builder options - can be removed if that is fixed $params['role_id']['api.aliases'] = array('participant_role'); $params['status_id']['api.aliases'] = array('participant_status'); } /** * Retrieve a specific participant, given a set of input params * If more than one matching participant exists, return an error, unless * the client has requested to return the first found contact * * @param array $params (reference ) input parameters * * @return array (reference ) array of properties, if error an array with an error id and error message * {@getfields participant_get} * @access public */ function civicrm_api3_participant_get($params) { $mode = CRM_Contact_BAO_Query::MODE_EVENT; $entity = 'participant'; list($dao, $query) = _civicrm_api3_get_query_object($params, $mode, $entity); $participant = array(); while ($dao->fetch()) { $participant[$dao->participant_id] = $query->store($dao); //@todo - is this required - contribution & pledge use the same query but don't self-retrieve custom data _civicrm_api3_custom_data_get($participant[$dao->participant_id], 'Participant', $dao->participant_id, NULL); } return civicrm_api3_create_success($participant, $params, 'participant', 'get', $dao); } /** * Adjust Metadata for Get action * * The metadata is used for setting defaults, documentation & validation * @param array $params array or parameters determined by getfields */ function _civicrm_api3_participant_get_spec(&$params) { $params['participant_test']['api.default'] = 0; } /** * Deletes an existing contact participant * * This API is used for deleting a contact participant * * @param array $params Array containing Id of the contact participant to be deleted * * {@getfields participant_delete} * @throws Exception * @return array * @access public */ function civicrm_api3_participant_delete($params) { $result = CRM_Event_BAO_Participant::deleteParticipant($params['id']); if ($result) { return civicrm_api3_create_success(); } else { throw new Exception('Error while deleting participant'); } }