poing/ylem

ylem /ˈiːlɛm/ - noun - (in the Big Bang theory) the primordial matter of the universe, originally conceived as composed of neutrons at high temperature and density..

Installs: 60

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 3

Language:CSS

dev-master 2019-05-15 22:46 UTC

README

ylem /ˈiːlɛm/ noun

(in the Big Bang theory) the primordial matter of the universe, originally conceived as composed of neutrons at high temperature and density.

ylem

This is an implementation of the TMF632 Party Management API REST Specification in Laravel. Supporting Individual, Organization, & Organizational Unit relational hierarchies.

composer require poing/ylem
php artisan ylem:seed

Like the primordial substance from which all matter is formed, this is intended as the core application fabric for business and consumer interaction.

Directed Acyclic Graph (DAG)

Topological ordering and directed acyclic graph functions are provided for Laravel Eloquent models by the gazsp/baum package. baum/baum is no longer maintained. While some key functions will be covered in this document, see the complete documentation for additional functions.

The use of the Dijkstras algorithm, to determine the shortest path, is not a necessary consideration of this project. Dijkstras algorithm functionally is not provided by the gazsp/baum package anyway.

Package discovery for gazsp/baum is handled by the extra section of this packages composer.json file. Just to make it easier to use.

Recursive Functions

Recursive functions are important for cyclining through all elements in the tree. This is because the depth of nodes and all decendants will be different. This is the advantage that DAG provides, you're not locked into a strict level of hierarchies.

.
├── alpha
│   └── bravo
│       └── charlie
└── one
    └── two
        └── three
            └── four
                └── five
                    └── six
                        └── seven
                            └── eight
                                └── nine
                                    └── ten
                                        └── eleven
                                            └── twelve

Blade

Below is an example of recursive iteration using the Blade templating engine provided with Laravel. Recursive iteration can be acheived with PHP and other languages too. Generating an unordered list output, similar to the tree shown above.

    function getBlade()  // Function or Route
    {
        $roots = \App\DirectedAcyclicGraph::roots()->get();
        return view('roots', compact('roots'));
    }
<!-- roots.blade.php -->
<ul>
    @foreach ($roots as $item)
        <li>{{ $item->someValue }}</li>
        @include('nodes', array('items' => $item->getImmediateDescendants()))
    @endforeach
</ul>
<!-- nodes.blade.php -->
</ul>
    @foreach ($items as $item)
        <li>{{ $item->someValue }}</li>
        @include('nodes', array('items' => $item->getImmediateDescendants()))
    @endforeach
</ul>

Quick Start

  1. Create a Laravel Project
laravel new project_name
 -or-
composer create-project --prefer-dist laravel/laravel project_name
  1. cd project_name
  2. composer require poing/ylem
  3. Publish the Laravel package
php artisan vendor:publish --provider Ylem\\Providers\\YlemServiceProvider
  1. php artisan migrate
  2. Seed the demo table This could take a while, builds 10 root nodes with random nested itmes.
php artisan db:seed --class=Ylem\\Database\\Seeds\\StubSeeder
  1. Open /ylem in a browser.

Stub Model and Data

You will see the random data associated to Ylem\Models\Stub. This is simply a test table, once seeded, it can be used to examine the relationships. Faker is used to create: Company Name, JOB TITLE, and People Name.

$faker->company
└── strtoupper($faker->jobTitle)
    └── $faker->name

php artisan tinker

Here are some tinker commands to check out:

$node = Ylem\Models\Stub::find(50);
$node->isRoot();            // Checks if root node
$node->getRoot();           // Gets the root node
$node->parent()->get();     // Gets parent node, if not root
$node->siblings()->get();   // Gets siblings, sharing the same parent
$node->children()->get();   // Gets any children for this node