3 require_once 'memberdashboard.civix.php';
5 define('MEMBERDASHBOARD_SETTINGS_GROUP', 'Member Dashboard Preferences');
6 define('MEMBERDASHBOARD_MAX_EMAIL_ALIASES', 5);
9 * Implementation of hook_civicrm_config
11 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
13 function memberdashboard_civicrm_config(&$config) {
14 _memberdashboard_civix_civicrm_config($config);
18 * Implementation of hook_civicrm_xmlMenu
20 * @param $files array(string)
22 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_xmlMenu
24 function memberdashboard_civicrm_xmlMenu(&$files) {
25 _memberdashboard_civix_civicrm_xmlMenu($files);
29 * Implementation of hook_civicrm_install
31 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
33 function memberdashboard_civicrm_install() {
34 _memberdashboard_civix_civicrm_install();
38 * Implementation of hook_civicrm_uninstall
40 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall
42 function memberdashboard_civicrm_uninstall() {
43 _memberdashboard_civix_civicrm_uninstall();
47 * Implementation of hook_civicrm_enable
49 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable
51 function memberdashboard_civicrm_enable() {
52 _memberdashboard_civix_civicrm_enable();
56 * Implementation of hook_civicrm_disable
58 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_disable
60 function memberdashboard_civicrm_disable() {
61 _memberdashboard_civix_civicrm_disable();
65 * Implementation of hook_civicrm_upgrade
67 * @param $op string, the type of operation being performed; 'check' or 'enqueue'
68 * @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks
70 * @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending)
71 * for 'enqueue', returns void
73 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_upgrade
75 function memberdashboard_civicrm_upgrade($op, CRM_Queue_Queue
$queue = NULL) {
76 return _memberdashboard_civix_civicrm_upgrade($op, $queue);
80 * Implementation of hook_civicrm_managed
82 * Generate a list of entities to create/deactivate/delete when this module
83 * is installed, disabled, uninstalled.
85 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_managed
87 function memberdashboard_civicrm_managed(&$entities) {
88 _memberdashboard_civix_civicrm_managed($entities);
92 * Implementation of hook_civicrm_caseTypes
94 * Generate a list of case-types
96 * Note: This hook only runs in CiviCRM 4.4+.
98 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_caseTypes
100 function memberdashboard_civicrm_caseTypes(&$caseTypes) {
101 _memberdashboard_civix_civicrm_caseTypes($caseTypes);
105 * Implementation of hook_civicrm_alterSettingsFolders
107 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterSettingsFolders
109 function memberdashboard_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
110 _memberdashboard_civix_civicrm_alterSettingsFolders($metaDataFolders);
114 * Implementation of hook_civicrm_post
116 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_post
118 function memberdashboard_civicrm_post($op, $objectName, $objectId, &$objectRef) {
119 // When a membership is modified, make a RPC to regenerate the
120 // member button for the contact.
121 $triggerOps = array('create', 'edit', 'delete');
123 if($objectName == 'Membership' && in_array($op, $triggerOps)) {
124 // TODO: Extract all of this to a class for clarity and
125 // organization's sake.
127 // Get the oldest join date for the contact's memberships.
128 $contactId = $objectRef->contact_id
;
129 $dao = CRM_Core_DAO
::executeQuery(
130 'SELECT join_date FROM civicrm_membership WHERE contact_id=%1 ORDER BY join_date ASC LIMIT 1',
131 array( 1 => array($contactId, 'Integer') )
135 // Make the API call.
136 $joinDate = $dao->join_date
;
137 $apiUrl = civicrm_api3('setting', 'getvalue', array(
138 'name' => 'memberdashboard_button_api_url',
139 'group' => MEMBERDASHBOARD_SETTINGS_GROUP
141 $user = civicrm_api3('setting', 'getvalue', array(
142 'name' => 'memberdashboard_button_api_user',
143 'group' => MEMBERDASHBOARD_SETTINGS_GROUP
145 $password = civicrm_api3('setting', 'getvalue', array(
146 'name' => 'memberdashboard_button_api_password',
147 'group' => MEMBERDASHBOARD_SETTINGS_GROUP
149 $params = http_build_query(array(
150 'contact_id' => $contactId,
154 if(!empty($apiUrl) && !empty($user) && !empty($password)) {
156 curl_setopt($curl, CURLOPT_HTTPAUTH
, CURLAUTH_BASIC
);
157 curl_setopt($curl, CURLOPT_USERPWD
, "$user:$password");
158 curl_setopt($curl, CURLOPT_URL
, "$apiUrl?$params");