Odyssey
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
CompassMenu Class Reference
Inheritance diagram for CompassMenu:
CreateMenu

Public Member Functions

 composeCompassMenu ($json_path='', $menu_json='', $append_html='')
 
 singleCompassMenuNode ($json_path='', $menu_json='', $node_id='', $full_node=false)
 
 isCuAndUser ()
 
 isErrorArray ($parent, $child)
 
- Public Member Functions inherited from CreateMenu
 __construct ($HB_ENV=[])
 
 isCuAndUser ()
 
 makeMenu ($params=[])
 
 makeSingleMenuNode ($node_id='', $params=[], $full_node=false)
 

Protected Member Functions

 addHiddenContent ($menu, $append_html='')
 
 setMenuJsonArray ($json='')
 
 setCompassParamsArray ($json_path='')
 
 addUserInfoIcons ()
 
 isUserInfoArrayMembers ($key)
 
 countAllWarnings ()
 
 getArrayCount ($arr)
 
 setBoolFromCount ($key)
 
 setMenuUrl ($key)
 
 setDisplayNum ($key, $max=5)
 
 getNestedTwoDeep ($parent='', $key='')
 
 getNestedThreeDeep ($parent='', $child='', $key='')
 
 isLiveEnvironment ()
 
 isErrorEnableClass ($parent, $child='', $enable_if_error=false)
 
 setAlertDivDisplay ($key)
 
- Protected Member Functions inherited from CreateMenu
 findNode ($node_id)
 
 recursivelyWalkArray ($node_id, $item)
 
 recurseDigArray ($node_id, $sub_array)
 
 setMenuArray ($params=[])
 
 jsonPathParam ($params)
 
 isValidConfig ($arr=[])
 
 setMenuParams ($params=[])
 
 makeMenuHtml ()
 
 createMenuToggleElement ()
 
 walkMenuItems ($items=[])
 
 createElementHtml ($arr=[], $close_tag=true)
 
 getElementId ($element=[])
 
 isAssociativeArray ($arr=[])
 
 hasDisplayValue ($id, $element=[])
 
 hasUserDisplayValue ($id, $display)
 
 openHtmlElement ($element=[])
 
 closeHtmlElement ($element=[])
 
 addIndent ($tag)
 
 addNewLine ($tag)
 
 closeElementOpen ($element=[])
 
 addElementAttributes ($id, $element=[])
 
 translateValuesIfRequired ($attr, $value)
 
 isAttributeMember ($element=[])
 
 addElementClasses ($id, $element=[])
 
 setMemberValue ($id, $value, $key_to_find, $element=[])
 
 setSubValue ($id, $key_to_find, $element=[])
 
 isKeyInArray ($id, $key_to_find, $input_string, $element=[])
 
 isClassMember ($element=[])
 
 addElementContent ($id, $element=[])
 
 userContentOverride ($id)
 
 isContentMember ($element=[])
 
 returnMenuHtml ()
 
 filterInputValue ($value)
 
 composeErrors ()
 
 isErrors ()
 

Protected Attributes

 $compass_params = []
 
 $json_array = []
 
- Protected Attributes inherited from CreateMenu
 $HB_ENV = []
 
 $params = []
 
 $menu_array = []
 
 $menu_html = ''
 
 $errors = []
 

Detailed Description

CompassMenu class

Create the upper right menu in home banking, now called the Compass menu. This concrete exists to customize params both from eternal elements and internal calculations.

See the foot of CreateMenu for usage and documentation.

As an extension no constructor is needed unless you need to do something on startup. :-)

Definition at line 14 of file CompassMenu.php.

Member Function Documentation

◆ addHiddenContent()

CompassMenu::addHiddenContent (   $menu,
  $append_html = '' 
)
protected

A "temporary measure" that may or may not have use in the future. Append the menu with any content we need to add to the DOM It will be wrapped in a hidden div by default.

Parameters
stringHTML $menu
stringHTML $append_html
Returns
string

Definition at line 63 of file CompassMenu.php.

64  {
65  if (empty($append_html)) {
66  return $menu;
67  }
68 
69  return $menu . "
70  <div id=\"compass-append-menu\" style=\"display:none;\">
71  $append_html
72  </div>
73  ";
74 
75  }

◆ addUserInfoIcons()

CompassMenu::addUserInfoIcons ( )
protected

Specialized method just for the user menu. The icons can vary, get what comes from $this->json_array from hcuFunctions.i and use the icon specified by that output.

Returns
$this

Definition at line 193 of file CompassMenu.php.

194  {
195  $icon_ids = [
196  'security' => 'security-expiring-icon',
197  'password' => 'update-password-icon',
198  'email' => 'email-alert-icon'
199  ];
200 
201  foreach ($icon_ids as $key => $icon_id) {
202 
203  if ($this->isUserInfoArrayMembers($key)) {
204 
205  $icon = 'fa-' . $this->json_array['user'][$key]['icon'];
206  $level = $this->json_array['user'][$key]['level'];
207 
208  if (in_array($level, ['warning', 'error'])) {
209 
210  $parent = 'update-' . $key;
211  $parent_class = ($level == 'error')? 'k-error-colored' : 'hcu-warning-color';
212  $this->compass_params['substitute_values']["$parent.attributes.class.$parent_class"] = true;
213  }
214 
215  $this->compass_params['substitute_values']["$icon_id.attributes.class.$icon"] = true;
216  }
217  }
218 
219  return $this;
220  }
isUserInfoArrayMembers($key)

◆ composeCompassMenu()

CompassMenu::composeCompassMenu (   $json_path = '',
  $menu_json = '',
  $append_html = '' 
)

ENTRY POINT. Set up our menu array, send to makeMenu(), and output the HTML. CreateMenu validates the JSON template path.

Parameters
string$json_path
string$menu_json,globaljson data
string$append_html
Returns
string

Definition at line 31 of file CompassMenu.php.

32  {
33  try {
34  $menu = $this
35  ->setMenuJsonArray($menu_json)
36  ->setCompassParamsArray($json_path)
37  ->addUserInfoIcons()
38  ->makeMenu($this->compass_params);
39 
40  return $this->addHiddenContent($menu, $append_html);
41 
42  } catch (Exception $e) {
43  return "<p>Exception creating menu: {$e->getMessage()}</p>";
44  }
45  }
addHiddenContent($menu, $append_html='')
Definition: CompassMenu.php:63

◆ countAllWarnings()

CompassMenu::countAllWarnings ( )
protected

Used only for the top level compass menu.

Returns
int

Definition at line 240 of file CompassMenu.php.

241  {
242  $count = 0;
243 
244  $arr = ['logout', 'activity', 'messages', 'status', 'user'];
245 
246  foreach ($arr as $key) {
247 
248  // Happens on logout for some reason.
249  if (! array_key_exists($key, $this->json_array)) {
250  continue;
251  }
252 
253  $count += $this->getArrayCount($this->json_array[$key]);
254 
255  foreach ($this->json_array[$key] as $value) {
256  if (is_array($value)) {
257 
258  $count += $this->getArrayCount($value);
259  }
260  }
261 
262  }
263 
264  if ($count > 8) {
265  return '9+';
266  }
267 
268  return $count;
269  }
getArrayCount($arr)

◆ getArrayCount()

CompassMenu::getArrayCount (   $arr)
protected
Parameters
$arr
Returns
int

Definition at line 275 of file CompassMenu.php.

276  {
277  if (isset($arr['count'])) {
278  return $arr['count'];
279  }
280 
281  return 0;
282  }

◆ getNestedThreeDeep()

CompassMenu::getNestedThreeDeep (   $parent = '',
  $child = '',
  $key = '' 
)
protected

Reach into a array value nested three deep and return if it exists. These members may not exist, whereas others used here will always exist.

Parameters
string$parent
string$child
string$key
Returns
string|null

Definition at line 355 of file CompassMenu.php.

356  {
357  if (isset($this->json_array[$parent][$child][$key])) {
358 
359  if ($key == 'icon') {
360  return 'fa-' . $this->json_array[$parent][$child][$key];
361  }
362 
363  return $this->json_array[$parent][$child][$key];
364  }
365 
366  return null;
367  }

◆ getNestedTwoDeep()

CompassMenu::getNestedTwoDeep (   $parent = '',
  $key = '' 
)
protected

Reach into an array value nested two deep and return if it exists.

Parameters
string$parent
string$key
Returns
string|null

Definition at line 337 of file CompassMenu.php.

338  {
339  if (isset($this->json_array[$parent][$key])) {
340 
341  return $this->json_array[$parent][$key];
342  }
343 
344  return null;
345  }

◆ isCuAndUser()

CompassMenu::isCuAndUser ( )

If we have no CU and user, no need to output anything.

Returns
bool

Definition at line 81 of file CompassMenu.php.

82  {
83  return (
84  isset($this->HB_ENV['Cu']) &&
85  (strlen($this->HB_ENV['Cu']) > 0) &&
86  isset($this->HB_ENV['Uid']) &&
87  (strlen($this->HB_ENV['Uid']) > 0)
88  );
89 
90  }

◆ isErrorArray()

CompassMenu::isErrorArray (   $parent,
  $child 
)

Helper for above.

Parameters
string$parent
string$child
Returns
array

Definition at line 406 of file CompassMenu.php.

407  {
408  if (
409  isset($this->json_array[$parent]) &&
410  isset($this->json_array[$parent][$child]) &&
411  ! empty ($child)
412  ) {
413  return $this->json_array[$parent][$child];
414  }
415 
416  if (isset($this->json_array[$parent])) {
417  return $this->json_array[$parent];
418  }
419 
420  return [];
421  }

◆ isErrorEnableClass()

CompassMenu::isErrorEnableClass (   $parent,
  $child = '',
  $enable_if_error = false 
)
protected

If there is an error, enable the error class in the menu JSON. A default class that generally always displays unless there is an error sends $enable_if_error = false (disables the class if there is an error: this method returns false.) A normally disabled class that needs to display if there is an error sends $enable_if_error = true (is enabled if there is an error, this method returns true.)

Parameters
string$parent
string$child
bool$enable_if_error
Returns
bool

Definition at line 389 of file CompassMenu.php.

390  {
391  $array = $this->isErrorArray($parent, $child);
392 
393  if (isset($array['level']) && in_array($array['level'], ['warning', 'error'])) {
394  return ($enable_if_error)? true : false;
395  }
396 
397  return ($enable_if_error)? false : true;
398  }
isErrorArray($parent, $child)

◆ isLiveEnvironment()

CompassMenu::isLiveEnvironment ( )
protected

Our method of determining environment.

Returns
bool

Definition at line 373 of file CompassMenu.php.

374  {
375  return $this->HB_ENV['live'];
376  }

◆ isUserInfoArrayMembers()

CompassMenu::isUserInfoArrayMembers (   $key)
protected

Helper for addUserInfoIcons(), check for valid member we need in the input json_array.

Parameters
string$key
Returns
bool

Definition at line 227 of file CompassMenu.php.

228  {
229  return
230  isset($this->json_array['user'][$key]['level']) &&
231  isset($this->json_array['user'][$key]['icon']) &&
232  in_array($this->json_array['user'][$key]['level'], ['info', 'warning', 'error']);
233 
234  }

◆ setAlertDivDisplay()

CompassMenu::setAlertDivDisplay (   $key)
protected

Set whether a given parent div should display.

Parameters
string$key
Returns
bool

