}
$urlParams = "action=add&reset=1&cid={$contactId}&selectedChild=activity&atype=";
- $activityTypes = $urls = array();
+ $allTypes = CRM_Utils_Array::value('values', civicrm_api3('OptionValue', 'get', array(
+ 'option_group_id' => 'activity_type',
+ 'is_active' => 1,
+ 'options' => array('limit' => 0, 'sort' => 'weight'),
+ )));
- $emailTypeId = CRM_Core_OptionGroup::getValue('activity_type',
- 'Email',
- 'name'
- );
+ $activityTypes = array();
- $letterTypeId = CRM_Core_OptionGroup::getValue('activity_type',
- 'Print PDF Letter',
- 'name'
- );
- $SMSId = CRM_Core_OptionGroup::getValue('activity_type',
- 'Text Message (SMS)',
- 'label'
- );
-
- if (CRM_Utils_Mail::validOutBoundMail() && $contactId) {
- list($name, $email, $doNotEmail, $onHold, $isDeseased) = CRM_Contact_BAO_Contact::getContactDetails($contactId);
- if (!$doNotEmail && $email && !$isDeseased) {
- $activityTypes = array($emailTypeId => ts('Send an Email'));
- }
- }
-
- if ($contactId && CRM_SMS_BAO_Provider::activeProviderCount()) {
- // Check for existence of a mobile phone and ! do not SMS privacy setting
- $mobileTypeID = CRM_Core_OptionGroup::getValue('phone_type', 'Mobile', 'name');
- list($name, $phone, $doNotSMS) = CRM_Contact_BAO_Contact_Location::getPhoneDetails($contactId, $mobileTypeID);
-
- if (!$doNotSMS && $phone) {
- $sendSMS = array($SMSId => ts('Send SMS'));
- $activityTypes += $sendSMS;
- }
- }
- // this returns activity types sorted by weight
- $otherTypes = CRM_Core_PseudoConstant::activityType(FALSE);
-
- $activityTypes += $otherTypes;
-
- foreach (array_keys($activityTypes) as $typeId) {
- if ($typeId == $emailTypeId) {
- $urls[$typeId] = CRM_Utils_System::url('civicrm/activity/email/add',
- "{$urlParams}{$typeId}", FALSE, NULL, FALSE
- );
+ foreach ($allTypes as $id => $act) {
+ $url = 'civicrm/activity/add';
+ if ($act['name'] == 'Email') {
+ if (!CRM_Utils_Mail::validOutBoundMail() || !$contactId) {
+ continue;
+ }
+ list($name, $email, $doNotEmail, $onHold, $isDeseased) = CRM_Contact_BAO_Contact::getContactDetails($contactId);
+ if (!$doNotEmail && $email && !$isDeseased) {
+ $url = 'civicrm/activity/email/add';
+ $act['label'] = ts('Send an Email');
+ }
+ else {
+ continue;
+ }
}
- elseif ($typeId == $SMSId) {
- $urls[$typeId] = CRM_Utils_System::url('civicrm/activity/sms/add',
- "{$urlParams}{$typeId}", FALSE, NULL, FALSE
- );
+ elseif ($act['name'] == 'SMS') {
+ if (!$contactId || !CRM_SMS_BAO_Provider::activeProviderCount()) {
+ continue;
+ }
+ // Check for existence of a mobile phone and ! do not SMS privacy setting
+ $mobileTypeID = CRM_Core_OptionGroup::getValue('phone_type', 'Mobile', 'name');
+ list($name, $phone, $doNotSMS) = CRM_Contact_BAO_Contact_Location::getPhoneDetails($contactId, $mobileTypeID);
+ if (!$doNotSMS && $phone) {
+ $url = 'civicrm/activity/sms/add';
+ }
+ else {
+ continue;
+ }
}
- elseif ($typeId == $letterTypeId) {
- $urls[$typeId] = CRM_Utils_System::url('civicrm/activity/pdf/add',
- "{$urlParams}{$typeId}", FALSE, NULL, FALSE
- );
+ elseif ($act['name'] == 'Print PDF Letter') {
+ $url = 'civicrm/activity/pdf/add';
}
- else {
- $urls[$typeId] = CRM_Utils_System::url('civicrm/activity/add',
- "{$urlParams}{$typeId}", FALSE, NULL, FALSE
- );
+ elseif (!empty($act['filter']) || (!empty($act['component_id']) && $act['component_id'] != '1')) {
+ continue;
}
+ $act['url'] = CRM_Utils_System::url($url,
+ "{$urlParams}{$id}", FALSE, NULL, FALSE
+ );
+ $act += array('icon' => 'fa-plus-square-o');
+ $activityTypes[$act['value']] = $act;
}
$self->assign('activityTypes', $activityTypes);
- $self->assign('urls', $urls);
$self->assign('suppressForm', TRUE);
}
{if $as_select} {* on 3.2, the activities can be either a drop down select (on the activity tab) or a list (on the action menu) *}
<select name="other_activity" class="crm-form-select crm-select2 crm-action-menu fa-plus">
<option value="">{ts}New Activity{/ts}</option>
-{foreach from=$activityTypes key=k item=link}
- <option value="{$urls.$k}">{$link}</option>
+{foreach from=$activityTypes item=act}
+ <option value="{$act.url}" data-icon="{$act.icon}">{$act.label}</option>
{/foreach}
</select>
{literal}
{else}
<ul>
<li class="crm-activity-tab"><a href="#" data-tab="activity">{ts}Record Activity:{/ts}</a></li>
-{foreach from=$activityTypes key=k item=link}
-<li class="crm-activity-type_{$k}"><a href="{$urls.$k}" data-tab="activity">{$link}</a></li>
+{foreach from=$activityTypes key=k item=act}
+<li class="crm-activity-type_{$k}">
+ <a href="{$act.url}" data-tab="activity">
+ <i class="crm-i {$act.icon}"></i> {$act.label}
+ </a>
+</li>
{/foreach}
{* add hook links if any *}