Introduction

This package is meant to help developers easily build a USSD application which is Operator Agnostic. It is built with PHP with no dependencies needed. The library was made flexible to allow for customization.

Installation and Setup

You can install the package via composer:

composer require cybersai/ussd

If not using composer, you can download the zip folder on github

Usage

Views

Views are classes that help render your USSD output on the mobile phone. USSD views usually include a list or not. This package ships with two abstract view Classes, TemplateView and TemplateListView. These views are rendered in the following format.

TemplateView

Diagram

Template View

Code

use Cybersai\Ussd\Templates\TemplateView;

class MyView extends TemplateView {

    public function __construct($request)
    {
        $this->title = 'Title'; // Optional, Default is an empty string
        $this->content = 'Content';
        $this->footer = 'Footer'; // Optional, Default is an empty string
        $this->next = NextView::class;
        parent::__construct($request);
    }

    function getSectionSeparatorOne()
    {
        // TODO: Implement getSectionSeparatorOne() method.
    }

    function getSectionSeparatorTwo()
    {
        // TODO: Implement getSectionSeparatorTwo() method.
    }
}

Explanation

A class that extends the TemplateView class has the following parameters: title, content, footer and next.

Title: The title of the view. Defaults to an empty string when not specified.

Footer: The footer of the view. Defaults to an empty string when not specified.

Content: The content needs to be specified and should be a string.

Next: The next parameter holds the Name of the next view including the correct path to its location.
Use NextView::class where NextView is the Class of the nextView.

There are two methods you have to implement and both must return a string.

function getSectionSeparatorOne()

This returns the string will separate the title from the content. An Empty String means the title and the content will be cascaded together without a space between them. A String with end of line character i.e. "\n" will leave a blank line between the title and the content.

To avoid making users override the method every time, especially with common logic. Traits that implement those logics have been included. They are:

Sample Usage
use Cybersai\Ussd\Templates\TemplateView;
use Cybersai\Ussd\Modifiers\SectionSeparatorOneDoubleLineBreak;

class MyView extends TemplateView {
use SectionSeparatorOneDoubleLineBreak;

    public function __construct($request)
    {
        $this->title = 'Title'; // Optional, Default is an empty string
        $this->content = 'Content';
        $this->footer = 'Footer'; // Optional, Default is an empty string
        $this->next = NextView::class;
        parent::__construct($request);
    }

    function getSectionSeparatorTwo()
    {
        // TODO: Implement getSectionSeparatorTwo() method.
    }
}
function getSectionSeparatorTwo()

Same as function getSectionSeparatorOne() except the space is between content and footer. Traits to help are:

To Avoid Having to Specify the Two Traits. Predefined Styles are included. They are:

Sample Usage With Styles
use Cybersai\Ussd\Templates\TemplateView;
use Cybersai\Ussd\Styles\NormalTitleWithFooterView;

class MyView extends TemplateView
{
    use NormalTitleWithFooterView;

    public function __construct($request)
    {
        $this->title = 'Title'; // Optional, Default is an empty string
        $this->content = 'Content';
        $this->footer = 'Footer'; // Optional, Default is an empty string
        $this->next = NextView::class;
        parent::__construct($request);
    }
}

TemplateListView

Diagram

Template List View

Code

use Cybersai\Ussd\Templates\TemplateListView

class MyListView extends TemplateListView {

    public function __construct($request)
    {
        $this->title = 'Title';
        $this->sub_title = 'Sub Title';
        $this->content = ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight'];
        $this->sub_footer = 'Sub Footer';
        $this->footer = 'Footer';
        $this->page = $request->getPage();
        $this->number_per_page = 3;
        $this->next = NextView::class;
        parent::__construct($request);
    }

    function getSectionSeparatorOne()
    {
        // TODO: Implement getSectionSeparatorOne() method.
    }

    function getSectionSeparatorTwo()
    {
        // TODO: Implement getSectionSeparatorTwo() method.
    }

    function getSubTitleSeparator()
    {
        // TODO: Implement getSubTitleSeparator() method.
    }

    function getListSeparator()
    {
        // TODO: Implement getListSeparator() method.
    }

    function getNumberingSeparator()
    {
        // TODO: Implement getNumberingSeparator() method.
    }

    function getNumberingForIndex($index)
    {
        // TODO: Implement getNumberingForIndex() method.
    }

    function getListItemForIndex($index)
    {
        // TODO: Implement getListItemForIndex() method.
    }

    function getSubFooterSeparator()
    {
        // TODO: Implement getSubFooterSeparator() method.
    }
}

Explanation

TemplateListView inherits from TemplateView. The method with needs to be implemented are similar to that of TemplateView. Then Extra data in the view are similar to that of TemplateView. Finally, there are modifiers and styles for TemplateListView as well. Just play around and be happy.

Sample Code With Style and Modifiers
use Cybersai\Ussd\Templates\TemplateListView;
use Cybersai\Ussd\Styles\NormalTitledWithFooterView;
use Cybersai\Ussd\Styles\CompactSubTitledWithSubFooterView;
use Cybersai\Ussd\Modifiers\RomanNumericLowerCaseNumbering;
use Cybersai\Ussd\Modifiers\ListSeparatorLineBreak;
use Cybersai\Ussd\Modifiers\NumberingSeparatorBracketPlusSpace;
use Cybersai\Ussd\Modifiers\StringArrayList;

class MyListView extends TemplateListView
{
    use NormalTitleWithFooterView;
    use CompactSubTitleWithSubFooterListView;
    use RomanNumericLowerCaseNumbering;
    use ListSeparatorLineBreak;
    use NumberingSeparatorBracketPlusSpace;
    use StringArrayList;

    public function __construct($request)
    {
        $this->title = 'Title';
        $this->sub_title = 'Sub Title';
        $this->content = ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight'];
        $this->sub_footer = 'Sub Footer';
        $this->footer = 'Footer';
        $this->page = $request->getPage();
        $this->number_per_page = 3;
        parent::__construct($request);
        $this->next = SecondView::class;
    }
}

Enquiries

For enquiries or want help with methods which have not been documented, you can get in touch with me: