public function buildQuickForm() {
$this->add('select', 'memberdashboard_info_profile_id',
'Member Info Profile', $this->fetchProfiles());
+ $this->add('text', 'memberdashboard_button_api_url',
+ 'Member Button API URL');
+ $this->add('text', 'memberdashboard_button_api_user',
+ 'Member Button API User');
+ $this->add('text', 'memberdashboard_button_api_password',
+ 'Member Button API Password');
$this->applyFilter('__ALL__', 'trim');
$this->addButtons(array(
array(
public function postProcess() {
$params = $this->exportValues();
- $key = 'memberdashboard_info_profile_id';
- $value = $params[$key];
+ $profileKey = 'memberdashboard_info_profile_id';
+ $urlKey = 'memberdashboard_button_api_url';
+ $userKey = 'memberdashboard_button_api_user';
+ $passwordKey = 'memberdashboard_button_api_password';
civicrm_api3('setting', 'create', array(
- $key => $value
+ $profileKey => $params[$profileKey],
+ $urlKey => $params[$urlKey],
+ $userKey => $params[$userKey],
+ $passwordKey => $params[$passwordKey]
));
CRM_Core_Session::setStatus(ts('Settings saved.'), '', 'success');
function memberdashboard_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
_memberdashboard_civix_civicrm_alterSettingsFolders($metaDataFolders);
}
+
+/**
+ * Implementation of hook_civicrm_post
+ *
+ * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_post
+ */
+function memberdashboard_civicrm_post($op, $objectName, $objectId, &$objectRef) {
+ // When a membership is modified, make a RPC to regenerate the
+ // member button for the contact.
+ $triggerOps = array('create', 'edit', 'delete');
+
+ if($objectName == 'Membership' && in_array($op, $triggerOps)) {
+ // TODO: Extract all of this to a class for clarity and
+ // organization's sake.
+
+ // Get the oldest join date for the contact's memberships.
+ $contactId = $objectRef->contact_id;
+ $dao = CRM_Core_DAO::executeQuery(
+ 'SELECT join_date FROM civicrm_membership WHERE contact_id=%1 ORDER BY join_date ASC LIMIT 1',
+ array( 1 => array($contactId, 'Integer') )
+ );
+
+ if($dao->fetch()) {
+ // Make the API call.
+ $joinDate = $dao->join_date;
+ $apiUrl = civicrm_api3('setting', 'getvalue', array(
+ 'name' => 'memberdashboard_button_api_url',
+ 'group' => MEMBERDASHBOARD_SETTINGS_GROUP
+ ));
+ $user = civicrm_api3('setting', 'getvalue', array(
+ 'name' => 'memberdashboard_button_api_user',
+ 'group' => MEMBERDASHBOARD_SETTINGS_GROUP
+ ));
+ $password = civicrm_api3('setting', 'getvalue', array(
+ 'name' => 'memberdashboard_button_api_password',
+ 'group' => MEMBERDASHBOARD_SETTINGS_GROUP
+ ));
+ $params = http_build_query(array(
+ 'contact_id' => $contactId,
+ 'date' => $joinDate
+ ));
+ $curl = curl_init();
+ curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
+ curl_setopt($curl, CURLOPT_USERPWD, "$user:$password");
+ curl_setopt($curl, CURLOPT_URL, "$apiUrl?$params");
+ curl_exec($curl);
+ }
+
+ $dao->free();
+ }
+}
'is_contact' => 0,
'description' => 'Info Profile ID',
'help_text' => 'Profile ID for member-editable contact information'
+ ),
+ 'memberdashboard_button_api_url' => array(
+ 'group_name' => 'Member Dashboard Preferences',
+ 'group' => 'memberdashboard',
+ 'name' => 'memberdashboard_button_api_url',
+ 'type' => 'String',
+ 'default' => '',
+ 'is_domain' => 1,
+ 'is_contact' => 0,
+ 'description' => 'Member button API URL',
+ 'help_text' => 'The location of the FSF member button generator API'
+ ),
+ 'memberdashboard_button_api_user' => array(
+ 'group_name' => 'Member Dashboard Preferences',
+ 'group' => 'memberdashboard',
+ 'name' => 'memberdashboard_button_api_user',
+ 'type' => 'String',
+ 'default' => '',
+ 'is_domain' => 1,
+ 'is_contact' => 0,
+ 'description' => 'User name for logging into the member button API',
+ 'help_text' => ''
+ ),
+ 'memberdashboard_button_api_password' => array(
+ 'group_name' => 'Member Dashboard Preferences',
+ 'group' => 'memberdashboard',
+ 'name' => 'memberdashboard_button_api_password',
+ 'type' => 'String',
+ 'default' => '',
+ 'is_domain' => 1,
+ 'is_contact' => 0,
+ 'description' => 'Password for the member button API',
+ 'help_text' => 'Super secret password for logging into the member button API'
)
-);
\ No newline at end of file
+);
{$form.memberdashboard_info_profile_id.html}
</td>
</tr>
+ <tr>
+ <td class="label">
+ {$form.memberdashboard_button_api_url.label}
+ </td>
+ <td>
+ {$form.memberdashboard_button_api_url.html}
+ </td>
+ </tr>
+ <tr>
+ <td class="label">
+ {$form.memberdashboard_button_api_user.label}
+ </td>
+ <td>
+ {$form.memberdashboard_button_api_user.html}
+ </td>
+ </tr>
+ <tr>
+ <td class="label">
+ {$form.memberdashboard_button_api_password.label}
+ </td>
+ <td>
+ {$form.memberdashboard_button_api_password.html}
+ </td>
+ </tr>
</table>
</fieldset>