Skip to content

Commit

Permalink
RecentItems - Use font-awesome icons in recent items sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Apr 4, 2022
1 parent 30238b5 commit 49c63a6
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 12 deletions.
9 changes: 7 additions & 2 deletions CRM/Activity/BAO/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,11 @@ public static function create(&$params) {
if (!isset($activity->parent_id)) {
$recentContactDisplay = CRM_Contact_BAO_Contact::displayName($recentContactId);
// add the recently created Activity
$activityTypes = CRM_Activity_BAO_Activity::buildOptions('activity_type_id');
$field = Civi\Api4\Activity::getFields(FALSE)
->addWhere('name', '=', 'activity_type_id')
->setLoadOptions(['id', 'label', 'icon'])
->execute()->single();
$activityTypes = array_column($field['options'], NULL, 'id');
$activitySubject = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activity->id, 'subject');

$title = "";
Expand All @@ -505,7 +509,8 @@ public static function create(&$params) {

$title = $title . $recentContactDisplay;
if (!empty($activityTypes[$activity->activity_type_id])) {
$title .= ' (' . $activityTypes[$activity->activity_type_id] . ')';
$title .= ' (' . $activityTypes[$activity->activity_type_id]['label'] . ')';
$recentOther['icon'] = $activityTypes[$activity->activity_type_id]['icon'] ?? NULL;
}

CRM_Utils_Recent::add($title,
Expand Down
11 changes: 10 additions & 1 deletion CRM/Activity/Form/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,21 @@ public function preProcess() {
if ($this->_action & CRM_Core_Action::VIEW) {
$this->_values['details'] = CRM_Utils_String::purifyHtml($this->_values['details'] ?? '');
$url = CRM_Utils_System::url(implode("/", $this->urlPath), "reset=1&id={$this->_activityId}&action=view&cid={$this->_values['source_contact_id']}");
$field = Civi\Api4\Activity::getFields(FALSE)
->addWhere('name', '=', 'activity_type_id')
->setLoadOptions(['id', 'label', 'icon'])
->execute()->single();
$activityTypes = array_column($field['options'], NULL, 'id');
$info = [
'icon' => $activityTypes[$this->_values['activity_type_id']]['icon'] ?? NULL,
];
CRM_Utils_Recent::add(CRM_Utils_Array::value('subject', $this->_values, ts('(no subject)')),
$url,
$this->_values['id'],
'Activity',
$this->_values['source_contact_id'],
$this->_values['source_contact']
$this->_values['source_contact'],
$info
);
}
}
Expand Down
11 changes: 10 additions & 1 deletion CRM/Activity/Form/ActivityView.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,21 @@ public function preProcess() {
$this->assign('values', $values);

$url = CRM_Utils_System::url(implode("/", $this->urlPath), "reset=1&id={$activityId}&action=view&cid={$defaults['source_contact_id']}");
$field = Civi\Api4\Activity::getFields(FALSE)
->addWhere('name', '=', 'activity_type_id')
->setLoadOptions(['id', 'label', 'icon'])
->execute()->single();
$activityTypes = array_column($field['options'], NULL, 'id');
$info = [
'icon' => $activityTypes[$defaults['activity_type_id']]['icon'] ?? NULL,
];
CRM_Utils_Recent::add($defaults['subject'],
$url,
$activityId,
'Activity',
$defaults['source_contact_id'],
$defaults['source_contact']
$defaults['source_contact'],
$info
);
}

Expand Down
27 changes: 27 additions & 0 deletions CRM/Utils/Recent.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public static function add(
'image_url' => $others['imageUrl'] ?? NULL,
'edit_url' => $others['editUrl'] ?? NULL,
'delete_url' => $others['deleteUrl'] ?? NULL,
'icon' => $others['icon'] ?? self::getIcon($type, $others['subtype'] ?? NULL),
]
);

Expand All @@ -136,6 +137,32 @@ public static function add(
$session->set(self::STORE_NAME, self::$_recent);
}

/**
* @param $type
* @param $subType
* @return string|null
*/
private static function getIcon($type, $subType) {
$icon = NULL;
$contactTypes = CRM_Contact_BAO_ContactType::getAllContactTypes();
if (!empty($contactTypes[$type])) {
// Pick icon from contact sub-type first if available, then contact type
$subTypesAndType = array_merge((array) CRM_Utils_Array::explodePadded($subType), [$type]);
foreach ($subTypesAndType as $contactType) {
$icon = $icon ?? $contactTypes[$contactType]['icon'] ?? NULL;
}
// If no contact type icon, proceed to lookup icon from dao
$type = 'Contact';
}
if (!$icon) {
$daoClass = CRM_Core_DAO_AllCoreTables::getFullName($type);
if ($daoClass) {
$icon = $daoClass::$_icon;
}
}
return $icon ?: 'fa-gear';
}

/**
* Callback for hook_civicrm_post().
* @param \Civi\Core\Event\PostEvent $event
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Block/RecentlyViewed.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{if $item.image_url}
<span class="icon crm-icon {if $item.subtype}{$item.subtype}{else}{$item.type}{/if}-icon" style="background: url('{$item.image_url}')"></span>
{else}
<span class="icon crm-icon {$item.type}{if $item.subtype}-subtype{/if}-icon"></span>
<i class="crm-i fa-fw {$item.icon}"></i>
{/if}
{if $item.isDeleted}<del>{/if}{$item.title}{if $item.isDeleted}</del>{/if}
</a>
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Activity/Form/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testSearch(): void {
$this->assertEquals([
[
'contact_id' => '3',
'contact_type' => '<a href="/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=3" data-tooltip-url="/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=3&amp;snippet=4&amp;is_show_email_task=1" class="crm-summary-link"><div class="icon crm-icon Individual-icon"></div></a>',
'contact_type' => '<a href="/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=3" data-tooltip-url="/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=3&amp;snippet=4&amp;is_show_email_task=1" class="crm-summary-link"><i class="crm-i fa-fw fa-user" title=""></i></a>',
'sort_name' => 'Anderson, Anthony',
'display_name' => 'Mr. Anthony Anderson II',
'activity_id' => '1',
Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/CRM/Financial/Page/AjaxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public function testGetFinancialTransactionsList(): void {
$_REQUEST['return'] = TRUE;
$json = CRM_Financial_Page_AJAX::getFinancialTransactionsList();
$json = str_replace(rtrim(CIVICRM_UF_BASEURL, '/'), 'http://FIX ME', $json);
$this->assertEquals('{"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["","<a href=\"/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=3\" data-tooltip-url=\"/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=3&amp;snippet=4&amp;is_show_email_task=1\" class=\"crm-summary-link\"><div'
. ' class=\"icon crm-icon Individual-icon\"></div></a>","<a href=/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=3>Anderson, Anthony</a>","$100.00","12345","' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM","' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM",'
$this->assertEquals('{"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["","<a href=\"/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=3\" data-tooltip-url=\"/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=3&amp;snippet=4&amp;is_show_email_task=1\" class=\"crm-summary-link\">'
. '<i class=\"crm-i fa-fw fa-user\" title=\"\"></i></a>","<a href=/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=3>Anderson, Anthony</a>","$100.00","12345","' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM","' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM",'
. '"Credit Card","Completed","Donation","<span><a href=\"/index.php?q=civicrm/contact/view/contribution&amp;reset=1&amp;id=1&amp;cid=3&amp;action=view&amp;context=contribution&amp;'
. 'selectedChild=contribute\" class=\"action-item crm-hover-button\" title=\'View Contribution\' >View</a></span>"]] }', $json);
}
Expand All @@ -66,8 +66,8 @@ public function testGetFinancialTransactionsListOpenBatch(): void {
$_REQUEST['return'] = TRUE;
$json = CRM_Financial_Page_AJAX::getFinancialTransactionsList();
$json = str_replace(rtrim(CIVICRM_UF_BASEURL, '/'), 'http://FIX ME', $json);
$this->assertEquals('{"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["<input type=\'checkbox\' id=\'mark_x_2\' name=\'mark_x_2\' value=\'1\' onclick=enableActions(\'x\')></input>","<a href=\"/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=3\" data-tooltip-url=\"/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=3&amp;snippet=4&amp;is_show_email_task=1\" class=\"crm-summary-link\"><div'
. ' class=\"icon crm-icon Individual-icon\"></div></a>","<a href=/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=3>Anderson, Anthony</a>","$5.00","12345","' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM","' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM",'
$this->assertEquals('{"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["<input type=\'checkbox\' id=\'mark_x_2\' name=\'mark_x_2\' value=\'1\' onclick=enableActions(\'x\')></input>","<a href=\"/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=3\" data-tooltip-url=\"/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=3&amp;snippet=4&amp;is_show_email_task=1\" class=\"crm-summary-link\">'
. '<i class=\"crm-i fa-fw fa-user\" title=\"\"></i></a>","<a href=/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=3>Anderson, Anthony</a>","$5.00","12345","' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM","' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM",'
. '"Credit Card","Completed","Donation","<span><a href=\"/index.php?q=civicrm/contact/view/contribution&amp;reset=1&amp;id=1&amp;cid=3&amp;action=view&amp;context=contribution&amp;'
. 'selectedChild=contribute\" class=\"action-item crm-hover-button\" title=\'View Contribution\' >View</a><a href=\"#\" class=\"action-item crm-hover-button disable-action\" title=\'Assign Transaction\' onclick = \"assignRemove( 2,\'assign\' );\">Assign</a></span>"]] }', $json);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Member/Selector/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testSelectorGetRows(): void {
$this->assertEquals([
'contact_id' => $this->_contactID,
'membership_id' => $membershipID,
'contact_type' => '<a href="/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=' . $this->_contactID . '" data-tooltip-url="/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=' . $this->_contactID . '&amp;snippet=4&amp;is_show_email_task=1" class="crm-summary-link"><div class="icon crm-icon Individual-icon"></div></a>',
'contact_type' => '<a href="/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=' . $this->_contactID . '" data-tooltip-url="/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=' . $this->_contactID . '&amp;snippet=4&amp;is_show_email_task=1" class="crm-summary-link"><i class="crm-i fa-fw fa-user" title=""></i></a>',
'sort_name' => 'Anderson, Anthony',
'membership_type' => 'General',
'membership_join_date' => date('Y-m-d'),
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Pledge/Form/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testSearch() {
'pledge_status_name' => 'Pending Label**',
'checkbox' => 'mark_x_1',
'action' => '<span><a href="/index.php?q=civicrm/contact/view/pledge&amp;reset=1&amp;id=1&amp;cid=3&amp;action=view&amp;context=search&amp;selectedChild=pledge&amp;key=' . $qfKey . '" class="action-item crm-hover-button" title=' . "'" . 'View Pledge' . "'" . ' >View</a><a href="/index.php?q=civicrm/contact/view/pledge&amp;reset=1&amp;action=update&amp;id=1&amp;cid=3&amp;context=search&amp;key=' . $qfKey . '" class="action-item crm-hover-button" title=' . "'" . 'Edit Pledge' . "'" . ' >Edit</a></span><span class=' . "'" . 'btn-slide crm-hover-button' . "'" . '>more<ul class=' . "'" . 'panel' . "'" . '><li><a href="/index.php?q=civicrm/contact/view/pledge&amp;reset=1&amp;action=detach&amp;id=1&amp;cid=3&amp;context=search&amp;key=' . $qfKey . '" class="action-item crm-hover-button" title=' . "'" . 'Cancel Pledge' . "'" . ' onclick = "return confirm(' . "'" . 'Cancelling this pledge will also cancel any scheduled (and not completed) pledge payments. This action cannot be undone. Do you want to continue?' . "'" . ');">Cancel</a></li><li><a href="/index.php?q=civicrm/contact/view/pledge&amp;reset=1&amp;action=delete&amp;id=1&amp;cid=3&amp;context=search&amp;key=' . $qfKey . '" class="action-item crm-hover-button small-popup" title=' . "'" . 'Delete Pledge' . "'" . ' >Delete</a></li></ul></span>',
'contact_type' => '<a href="/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=3" data-tooltip-url="/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=3&amp;snippet=4&amp;is_show_email_task=1" class="crm-summary-link"><div class="icon crm-icon Individual-icon"></div></a>',
'contact_type' => '<a href="/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=3" data-tooltip-url="/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=3&amp;snippet=4&amp;is_show_email_task=1" class="crm-summary-link"><i class="crm-i fa-fw fa-user" title=""></i></a>',
], $rows[0]);
}

Expand Down

0 comments on commit 49c63a6

Please sign in to comment.