2017 © Pedro Peláez
 

library parse-menu

Parse menus from the Wayne State University API

image

waynestate/parse-menu

Parse menus from the Wayne State University API

  • Friday, November 4, 2016
  • by nickdenardis
  • Repository
  • 3 Watchers
  • 0 Stars
  • 11,678 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 13 Versions
  • 7 % Grown

The README.md

ParseMenu Class

Parse menus from the Wayne State University API, (*1)

Latest Stable Version Build Status Total Downloads License, (*2)

Installation

To install this library, run the command below and you will get the latest version, (*3)

composer require waynestate/parse-menu

Usage

Create the object, (*4)

# start.php

use Waynestate\Menuitems\ParseMenu;

...

$parseMenu = new ParseMenu;

Make an API call for the menu, (*5)

# controller.php

try {
    // Pull a specific menu from the API for a site
    $params = array(
        'site_id' => 1,
        'menu_id' => 2,
        'ttl' => TTL,
    );
    $menus = $api->sendRequest('cms.menuitems.listing', $params);

    // Menu config
    $menu_config = array(
        'page_selected' => 1,
    );

    // Get a final array to display the main menu
    $main_menu = $parseMenu->parse($menus[2], $menu_config);

    // Get the breadcrumbs from the parsed menu $main_menu
    $breadcrumbs = array();
    if(count($site_menu['meta']['path']) > 0) {
        $breadcrumbs = $parseMenu->getBreadCrumbs($main_menu);

        // Add the site root crumb
        $root_crumb = [
            'display_name' => 'Home',
            'relative_url' => '/',
        ];
        $breadcrumbs = $parseMenu->prependBreadCrumb($breadcrumbs, $root_crumb);
    }

    // Just display the first level in the header
    $top_menu_config = array(
        'display_levels' => 1,
    );

    // Parse the existing menu with the specific top_menu config
    $top_menu = $parseMenu->parse($main_menu, $top_menu_config);

} catch (Exception $e) {

    echo 'Caught exception: '.  $e->getMessage(). "\n";
}

Return values, (*6)

$main_menu['meta'] = [
    'has_selected' => boolean, // default: false
    'has_submenu' => boolean, // default: false
    'depth' => integer, // default: 0
    'path' => array, // default: array()
]

$main_menu['menu'] = [
    // Array of the menu
]

$breadcrumbs = [
    // Sequential array of individual breadcrumbs in order based on the $main_menu['meta']['path']
]

Config Options, (*7)

'page_selected' = Page ID for selection path (optional)
'skip_levels' = Number of levels to skip from the root (requires page_selected)
'display_levels' = Number of levels to display from the root (requires page_selected, if > 1)
'full_menu' = Return the full menu regardless if there is a page selected (boolean, default: false)
TODO: 'show_levels' = Number of levels to display from the leaf (requires page_selected)
TODO: 'add_home' = Add 'Home' as the first menu item (this may not be needed)

Exceptions, (*8)

InvalidDisplayLevelsException = If 'display_levels' > 1 and no 'page_selected' found

Tests, (*9)

phpunit

Code Coverage, (*10)

phpunit --coverage-html ./coverage

The Versions

04/11 2016

dev-master

9999999-dev http://github.com/waynestate/parse-menu

Parse menus from the Wayne State University API

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser array

04/11 2016

dev-develop

dev-develop http://github.com/waynestate/parse-menu

Parse menus from the Wayne State University API

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser array

04/11 2016

1.2.2

1.2.2.0 http://github.com/waynestate/parse-menu

Parse menus from the Wayne State University API

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser array

10/05 2016

1.2.1

1.2.1.0 http://github.com/waynestate/parse-menu

Parse menus from the Wayne State University API

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser array

09/05 2016

1.2.0

1.2.0.0 http://github.com/waynestate/parse-menu

Parse menus from the Wayne State University API

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser array

17/03 2016

1.1.0

1.1.0.0 http://github.com/waynestate/parse-menu

Parse menus from the Wayne State University API

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser array

19/02 2016

1.0.0

1.0.0.0 http://github.com/waynestate/parse-menu

Parse menus from the Wayne State University API

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser array

15/10 2015

0.2.1

0.2.1.0 http://github.com/waynestate/parse-menu

Parse menus from the Wayne State University API

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser array

28/05 2015

0.2.0

0.2.0.0 http://github.com/waynestate/parse-menu

Parse menus from the Wayne State University API

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser array

19/09 2014

0.1.3

0.1.3.0 http://github.com/waynestate/parse-menu

Parse menus from the Wayne State University API

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser array

14/09 2014

0.1.2

0.1.2.0 http://github.com/waynestate/parse-menu

Parse menus from the Wayne State University API

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser array

13/09 2014

0.1.1

0.1.1.0 http://github.com/waynestate/parse-menu

Parse menus from the Wayne State University API

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser array

12/09 2014

0.1.0

0.1.0.0 http://github.com/waynestate/parse-menu

Parse menus from the Wayne State University API

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

parser array