Commit | Line | Data |
---|---|---|
33b56ebf DT |
1 | <?php |
2 | ||
3 | require_once 'memberdashboard.civix.php'; | |
4 | ||
79dea0b5 | 5 | define('MEMBERDASHBOARD_SETTINGS_GROUP', 'Member Dashboard Preferences'); |
73f5f860 | 6 | define('MEMBERDASHBOARD_MAX_EMAIL_ALIASES', 5); |
79dea0b5 | 7 | |
33b56ebf DT |
8 | /** |
9 | * Implementation of hook_civicrm_config | |
10 | * | |
11 | * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config | |
12 | */ | |
13 | function memberdashboard_civicrm_config(&$config) { | |
14 | _memberdashboard_civix_civicrm_config($config); | |
15 | } | |
16 | ||
17 | /** | |
18 | * Implementation of hook_civicrm_xmlMenu | |
19 | * | |
20 | * @param $files array(string) | |
21 | * | |
22 | * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_xmlMenu | |
23 | */ | |
24 | function memberdashboard_civicrm_xmlMenu(&$files) { | |
25 | _memberdashboard_civix_civicrm_xmlMenu($files); | |
26 | } | |
27 | ||
28 | /** | |
29 | * Implementation of hook_civicrm_install | |
30 | * | |
31 | * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install | |
32 | */ | |
33 | function memberdashboard_civicrm_install() { | |
34 | _memberdashboard_civix_civicrm_install(); | |
35 | } | |
36 | ||
37 | /** | |
38 | * Implementation of hook_civicrm_uninstall | |
39 | * | |
40 | * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall | |
41 | */ | |
42 | function memberdashboard_civicrm_uninstall() { | |
43 | _memberdashboard_civix_civicrm_uninstall(); | |
44 | } | |
45 | ||
46 | /** | |
47 | * Implementation of hook_civicrm_enable | |
48 | * | |
49 | * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable | |
50 | */ | |
51 | function memberdashboard_civicrm_enable() { | |
52 | _memberdashboard_civix_civicrm_enable(); | |
53 | } | |
54 | ||
55 | /** | |
56 | * Implementation of hook_civicrm_disable | |
57 | * | |
58 | * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_disable | |
59 | */ | |
60 | function memberdashboard_civicrm_disable() { | |
61 | _memberdashboard_civix_civicrm_disable(); | |
62 | } | |
63 | ||
64 | /** | |
65 | * Implementation of hook_civicrm_upgrade | |
66 | * | |
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 | |
69 | * | |
70 | * @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending) | |
71 | * for 'enqueue', returns void | |
72 | * | |
73 | * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_upgrade | |
74 | */ | |
75 | function memberdashboard_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) { | |
76 | return _memberdashboard_civix_civicrm_upgrade($op, $queue); | |
77 | } | |
78 | ||
79 | /** | |
80 | * Implementation of hook_civicrm_managed | |
81 | * | |
82 | * Generate a list of entities to create/deactivate/delete when this module | |
83 | * is installed, disabled, uninstalled. | |
84 | * | |
85 | * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_managed | |
86 | */ | |
87 | function memberdashboard_civicrm_managed(&$entities) { | |
88 | _memberdashboard_civix_civicrm_managed($entities); | |
89 | } | |
90 | ||
91 | /** | |
92 | * Implementation of hook_civicrm_caseTypes | |
93 | * | |
94 | * Generate a list of case-types | |
95 | * | |
96 | * Note: This hook only runs in CiviCRM 4.4+. | |
97 | * | |
98 | * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_caseTypes | |
99 | */ | |
100 | function memberdashboard_civicrm_caseTypes(&$caseTypes) { | |
101 | _memberdashboard_civix_civicrm_caseTypes($caseTypes); | |
102 | } | |
103 | ||
104 | /** | |
105 | * Implementation of hook_civicrm_alterSettingsFolders | |
106 | * | |
107 | * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterSettingsFolders | |
108 | */ | |
109 | function memberdashboard_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) { | |
110 | _memberdashboard_civix_civicrm_alterSettingsFolders($metaDataFolders); | |
111 | } | |
fdb5b92e DT |
112 | |
113 | /** | |
114 | * Implementation of hook_civicrm_post | |
115 | * | |
116 | * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_post | |
117 | */ | |
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'); | |
122 | ||
123 | if($objectName == 'Membership' && in_array($op, $triggerOps)) { | |
8abf1068 DT |
124 | try { |
125 | // TODO: Extract all of this to a class for clarity and | |
126 | // organization's sake. | |
127 | ||
128 | // Get the oldest join date for the contact's memberships. | |
129 | $contactId = $objectRef->contact_id; | |
130 | $dao = CRM_Core_DAO::executeQuery( | |
131 | 'SELECT join_date FROM civicrm_membership WHERE contact_id=%1 ORDER BY join_date ASC LIMIT 1', | |
132 | array( 1 => array($contactId, 'Integer') ) | |
133 | ); | |
134 | ||
135 | if($dao->fetch()) { | |
136 | // Make the API call. | |
137 | $joinDate = $dao->join_date; | |
138 | $apiUrl = civicrm_api3('setting', 'getvalue', array( | |
139 | 'name' => 'memberdashboard_button_api_url', | |
140 | 'group' => MEMBERDASHBOARD_SETTINGS_GROUP | |
141 | )); | |
142 | $user = civicrm_api3('setting', 'getvalue', array( | |
143 | 'name' => 'memberdashboard_button_api_user', | |
144 | 'group' => MEMBERDASHBOARD_SETTINGS_GROUP | |
145 | )); | |
146 | $password = civicrm_api3('setting', 'getvalue', array( | |
147 | 'name' => 'memberdashboard_button_api_password', | |
148 | 'group' => MEMBERDASHBOARD_SETTINGS_GROUP | |
149 | )); | |
8abf1068 DT |
150 | |
151 | if(!empty($apiUrl) && !empty($user) && !empty($password)) { | |
b7839c05 | 152 | $url = "$apiUrl?contact_id=" . $contactId . "&date=" . $joinDate; |
8abf1068 DT |
153 | $curl = curl_init(); |
154 | curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); | |
155 | curl_setopt($curl, CURLOPT_USERPWD, "$user:$password"); | |
b7839c05 | 156 | curl_setopt($curl, CURLOPT_URL, $url); |
8abf1068 DT |
157 | curl_exec($curl); |
158 | } | |
697255fc | 159 | } |
fdb5b92e | 160 | |
8abf1068 DT |
161 | $dao->free(); |
162 | } catch(Exception $e) { | |
163 | // Ignore it. Not the end of the world if this fails. | |
164 | } | |
fdb5b92e DT |
165 | } |
166 | } | |
23aa70df DT |
167 | |
168 | function memberdashboard_civicrm_buildForm($formName, &$form) { | |
169 | // Hack to fix state select box in 4.4.x | |
170 | if($formName == 'CRM_Profile_Form_Edit') { | |
171 | $contactId = CRM_Core_Session::singleton()->get('userID'); | |
ef266336 DT |
172 | if($concactId) { |
173 | $contact = civicrm_api3('contact', 'getsingle', array( 'id' => $contactId )); | |
174 | $defaults['state_province-Primary'] = $contact['state_province_id']; | |
175 | $form->setDefaults($defaults); | |
176 | } | |
23aa70df DT |
177 | } |
178 | } |