3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Helper class to build navigation links
21 class CRM_Campaign_Form_Survey_TabHeader
{
26 * @param CRM_Core_Form $form
30 public static function build(&$form) {
31 $tabs = $form->get('tabHeader');
32 if (!$tabs ||
empty($_GET['reset'])) {
33 $tabs = self
::process($form);
34 $form->set('tabHeader', $tabs);
36 $form->assign_by_ref('tabHeader', $tabs);
37 CRM_Core_Resources
::singleton()
38 ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
41 'active' => self
::getCurrentTab($tabs),
48 * @param CRM_Core_Form $form
52 public static function process(&$form) {
53 if ($form->getVar('_surveyId') <= 0) {
59 'title' => ts('Main Information'),
66 'title' => ts('Questions'),
73 'title' => ts('Results'),
81 $surveyID = $form->getVar('_surveyId');
82 $class = $form->getVar('_name');
83 $class = CRM_Utils_String
::getClassName($class);
84 $class = strtolower($class);
86 if (array_key_exists($class, $tabs)) {
87 $tabs[$class]['current'] = TRUE;
88 $qfKey = $form->get('qfKey');
90 $tabs[$class]['qfKey'] = "&qfKey={$qfKey}";
95 $reset = !empty($_GET['reset']) ?
'reset=1&' : '';
97 foreach ($tabs as $key => $value) {
98 if (!isset($tabs[$key]['qfKey'])) {
99 $tabs[$key]['qfKey'] = NULL;
102 $tabs[$key]['link'] = CRM_Utils_System
::url("civicrm/survey/configure/{$key}",
103 "{$reset}action=update&id={$surveyID}{$tabs[$key]['qfKey']}"
105 $tabs[$key]['active'] = $tabs[$key]['valid'] = TRUE;
112 * @param CRM_Core_Form $form
114 public static function reset(&$form) {
115 $tabs = self
::process($form);
116 $form->set('tabHeader', $tabs);
124 public static function getCurrentTab($tabs) {
125 static $current = FALSE;
131 if (is_array($tabs)) {
132 foreach ($tabs as $subPage => $pageVal) {
133 if ($pageVal['current'] === TRUE) {
140 $current = $current ?
$current : 'main';
149 public static function getNextTab(&$form) {
150 static $next = FALSE;
155 $tabs = $form->get('tabHeader');
156 if (is_array($tabs)) {
158 foreach ($tabs as $subPage => $pageVal) {
163 if ($pageVal['current'] === TRUE) {
169 $next = $next ?
$next : 'main';