Skip to content
Snippets Groups Projects
Verified Commit fbf56476 authored by Coleman Watts's avatar Coleman Watts Committed by Kevin Cristiano
Browse files

Simple function extraction

parent b9fb33da
No related branches found
No related tags found
No related merge requests found
......@@ -264,23 +264,57 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
$lastModified = CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact');
$this->assign_by_ref('lastModified', $lastModified);
$allTabs = array();
$weight = 10;
$this->_viewOptions = CRM_Core_BAO_Setting::valueOptions(
CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'contact_view_options',
TRUE
);
// show the tabs only if user has generic access to CiviCRM
$accessCiviCRM = CRM_Core_Permission::check('access CiviCRM');
$changeLog = $this->_viewOptions['log'];
$this->assign_by_ref('changeLog', $changeLog);
$components = CRM_Core_Component::getEnabledComponents();
foreach ($components as $name => $component) {
$this->assign('allTabs', $this->getTabs());
// hook for contact summary
// ignored but needed to prevent warnings
$contentPlacement = CRM_Utils_Hook::SUMMARY_BELOW;
CRM_Utils_Hook::summary($this->_contactId, $content, $contentPlacement);
if ($content) {
$this->assign_by_ref('hookContent', $content);
$this->assign('hookContentPlacement', $contentPlacement);
}
}
/**
* @return string
*/
public function getTemplateFileName() {
if ($this->_contactId) {
$contactSubtypes = $this->get('contactSubtype') ? explode(CRM_Core_DAO::VALUE_SEPARATOR, $this->get('contactSubtype')) : array();
// there could be multiple subtypes. We check templates for each of the subtype, and return the first one found.
foreach ($contactSubtypes as $csType) {
if ($csType) {
$templateFile = "CRM/Contact/Page/View/SubType/{$csType}.tpl";
$template = CRM_Core_Page::getTemplate();
if ($template->template_exists($templateFile)) {
return $templateFile;
}
}
}
}
return parent::getTemplateFileName();
}
/**
* @return array
* @throws \CRM_Core_Exception
*/
public function getTabs() {
$allTabs = [];
$weight = 10;
foreach (CRM_Core_Component::getEnabledComponents() as $name => $component) {
if (!empty($this->_viewOptions[$name]) &&
CRM_Core_Permission::access($component->name)
) {
......@@ -302,14 +336,14 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) {
$q .= "&isTest=1";
}
$allTabs[] = array(
$allTabs[] = [
'id' => $i,
'url' => CRM_Utils_System::url("civicrm/contact/view/$u", $q),
'title' => $elem['title'],
'weight' => $elem['weight'],
'count' => CRM_Contact_BAO_Contact::getCountComponent($u, $this->_contactId),
'class' => 'livePage',
);
];
// make sure to get maximum weight, rest of tabs go after
// FIXME: not very elegant again
if ($weight < $elem['weight']) {
......@@ -318,34 +352,36 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
}
}
$rest = array(
'activity' => array(
$rest = [
'activity' => [
'title' => ts('Activities'),
'class' => 'livePage',
),
'rel' => array(
],
'rel' => [
'title' => ts('Relationships'),
'class' => 'livePage',
),
'group' => array(
],
'group' => [
'title' => ts('Groups'),
'class' => 'ajaxForm',
),
'note' => array(
],
'note' => [
'title' => ts('Notes'),
'class' => 'livePage',
),
'tag' => array(
],
'tag' => [
'title' => ts('Tags'),
),
'log' => array(
],
'log' => [
'title' => ts('Change Log'),
),
);
],
];
// show the tabs only if user has generic access to CiviCRM
$accessCiviCRM = CRM_Core_Permission::check('access CiviCRM');
foreach ($rest as $k => $v) {
if ($accessCiviCRM && !empty($this->_viewOptions[$k])) {
$allTabs[] = $v + array(
$allTabs[] = $v + [
'id' => $k,
'url' => CRM_Utils_System::url(
"civicrm/contact/view/$k",
......@@ -353,7 +389,7 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
),
'weight' => $weight,
'count' => CRM_Contact_BAO_Contact::getCountComponent($k, $this->_contactId),
);
];
$weight += 10;
}
}
......@@ -368,7 +404,7 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
foreach ($activeGroups as $group) {
$id = "custom_{$group['id']}";
$allTabs[] = array(
$allTabs[] = [
'id' => $id,
'url' => CRM_Utils_System::url($group['path'], $group['query'] . "&selectedChild=$id"),
'title' => $group['title'],
......@@ -376,56 +412,25 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
'count' => CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $group['table_name']),
'hideCount' => !$group['is_multiple'],
'class' => 'livePage',
);
];
$weight += 10;
}
$context = array('contact_id' => $this->_contactId);
$context = ['contact_id' => $this->_contactId];
// see if any other modules want to add any tabs
CRM_Utils_Hook::tabs($allTabs, $this->_contactId);
CRM_Utils_Hook::tabset('civicrm/contact/view', $allTabs, $context);
$allTabs[] = array(
$allTabs[] = [
'id' => 'summary',
'url' => '#contact-summary',
'title' => ts('Summary'),
'weight' => 0,
);
];
// now sort the tabs based on weight
usort($allTabs, array('CRM_Utils_Sort', 'cmpFunc'));
$this->assign('allTabs', $allTabs);
// hook for contact summary
// ignored but needed to prevent warnings
$contentPlacement = CRM_Utils_Hook::SUMMARY_BELOW;
CRM_Utils_Hook::summary($this->_contactId, $content, $contentPlacement);
if ($content) {
$this->assign_by_ref('hookContent', $content);
$this->assign('hookContentPlacement', $contentPlacement);
}
}
/**
* @return string
*/
public function getTemplateFileName() {
if ($this->_contactId) {
$contactSubtypes = $this->get('contactSubtype') ? explode(CRM_Core_DAO::VALUE_SEPARATOR, $this->get('contactSubtype')) : array();
// there could be multiple subtypes. We check templates for each of the subtype, and return the first one found.
foreach ($contactSubtypes as $csType) {
if ($csType) {
$templateFile = "CRM/Contact/Page/View/SubType/{$csType}.tpl";
$template = CRM_Core_Page::getTemplate();
if ($template->template_exists($templateFile)) {
return $templateFile;
}
}
}
}
return parent::getTemplateFileName();
usort($allTabs, ['CRM_Utils_Sort', 'cmpFunc']);
return $allTabs;
}
}
......@@ -47,7 +47,7 @@ class CRM_Core_Component {
/**
* @param bool $force
*
* @return array|null
* @return CRM_Core_Component_Info[]
*/
private static function &_info($force = FALSE) {
if (!isset(Civi::$statics[__CLASS__]['info'])|| $force) {
......@@ -84,7 +84,7 @@ class CRM_Core_Component {
/**
* @param bool $force
*
* @return array
* @return CRM_Core_Component_Info[]
* @throws Exception
*/
public static function &getComponents($force = FALSE) {
......@@ -132,7 +132,7 @@ class CRM_Core_Component {
/**
* @param bool $force
*
* @return array|null
* @return CRM_Core_Component_Info[]
*/
static public function &getEnabledComponents($force = FALSE) {
return self::_info($force);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment