Mecha CMS

Deep learning on using the API.

Class Elevator

Author: Taufik Nurrohman · 105 Views

Tweet

Navigation item generator.

Table of Content

This class was inspired by a vertical transportation that moves people or goods between floors called Elevator. This class produces some navigation items that can be used to go to the next and previous chunks, step by step, just like navigation buttons in an elevator.

Constructor 

Elevator($input, $chunk = 5, $index = 0, $path = true, $config = [], $NS = "");

Example:

$elevator = new Elevator([0, 1, 2, 3, 4, 5, 6, 7], 3, 0, 'foo/bar');
$elevator_str = $elevator . "";

Result:

$elevator = [
    'up' => null,
    "" => 'foo/bar',
    'down' => 'foo/bar/2'
];
$elevator_str = '<span>▲</span> <a href="foo/bar">◆</a> <a href="foo/bar/2">▼</a>';

To create horizontal elevator:

$elevator = new Elevator([0, 1, 2, 3, 4, 5, 6, 7], 3, 0, 'foo/bar', [
    'direction' => [
       '-1' => 'previous', // ← default is `up`
        '0' => "", // ← default is ``
        '1' => 'next' // ← default is `down`
    ],
    'union' => [
        // previous link
       '-1' => [
            1 => '&#x25C0;' // union content
        ],
        // next link
        '1' => [
            1 => '&#x25B6;'
        ]
    ]
]);

$elevator_str = $elevator . "";

Result:

$elevator = [
    'previous' => null,
    "" => 'foo/bar',
    'next' => 'foo/bar/2'
];
$elevator_str = '<span>◀</span> <a href="foo/bar">◆</a> <a href="foo/bar/2">▶</a>';

Info: For item page elevator, set the $chunk parameter as null and $index parameter by array value you treat as the current item.

$elevator = new Elevator(['foo', 'bar', 'baz'], null, 'bar');

Advance 

->{$property}; // as property
->{$property}($text); // as function

Create custom markup by calling the available properties generated by the constructor:

<nav class="pager">
  <span class="pager-previous"><?php echo $elevator->previous('Previous'); ?></span>
  <span class="pager-next"><?php echo $elevator->next('Next'); ?></span>
</nav>
<nav class="pager">
  <span class="pager-previous">
    <a href="<?php echo $elevator->previous; ?>">Previous</a>
  </span>
  <span class="pager-next">
    <a href="<?php echo $elevator->next; ?>">Next</a>
  </span>
</nav>

Constants 

NameValue
Elevator::HUB
Elevator::NORTH
Elevator::SOUTH
Elevator::WEST
Elevator::EAST

Hooks 

KeyDescription
elevator.{$NS}
elevator.{$NS}.links
elevator.{$NS}.unit

0 Comments

No comments yet.