Definition at line 428 of file CompassMenu.php.

429  {
430  return isset($this->json_array['user'][$key]) && is_array($this->json_array['user'][$key]);
431  }

◆ setBoolFromCount()

CompassMenu::setBoolFromCount (   $key)
protected

Looks for the key 'count' in array member $key and returns true if > 0

Parameters
string$key
Returns
bool

Definition at line 289 of file CompassMenu.php.

290  {
291  if (! isset($this->json_array[$key]['count'])) {
292  return false;
293  }
294 
295  return ($this->json_array[$key]['count'] > 0)? true : false;
296  }

◆ setCompassParamsArray()

CompassMenu::setCompassParamsArray (   $json_path = '')
protected

Sets the array to inject into the parent makeMenu() method from dynamic external params. It looks complex, but is pretty straightforward. Visualize html elements

Text

Can be referenced with nested dot syntax by **element Id."

'some-div.attributes.class.this' = false // turns OFF "this" class 'somewhere-link.attributes.title' = 'My Title' // populates anchor title 'somewhere-link.attributes.class.the' = false // turns off 'the' class 'somewhere-link.content' = 'Use Meaningful Text' // Exchanges 'Text' for this value

Keys must exist in the JSON structure, they will not be added (in this version) See head of CreateMenu for full documentation.

Parameters
string$json_path,pathto JSON template
Returns
$this

Definition at line 130 of file CompassMenu.php.

131  {
132  $compass_count = $this->countAllWarnings();
133 
134  $this->compass_params = [
135  'json_path' => $json_path,
136  'substitute_values' => [
137  'compass-menu-badge.display' => ($compass_count > 0)? true : false,
138  //'compass-menu-badge.content' => $compass_count,
139  //'compass-menu-badge.content' => '&nbsp;',
140  'user-activity.attributes.class.hcu-navbar-alert' => $this->setBoolFromCount('activity'),
141  'user-activity-link.attributes.href' => $this->setMenuUrl('activity'),
142  'activity-link-text.content' => $this->getNestedTwoDeep('activity', 'display'),
143  'user-activity-badge.display' => $this->setBoolFromCount('activity'),
144  'user-activity-badge.content' => $this->setDisplayNum('activity', 9),
145  'secure-email-item.attributes.class.hcu-navbar-alert' => $this->setBoolFromCount('messages'),
146  'secure-email-link.attributes.href' => $this->setMenuUrl('messages'),
147  'secure-email-link-text.content' => $this->getNestedTwoDeep('messages', 'display'),
148  'secure-email-badge.display' => $this->setBoolFromCount('messages'),
149  'secure-email-badge.content' => $this->setDisplayNum('messages', 9),
150  'user-status.attributes.class.hcu-navbar-alert' => $this->setBoolFromCount('status'),
151  'user-status-badge.display' => $this->setBoolFromCount('status'),
152  'user-status-badge.content' => $this->setDisplayNum('status', 9),
153  'user-status-dropdown-link.attributes.href' => $this->getNestedTwoDeep('status', 'endpoint'),
154  'status-link-text.content' => $this->getNestedTwoDeep('status', 'display'),
155  'failed-login-k-b.attributes.class.hcu-warning-color' => $this->isErrorEnableClass('status', 'fail', true),
156  'failed-login-summary-desc-label.content' => $this->getNestedThreeDeep('status', 'fail', 'title'),
157  'failed-login-summary-desc-p.content' => $this->getNestedThreeDeep('status', 'fail', 'date'),
158  'last-login-summary-desc-label.content' => $this->getNestedThreeDeep('status', 'prior', 'title'),
159  'last-login-summary-value-label.content' => $this->getNestedThreeDeep('status', 'prior', 'date'),
160  'acct-status-summary-desc.display' => $this->isLiveEnvironment(),
161  'acct-status-summary-desc-label.content' => $this->getNestedThreeDeep('status', 'system', 'title'),
162  'acct-status-summary-p.content' => $this->getNestedThreeDeep('status', 'system', 'date'),
163  'user-dropdown.attributes.class.hcu-navbar-alert' => $this->setBoolFromCount('user'),
164  'user-menu-badge.display' => $this->setBoolFromCount('user'),
165  'user-menu-badge.content' => $this->setDisplayNum('user', 9),
166  'user-link-text.content' => $this->getNestedTwoDeep('user', 'display'),
167  'update-password.display' => $this->setAlertDivDisplay('password'),
168  'update-password-icon-block' => $this->getNestedThreeDeep('user', 'password', 'icon'),
169  'update-password-alert-text.content' => $this->getNestedThreeDeep('user', 'password', 'message'),
170  'update-password-link.attributes.href' => $this->getNestedThreeDeep('user', 'password', 'url'),
171  'update-password-link.content' => $this->getNestedThreeDeep('user', 'password', 'link'),
172  'update-security.display' => $this->setAlertDivDisplay('security'),
173  'security-expiring-text.content' => $this->getNestedThreeDeep('user', 'security', 'message'),
174  'update-security-link.attributes.href' => $this->getNestedThreeDeep('user', 'security', 'url'),
175  'update-security-link.content' => $this->getNestedThreeDeep('user', 'security', 'link'),
176  'email-message-p.content' => $this->getNestedThreeDeep('user', 'email', 'message'),
177  'email-message-title.content' => $this->getNestedThreeDeep('user', 'email', 'title'),
178  'update-email-link.attributes.href' => $this->getNestedThreeDeep('user', 'email', 'url'),
179  'update-email-link.content' => $this->getNestedThreeDeep('user', 'email', 'link'),
180  'quicknav-logout-link.attributes.href' => $this->setMenuUrl('logout'),
181  'logout-link-text.content' => $this->getNestedTwoDeep('logout', 'display'),
182  ]
183  ];
184 
185  return $this;
186  }
setMenuUrl($key)
setDisplayNum($key, $max=5)
setAlertDivDisplay($key)
getNestedThreeDeep($parent='', $child='', $key='')
isErrorEnableClass($parent, $child='', $enable_if_error=false)
getNestedTwoDeep($parent='', $key='')
setBoolFromCount($key)

