';
$params['toEmail'] = $objectRef['email-1'];
$params['toName'] = "{$objectRef['first_name']} {$objectRef['last_name']}";
$params['subject'] = "Thank you for supporting My Org";
$params['cc'] = 'myorg@example.org';
$objectValues = print_r( $objectRef, true );
$params['text'] = "
Dear $toName:
Thank you for your show of support. The details u signed up with are:
$objectValues
Regards
My Org Team
";
CRM_Utils_Mail::send( $params );
}
function civitest_civicrm_custom( $op, $groupID, $entityID, &$params ) {
if ( $op != 'create' && $op != 'edit' ) {
return;
}
// this is the custom group i am interested in updating when the row is updated
if ( $groupID != 1 ) {
return;
}
$tableName = CRM_Core_DAO::getFieldValue( 'CRM_Core_DAO_CustomGroup',
$groupID,
'table_name' );
$sql = "
UPDATE $tableName
SET random_code_data_3 = 23
WHERE entity_id = $entityID
";
CRM_Core_DAO::executeQuery( $sql,
CRM_Core_DAO::$_nullArray );
}
/**
* Get the permissioned where clause for the user
*
* @param int $type the type of permission needed
* @param array $tables (reference ) add the tables that are needed for the select clause
* @param array $whereTables (reference ) add the tables that are needed for the where clause
* @param int $contactID the contactID for whom the check is made
*
* @return string the group where clause for this user
* @access public
*/
function civitest_civicrm_aclWhereClause( $type, &$tables, &$whereTables, &$contactID, &$where ) {
if ( ! $contactID ) {
return;
}
$permissionTable = 'civicrm_value_permission';
$regionTable = 'civicrm_value_region';
$fields = array( 'electorate' => 'Integer',
'province' => 'Integer',
'branch' => 'Integer' );
// get all the values from the permission table for this contact
$keys = implode( ', ', array_keys( $fields ) );
$sql = "
SELECT $keys
FROM {$permissionTable}
WHERE entity_id = $contactID
";
$dao = CRM_Core_DAO::executeQuery( $sql,
CRM_Core_DAO::$_nullArray );
if ( ! $dao->fetch( ) ) {
return;
}
$tables[$regionTable] = $whereTables[$regionTable] =
"LEFT JOIN {$regionTable} regionTable ON contact_a.id = regionTable.entity_id";
$clauses = array( );
foreach( $fields as $field => $fieldType ) {
if ( ! empty( $dao->$field ) ) {
if ( strpos( CRM_Core_DAO::VALUE_SEPARATOR, $dao->$field ) !== false ) {
$value = substr( $dao->$field, 1, -1 );
$values = explode( CRM_Core_DAO::VALUE_SEPARATOR, $value );
foreach ( $values as $v ) {
$clauses[] = "regionTable.{$field} = $v";
}
} else {
if ( $fieldType == 'String' ) {
$clauses[] = "regionTable.{$field} = '{$dao->$field}'";
} else {
$clauses[] = "regionTable.{$field} = {$dao->$field}";
}
}
}
}
if ( ! empty( $clauses ) ) {
$where .= ' AND (' . implode( ' OR ', $clauses ) . ')';
}
}
function civitest_civicrm_dashboard( $contactID, &$contentPlacement ) {
// REPLACE Activity Listing with custom content
$contentPlacement = 3;
return array( 'Custom Content' => "Here is some custom content: $contactID",
'Custom Table' => "
Contact Name | Date |
Foo | Bar |
Goo | Tar |
",
);
}
function civitest_civicrm_buildAmount( $pageType,
&$form,
&$amount ) {
// only modify the contributon page with id = 1
if ( $pageType != 'contribution' ||
$form->_id != 1 ) {
return;
}
// lets add an arbitrary amount here, just to show folks
// the power of a hook :)
$amount[1000] = array( 'value' => 400,
'label' => 'Hook',
'amount_id' => 1000 );
// now lets get a bit more ambitious
// *GOAL*: lets plan to give 20% discount to students
$membershipType = 'Student';
$discountPercent = 20;
// get the membership-type-id for the membership-type
$membershipTypeId = CRM_Core_DAO::getFieldValue( 'CRM_Member_DAO_MembershipType',
$membershipType,
'id',
'name' );
// get the logged in user id
$session =& CRM_Core_Session::singleton();
$userID = $session->get( 'userID' );
if ( $userID ) {
// check if logged in user has 'Student' membership
require_once 'CRM/Member/BAO/Membership.php';
$membership = CRM_Member_BAO_Membership::getContactMembership( $userID, $membershipTypeId, null );
// If logged in contact is a member as on today, modify the amount
// to reflect the discount.
if ( CRM_Utils_Array::value( 'is_current_member', $membership ) ) {
foreach ( $amount as $amountId => $amountInfo ) {
$amount[$amountId]['value'] = $amount[$amountId]['value'] -
ceil($amount[$amountId]['value'] * $discountPercent / 100);
$amount[$amountId]['label'] = $amount[$amountId]['label'] .
"\t - with {$discountPercent}% discount (for $membershipType)";
}
}
}
}
function civitest_civicrm_aclGroup( $type, $contactID, $tableName, &$allGroups, &$currentGroups ) {
// only process saved search
if ( $tableName != 'civicrm_saved_search' ) {
return;
}
hrd_initialize( );
$currentGroups = $allGroups;
if ( ! CRM_Core_Permission::check( 'access secure contacts' ) ) {
unset( $currentGroups[HRD_SECURE_GROUP_ID] );
}
$currentGroups = array_keys( $currentGroups );
}
function civitest_civicrm_tabs( &$tabs, $contactID ) {
// unset the contribition tab
unset( $tabs[1] );
// lets rename the contribution tab with a differnt name and put it last
// this is just a demo, in the real world, you would create a url which would
// return an html snippet etc
$url = CRM_Utils_System::url( 'civicrm/contact/view/contribution',
"reset=1&snippet=1&force=1&cid=$contactID" );
$tabs[] = array( 'id' => 'mySupercoolTab',
'url' => $url,
'title' => 'Contribution Tab Renamed',
'weight' => 300 );
}
function civitest_civicrm_tokens( &$tokens ) {
$tokens['contribution'] = array( 'contribution.amount', 'contribution.date' );
}
function civitest_civicrm_tokenValues( &$values, &$contactIDs ) {
if ( is_array( $contactIDs ) ) {
$contactIDString = implode( ',', array_values( $contactIDs ) );
$single = false;
} else {
$contactIDString = "( $contactIDs )";
$single = true;
}
$query = "
SELECT sum( total_amount ) as total_amount,
contact_id,
max( receive_date ) as receive_date
FROM civicrm_contribution
WHERE contact_id IN ( $contactIDString )
AND is_test = 0
GROUP BY contact_id
";
$dao = CRM_Core_DAO::executeQuery( $query );
while ( $dao->fetch( ) ) {
if ( $single ) {
$value =& $values;
} else {
if ( ! array_key_exists( $dao->contact_id, $values ) ) {
$values[$dao->contact_id] = array( );
}
$value =& $values[$dao->contact_id];
}
$value['contribution.amount'] = $dao->total_amount;
$value['contribution.date' ] = $dao->receive_date;
}
}
function civitest_civicrm_pageRun( &$page ) {
// You can assign variables to the template using:
// $page->assign( 'varName', $varValue );
// in your template, {$varName} will output the contents of $varValue
// you should customize your template if doing so
$page->assign( 'varName', 'This is a variable assigned by the hook' );
}
/*
* The hook_nodeapi implementation to set the node title to that of event title.
* Could also be used set the title to anything we want.
*
*/
function civicrm_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
if ($op == 'load' && $node->type == 'event') {
$node->title = civicrm_cck_event_field_values('title', $node->field_title[0]['value']);
}
}
/*
* The function to pull out event data from civicrm for cck fields related to event.
*
*/
function civicrm_cck_event_field_values($field, $index = null) {
static $eventInfo;
if ( ! $eventInfo ) {
if ( ! civicrm_initialize( ) ) {
return;
}
require_once 'api/v2/Event.php';
$params = array( );
$eventInfo = civicrm_event_search( $params );
}
if ( strpos($_GET['q'], 'edit') ||
strpos($_GET['q'], 'add') ) {
$isAppend = true;
}
if ( isset( $index ) ) {
$isAppend = false;
}
$retArray = array( );
switch( $field ) {
case 'when':
foreach ( $eventInfo as $info ) {
$str = "{$info['start_date']} > through > {$info['end_date']}";
$retArray[] = $isAppend ? ("{$info['title']}:: " . $str) : $str;
}
break;
case 'location':
foreach ( $eventInfo as $info ) {
$params = array( 'entity_id' => $info['id'],'entity_table' => 'civicrm_event');
require_once 'CRM/Core/BAO/Location.php';
$values['location'] = CRM_Core_BAO_Location::getValues( $params, true );
$str = $values['location']['address'][1]['display'];
$retArray[] = $isAppend ? ("{$info['title']}:: " . $str) : $str;
}
break;
case 'register_link':
foreach ( $eventInfo as $info ) {
$str = '» Register Now';
$retArray[] = $isAppend ? ("{$info['title']}:: " . $str) : $str;
}
break;
case 'feeblock' :
require_once 'CRM/Core/BAO/Discount.php';
require_once 'CRM/Core/OptionGroup.php';
foreach ( $eventInfo as $info ) {
$discountId = CRM_Core_BAO_Discount::findSet( $info['id'], 'civicrm_event' );
if ( $discountId ) {
CRM_Core_OptionGroup::getAssoc( CRM_Core_DAO::getFieldValue( 'CRM_Core_DAO_Discount',
$discountId, 'option_group_id' ),
$feeBlock, true, 'id' );
} else {
CRM_Core_OptionGroup::getAssoc( "civicrm_event.amount.{$info['id']}", $feeBlock, true );
}
$feeLabels = array();
foreach ( $feeBlock as $block ) {
$feeLabels[] = $block['label'] . " $" . $block['value'];
}
$str = ' ' . implode($feeLabels, '
');
$retArray[] = $isAppend ? ("{$info['title']}:: " . $str) : $str;
}
break;
default:
foreach ( $eventInfo as $info ) {
if ( isset($info[$field]) ) {
$str = $info[$field];
$retArray[] = $isAppend ? ("{$info['title']}:: " . $str) : $str;
}
}
}
return empty($retArray) ? array() : isset($index) ? $retArray[$index] : $retArray;
}
function civitest_civicrm_customFieldOptions( $fieldID, &$options ) {
if ( $fieldID == 1 ) {
$options['Rocks'] = t( 'Hooks Rock' );
unset( $options['Edu'] );
} else if ( $fieldID == 2 ) {
$options['H'] = t(' Hook me' );
unset( $options['S'] );
}
}
function civitest_civicrm_searchTasks( $objectType, &$tasks ) {
$tasks[100] = array( 'title' => t( 'Hook Action Task' ),
'class' => 'CRM_Contact_Form_Task_HookSample',
'result' => false );
}
function civitest_civicrm_validate( $formName, &$fields, &$files, &$form ) {
// sample implementation
$errors = array( );
if ( $formName == 'CRM_Contact_Form_Edit' ) {
// ensure that external identifier is present and valid
$externalID = CRM_Utils_Array::value( 'external_identifier', $fields );
if ( ! $externalID ) {
$errors['external_identifier'] = ts( 'External Identifier is a required field' );
} else {
require_once "CRM/Utils/Rule.php";
if ( ! CRM_Utils_Rule::integer( $externalID ) ) {
$errors['external_identifier'] = ts( 'External Identifier is not an integer' );
}
}
}
return empty( $errors ) ? true : $errors;
}
function civitest_civicrm_pageRun( &$page ) {
// we are only interested in profile pages with gid = 1 and have a valid contact id
if ( $page->getVar( '_name' ) != 'CRM_Profile_Page_View' ||
$page->getVar( '_gid' ) != 1 ||
! CRM_Utils_Rule::positiveInteger( $page->getVar( '_id' ) ) ) {
return;
}
// get all relationships of
require_once 'CRM/Contact/BAO/Relationship.php';
$relationships = CRM_Contact_BAO_Relationship::getRelationship( $page->getVar( '_id' ) );
// if you want to filter and display only certain relationship, you can do so before assigninng to
// smarty. Do a CRM_Core_Error::debug( $relationships ) to see all the fields
$page->assign( 'relationships', $relationships );
// in addition to this, you also need to customize: templates/CRM/Profile/Page/View.tpl
// check: http://wiki.civicrm.org/confluence/display/CRMDOC/Customize+Built-in,+Profile,+Contribution+and+Event+Registration+Screens
// some sample tpl code is included here, modify as needed
/**
{if $relationships}
Name |
Relation |
Country |
{foreach from=$relationships item=relation}
{$relation.name} |
{$relation.relation} |
{$relation.country} |
{/foreach}
{/if}
**/
}
function civitest_civicrm_eventDiscount( &$form, &$params ) {
require_once 'CRM/Utils/Money.php';
// we only are interested in event id 1
if ( $form->getVar( '_eventId' ) != 1 ) {
return;
}
$numParticipants = 0;
foreach ( $params as $key => $value ) {
if ( isset( $params[$key]['amount'] ) &&
$params[$key]['amount'] > 0 ) {
$numParticipants++;
}
}
// Set discount rule (Example: if more than 1 participant, 5% additional discount per paying participant, upto a max of 50%)
if ( $numParticipants > 1 ) {
$discountPercentage = $numParticipants * 5;
if ( $discountPercentage > 50 ) {
$discountPercentage = 50;
}
$totalDiscount = 0;
foreach ( $params as $key => $value ) {
if ( CRM_Utils_Array::value( 'amount', $params[$key] ) > 0 ) {
$discount = round( ( $params[$key]['amount'] * $discountPercentage ) / 100.0 );
$totalDiscount += $discount;
$params[$key]['discountAmount'] = $discount;
$discountDisplay = CRM_Utils_Money::format( $discount, null, null );
// Set discount info added to participant.fee_level and contribution.amount_level
$params[$key]['discountMessage'] = " (discount: $discountDisplay)";
}
}
$totalDiscountDisplay = CRM_Utils_Money::format( $totalDiscount, null, null );
// Set the message to show on confirmation page, thank-you page and receipt
$params[0]['discount'] =
array( 'message' => "a discount of $totalDiscountDisplay has been applied to the total amount",
'applied' => true );
}
}
/**
* buildForm hook sample
*
* we want the custom date to be today's date. custom_3 is marriage date
* in the sample data
*/
function civitest_civicrm_buildForm( $formName, &$form ) {
if ( $formName == 'CRM_Contact_Form_Edit' ) {
$defaultDate = array( );
CRM_Utils_Date::getAllDefaultValues( $defaultDate );
$defaults['custom_3_-1'] = $defaultDate;
$form->setDefaults( $defaults );
}
// enable tracking feature
if ( ( $formName == 'CRM_Contribute_Form_Contribution_Main' ||
$formName == 'CRM_Contribute_Form_Contribution_Confirm' ||
$formName == 'CRM_Contribute_Form_Contribution_ThankYou' ) &&
$form->getVar( '_id' ) == 1 ) { // use CONTRIBUTION PAGE ID here
// use the custom field ID and custom field label here
$trackingFields = array( 'custom_4' => 'Campaign',
'custom_5' => 'Appeal',
'custom_6' => 'Fund' );
$form->assign( 'trackingFields', $trackingFields );
}
}
/**
* buildForm hook that would allow contacts to renew only existing memberships.
*/
function civitest_civicrm_buildForm( $formName, &$form ) {
if ( $formName == 'CRM_Contribute_Form_Contribution_Main' ) {
if ( is_array( $form->_membershipBlock ) ) {
//get logged in contact
$session = & CRM_Core_Session::singleton();
$contactID = $session->get('userID');
//check for existing membership
$query = "SELECT membership_type_id
FROM civicrm_membership
WHERE membership_type_id IN ( {$form->_membershipBlock['membership_types']} )
AND civicrm_membership.contact_id = {$contactID}";
$dao = CRM_Core_DAO::executeQuery( $query );
$membershipTypeID = null;
while ( $dao->fetch( ) ) {
$membershipTypeID = $dao->membership_type_id;
}
if ( $membershipTypeID ) {
$form->freeze(array('selectMembership'));
$defaults['selectMembership'] = $membershipTypeID;
$form->setDefaults( $defaults );
}
}
}
}
function civitest_civicrm_mailingGroups( &$form, &$groups, &$mailings ) {
unset( $groups[4] );
$mailings[1] = 'This Mailing does not exist';
}
function _civitest_discountHelper( $eventID, $discountCode ) {
$sql = "
SELECT v.id as id, v.value as value, v.weight as weight
FROM civicrm_option_value v,
civicrm_option_group g
WHERE v.option_group_id = g.id
AND v.name = %1
AND g.name = %2
";
$params = array( 1 => array( $discountCode , 'String' ),
2 => array( "event_discount_{$eventID}", 'String' ) );
$dao = CRM_Core_DAO::executeQuery( $sql, $params );
if ( $dao->fetch( ) ) {
// ensure discountPercent is a valid numeric number <= 100
if ( $dao->value &&
is_numeric( $dao->value ) &&
$dao->value >= 0 &&
$dao->value <= 100 &&
is_numeric( $dao->weight ) ) {
return array( $dao->id, $dao->value, $dao->weight );
}
}
return array( null, null, null );
}
function civitest_civicrm_buildForm( $formName, &$form ) {
if ( $formName == 'CRM_Event_Form_Registration_Register' &&
$form->getVar( '_eventId' ) == 3 ) {
$form->addElement( 'text', 'discountCode', ts( 'Discount Code' ) );
// in template use
// {$form.discountCode.label} {$form.discountCode.html}
// also assign to template
$template =& CRM_Core_Smarty::singleton( );
$beginHookFormElements = $template->get_template_vars( 'beginHookFormElements' );
if ( ! $beginHookFormElements ) {
$beginHookFormElements = array( );
}
$beginHookFormElements[] = 'discountCode';
$form->assign( 'beginHookFormElements', $beginHookFormElements );
$discountCode = CRM_Utils_Request::retrieve( 'discountCode', 'String', $form, false, null, $_REQUEST );
if ( $discountCode ) {
$defaults = array( 'discountCode' => $discountCode );
$form->setDefaults( $defaults );
}
}
}
/*
* Give random discounts for event signup.
*
* Warning : while implementing this hook, another post process hook
* : also need implementing to make sure code is only used for
* : the number of times that's allowed to.
*/
function civitest_civicrm_buildAmount( $pageType,
&$form,
&$amount ) {
$eventID = $form->getVar( '_eventId' );
if ( $pageType != 'event' ||
$eventID != 3 ) {
return;
}
$discountCode = CRM_Utils_Request::retrieve( 'discountCode', 'String', $form, false, null, $_REQUEST );
if ( ! $discountCode ) {
return;
}
list( $discountID, $discountPercent, $discountNumber ) = _civitest_discountHelper( $eventID, $discountCode );
if ( $discountNumber <= 0 ) {
// no more discount left
return;
}
foreach ( $amount as $amountId => $amountInfo ) {
$amount[$amountId]['value'] = $amount[$amountId]['value'] -
ceil($amount[$amountId]['value'] * $discountPercent / 100);
$amount[$amountId]['label'] = $amount[$amountId]['label'] .
"\t - with {$discountPercent}% discount";
}
}
/*
* The hook updates the random code used with event signup.
*/
function civitest_civicrm_postProcess( $class, &$form ) {
$eventID = $form->getVar( '_eventId' );
if ( ! is_a($form, 'CRM_Event_Form_Registration_Confirm') ||
$eventID != 3 ) {
return;
}
$discountCode = CRM_Utils_Request::retrieve( 'discountCode', 'String', $form, false, null, $_REQUEST );
if ( ! $discountCode ) {
return;
}
list( $discountID, $discountPercent, $discountNumber ) = _civitest_discountHelper( $eventID, $discountCode );
if ( ! $discountID ||
$discountNumber <= 0 ||
$discountNumber == 123456789 ) {
return;
}
$query = "
UPDATE civicrm_option_value v
SET v.weight = v.weight - 1
WHERE v.id = %1
AND v.weight > 0
";
$params = array( 1 => array( $discountID, 'Integer' ) );
CRM_Core_DAO::executeQuery( $query, $params );
}
/**
* Sample hook to add more shortcuts
*/
function civitest_civicrm_shortcuts( &$options ) {
// add link to create new profile
$options[] = array( 'url' => '/civicrm/admin/uf/group?action=add&reset=1',
'title' => ts('New Profile'),
'ref' => 'new-profile');
}
function civitest_civicrm_membershipTypeValues( &$form, &$membershipTypeValues ) {
$membershipTypeValues[1]['name'] = 'General (50% discount)';
$membershipTypeValues[1]['minimum_fee'] = '50.00';
$membershipTypeValues[2]['name'] = 'Student (50% discount)';
$membershipTypeValues[2]['minimum_fee'] = '25.00';
}
function civitest_civicrm_summary( $contactID, &$content, &$contentPlacement ) {
// REPLACE default Contact Summary with your customized content
$contentPlacement = 3;
$content = "
";
}
function civitest_civicrm_contactListQuery( &$query, $name, $context, $id ) {
// This example limits contacts in my contact reference field lookup to a specific group
// Connect the hook to your Contact Reference custom field using the field ID (field id is 4 in this case)
if ( $context == 'customfield' &&
$id == 4 ) {
// Now construct the query to select only the contacts we want
// The query must return two columns - contact sort_name, and contact id
$query = "
SELECT c.sort_name, c.id
FROM civicrm_contact c, civicrm_group_contact cg
WHERE c.sort_name LIKE '$name%'
AND cg.group_id IN ( 4 )
AND cg.contact_id = c.id
AND cg.status = 'Added'
ORDER BY c.sort_name ";
}
}
/**
* Hook implementation for altering payment parameters before talking to a payment processor back end.
*
* @param string $paymentObj
* instance of payment class of the payment processor invoked (e.g., 'CRM_Core_Payment_Dummy')
* @param array &$rawParams
* array of params as passed to to the processor
* @params array &$cookedParams
* params after the processor code has translated them into its own key/value pairs
* @return void
*/
function civitest_civicrm_alterPaymentProcessorParams( $paymentObj,
&$rawParams,
&$cookedParams ) {
$mode = $paymentObj->getVar('_mode');
$type = $paymentObj->getVar('_paymentProcessor');
$processorType = $type['payment_processor_type'];
if ( $paymentObj instanceof CRM_Core_Payment_Dummy ) {
$employer = empty($rawParams['custom_1']) ? '' : $rawParams['custom_1'];
$occupation = empty($rawParams['custom_2']) ? '' : $rawParams['custom_2'];
$cookedParams['custom'] = "$employer|$occupation";
} else if ( $paymentObj instanceof CRM_Contribute_Payment_AuthorizeNet ) {
//Actual translation for one application:
//Employer > Ship to Country (x_ship_to_country)
//Occupation > Company (x_company)
//Solicitor > Ship-to First Name (x_ship_to_first_name)
//Event > Ship-to Last Name (x_ship_to_last_name)
//Other > Ship-to Company (x_ship_to_company)
$cookedParams['x_ship_to_country'] = $rawParams['custom_1'];
$cookedParams['x_company'] = $rawParams['custom_2'];
$cookedParams['x_ship_to_last_name'] = $rawParams['accountingCode']; //for now
$country_info = da_core_fetch_country_data_by_crm_id($rawParams['country-1']);
$cookedParams['x_ship_to_company'] = $country_info['iso_code'];
} else if( $paymentObj instanceof CRM_Core_Payment_PayPalImpl && $processorType == 'PayPal' ) {
// Website Pro Checkout
$obj = $paymentObj->getVar('_paymentForm');
$value = $obj->getVar('_values');
$id = $value['id'];
if ( $value['event']['id'] ) {
$id = $value['event']['id'];
}
$cookedParams['desc'] = $rawParams['description'];
$cookedParams['custom'] = $id;
} elseif ( $paymentObj instanceof CRM_Core_Payment_PayPalImpl && $processorType == 'PayPal_Express' ) {
// Express Checkout
$cookedParams['desc'] = $rawParams['eventName'];
$cookedParams['custom'] = $rawParams['eventId'];
}
}
function civitest_civicrm_customFieldOptions($fieldID, &$options, $detailedFormat = false ) {
if ( $fieldID == 1 || $fieldID == 2 ) {
if ( $detailedFormat ) {
$options['fake_id_1'] = array( 'id' => 'fake_id_1',
'value' => 'XXX',
'label' => 'XXX' );
$options['fake_id_2'] = array( 'id' => 'fake_id_2',
'value' => 'YYY',
'label' => 'YYY' );
} else {
$options['XXX'] = 'XXX';
$options['YYY'] = 'YYY';
}
}
}
function civitest_civicrm_config( &$config ) {
$civitestRoot = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
// fix php include path
$include_path = $civitestRoot . PATH_SEPARATOR . get_include_path( );
set_include_path( $include_path );
// fix template path
$templateDir = $civitestRoot . 'templates' . DIRECTORY_SEPARATOR;
$template =& CRM_Core_Smarty::singleton( );
if ( is_array( $template->template_dir ) ) {
$template->template_dir = array( $templateDir ) + $template->template_dir;
} else {
$template->template_dir = array( $templateDir, $template->template_dir );
}
}
function custom_ts( $string, $params = array( ) ) {
$string = str_replace( 'Participant', 'Delegate', $string );
static $i18n = null;
if ( ! $i18n ) {
$i18n =& CRM_Core_I18n::singleton();
}
return $i18n->crm_translate( $string, $params );
}
/**
* You want a contribution page with exactly one amount and you
* you want to set all the values fixed and not give the user
* any choice
*/
function civitest_civicrm_buildForm( $formName, &$form ) {
if ( $formName == 'CRM_Contribute_Form_Contribution_Main' &&
$form->getVar( '_id' ) == 1 ) {
// 358 is the "option value id" of the only value in the amount table,
// you can get this id, by doing a view source on the HTML
$defaults = array( 'amount' => 358,
'is_recur' => 1,
'frequency_interval' => 1,
'frequency_unit' => 'month',
'installments' => 12 );
$form->setDefaults( $defaults );
// also freeze these elements
$elementNames = array_keys( $defaults );
foreach ( $elementNames as $element ) {
$elm =& $form->getElement( $element );
$elm->freeze( );
}
}
}
function civitest_civicrm_caseSummary($caseID) {
/* Quick way to test what some results look like.
return array('some_unique_id' => array( 'label' => ts('Some Date'),
'value' => '2009-02-11',
),
'some_other_id' => array( 'label' => ts('Some String'),
'value' => ts('Coconuts'),
),
);
*/
/*
For styling put this in css/extras.css:
#caseSummary {display: table;}
#modrtw {display: table-row; border: 1px solid #999999; width: 200px;}
#mcstat {display: table-row; border: 1px solid #999999; border-left: 0; width: 200px;}
#caseSummary label {display: table-cell;}
#caseSummary div {display: table-cell; padding-left: 5px; padding-right: 5px;}
*/
// More realistic example, but will return nothing unless you have these activities in your database.
// TIP: Put these queries into methods in a custom class. You will likely want to re-use them elsewhere, such as in a CiviReport.
// This query finds the earliest date of return to modified duties in a workplace disability case.
$params = array( 1 => array( $caseID, 'Integer' ) );
$sql = "SELECT min(activity_date_time) as mindate
FROM civicrm_activity a
INNER JOIN civicrm_case_activity ca on a.id=ca.activity_id
LEFT OUTER JOIN civicrm_option_group og on og.name='activity_type'
LEFT OUTER JOIN civicrm_option_value ov on
(og.id=ov.option_group_id AND ov.name='Return to modified duties')
WHERE ca.case_id=%1
AND ov.value=a.activity_type_id
LIMIT 1";
$modrtw = CRM_Core_DAO::singleValueQuery( $sql, $params );
// This query returns the current status of the medical consent as determined by
// the presence or absence of related activities.
$sql = "SELECT CASE WHEN count(received.case_id) > 0 THEN 'Received'
WHEN count(sent.case_id) > 0 AND DATEDIFF(CURRENT_TIMESTAMP, sent.activity_date_time) > 14 THEN 'Overdue'
WHEN count(sent.case_id) > 0 THEN 'Sent'
ELSE 'Not Sent'
END
FROM
(SELECT ca.case_id, a1.activity_date_time FROM civicrm_activity a1
INNER JOIN civicrm_case_activity ca on a1.id=ca.activity_id
LEFT OUTER JOIN civicrm_option_group og on og.name='activity_type'
LEFT OUTER JOIN civicrm_option_value ov on
(og.id=ov.option_group_id AND ov.name='Send Consent Letter')
WHERE ca.case_id=%1
AND ov.value=a1.activity_type_id
LIMIT 1
) AS sent
LEFT OUTER JOIN
(SELECT ca2.case_id FROM civicrm_activity a2
INNER JOIN civicrm_case_activity ca2 on a2.id=ca2.activity_id
LEFT OUTER JOIN civicrm_option_group og2 on og2.name='activity_type'
LEFT OUTER JOIN civicrm_option_value ov2 on
(og2.id=ov2.option_group_id AND ov2.name='File Received Consent')
WHERE ca2.case_id=%1
AND ov2.value=a2.activity_type_id
LIMIT 1
) AS received
ON received.case_id=sent.case_id";
$mcstat = CRM_Core_DAO::singleValueQuery( $sql, $params );
return array('modrtw' => array( 'label' => ts('Mod RTW:'),
'value' => $modrtw,
),
'mcstat' => array( 'label' => ts('Consent Status:'),
'value' => ts($mcstat),
),
);
}