CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

TabbedContentUI.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: TabbedContentUI.php
4 #
5 # Part of the Collection Workflow Integration System (CWIS)
6 # Copyright 2018 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis/
8 #
9
13 class TabbedContentUI
14 {
15 # ---- PUBLIC INTERFACE --------------------------------------------------
16
26 public function BeginTab($TabLabel)
27 {
28 # check to make sure tab label is not a duplicate or already started
29 if (isset($this->CurrentTab[$TabLabel]))
30 {
31 throw new InvalidArgumentException(
32 "Duplicate tab name (\"".$TabLabel."\").");
33 }
34 if ($TabLabel == $this->CurrentTab)
35 {
36 throw new InvalidArgumentException(
37 "Tab \"".$TabLabel."\" already started.");
38 }
39
40 # if another tab is currently started
41 if (isset($this->CurrentTab))
42 {
43 # end current tab
44 $this->EndTab();
45 }
46
47 # set default active tab if no active tab already set
48 if (!isset($this->ActiveTab))
49 {
50 $this->ActiveTab = $TabLabel;
51 }
52
53 # beginning buffering content for new tab
54 $this->CurrentTab = $TabLabel;
55 ob_start();
56 }
57
65 public function EndTab()
66 {
67 # check to make sure tab has been started
68 if (!isset($this->CurrentTab))
69 {
70 throw new Exception("No tab currently in progress.");
71 }
72
73 # stop buffering and save content for tab
74 $this->TabContent[$this->CurrentTab] = ob_get_contents();
75 ob_end_clean();
76
77 # note that no tab is currently under way
78 unset($this->CurrentTab);
79 }
80
86 public function ActiveTab($NewValue = NULL)
87 {
88 if ($NewValue !== NULL)
89 {
90 $this->ActiveTab = $NewValue;
91 }
92 return $this->ActiveTab;
93 }
94
100 public function Display($Id = "cw-tabs")
101 {
102 # if tab is currently started
103 if (isset($this->CurrentTab))
104 {
105 # end current tab
106 $this->EndTab();
107 }
108
109 # check to make sure active tab is valid
110 if (!isset($this->TabContent[$this->ActiveTab]))
111 {
112 throw new Exception("Active tab (.\"".$this->ActiveTab."\") is invalid.");
113 }
114
115 # make sure JavaScript and CSS needed for tabbed interface is loaded
116 $GLOBALS["AF"]->RequireUIFile('jquery-ui.css',
117 ApplicationFramework::ORDER_FIRST);
118 $GLOBALS["AF"]->RequireUIFile('jquery-ui.js');
119
120 # begin tabbed content
121 ?><div class="cw-tab-container"><div id="<?= $Id ?>"><?PHP
122
123 # begin tab navigation
124 ?><ul class="cw-tab-nav">
125 <?PHP
126
127 # for each tab
128 foreach ($this->TabContent as $Label => $Content)
129 {
130 # add navigation for tab
131 $Suffix = self::GetIdSuffix($Label);
132 ?><li><a href="#cw-tabs-<?= $Suffix ?>"><b><?=
133 htmlspecialchars($Label) ?></b></a></li><?PHP
134 }
135
136 # end tab navigation
137 ?></ul>
138 <?PHP
139
140 # for each tab
141 $TabIndex = 0;
142 $ActiveTabIndex = 0;
143 foreach ($this->TabContent as $Label => $Content)
144 {
145 # add content section for tab
146 $Suffix = self::GetIdSuffix($Label);
147 ?><div id="cw-tabs-<?= $Suffix ?>"><?= $Content ?></div>
148 <?PHP
149
150 # if tab is active save tab index for later use
151 if ($Label == $this->ActiveTab)
152 {
153 $ActiveTabIndex = $TabIndex;
154 }
155 $TabIndex++;
156 }
157
158 # end tabbed content
159 ?></div></div><?PHP
160
161 # add JavaScript to select active tab
162 ?><script type='text/javascript'>
163 jQuery(document).ready(function() {
164 jQuery('#<?= $Id ?>').tabs({active: '<?= $ActiveTabIndex ?>'}); });
165 </script><?PHP
166 }
167
168 # ---- PRIVATE INTERFACE -------------------------------------------------
169
170 private $ActiveTab;
171 private $CurrentTab;
172 private $TabContent;
173
179 private static function GetIdSuffix($Text)
180 {
181 return strtolower(preg_replace("/[^a-z]+/i", "", $Text));
182 }
183 }
TabbedContentUI\Display
Display($Id="cw-tabs")
Output HTML for tabbed content.
Definition: TabbedContentUI.php:100
PHP
PHP
Definition: RSSClient--Test.php:12
TabbedContentUI\ActiveTab
ActiveTab($NewValue=NULL)
Get/set tab to be active (i.e.
Definition: TabbedContentUI.php:86
TabbedContentUI\BeginTab
BeginTab($TabLabel)
Begin content for tab.
Definition: TabbedContentUI.php:26
ApplicationFramework\ORDER_FIRST
const ORDER_FIRST
Handle item first (i.e.
Definition: ApplicationFramework.php:2504
TabbedContentUI\EndTab
EndTab()
End current tab.
Definition: TabbedContentUI.php:65
TabbedContentUI
Class to provide a user interface for displaying content in a tabbed format.
Definition: TabbedContentUI.php:13