◆ setDisplayNum()

CompassMenu::setDisplayNum (   $key,
  $max = 5 
)
protected

Set a display number for the menus, if > $max output "$max+"

Parameters
string$key
int$max
Returns
string

Definition at line 322 of file CompassMenu.php.

323  {
324  if (! isset($this->json_array[$key]['count'])) {
325  return '0';
326  }
327 
328  return ($this->json_array[$key]['count'] > $max)? $max . '+' : $this->json_array[$key]['count'];
329  }

◆ setMenuJsonArray()

CompassMenu::setMenuJsonArray (   $json = '')
protected

Set the JSON into the internal array.

Parameters
string$json
Exceptions
Exception
Returns
$this

Definition at line 98 of file CompassMenu.php.

99  {
100  $this->json_array = json_decode($json, 1);
101 
102  if ($this->json_array === false) {
103  throw new Exception("Could not decode global JSON array in CompassMenu.");
104  }
105 
106  return $this;
107  }

◆ setMenuUrl()

CompassMenu::setMenuUrl (   $key)
protected

Utility for building a URL from input params.

Parameters
string$key
Returns
string|null

Definition at line 303 of file CompassMenu.php.

304  {
305  if (isset($this->json_array[$key]['url'])) {
306  return $this->json_array[$key]['url'];
307  }
308 
309  if (isset($this->json_array[$key]['script'])) {
310  return "{$this->HB_ENV['loginpath']}/{$this->json_array[$key]['script']}?{$this->HB_ENV['cuquery']}";
311  }
312 
313  return null;
314  }

The documentation for this class was generated from the following file: