return CRM_Memberdashboard_BAO_EmailAlias::allForContact($this->contact['id']);
}
+ function hasValidMembership() {
+ // Since we don't currently shut off an expired member's benefits,
+ // we only test that they have a membership, not that it is current.
+ $params = array(
+ 'contact_id' => $this->contact['id']
+ );
+
+ try {
+ $result = civicrm_api3('membership', 'get', $params);
+ return $result['count'] > 0;
+ } catch (CiviCRM_API3_Exception $e) {
+ return false;
+ }
+ }
+
function postProcess() {
$action = $_REQUEST['action'];
- switch($action) {
- case 'add':
- $this->add();
- break;
+ // Short-circuit if user doesn't have a membership.
+ if($this->hasValidMembership()) {
+ switch($action) {
+ case 'add':
+ $this->add();
+ break;
- case 'edit':
- $this->edit();
- break;
+ case 'edit':
+ $this->edit();
+ break;
+ }
+ } else {
+ CRM_Core_Session::setStatus('Only members can have email aliases',
+ 'Error', 'error');
}
}
$this->assign('user', $user);
$this->assign('emailAliases', $emailAliases);
+ $this->assign('hasValidMembership', $this->hasValidMembership());
parent::run();
}