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

Simple function extraction

parent c4c5de9c
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 { ...@@ -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'); $lastModified = CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact');
$this->assign_by_ref('lastModified', $lastModified); $this->assign_by_ref('lastModified', $lastModified);
$allTabs = array();
$weight = 10;
$this->_viewOptions = CRM_Core_BAO_Setting::valueOptions( $this->_viewOptions = CRM_Core_BAO_Setting::valueOptions(
CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'contact_view_options', 'contact_view_options',
TRUE TRUE
); );
// show the tabs only if user has generic access to CiviCRM
$accessCiviCRM = CRM_Core_Permission::check('access CiviCRM');
$changeLog = $this->_viewOptions['log']; $changeLog = $this->_viewOptions['log'];
$this->assign_by_ref('changeLog', $changeLog); $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]) && if (!empty($this->_viewOptions[$name]) &&
CRM_Core_Permission::access($component->name) CRM_Core_Permission::access($component->name)
) { ) {
...@@ -302,14 +336,14 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { ...@@ -302,14 +336,14 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) { if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) {
$q .= "&isTest=1"; $q .= "&isTest=1";
} }
$allTabs[] = array( $allTabs[] = [
'id' => $i, 'id' => $i,
'url' => CRM_Utils_System::url("civicrm/contact/view/$u", $q), 'url' => CRM_Utils_System::url("civicrm/contact/view/$u", $q),
'title' => $elem['title'], 'title' => $elem['title'],
'weight' => $elem['weight'], 'weight' => $elem['weight'],
'count' => CRM_Contact_BAO_Contact::getCountComponent($u, $this->_contactId), 'count' => CRM_Contact_BAO_Contact::getCountComponent($u, $this->_contactId),
'class' => 'livePage', 'class' => 'livePage',
); ];
// make sure to get maximum weight, rest of tabs go after // make sure to get maximum weight, rest of tabs go after
// FIXME: not very elegant again // FIXME: not very elegant again
if ($weight < $elem['weight']) { if ($weight < $elem['weight']) {
...@@ -318,34 +352,36 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { ...@@ -318,34 +352,36 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
} }
} }
$rest = array( $rest = [
'activity' => array( 'activity' => [
'title' => ts('Activities'), 'title' => ts('Activities'),
'class' => 'livePage', 'class' => 'livePage',
), ],
'rel' => array( 'rel' => [
'title' => ts('Relationships'), 'title' => ts('Relationships'),
'class' => 'livePage', 'class' => 'livePage',
), ],
'group' => array( 'group' => [
'title' => ts('Groups'), 'title' => ts('Groups'),
'class' => 'ajaxForm', 'class' => 'ajaxForm',
), ],
'note' => array( 'note' => [
'title' => ts('Notes'), 'title' => ts('Notes'),
'class' => 'livePage', 'class' => 'livePage',
), ],
'tag' => array( 'tag' => [
'title' => ts('Tags'), 'title' => ts('Tags'),
), ],
'log' => array( 'log' => [
'title' => ts('Change 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) { foreach ($rest as $k => $v) {
if ($accessCiviCRM && !empty($this->_viewOptions[$k])) { if ($accessCiviCRM && !empty($this->_viewOptions[$k])) {
$allTabs[] = $v + array( $allTabs[] = $v + [
'id' => $k, 'id' => $k,
'url' => CRM_Utils_System::url( 'url' => CRM_Utils_System::url(
"civicrm/contact/view/$k", "civicrm/contact/view/$k",
...@@ -353,7 +389,7 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { ...@@ -353,7 +389,7 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
), ),
'weight' => $weight, 'weight' => $weight,
'count' => CRM_Contact_BAO_Contact::getCountComponent($k, $this->_contactId), 'count' => CRM_Contact_BAO_Contact::getCountComponent($k, $this->_contactId),
); ];
$weight += 10; $weight += 10;
} }
} }
...@@ -368,7 +404,7 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { ...@@ -368,7 +404,7 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
foreach ($activeGroups as $group) { foreach ($activeGroups as $group) {
$id = "custom_{$group['id']}"; $id = "custom_{$group['id']}";
$allTabs[] = array( $allTabs[] = [
'id' => $id, 'id' => $id,
'url' => CRM_Utils_System::url($group['path'], $group['query'] . "&selectedChild=$id"), 'url' => CRM_Utils_System::url($group['path'], $group['query'] . "&selectedChild=$id"),
'title' => $group['title'], 'title' => $group['title'],
...@@ -376,56 +412,25 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { ...@@ -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']), 'count' => CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $group['table_name']),
'hideCount' => !$group['is_multiple'], 'hideCount' => !$group['is_multiple'],
'class' => 'livePage', 'class' => 'livePage',
); ];
$weight += 10; $weight += 10;
} }
$context = array('contact_id' => $this->_contactId); $context = ['contact_id' => $this->_contactId];
// see if any other modules want to add any tabs // see if any other modules want to add any tabs
CRM_Utils_Hook::tabs($allTabs, $this->_contactId); CRM_Utils_Hook::tabs($allTabs, $this->_contactId);
CRM_Utils_Hook::tabset('civicrm/contact/view', $allTabs, $context); CRM_Utils_Hook::tabset('civicrm/contact/view', $allTabs, $context);
$allTabs[] = array( $allTabs[] = [
'id' => 'summary', 'id' => 'summary',
'url' => '#contact-summary', 'url' => '#contact-summary',
'title' => ts('Summary'), 'title' => ts('Summary'),
'weight' => 0, 'weight' => 0,
); ];
// now sort the tabs based on weight // now sort the tabs based on weight
usort($allTabs, array('CRM_Utils_Sort', 'cmpFunc')); usort($allTabs, ['CRM_Utils_Sort', 'cmpFunc']);
return $allTabs;
$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();
} }
} }
...@@ -47,7 +47,7 @@ class CRM_Core_Component { ...@@ -47,7 +47,7 @@ class CRM_Core_Component {
/** /**
* @param bool $force * @param bool $force
* *
* @return array|null * @return CRM_Core_Component_Info[]
*/ */
private static function &_info($force = FALSE) { private static function &_info($force = FALSE) {
if (!isset(Civi::$statics[__CLASS__]['info'])|| $force) { if (!isset(Civi::$statics[__CLASS__]['info'])|| $force) {
...@@ -84,7 +84,7 @@ class CRM_Core_Component { ...@@ -84,7 +84,7 @@ class CRM_Core_Component {
/** /**
* @param bool $force * @param bool $force
* *
* @return array * @return CRM_Core_Component_Info[]
* @throws Exception * @throws Exception
*/ */
public static function &getComponents($force = FALSE) { public static function &getComponents($force = FALSE) {
...@@ -132,7 +132,7 @@ class CRM_Core_Component { ...@@ -132,7 +132,7 @@ class CRM_Core_Component {
/** /**
* @param bool $force * @param bool $force
* *
* @return array|null * @return CRM_Core_Component_Info[]
*/ */
static public function &getEnabledComponents($force = FALSE) { static public function &getEnabledComponents($force = FALSE) {
return self::_info($force); 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