public function table(WorkOrder $workOrder, Inventory $item)
    {
        $stocks = $item->stocks();

        return $this->table->of('work-orders.parts.stocks', function (TableGrid $table) use ($workOrder, $item, $stocks) {
            $table->with($stocks)->paginate($this->perPage);

            $table->column('location', function (Column $column) use ($item) {
                $column->value = function (InventoryStock $stock) use ($item) {
                    $name = $stock->location->trail;

                    return link_to_route('maintenance.inventory.stocks.show', $name, [$item->getKey(), $stock->getKey()]);
                };
            });

            $table->column('quantity');

            $table->column('select', function (Column $column) use ($workOrder, $item) {
                $column->value = function (InventoryStock $stock) use ($workOrder, $item) {
                    $route = 'maintenance.work-orders.parts.stocks.take';

                    $params = [$workOrder->getKey(), $item->getKey(), $stock->getKey()];

                    $attributes = [
                        'class' => 'btn btn-default btn-sm',
                    ];

                    return link_to_route($route, 'Select', $params, $attributes);
                };
            });
        });
    }

Returns a new table of stocks for the specified inventory
item for work order part selection.

@param WorkOrder $workOrder
@param Inventory $item

@return \Orchestra\Contracts\Html\Builder

Returns a new table of stocks for the specified inventory item for work order part selection .


public function formTake(WorkOrder $workOrder, Inventory $inventory, InventoryStock $stock)
    {
        return $this->form->of('work-orders.parts.stocks.take', function (FormGrid $form) use ($workOrder, $inventory, $stock) {
            $form->attributes([
                'method' => 'POST',
                'url'    => route('maintenance.work-orders.parts.stocks.take', [$workOrder->getKey(), $inventory->getKey(), $stock->getKey()]),
            ]);

            $form->submit = 'Save';

            $form->fieldset(function (Fieldset $fieldset) use ($inventory) {
                $metric = $inventory->getMetricSymbol();

                $fieldset
                    ->control('input:text', 'quantity')
                    ->value(0)
                    ->attribute([
                        'placeholder' => "Enter Quantity in $metric",
                    ]);
            });
        });
    }

Returns a new form for taking stock from the specified
inventory for the specified work order.

@param WorkOrder      $workOrder
@param Inventory      $inventory
@param InventoryStock $stock

@return \Orchestra\Contracts\Html\Builder

Returns a new form for taking stock from the specified inventory for the specified work order .


public function formPut(WorkOrder $workOrder, Inventory $inventory, InventoryStock $stock)
    {
        return $this->form->of('work-orders.parts.stocks.put', function (FormGrid $form) use ($workOrder, $inventory, $stock) {
            $form->attributes([
                'method' => 'POST',
                'url'    => route('maintenance.work-orders.parts.stocks.put', [$workOrder->getKey(), $inventory->getKey(), $stock->getKey()]),
            ]);

            $form->submit = 'Save';

            $form->fieldset(function (Fieldset $fieldset) use ($inventory, $stock) {
                $metric = $inventory->getMetricSymbol();

                $fieldset
                    ->control('input:text', 'quantity', function (Field $field) {
                        $field->label = 'Return Quantity';
                    })
                    ->value($stock->pivot->quantity)
                    ->attribute([
                        'placeholder' => "Enter Quantity in $metric",
                    ]);
            });
        });
    }

Returns a new form for putting the stock from the
specified work order back into inventory.

@param WorkOrder      $workOrder
@param Inventory      $inventory
@param InventoryStock $stock

@return \Orchestra\Contracts\Html\Builder

Returns a new form for putting the stock from the specified work order back into inventory .


public function destroy($id)
    {
        if ($this->processor->destroy($id)) {
            flash()->success('Success!', 'Successfully deleted inventory item.');

            return redirect()->route('maintenance.inventory.index');
        } else {
            flash()->error('Error!', 'There was an issue deleting this inventory item. Please try again.');

            return redirect()->route('maintenance.inventory.show', [$id]);
        }
    }

Deletes the specified inventory item.

@param int|string $id

@return \Illuminate\Http\RedirectResponse


public function create($title, $message, $level = 'info', $key = 'flash_message')
    {
        $timer = $this->timer;

        session()->flash($key, compact('title', 'message', 'level', 'info', 'timer'));
    }

public function create ( $ title , $ message , $ level = 'info' , $ key = 'flash_message' ) { $ timer = $ this -> timer ; session ( ) -> flash ( $ key , compact ( 'title' , 'message' , 'level' , 'info' , 'timer' ) ) ; }

Generates a new session flash message.

@param string $title
@param string $message
@param string $level
@param string $key


public function create($workOrderId)
    {
        try {
            return $this->processor->create($workOrderId);
        } catch (ReportExistsException $e) {
            flash()->error('Error!', 'This work order already has already been completed.');

            return redirect()->route('maintenance.work-orders.show', [$workOrderId]);
        }
    }

Displays the form for creating a report
for the specified work order.

@param int|string $workOrderId

@return \Illuminate\View\View

Displays the form for creating a report for the specified work order .


public function store(ReportRequest $request, $workOrderId)
    {
        if ($this->processor->store($request, $workOrderId)) {
            flash()->success('Success!', 'Successfully created work order report.');

            return redirect()->route('maintenance.work-orders.show', [$workOrderId]);
        } else {
            flash()->error('Error!', 'There was an issue creating a work order report. Please try again');

            return redirect()->route('maintenance.work-orders.report.create', [$workOrderId]);
        }
    }

Creates a new report for the specified work order.

@param ReportRequest $request
@param int|string    $workOrderId

@return \Illuminate\Http\RedirectResponse

Creates a new report for the specified work order .


public function index($resourceId)
    {
        $routes = $this->routes;

        $eventable = $this->getEventableRepository()->model()->findOrFail($resourceId);

        return view('events.eventables.index', compact('eventable', 'routes'));
    }

public function index ( $ resourceId ) { $ routes = $ this -> routes ; $ eventable = $ this -> getEventableRepository ( ) -> model ( ) -> findOrFail ( $ resourceId ) ; return view ( 'events.eventables.index' , compact ( 'eventable' , 'routes' ) ) ; }

Displays all of the specified eventables events.

@param int|string $resourceId

@return \Illuminate\View\View

Displays all of the specified eventables events .


public function store(EventRequest $request, $resourceId)
    {
        $eventable = $this->getEventableRepository()->model()->findOrFail($resourceId);

        $event = $this->event->create($request);

        if ($event && method_exists($eventable, 'events')) {
            $eventable->events()->attach($event->id);

            $message = 'Successfully created event.';

            return redirect()->route($this->routes['index'], $eventable->id)->withSuccess($message);
        } else {
            $message = 'There was an issue creating an event. Please try again.';

            return redirect()->route($this->routes['create'])->withErrors($message);
        }
    }

Creates a new event and attaches it to the specified eventable.

@param EventRequest $request
@param int|string   $resourceId

@return \Illuminate\Http\RedirectResponse

Creates a new event and attaches it to the specified eventable .


public function show($resourceId, $eventId)
    {
        $routes = $this->routes;

        $eventable = $this->getEventableRepository()->model()->findOrFail($resourceId);

        if (method_exists($eventable, 'events')) {
            $event = $eventable->events()->find($eventId);

            if ($event) {
                $apiObject = $this->event->findApiObject($event->api_id);

                return view('events.eventables.show', compact('routes', 'eventable', 'event', 'apiObject'));
            }
        }

        abort(404);
    }

public function show ( $ resourceId , $ eventId ) { $ routes = $ this -> routes ; $ eventable = $ this -> getEventableRepository ( ) -> model ( ) -> findOrFail ( $ resourceId ) ; if ( method_exists ( $ eventable , 'events' ) ) { $ event = $ eventable -> events ( ) -> find ( $ eventId ) ; if ( $ event ) { $ apiObject = $ this -> event -> findApiObject ( $ event -> api_id ) ; return view ( 'events.eventables.show' , compact ( 'routes' , 'eventable' , 'event' , 'apiObject' ) ) ; } } abort ( 404 ) ; }

Displays the specified event attached to the specified eventable.

@param int|string $resourceId
@param int|string $eventId

@return \Illuminate\View\View

Displays the specified event attached to the specified eventable .


public function update(EventRequest $request, $resourceId, $eventId)
    {
        $eventable = $this->getEventableRepository()->model()->findOrFail($resourceId);

        $event = $this->event->update($request, $eventId);

        if ($event) {
            $message = 'Successfully updated event.';

            return redirect()->route($this->routes['show'], [$eventable->id, $event->id])->withSuccess($message);
        } else {
            $message = 'There was an issue updating this event. Please try again.';

            return redirect()->route($this->routes['edit'], [$eventable->id])->withErrors($message);
        }
    }

Updates the specified event attached to the specified eventable.

@param EventRequest $request
@param int|string   $resourceId
@param int|string   $eventId

@return \Illuminate\Http\RedirectResponse

Updates the specified event attached to the specified eventable .


public function destroy($resourceId, $eventId)
    {
        $eventable = $this->getEventableRepository()->model()->findOrFail($resourceId);

        if (method_exists($eventable, 'events')) {
            $event = $eventable->events()->find($eventId);

            if ($event && $this->event->delete($event->id)) {
                $message = 'Successfully deleted event.';

                return redirect()->route($this->routes['index'], $eventable->id)->withSuccess($message);
            } else {
                $message = 'There was an issue deleting this event. Please try again.';

                return redirect()->route($this->routes['show'], $eventable->id, $event->id)->withErrors($message);
            }
        }

        abort(404);
    }

Deletes the specified event attached to the specified eventable.

@param int|string $resourceId
@param int|string $eventId

@return \Illuminate\Http\RedirectResponse

Deletes the specified event attached to the specified eventable .


public function scopeCategory($query, $categoryId = null)
    {
        if ($categoryId) {
            // Get descendants and self inventory category nodes
            $categories = Category::find($categoryId)->getDescendantsAndSelf();

            // Perform a sub-query on main query
            $query->where(function ($query) use ($categories) {
                // For each category, apply a orWhere query to the sub-query
                foreach ($categories as $category) {
                    $query->orWhere('category_id', $category->id);
                }
            });
        }

        return $query;
    }

Filters results by specified category.

@param mixed      $query
@param int|string $categoryId

@return mixed


public function form()
    {
        return $this->form->of('label', function (FormGrid $form) {
            $form->attributes(['url' => route('maintenance.login.index')]);

            $form->submit = 'Sign In';

            $form->fieldset(function (Fieldset $fieldset) {
                $fieldset->control('input:text', 'email')
                    ->label('Email')
                    ->attributes(['placeholder' => 'Enter your Email']);

                $fieldset->control('input:password', 'password')
                    ->label('Password')
                    ->attributes(['placeholder' => 'Enter your Password']);
            });
        });
    }

public
function
form
(
)
{
return
$
this
->
form
->
of
(
'label'
,
function
(
FormGrid
$
form
)
{
$
form
->
attributes
(
[
'url'
=>
route
(
'maintenance.login.index'
)
]
)
;
$
form
->
submit
=
'Sign In'
;
$
form
->
fieldset
(
function
(
Fieldset
$
fieldset
)
{
$
fieldset
->
control
(
'input:text'
,
'email'
)
->
label
(
'Email'
)
->
attributes
(
[
'placeholder'
=>
'Enter your Email'
]
)
;
$
fieldset
->
control
(
'input:password'
,
'password'
)
->
label
(
'Password'
)
->
attributes
(
[
'placeholder'
=>
'Enter your Password'
]
)
;
}
)
;
}
)
;
}

Returns a form for the login page.

@return \Orchestra\Contracts\Html\Builder


public function store(ManualRequest $request, $id)
    {
        $asset = $this->asset->find($id);

        $attachments = $this->manual->upload($request, $asset, $asset->manuals());

        if ($attachments) {
            $message = 'Successfully uploaded files.';

            return redirect()->route('maintenance.assets.manuals.index', [$asset->id])->withSuccess($message);
        } else {
            $message = 'There was an issue uploading the files you selected. Please try again.';

            return redirect()->route('maintenance.assets.manuals.create', [$id])->withErrors($message);
        }
    }

Uploads manuals and attaches them to the specified asset.

@param ManualRequest $request
@param int|string    $id

@return \Illuminate\Http\RedirectResponse

Uploads manuals and attaches them to the specified asset .


public function show($id, $manualId)
    {
        $asset = $this->asset->find($id);

        $manual = $asset->manuals()->find($manualId);

        if ($manual) {
            return view('assets.manuals.show', compact('asset', 'manual'));
        }

        abort(404);
    }

public function show ( $ id , $ manualId ) { $ asset = $ this -> asset -> find ( $ id ) ; $ manual = $ asset -> manuals ( ) -> find ( $ manualId ) ; if ( $ manual ) { return view ( 'assets.manuals.show' , compact ( 'asset' , 'manual' ) ) ; } abort ( 404 ) ; }

Displays the asset manual.

@param int|string $id
@param int|string $manualId

@return \Illuminate\View\View


public function update(AttachmentUpdateRequest $request, $id, $manualId)
    {
        $asset = $this->asset->find($id);

        $manual = $this->manual->update($request, $asset->manuals(), $manualId);

        if ($manual) {
            $message = 'Successfully updated manual.';

            return redirect()->route('maintenance.assets.manuals.show', [$asset->id, $manual->id])->withSuccess($message);
        } else {
            $message = 'There was an issue updating this manual. Please try again.';

            return redirect()->route('maintenance.assets.manuals.show', [$id, $manualId])->withErrors($message);
        }
    }

Updates the specified asset manual upload.

@param AttachmentUpdateRequest $request
@param int|string              $id
@param int|string              $manualId

@return \Illuminate\Http\RedirectResponse

Updates the specified asset manual upload .


public function store($assetId, $workOrderId)
    {
        if ($this->asset->attachWorkOrder($assetId, $workOrderId)) {
            $message = 'Successfully attached work order.';

            return redirect()->route('maintenance.assets.work-orders.index', [$assetId])->withSuccess($message);
        } else {
            $message = 'There was an issue attaching this work order. Please try again.';

            return redirect()->route('maintenance.assets.work-orders.attach.index', [$assetId])->withErrors($message);
        }
    }

Attaches the specified work order to the specified asset.

@param int|string $assetId
@param int|string $workOrderId

@return \Illuminate\Http\RedirectResponse

Attaches the specified work order to the specified asset .


public function remove($assetId, $workOrderId)
    {
        if ($this->asset->detachWorkOrder($assetId, $workOrderId)) {
            $message = 'Successfully detached work order.';

            return redirect()->route('maintenance.assets.work-orders.index', [$assetId])->withSuccess($message);
        } else {
            $message = 'There was an issue detaching this work order. Please try again.';

            return redirect()->route('maintenance.assets.work-orders.index', [$assetId])->withErrors($message);
        }
    }

Removes the specified work order from the specified asset.

@param int|string $assetId
@param int|string $workOrderId

@return \Illuminate\Http\RedirectResponse

Removes the specified work order from the specified asset .


public function store($workRequestId)
    {
        if ($this->updateValidator->passes()) {
            $workRequest = $this->workRequest->find($workRequestId);

            $update = $this->update->setInput($this->inputAll())->create();

            $this->workRequest->saveUpdate($workRequest, $update);

            $this->message = 'Successfully added update';
            $this->messageType = 'success';
            $this->redirect = routeBack('maintenance.work-requests.show', [$workRequest->id]);
        } else {
            $this->errors = $this->updateValidator->getErrors();
            $this->redirect = routeBack('maintenance.work-requests.show', [$workRequestId]);
        }

        return $this->response();
    }

public
function
store
(
$
workRequestId
)
{
if
(
$
this
->
updateValidator
->
passes
(
)
)
{
$
workRequest
=
$
this
->
workRequest
->
find
(
$
workRequestId
)
;
$
update
=
$
this
->
update
->
setInput
(
$
this
->
inputAll
(
)
)
->
create
(
)
;
$
this
->
workRequest
->
saveUpdate
(
$
workRequest
,
$
update
)
;
$
this
->
message
=
'Successfully added update'
;
$
this
->
messageType
=
'success'
;
$
this
->
redirect
=
routeBack
(
'maintenance.work-requests.show'
,
[
$
workRequest
->
id
]
)
;
}
else
{
$
this
->
errors
=
$
this
->
updateValidator
->
getErrors
(
)
;
$
this
->
redirect
=
routeBack
(
'maintenance.work-requests.show'
,
[
$
workRequestId
]
)
;
}
return
$
this
->
response
(
)
;
}

Creates a new work order customer update.

@param int $workRequestId

@return mixed

Creates a new work order customer update .


public function destroy($workRequestId, $updateId)
    {
        $workRequest = $this->workRequest->find($workRequestId);

        if ($this->update->destroy($updateId)) {
            $this->message = 'Successfully deleted update';
            $this->messageType = 'success';
            $this->redirect = route('maintenance.work-requests.show', [$workRequest->id, '#tab_updates']);
        } else {
            $this->message = 'There was an error trying to delete this update. Please try again.';
            $this->messageType = 'danger';
            $this->redirect = route('maintenance.work-requests.show', [$workRequest->id, '#tab_updates']);
        }

        return $this->response();
    }

Processes deleting a work order update.

@param $workRequestId
@param $updateId

@return \Illuminate\Http\JsonResponse|mixed

Processes deleting a work order update .


public function index($workOrderId, $itemId)
    {
        $workOrder = $this->workOrder->findOrFail($workOrderId);

        $item = $this->inventory->findOrFail($itemId);

        $stocks = $this->presenter->table($workOrder, $item);

        $variants = $this->presenter->tableVariants($workOrder, $item);

        return view('work-orders.parts.stocks.index', compact('stocks', 'variants'));
    }

public function index ( $ workOrderId , $ itemId ) { $ workOrder = $ this -> workOrder -> findOrFail ( $ workOrderId ) ; $ item = $ this -> inventory -> findOrFail ( $ itemId ) ; $ stocks = $ this -> presenter -> table ( $ workOrder , $ item ) ; $ variants = $ this -> presenter -> tableVariants ( $ workOrder , $ item ) ; return view ( 'work-orders.parts.stocks.index' , compact ( 'stocks' , 'variants' ) ) ; }

Displays all stocks and variants available for selection.

@param int|string $workOrderId
@param int|string $itemId

@return \Illuminate\View\View

Displays all stocks and variants available for selection .


public function getTake($workOrderId, $itemId, $stockId)
    {
        $workOrder = $this->workOrder->findOrFail($workOrderId);

        $item = $this->inventory->findOrFail($itemId);

        $stock = $item->stocks()->findOrFail($stockId);

        $form = $this->presenter->formTake($workOrder, $item, $stock);

        return view('work-orders.parts.stocks.take', compact('workOrder', 'item', 'stock', 'form'));
    }

public function getTake ( $ workOrderId , $ itemId , $ stockId ) { $ workOrder = $ this -> workOrder -> findOrFail ( $ workOrderId ) ; $ item = $ this -> inventory -> findOrFail ( $ itemId ) ; $ stock = $ item -> stocks ( ) -> findOrFail ( $ stockId ) ; $ form = $ this -> presenter -> formTake ( $ workOrder , $ item , $ stock ) ; return view ( 'work-orders.parts.stocks.take' , compact ( 'workOrder' , 'item' , 'stock' , 'form' ) ) ; }

Displays the form for taking inventory for the specified work order.

@param int|string $workOrderId
@param int|string $itemId
@param int|string $stockId

@return \Illuminate\View\View

Displays the form for taking inventory for the specified work order .


public function postTake(PartTakeRequest $request, $workOrderId, $itemId, $stockId)
    {
        $workOrder = $this->workOrder->findOrFail($workOrderId);

        $item = $this->inventory->findOrFail($itemId);

        $stock = $item->stocks()->findOrFail($stockId);

        return $this->dispatch(new Take($request, $workOrder, $stock));
    }

public function postTake ( PartTakeRequest $ request , $ workOrderId , $ itemId , $ stockId ) { $ workOrder = $ this -> workOrder -> findOrFail ( $ workOrderId ) ; $ item = $ this -> inventory -> findOrFail ( $ itemId ) ; $ stock = $ item -> stocks ( ) -> findOrFail ( $ stockId ) ; return $ this -> dispatch ( new Take ( $ request , $ workOrder , $ stock ) ) ; }

Processes taking inventory for the specified work order.

@param PartTakeRequest $request
@param int|string      $workOrderId
@param int|string      $itemId
@param int|string      $stockId

@throws \Stevebauman\Inventory\Exceptions\InvalidQuantityException
@throws \Stevebauman\Inventory\Exceptions\NotEnoughStockException

@return bool

Processes taking inventory for the specified work order .


public function getPut($workOrderId, $itemId, $stockId)
    {
        $workOrder = $this->workOrder->findOrFail($workOrderId);

        $item = $this->inventory->findOrFail($itemId);

        $stock = $workOrder->parts()->findOrFail($stockId);

        $form = $this->presenter->formPut($workOrder, $item, $stock);

        return view('work-orders.parts.stocks.put', compact('workOrder', 'item', 'stock', 'form'));
    }

public function getPut ( $ workOrderId , $ itemId , $ stockId ) { $ workOrder = $ this -> workOrder -> findOrFail ( $ workOrderId ) ; $ item = $ this -> inventory -> findOrFail ( $ itemId ) ; $ stock = $ workOrder -> parts ( ) -> findOrFail ( $ stockId ) ; $ form = $ this -> presenter -> formPut ( $ workOrder , $ item , $ stock ) ; return view ( 'work-orders.parts.stocks.put' , compact ( 'workOrder' , 'item' , 'stock' , 'form' ) ) ; }

Displays the form for putting inventory from the
work order back into the specified stock.

@param int|string $workOrderId
@param int|string $itemId
@param int|string $stockId

@return \Illuminate\View\View

Displays the form for putting inventory from the work order back into the specified stock .


public function postPut(PartReturnRequest $request, $workOrderId, $itemId, $stockId)
    {
        $workOrder = $this->workOrder->findOrFail($workOrderId);

        // Even though the inventory item isn't necessary here, we'll
        // find it anyway so we can check for the requests validity
        // and ensure the specified stock is actually attached to
        // the one requested.
        $item = $this->inventory->findOrFail($itemId);

        $item->stocks()->findOrFail($stockId);

        $stock = $workOrder->parts()->findOrFail($stockId);

        return $this->dispatch(new Put($request, $workOrder, $stock));
    }

Processes returning stock from the work order back into the specified inventory.

@param PartReturnRequest $request
@param int|string        $workOrderId
@param int|string        $itemId
@param int|string        $stockId

@throws \Stevebauman\Inventory\Exceptions\InvalidQuantityException

@return bool

Processes returning stock from the work order back into the specified inventory .


public function index()
    {
        $workRequests = $this->presenter->table($this->workRequest);

        $navbar = $this->presenter->navbar();

        return view('work-requests.index', compact('workRequests', 'navbar'));
    }

public function index ( ) { $ workRequests = $ this -> presenter -> table ( $ this -> workRequest ) ; $ navbar = $ this -> presenter -> navbar ( ) ; return view ( 'work-requests.index' , compact ( 'workRequests' , 'navbar' ) ) ; }

Displays all work requests.

@return \Illuminate\View\View


public function edit($id)
    {
        $workRequest = $this->workRequest->findOrFail($id);

        $form = $this->presenter->form($workRequest);

        return view('work-requests.edit', compact('form'));
    }

public function edit ( $ id ) { $ workRequest = $ this -> workRequest -> findOrFail ( $ id ) ; $ form = $ this -> presenter -> form ( $ workRequest ) ; return view ( 'work-requests.edit' , compact ( 'form' ) ) ; }

Displays the form for editing the specified work request.

@param int|string $id

@return \Illuminate\View\View

Displays the form for editing the specified work request .


public function update(WorkHttpRequest $request, $id)
    {
        $workRequest = $this->workRequest->findOrFail($id);

        return $this->dispatch(new Update($request, $workRequest));
    }

public function update ( WorkHttpRequest $ request , $ id ) { $ workRequest = $ this -> workRequest -> findOrFail ( $ id ) ; return $ this -> dispatch ( new Update ( $ request , $ workRequest ) ) ; }

Updates the specified work request.

@param WorkHttpRequest $request
@param int|string      $id

@return bool


public function create($id = null)
    {
        // If an ID is supplied then we're creating a child category
        if ($id) {
            $category = $this->repository->find($id);

            if ($category) {
                return view('categories.nodes.create', [
                    'category' => $category,
                    'resource' => $this->resource,
                    'routes'   => $this->routes,
                ]);
            }
        }

        return view('categories.create', [
            'resource' => $this->resource,
            'routes'   => $this->routes,
        ]);
    }

Shows the form for creating a new category
or category node if an ID is supplied.

@param int|string $id

@return \Illuminate\View\View

Shows the form for creating a new category or category node if an ID is supplied .


public function store(CategoryRequest $request, $id = null)
    {
        $category = $this->repository->create($request, $id);

        if ($category) {
            $message = "Successfully created $this->resource";

            return redirect()->route($this->routes['index'])->withSuccess($message);
        } else {
            $message = "There was an issue creating a $this->resource. Please try again.";

            return redirect()->route($this->routes['create'], $id)->withErrors($message);
        }
    }

Processes storing a new category or storing a new category
underneath another if an ID is specified.

@param CategoryRequest $request
@param int|string      $id

@return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse

Processes storing a new category or storing a new category underneath another if an ID is specified .


public function edit($id)
    {
        $category = $this->repository->find($id);

        return view('categories.edit', [
            'category' => $category,
            'resource' => $this->resource,
            'routes'   => $this->routes,
        ]);
    }

public function edit ( $ id ) { $ category = $ this -> repository -> find ( $ id ) ; return view ( 'categories.edit' , [ 'category' => $ category , 'resource' => $ this -> resource , 'routes' => $ this -> routes , ] ) ; }

Show the form for editing the specified category.

@param int|string $id

@return \Illuminate\View\View

Show the form for editing the specified category .


public function update(CategoryRequest $request, $id)
    {
        $category = $this->repository->update($request, $id);

        if ($category) {
            $message = "Successfully updated $this->resource";

            return redirect()->route($this->routes['index'])->withSuccess($message);
        } else {
            $message = "There was an issue updating this $this->resource. Please try again.";

            return redirect()->route($this->routes['edit'], $id)->withErrors($message);
        }
    }

Processes updating the specified category.

@param CategoryRequest $request
@param int|string      $id

@return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse

Processes updating the specified category .


public function destroy($id)
    {
        $record = $this->repository->find($id);

        if ($record->delete()) {
            $message = "Successfully deleted $this->resource.";

            return redirect()->route($this->routes['index'])->withSuccess($message);
        } else {
            $message = "There was an issue deleting this $this->resource. Please try again.";

            return redirect()->route($this->routes['index'])->withErrors($message);
        }
    }

Processes removing the specified category.

@param int|string $id

@return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse

Processes removing the specified category .


public function table(WorkOrder $workOrder)
    {
        $sessions = $workOrder->sessions();

        return $this->table->of('work-orders.sessions', function (TableGrid $table) use ($sessions) {
            $table->with($sessions)->paginate($this->perPage);

            $table->attributes([
                'class' => 'table table-hover table-striped',
            ]);

            $table->column('user', function (Column $column) {
                $column->value = function (WorkOrderSession $session) {
                    return $session->user->fullname;
                };
            });

            $table->column('Hours', function (Column $column) {
                $column->value = function (WorkOrderSession $session) {
                    return $session->getHours();
                };
            });

            $table->column('in');

            $table->column('out', function (Column $column) {
                $column->value = function (WorkOrderSession $session) {
                    return $session->getOutLabel();
                };
            });
        });
    }

public
function
table
(
WorkOrder
$
workOrder
)
{
$
sessions
=
$
workOrder
->
sessions
(
)
;
return
$
this
->
table
->
of
(
'work-orders.sessions'
,
function
(
TableGrid
$
table
)
use
(
$
sessions
)
{
$
table
->
with
(
$
sessions
)
->
paginate
(
$
this
->
perPage
)
;
$
table
->
attributes
(
[
'class'
=>
'table table-hover table-striped'
,
]
)
;
$
table
->
column
(
'user'
,
function
(
Column
$
column
)
{
$
column
->
value
=
function
(
WorkOrderSession
$
session
)
{
return
$
session
->
user
->
fullname
;
}
;
}
)
;
$
table
->
column
(
'Hours'
,
function
(
Column
$
column
)
{
$
column
->
value
=
function
(
WorkOrderSession
$
session
)
{
return
$
session
->
getHours
(
)
;
}
;
}
)
;
$
table
->
column
(
'in'
)
;
$
table
->
column
(
'out'
,
function
(
Column
$
column
)
{
$
column
->
value
=
function
(
WorkOrderSession
$
session
)
{
return
$
session
->
getOutLabel
(
)
;
}
;
}
)
;
}
)
;
}

Returns a new table of all work order sessions.

@param WorkOrder $workOrder

@return \Orchestra\Contracts\Html\Builder

Returns a new table of all work order sessions .


public function tablePerWorker(WorkOrder $workOrder)
    {
        $sessions = $workOrder->getUniqueSessions();

        return $this->table->of('work-orders.sessions.per-worker', function (TableGrid $table) use ($sessions) {
            $table->with($sessions);

            $table->attributes([
                'class' => 'table table-hover table-striped',
            ]);

            $table->column('worker', function (Column $column) {
                $column->value = function (WorkOrderSession $session) {
                    return $session->user->fullname;
                };
            });

            $table->column('total_hours', function (Column $column) {
                $column->value = function (WorkOrderSession $session) {
                    return $session->total_hours;
                };
            });
        });
    }

public
function
tablePerWorker
(
WorkOrder
$
workOrder
)
{
$
sessions
=
$
workOrder
->
getUniqueSessions
(
)
;
return
$
this
->
table
->
of
(
'work-orders.sessions.per-worker'
,
function
(
TableGrid
$
table
)
use
(
$
sessions
)
{
$
table
->
with
(
$
sessions
)
;
$
table
->
attributes
(
[
'class'
=>
'table table-hover table-striped'
,
]
)
;
$
table
->
column
(
'worker'
,
function
(
Column
$
column
)
{
$
column
->
value
=
function
(
WorkOrderSession
$
session
)
{
return
$
session
->
user
->
fullname
;
}
;
}
)
;
$
table
->
column
(
'total_hours'
,
function
(
Column
$
column
)
{
$
column
->
value
=
function
(
WorkOrderSession
$
session
)
{
return
$
session
->
total_hours
;
}
;
}
)
;
}
)
;
}

Displays unique sessions per worker and totals their hours.

@param WorkOrder $workOrder

@return \Orchestra\Contracts\Html\Builder

Displays unique sessions per worker and totals their hours .


public function deleted(Inventory $model)
    {
        $stocks = $model->stocks()->get();

        if (count($stocks) > 0) {
            foreach ($stocks as $stock) {
                $stock->delete();
            }
        }
    }

public function deleted ( Inventory $ model ) { $ stocks = $ model -> stocks ( ) -> get ( ) ; if ( count ( $ stocks ) > 0 ) { foreach ( $ stocks as $ stock ) { $ stock -> delete ( ) ; } } }

Captures the Inventory models deleted event
and cascades the delete to all of it's stocks.

@param Inventory $model

Captures the Inventory models deleted event and cascades the delete to all of it s stocks .


public function restored(Inventory $model)
    {
        $stocks = $model->stocks()->onlyTrashed()->get();

        if (count($stocks) > 0) {
            foreach ($stocks as $stock) {
                $stock->restore();
            }
        }
    }

public function restored ( Inventory $ model ) { $ stocks = $ model -> stocks ( ) -> onlyTrashed ( ) -> get ( ) ; if ( count ( $ stocks ) > 0 ) { foreach ( $ stocks as $ stock ) { $ stock -> restore ( ) ; } } }

Captures the Inventory models restored event
and cascades the restore to all of it's stocks.

@param Inventory $model

Captures the Inventory models restored event and cascades the restore to all of it s stocks .


public function index()
    {
        $inventory = $this->presenter->tableNoVariants($this->inventory);

        $navbar = $this->presenter->navbar();

        return view('inventory.index', compact('inventory', 'navbar'));
    }

public function index ( ) { $ inventory = $ this -> presenter -> tableNoVariants ( $ this -> inventory ) ; $ navbar = $ this -> presenter -> navbar ( ) ; return view ( 'inventory.index' , compact ( 'inventory' , 'navbar' ) ) ; }

Displays all inventory items.

@return \Illuminate\View\View


public function store(InventoryRequest $request)
    {
        $item = $this->inventory->newInstance();

        return $this->dispatch(new Store($request, $item));
    }

public function store ( InventoryRequest $ request ) { $ item = $ this -> inventory -> newInstance ( ) ; return $ this -> dispatch ( new Store ( $ request , $ item ) ) ; }

Creates a new inventory item.

@param InventoryRequest $request

@return bool


public function show($id)
    {
        $item = $this->inventory->find($id);

        $variants = $this->presenter->tableVariants($item);

        $stocks = $this->presenter->tableStocks($item);

        $navbarProfile = $this->presenter->navbarProfile($item);

        $navbarVariants = $this->presenter->navbarVariants($item);

        $navbarStocks = $this->presenter->navbarStocks($item);

        return view('inventory.show', compact(
            'item',
            'stocks',
            'variants',
            'navbarProfile',
            'navbarVariants',
            'navbarStocks'
        ));
    }

public function show ( $ id ) { $ item = $ this -> inventory -> find ( $ id ) ; $ variants = $ this -> presenter -> tableVariants ( $ item ) ; $ stocks = $ this -> presenter -> tableStocks ( $ item ) ; $ navbarProfile = $ this -> presenter -> navbarProfile ( $ item ) ; $ navbarVariants = $ this -> presenter -> navbarVariants ( $ item ) ; $ navbarStocks = $ this -> presenter -> navbarStocks ( $ item ) ; return view ( 'inventory.show' , compact ( 'item' , 'stocks' , 'variants' , 'navbarProfile' , 'navbarVariants' , 'navbarStocks' ) ) ; }

Displays the specified inventory item.

@param int|string $id

@return \Illuminate\View\View


public function edit($id)
    {
        $item = $this->inventory->findOrFail($id);

        $form = $this->presenter->form($item);

        return view('inventory.edit', compact('form'));
    }

public function edit ( $ id ) { $ item = $ this -> inventory -> findOrFail ( $ id ) ; $ form = $ this -> presenter -> form ( $ item ) ; return view ( 'inventory.edit' , compact ( 'form' ) ) ; }

Displays the form for editing the specified inventory item.

@param int|string $id

@return \Illuminate\View\View

Displays the form for editing the specified inventory item .


public function table(Inventory $item)
    {
        $stocks = $item->stocks();

        return $this->table->of('inventory.stocks', function (TableGrid $table) use ($item, $stocks) {
            $table->with($stocks);

            $table->attributes([
                'class' => 'table table-hover table-striped',
            ]);

            $table->column('quantity');

            $table->column('location', function (Column $column) use ($item) {
                $column->value = function (InventoryStock $stock) use ($item) {
                    $name = $stock->location->trail;

                    return link_to_route('maintenance.inventory.stocks.show', $name, [$item->getKey(), $stock->getKey()]);
                };
            });

            $table->column('last_movement', function (Column $column) {
                $column->value = function (InventoryStock $stock) {
                    return $stock->last_movement;
                };
            });

            $table->column('last_movement_by', function (Column $column) {
                $column->value = function (InventoryStock $stock) {
                    return $stock->last_movement_by;
                };
            });
        });
    }

public
function
table
(
Inventory
$
item
)
{
$
stocks
=
$
item
->
stocks
(
)
;
return
$
this
->
table
->
of
(
'inventory.stocks'
,
function
(
TableGrid
$
table
)
use
(
$
item
,
$
stocks
)
{
$
table
->
with
(
$
stocks
)
;
$
table
->
attributes
(
[
'class'
=>
'table table-hover table-striped'
,
]
)
;
$
table
->
column
(
'quantity'
)
;
$
table
->
column
(
'location'
,
function
(
Column
$
column
)
use
(
$
item
)
{
$
column
->
value
=
function
(
InventoryStock
$
stock
)
use
(
$
item
)
{
$
name
=
$
stock
->
location
->
trail
;
return
link_to_route
(
'maintenance.inventory.stocks.show'
,
$
name
,
[
$
item
->
getKey
(
)
,
$
stock
->
getKey
(
)
]
)
;
}
;
}
)
;
$
table
->
column
(
'last_movement'
,
function
(
Column
$
column
)
{
$
column
->
value
=
function
(
InventoryStock
$
stock
)
{
return
$
stock
->
last_movement
;
}
;
}
)
;
$
table
->
column
(
'last_movement_by'
,
function
(
Column
$
column
)
{
$
column
->
value
=
function
(
InventoryStock
$
stock
)
{
return
$
stock
->
last_movement_by
;
}
;
}
)
;
}
)
;
}

Returns a new table of all stocks of the specified inventory item.

@param Inventory $item

@return \Orchestra\Contracts\Html\Builder

Returns a new table of all stocks of the specified inventory item .


public function tableMovements(Inventory $item, InventoryStock $stock)
    {
        $movements = $stock->movements();

        return $this->table->of('inventory.stocks.movements', function (TableGrid $table) use ($item, $movements) {
            $table->with($movements)->paginate($this->perPage);

            $table->pageName = 'stock-movements';

            $table->column('before');

            $table->column('after');

            $table->column('change');

            $table->column('cost');

            $table->column('reason');

            $table->column('Change By', function (Column $column) {
                return $column->value = function (InventoryStockMovement $movement) {
                    if ($movement->user instanceof User) {
                        return $movement->user->getRecipientName();
                    }

                    return HTML::create('em', 'Unknown');
                };
            });

            $table->column('Change On', 'created_at');
        });
    }

public
function
tableMovements
(
Inventory
$
item
,
InventoryStock
$
stock
)
{
$
movements
=
$
stock
->
movements
(
)
;
return
$
this
->
table
->
of
(
'inventory.stocks.movements'
,
function
(
TableGrid
$
table
)
use
(
$
item
,
$
movements
)
{
$
table
->
with
(
$
movements
)
->
paginate
(
$
this
->
perPage
)
;
$
table
->
pageName
=
'stock-movements'
;
$
table
->
column
(
'before'
)
;
$
table
->
column
(
'after'
)
;
$
table
->
column
(
'change'
)
;
$
table
->
column
(
'cost'
)
;
$
table
->
column
(
'reason'
)
;
$
table
->
column
(
'Change By'
,
function
(
Column
$
column
)
{
return
$
column
->
value
=
function
(
InventoryStockMovement
$
movement
)
{
if
(
$
movement
->
user
instanceof
User
)
{
return
$
movement
->
user
->
getRecipientName
(
)
;
}
return
HTML
::
create
(
'em'
,
'Unknown'
)
;
}
;
}
)
;
$
table
->
column
(
'Change On'
,
'created_at'
)
;
}
)
;
}

Returns a new table of all movements for the specified inventory stock.

@param Inventory      $item
@param InventoryStock $stock

@return \Orchestra\Contracts\Html\Builder

Returns a new table of all movements for the specified inventory stock .


public function form(Inventory $item, InventoryStock $stock)
    {
        return $this->form->of('inventory.stocks', function (FormGrid $form) use ($item, $stock) {
            if ($stock->exists) {
                $method = 'PATCH';
                $url = route('maintenance.inventory.stocks.update', [$item->getKey(), $stock->getKey()]);
                $form->submit = 'Save';
            } else {
                $method = 'POST';
                $url = route('maintenance.inventory.stocks.store', [$item->getKey()]);
                $form->submit = 'Create';
            }

            $locations = Location::getSelectHierarchy();

            $form->with($stock);
            $form->attributes(compact('method', 'url'));

            $form->fieldset(function (Fieldset $fieldset) use ($locations) {
                $fieldset
                    ->control('select', 'location')
                    ->value(function (InventoryStock $stock) {
                        return $stock->location_id;
                    })
                    ->options($locations);

                $fieldset
                    ->control('input:text', 'quantity')
                    ->attributes([
                        'placeholder' => 'ex. 45',
                    ]);

                $fieldset
                    ->control('input:text', 'reason')
                    ->attributes([
                        'placeholder' => 'ex. Stock Update',
                    ]);

                $fieldset
                    ->control('input:text', 'cost')
                    ->attributes([
                        'placeholder' => 'ex. 15.00',
                    ]);
            });
        });
    }

public
function
form
(
Inventory
$
item
,
InventoryStock
$
stock
)
{
return
$
this
->
form
->
of
(
'inventory.stocks'
,
function
(
FormGrid
$
form
)
use
(
$
item
,
$
stock
)
{
if
(
$
stock
->
exists
)
{
$
method
=
'PATCH'
;
$
url
=
route
(
'maintenance.inventory.stocks.update'
,
[
$
item
->
getKey
(
)
,
$
stock
->
getKey
(
)
]
)
;
$
form
->
submit
=
'Save'
;
}
else
{
$
method
=
'POST'
;
$
url
=
route
(
'maintenance.inventory.stocks.store'
,
[
$
item
->
getKey
(
)
]
)
;
$
form
->
submit
=
'Create'
;
}
$
locations
=
Location
::
getSelectHierarchy
(
)
;
$
form
->
with
(
$
stock
)
;
$
form
->
attributes
(
compact
(
'method'
,
'url'
)
)
;
$
form
->
fieldset
(
function
(
Fieldset
$
fieldset
)
use
(
$
locations
)
{
$
fieldset
->
control
(
'select'
,
'location'
)
->
value
(
function
(
InventoryStock
$
stock
)
{
return
$
stock
->
location_id
;
}
)
->
options
(
$
locations
)
;
$
fieldset
->
control
(
'input:text'
,
'quantity'
)
->
attributes
(
[
'placeholder'
=>
'ex. 45'
,
]
)
;
$
fieldset
->
control
(
'input:text'
,
'reason'
)
->
attributes
(
[
'placeholder'
=>
'ex. Stock Update'
,
]
)
;
$
fieldset
->
control
(
'input:text'
,
'cost'
)
->
attributes
(
[
'placeholder'
=>
'ex. 15.00'
,
]
)
;
}
)
;
}
)
;
}

Returns a new form of the specified inventory stock.

@param Inventory      $item
@param InventoryStock $stock

@return \Orchestra\Contracts\Html\Builder

Returns a new form of the specified inventory stock .


public function navbar(Inventory $item)
    {
        return $this->fluent([
            'id'         => 'inventory-stocks',
            'title'      => 'Item Stocks',
            'url'        => route('maintenance.inventory.stocks.index', [$item->getKey()]),
            'menu'       => view('inventory.stocks._nav', compact('item')),
            'attributes' => [
                'class' => 'navbar-default',
            ],
        ]);
    }

public
function
navbar
(
Inventory
$
item
)
{
return
$
this
->
fluent
(
[
'id'
=>
'inventory-stocks'
,
'title'
=>
'Item Stocks'
,
'url'
=>
route
(
'maintenance.inventory.stocks.index'
,
[
$
item
->
getKey
(
)
]
)
,
'menu'
=>
view
(
'inventory.stocks._nav'
,
compact
(
'item'
)
)
,
'attributes'
=>
[
'class'
=>
'navbar-default'
,
]
,
]
)
;
}

Returns a new navbar for the inventory stock index.

@param Inventory $item

@return \Illuminate\Support\Fluent

Returns a new navbar for the inventory stock index .


public function table(WorkOrder $workOrder)
    {
        $parts = $workOrder->parts();

        return $this->table->of('work-orders.parts', function (TableGrid $table) use ($workOrder, $parts) {
            $table->with($parts)->paginate($this->perPage);

            $table->pageName = 'page-parts';

            $table->column('ID', 'id');

            $table->column('SKU', function (Column $column) {
                $column->value = function (InventoryStock $stock) {
                    return $stock->item->getSku();
                };
            });

            $table->column('name', function (Column $column) {
                $column->value = function (InventoryStock $stock) {
                    return $stock->item->name;
                };
            });

            $table->column('location', function (Column $column) {
                $column->value = function (InventoryStock $stock) {
                    return $stock->location->trail;
                };
            });

            $table->column('taken', function (Column $column) {
                $column->value = function (InventoryStock $stock) {
                    return $stock->quantity;
                };
            });

            $table->column('return', function (Column $column) use ($workOrder) {
                $column->label = 'Return Stock';
                $column->value = function (InventoryStock $stock) use ($workOrder) {
                    $route = 'maintenance.work-orders.parts.stocks.put';

                    $params = [$workOrder->getKey(), $stock->item->getKey(), $stock->getKey()];

                    $attributes = [
                        'class' => 'btn btn-default btn-sm',
                    ];

                    return link_to_route($route, 'Return', $params, $attributes);
                };
            });
        });
    }

Returns a new table of all parts attached to the specified work order.

@param WorkOrder $workOrder

@return \Orchestra\Contracts\Html\Builder

Returns a new table of all parts attached to the specified work order .


public function tableInventory(WorkOrder $workOrder, Inventory $inventory)
    {
        $inventory = $inventory->noVariants();

        return $this->table->of('work-orders.inventory', function (TableGrid $table) use ($inventory, $workOrder) {
            $table->with($inventory)->paginate($this->perPage);

            $table->pageName = 'page-inventory';

            $table->column('ID', 'id');

            $table->column('sku', function (Column $column) {
                $column->label = 'SKU';

                $column->value = function (Inventory $item) {
                    return $item->getSku();
                };
            });

            $table->column('name', function (Column $column) {
                $column->value = function (Inventory $item) {
                    return link_to_route('maintenance.inventory.show', $item->name, [$item->getKey()]);
                };
            });

            $table->column('category', function (Column $column) {
                $column->value = function (Inventory $item) {
                    return $item->category->trail;
                };
            });

            $table->column('current_stock', function (Column $column) {
                $column->value = function (Inventory $item) {
                    return $item->getTotalStock();
                };
            });

            $table->column('select', function (Column $column) use ($workOrder) {
                $column->value = function (Inventory $item) use ($workOrder) {
                    $route = 'maintenance.work-orders.parts.stocks.index';

                    $params = [$workOrder->getKey(), $item->getKey()];

                    $attributes = [
                        'class' => 'btn btn-default btn-sm',
                    ];

                    return link_to_route($route, 'Select', $params, $attributes);
                };
            });
        });
    }

Displays all inventory available for selection.

@param WorkOrder $workOrder
@param Inventory $inventory

@return \Orchestra\Contracts\Html\Builder

Displays all inventory available for selection .


public function navbarParts(WorkOrder $workOrder)
    {
        return $this->fluent([
            'id'         => 'work-orders-parts',
            'title'      => 'Parts Added',
            'url'        => route('maintenance.work-orders.parts.index', [$workOrder->getKey()]),
            'menu'       => view('work-orders.parts._nav', compact('workOrder')),
            'attributes' => [
                'class' => 'navbar-default',
            ],
        ]);
    }

public
function
navbarParts
(
WorkOrder
$
workOrder
)
{
return
$
this
->
fluent
(
[
'id'
=>
'work-orders-parts'
,
'title'
=>
'Parts Added'
,
'url'
=>
route
(
'maintenance.work-orders.parts.index'
,
[
$
workOrder
->
getKey
(
)
]
)
,
'menu'
=>
view
(
'work-orders.parts._nav'
,
compact
(
'workOrder'
)
)
,
'attributes'
=>
[
'class'
=>
'navbar-default'
,
]
,
]
)
;
}

Returns a new navbar for the work order parts table.

@param WorkOrder $workOrder

@return \Illuminate\Support\Fluent

Returns a new navbar for the work order parts table .


public function index($workOrderId)
    {
        $workOrder = $this->workOrder->findOrFail($workOrderId);

        $sessions = $this->presenter->table($workOrder);

        $navbar = $this->presenter->navbar();

        return view('work-orders.sessions.index', compact('sessions', 'navbar'));
    }

public function index ( $ workOrderId ) { $ workOrder = $ this -> workOrder -> findOrFail ( $ workOrderId ) ; $ sessions = $ this -> presenter -> table ( $ workOrder ) ; $ navbar = $ this -> presenter -> navbar ( ) ; return view ( 'work-orders.sessions.index' , compact ( 'sessions' , 'navbar' ) ) ; }

Displays all sessions for the specified work order.

@param int|string $workOrderId

@return \Illuminate\View\View

Displays all sessions for the specified work order .


public function start($workOrderId)
    {
        $workOrder = $this->workOrder->findOrFail($workOrderId);

        return $this->dispatch(new Start($workOrder));
    }

public function start ( $ workOrderId ) { $ workOrder = $ this -> workOrder -> findOrFail ( $ workOrderId ) ; return $ this -> dispatch ( new Start ( $ workOrder ) ) ; }

Starts the current users session for the specified work order.

@param int|string $workOrderId

@return mixed

Starts the current users session for the specified work order .


public function end($workOrderId)
    {
        $workOrder = $this->workOrder->findOrFail($workOrderId);

        return $this->dispatch(new End($workOrder));
    }

public function end ( $ workOrderId ) { $ workOrder = $ this -> workOrder -> findOrFail ( $ workOrderId ) ; return $ this -> dispatch ( new End ( $ workOrder ) ) ; }

Ends the current users session for the specified work order.

@param int|string $workOrderId

@return mixed

Ends the current users session for the specified work order .


public function getChangeAttribute()
    {
        if ($this->before > $this->after) {
            return sprintf('- %s', $this->before - $this->after);
        } elseif ($this->after > $this->before) {
            return sprintf('+ %s', $this->after - $this->before);
        } else {
            return 'None';
        }
    }

public
function
getChangeAttribute
(
)
{
if
(
$
this
->
before
>
$
this
->
after
)
{
return
sprintf
(
'- %s'
,
$
this
->
before
$
this
->
after
)
;
}
elseif
(
$
this
->
after
>
$
this
->
before
)
{
return
sprintf
(
'+ %s'
,
$
this
->
after
$
this
->
before
)
;
}
else
{
return
'None'
;
}
}

Returns the change of a stock.

For example: '+ 25' or '- 25'

@return string


public function store(NoteRequest $request, $id)
    {
        $note = $this->inventory->createNote($request, $id);

        if ($note) {
            $message = 'Successfully created note.';

            return redirect()->route('maintenance.inventory.show', [$id])->withSuccess($message);
        } else {
            $message = 'There was an issue creating a note. Please try again.';

            return redirect()->route('maintenance.inventory.notes.create', [$id])->withErrors($message);
        }
    }

Creates a note for the specified inventory.

@param NoteRequest $request
@param int|string  $id

@return \Illuminate\Http\RedirectResponse

Creates a note for the specified inventory .


public function show($id, $noteId)
    {
        $item = $this->inventory->find($id);

        $note = $item->notes()->find($noteId);

        if ($note) {
            return view('inventory.notes.show', compact('item', 'note'));
        }

        abort(404);
    }

public function show ( $ id , $ noteId ) { $ item = $ this -> inventory -> find ( $ id ) ; $ note = $ item -> notes ( ) -> find ( $ noteId ) ; if ( $ note ) { return view ( 'inventory.notes.show' , compact ( 'item' , 'note' ) ) ; } abort ( 404 ) ; }

Displays the specified inventory note.

@param int|string $id
@param int|string $noteId

@return \Illuminate\View\View


public function update(NoteRequest $request, $id, $noteId)
    {
        $note = $this->inventory->updateNote($request, $id, $noteId);

        if ($note) {
            $message = 'Successfully updated note.';

            return redirect()->route('maintenance.inventory.notes.show', [$id, $noteId])->withSuccess($message);
        } else {
            $message = 'There was an issue updating this note. Please try again.';

            return redirect()->route('maintenance.inventory.notes.update', [$id, $noteId])->withErrors($message);
        }
    }

Updates the specified note for the specified inventory.

@param NoteRequest $request
@param int|string  $id
@param int|string  $noteId

@return \Illuminate\Http\RedirectResponse

Updates the specified note for the specified inventory .


public function destroy($id, $noteId)
    {
        if ($this->inventory->deleteNote($id, $noteId)) {
            $message = 'Successfully updated note.';

            return redirect()->route('maintenance.inventory.show', [$id])->withSuccess($message);
        } else {
            $message = 'There was an issue deleting this note. Please try again.';

            return redirect()->route('maintenance.inventory.notes.show', [$id, $noteId])->withErrors($message);
        }
    }

Deletes the specified note attached to the specified inventory.

@param int|string $id
@param int|string $noteId

@return \Illuminate\Http\RedirectResponse

Deletes the specified note attached to the specified inventory .


public function getLastMovementAttribute()
    {
        if ($this->movements->count() > 0) {
            $movement = $this->movements->first();

            if ($movement instanceof InventoryStockMovement
                && $movement->after > $movement->before) {
                return sprintf('%s (Stock was added - %s) - Reason: %s', $movement->change, $movement->created_at, $movement->reason);
            } elseif ($movement->before > $movement->after) {
                return sprintf('%s (Stock was removed - %s) - Reason: %s', $movement->change, $movement->created_at, $movement->reason);
            } else {
                return sprintf('%s (No Change - %s) - Reason: %s', $movement->change, $movement->created_at, $movement->reason);
            }
        }

        return;
    }

Accessor for viewing the last movement of the stock.

@return null|string

Accessor for viewing the last movement of the stock .


public function getLastMovementByAttribute()
    {
        if ($this->movements->count() > 0) {
            $movement = $this->movements->first();

            if ($movement instanceof InventoryStockMovement
                && $movement->user instanceof User) {
                return $movement->user->getRecipientName();
            }
        }

        return;
    }

public function getLastMovementByAttribute ( ) { if ( $ this -> movements -> count ( ) > 0 ) { $ movement = $ this -> movements -> first ( ) ; if ( $ movement instanceof InventoryStockMovement && $ movement -> user instanceof User ) { return $ movement -> user -> getRecipientName ( ) ; } } return ; }

Accessor for viewing the user responsible for the last
movement.

@return null|string

Accessor for viewing the user responsible for the last movement .


public function getQuantityMetricAttribute()
    {
        $quantity = $this->getAttribute('quantity');

        if ($this->item && $this->item->metric) {
            $metric = $this->item->metric->name;
        } else {
            $metric = null;
        }

        return trim(sprintf('%s %s', $quantity, $metric));
    }

public
function
getQuantityMetricAttribute
(
)
{
$
quantity
=
$
this
->
getAttribute
(
'quantity'
)
;
if
(
$
this
->
item
&&
$
this
->
item
->
metric
)
{
$
metric
=
$
this
->
item
->
metric
->
name
;
}
else
{
$
metric
=
;
}
return
trim
(
sprintf
(
'%s %s'
,
$
quantity
,
$
metric
)
)
;
}

Accessor for viewing the quantity combined with the item metric.

@return string

Accessor for viewing the quantity combined with the item metric .


public function btnPutBackSomeForWorkOrder(WorkOrder $workOrder)
    {
        if ($this->entity->item) {
            return view('viewers.inventory.stock.buttons.put-back-some-work-order', [
                'workOrder' => $workOrder,
                'stock'     => $this->entity,
            ]);
        }

        return;
    }

Returns the stocks put back some work order button view.

@param WorkOrder $workOrder

@return \Illuminate\View\View

Returns the stocks put back some work order button view .


public function btnPutBackAllForWorkOrder(WorkOrder $workOrder)
    {
        if ($this->entity->item) {
            return view('viewers.inventory.stock.buttons.put-back-all-work-order', [
                'workOrder' => $workOrder,
                'stock'     => $this->entity,
            ]);
        }

        return;
    }

Returns the stocks put back all work order button view.

@param WorkOrder $workOrder

@return \Illuminate\View\View

Returns the stocks put back all work order button view .


public function end($workOrderId)
    {
        if ($this->processor->end($workOrderId)) {
            flash()->success('Success!', 'Successfully ended your session. Your hours have been logged.');

            return redirect()->route('maintenance.work-orders.show', [$workOrderId]);
        } else {
            flash()->error('Error!', 'There was an issue ending your session. Please try again.');

            return redirect()->route('maintenance.work-orders.show', [$workOrderId]);
        }
    }

Ends a maintenance workers session on a work order.

@param int|string $workOrderId

@return \Illuminate\Http\RedirectResponse

Ends a maintenance workers session on a work order .


public function table($workRequest)
    {
        return $this->table->of('work-requests', function (TableGrid $table) use ($workRequest) {
            $table->with($workRequest)->paginate($this->perPage);

            $table->attributes([
                'class' => 'table table-hover table-striped',
            ]);

            $table->column('ID', 'id');

            $table->column('subject', function (Column $column) {
                $column->value = function (WorkRequest $workRequest) {
                    return link_to_route('maintenance.work-requests.show', $workRequest->subject, [$workRequest->getKey()]);
                };
            });

            $table->column('best_time');

            $table->column('created_at');
        });
    }

public
function
table
(
$
workRequest
)
{
return
$
this
->
table
->
of
(
'work-requests'
,
function
(
TableGrid
$
table
)
use
(
$
workRequest
)
{
$
table
->
with
(
$
workRequest
)
->
paginate
(
$
this
->
perPage
)
;
$
table
->
attributes
(
[
'class'
=>
'table table-hover table-striped'
,
]
)
;
$
table
->
column
(
'ID'
,
'id'
)
;
$
table
->
column
(
'subject'
,
function
(
Column
$
column
)
{
$
column
->
value
=
function
(
WorkRequest
$
workRequest
)
{
return
link_to_route
(
'maintenance.work-requests.show'
,
$
workRequest
->
subject
,
[
$
workRequest
->
getKey
(
)
]
)
;
}
;
}
)
;
$
table
->
column
(
'best_time'
)
;
$
table
->
column
(
'created_at'
)
;
}
)
;
}

Returns a new table of all work requests.

@param WorkRequest $workRequest

@return \Orchestra\Contracts\Html\Builder

Returns a new table of all work requests .


public function form(WorkRequest $request)
    {
        return $this->form->of('work-requests', function (FormGrid $form) use ($request) {
            if ($request->exists) {
                $method = 'PATCH';
                $url = route('maintenance.work-requests.update', [$request->getKey()]);
                $form->submit = 'Save';
            } else {
                $method = 'POST';
                $url = route('maintenance.work-requests.store');
                $form->submit = 'Create';
            }

            $form->with($request);

            $form->attributes(compact('method', 'url'));

            $form->fieldset(function (Fieldset $fieldset) {
                $fieldset
                    ->control('input:text', 'subject')
                    ->attributes([
                        'placeholder' => 'Enter Subject',
                    ]);

                $fieldset
                    ->control('input:text', 'best_time')
                    ->attributes([
                        'placeholder' => 'Enter Best Time',
                    ]);

                $fieldset
                    ->control('input:textarea', 'description');
            });
        });
    }

public
function
form
(
WorkRequest
$
request
)
{
return
$
this
->
form
->
of
(
'work-requests'
,
function
(
FormGrid
$
form
)
use
(
$
request
)
{
if
(
$
request
->
exists
)
{
$
method
=
'PATCH'
;
$
url
=
route
(
'maintenance.work-requests.update'
,
[
$
request
->
getKey
(
)
]
)
;
$
form
->
submit
=
'Save'
;
}
else
{
$
method
=
'POST'
;
$
url
=
route
(
'maintenance.work-requests.store'
)
;
$
form
->
submit
=
'Create'
;
}
$
form
->
with
(
$
request
)
;
$
form
->
attributes
(
compact
(
'method'
,
'url'
)
)
;
$
form
->
fieldset
(
function
(
Fieldset
$
fieldset
)
{
$
fieldset
->
control
(
'input:text'
,
'subject'
)
->
attributes
(
[
'placeholder'
=>
'Enter Subject'
,
]
)
;
$
fieldset
->
control
(
'input:text'
,
'best_time'
)
->
attributes
(
[
'placeholder'
=>
'Enter Best Time'
,
]
)
;
$
fieldset
->
control
(
'input:textarea'
,
'description'
)
;
}
)
;
}
)
;
}

Returns a new form for the specified work request.

@param WorkRequest $request

@return \Orchestra\Contracts\Html\Builder

Returns a new form for the specified work request .


public function store($workOrder_id)
    {
        if ($this->assignmentValidator->passes()) {
            $workOrder = $this->workOrder->find($workOrder_id);

            $data = $this->inputAll();
            $data['work_order_id'] = $workOrder->id;

            $records = $this->assignment->setInput($data)->create();

            if ($records) {
                $this->message = 'Successfully assigned worker(s)';
                $this->messageType = 'success';
                $this->redirect = route('maintenance.work-orders.show', [$workOrder->id]);
            } else {
                $this->message = 'There was an error trying to assign workers to this work order. Please try again.';
                $this->messageType = 'danger';
                $this->redirect = route('maintenance.work-orders.show', [$workOrder->id]);
            }
        } else {
            $this->errors = $this->assignmentValidator->getErrors();
            $this->redirect = route('maintenance.work-orders.show', [$workOrder_id]);
        }

        return $this->response();
    }

Assigns workers to the specified work order ID.

@param string|int $workOrder_id

@return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse

Assigns workers to the specified work order ID .


public function destroy($workOrder_id, $assignment_id)
    {
        if ($this->assignment->destroy($assignment_id)) {
            $this->message = 'Successfully removed worker from this work order.';
            $this->messageType = 'success';
            $this->redirect = route('maintenance.work-orders.show', [$workOrder_id]);
        } else {
            $this->message = 'There was an error trying to remove this worker from this work order. Please try again later.';
            $this->messageType = 'danger';
            $this->redirect = route('maintenance.work-orders.show', [$workOrder_id]);
        }

        return $this->response();
    }

Removes the specified assignent from the specified work order.

@param string|int $workOrder_id
@param string|int $assignment_id

@return \Illuminate\Http\JsonResponse|mixed

Removes the specified assignent from the specified work order .


public function datalist(string $id, array $list = []): Htmlable
    {
        $this->type = 'datalist';

        $attributes['id'] = $id;

        $html = [];

        if (Arr::isAssoc($list)) {
            foreach ($list as $value => $display) {
                $html[] = $this->option($display, $value, null, []);
            }
        } else {
            foreach ($list as $value) {
                $html[] = $this->option($value, $value, null, []);
            }
        }

        $attributes = $this->getHtmlBuilder()->attributes($attributes);

        $list = \implode('', $html);

        return $this->toHtmlString("<datalist{$attributes}>{$list}</datalist>");
    }

Create a datalist box field.

@param  string $id
@param  array  $list

@return \Illuminate\Contracts\Support\Htmlable


protected function placeholderOption(string $display, $selected): Htmlable
    {
        $options = [
            'selected' => $this->getSelectedValue(null, $selected),
            'disabled' => true,
            'value'    => '',
        ];

        return $this->toHtmlString(\sprintf(
            '<option%s>%s</option>',
            $this->getHtmlBuilder()->attributes($options),
            $this->entities($display)
        ));
    }

protected function placeholderOption ( string $ display , $ selected ) : Htmlable { $ options = [ 'selected' => $ this -> getSelectedValue ( null , $ selected ) , 'disabled' => true , 'value' => '' , ] ; return $ this -> toHtmlString ( \ sprintf ( '<option%s>%s</option>' , $ this -> getHtmlBuilder ( ) -> attributes ( $ options ) , $ this -> entities ( $ display ) ) ) ; }

Create a placeholder select element option.

@param string  $display
@param string|iterable|null  $selected

@return \Illuminate\Contracts\Support\Htmlable

Create a placeholder select element option .


protected function getAppendage(string $method): string
    {
        list($method, $appendage) = [\strtoupper($method), ''];

        // If the HTTP method is in this list of spoofed methods, we will attach the
        // method spoofer hidden input to the form. This allows us to use regular
        // form to initiate PUT and DELETE requests in addition to the typical.
        if (\in_array($method, $this->spoofedMethods)) {
            $appendage .= $this->hidden('_method', $method);
        }

        // If the method is something other than GET we will go ahead and attach the
        // CSRF token to the form, as this can't hurt and is convenient to simply
        // always have available on every form the developers creates for them.
        if ($method != 'GET') {
            $appendage .= $this->token();
        }

        return $appendage;
    }

Get the form appendage for the given method.

@param  string  $method

@return string

Get the form appendage for the given method .


protected function renderComponent(string $name, array $arguments): Htmlable
    {
        $component = static::$components[$name];
        $data      = $this->getComponentData($component['signature'], $arguments);

        return new HtmlString(
          $this->view->make($component['view'], $data)->render()
        );
    }

protected function renderComponent ( string $ name , array $ arguments ) : Htmlable { $ component = static :: $ components [ $ name ] ; $ data = $ this -> getComponentData ( $ component [ 'signature' ] , $ arguments ) ; return new HtmlString ( $ this -> view -> make ( $ component [ 'view' ] , $ data ) -> render ( ) ) ; }

Render a custom component.

@param  string  $name
@param  array  $arguments

@return \Illuminate\Contracts\Support\Htmlable


protected function getComponentData(array $signature, array $arguments): array
    {
        $data = [];

        $i = 0;
        foreach ($signature as $variable => $default) {
            // If the "variable" value is actually a numeric key, we can assume that
            // no default had been specified for the component argument and we'll
            // just use null instead, so that we can treat them all the same.
            if (\is_numeric($variable)) {
                $variable = $default;
                $default  = null;
            }

            $data[$variable] = $arguments[$i] ?? $default;

            ++$i;
        }

        return $data;
    }

Prepare the component data, while respecting provided defaults.

@param  array $signature
@param  array $arguments

@return array

Prepare the component data while respecting provided defaults .


protected function register()
    {
        $this->app->afterResolving('blade.compiler', function (BladeCompiler $bladeCompiler) {
            $namespaces = [
                'Html' => \get_class_methods(HtmlBuilder::class),
                'Form' => \get_class_methods(FormBuilder::class),
            ];

            foreach ($namespaces as $namespace => $methods) {
                foreach ($methods as $method) {
                    if (\in_array($method, $this->directives)) {
                        $snakeMethod = Str::snake($method);
                        $directive = \strtolower($namespace).'_'.$snakeMethod;

                        $bladeCompiler->directive($directive, function ($expression) use ($namespace, $method) {
                            return "<?php echo $namespace::$method($expression); ?>";
                        });
                    }
                }
            }
        });
    }

Register Blade directives.

@return void


public function model($model, array $options = []): Htmlable
    {
        $this->model = $model;

        return $this->open($options);
    }

public function model ( $ model , array $ options = [ ] ) : Htmlable { $ this -> model = $ model ; return $ this -> open ( $ options ) ; }

Create a new model based form builder.

@param  mixed  $model
@param  array  $options

@return \Illuminate\Contracts\Support\Htmlable


protected function formatLabel(string $name, ?string $value): string
    {
        return $value ?? \ucwords(\str_replace('_', ' ', $name));
    }

protected
function
formatLabel
(
string
$
name
,
string
$
value
)
:
string
{
return
$
value
??
\
ucwords
(
\
str_replace
(
'_'
,
' '
,
$
name
)
)
;
}

Format the label value.

@param  string  $name
@param  string|null  $value

@return string


public function reset(?string $value = null, array $attributes = []): Htmlable
    {
        return $this->input('reset', null, $value, $attributes);
    }

public function reset ( ? string $ value = null , array $ attributes = [ ] ) : Htmlable { return $ this -> input ( 'reset' , null , $ value , $ attributes ) ; }

Create a HTML reset input element.

@param  string|null  $value
@param  array  $attributes

@return \Illuminate\Contracts\Support\Htmlable


public function submit(?string $value = null, array $options = []): Htmlable
    {
        return $this->input('submit', null, $value, $options);
    }

public function submit ( ? string $ value = null , array $ options = [ ] ) : Htmlable { return $ this -> input ( 'submit' , null , $ value , $ options ) ; }

Create a submit button element.

@param  string|null  $value
@param  array  $options

@return \Illuminate\Contracts\Support\Htmlable


protected function request(string $name)
    {
        if (! $this->considerRequest || ! isset($this->request)) {
            return null;
        }

        return $this->request->input($this->transformKey($name));
    }

protected function request ( string $ name ) { if ( ! $ this -> considerRequest || ! isset ( $ this -> request ) ) { return null ; } return $ this -> request -> input ( $ this -> transformKey ( $ name ) ) ; }

Get value from current Request.

@param string $name

@return array|string|null


public function linkAsset(string $url, ?string $title = null, array $attributes = [], ?bool $secure = null): Htmlable
    {
        $url = $this->url->asset($url, $secure);

        return $this->link($url, $title ?: $url, $attributes, $secure);
    }

public function linkAsset ( string $ url , ? string $ title = null , array $ attributes = [ ] , ? bool $ secure = null ) : Htmlable { $ url = $ this -> url -> asset ( $ url , $ secure ) ; return $ this -> link ( $ url , $ title ? : $ url , $ attributes , $ secure ) ; }

Generate a HTML link to an asset.

@param  string  $url
@param  string|null  $title
@param  array  $attributes
@param  bool|null  $secure

@return \Illuminate\Contracts\Support\Htmlable


public function linkRoute(string $name, ?string $title = null, array $parameters = [], array $attributes = []): Htmlable
    {
        return $this->link($this->url->route($name, $parameters), $title, $attributes);
    }

public function linkRoute ( string $ name , ? string $ title = null , array $ parameters = [ ] , array $ attributes = [ ] ) : Htmlable { return $ this -> link ( $ this -> url -> route ( $ name , $ parameters ) , $ title , $ attributes ) ; }

Generate a HTML link to a named route.

@param  string  $name
@param  string|null  $title
@param  array  $parameters
@param  array  $attributes

@return \Illuminate\Contracts\Support\Htmlable


protected function listingElement($key, string $type, $value): string
    {
        if (\is_array($value)) {
            return $this->nestedListing($key, $type, $value);
        } else {
            return '<li>'.$this->entities($value).'</li>';
        }
    }

protected function listingElement ( $ key , string $ type , $ value ) : string { if ( \ is_array ( $ value ) ) { return $ this -> nestedListing ( $ key , $ type , $ value ) ; } else { return '<li>' . $ this -> entities ( $ value ) . '</li>' ; } }

Create the HTML for a listing element.

@param  mixed  $key
@param  string  $type
@param  mixed  $value

@return string


public function attributes(array $attributes): string
    {
        $html = [];

        // For numeric keys we will assume that the key and the value are the same
        // as this will convert HTML attributes such as "required" to a correct
        // form like required="required" instead of using incorrect numerics.
        foreach ((array) $attributes as $key => $value) {
            if (\is_array($value) && $key !== 'class') {
                foreach ((array) $value as $name => $val) {
                    $element = $this->attributeElement($key.'-'.$name, $val);
                    if (! \is_null($element)) {
                        $html[] = $element;
                    }
                }
            } else {
                $element = $this->attributeElement($key, $value);
                if (! \is_null($element)) {
                    $html[] = $element;
                }
            }
        }

        return \count($html) > 0 ? ' '.\implode(' ', $html) : '';
    }

Build an HTML attribute string from an array.

@param  array  $attributes

@return string

Build an HTML attribute string from an array .


protected function registerHtmlBuilder(): void
    {
        $this->app->singleton('html', function ($app) {
            return new HtmlBuilder(
                $app->make('url'), $app->make('view')
            );
        });
    }

protected function registerHtmlBuilder ( ) : void { $ this -> app -> singleton ( 'html' , function ( $ app ) { return new HtmlBuilder ( $ app -> make ( 'url' ) , $ app -> make ( 'view' ) ) ; } ) ; }

Register the HTML builder instance.

@return void


protected function registerFormBuilder(): void
    {
        $this->app->singleton('form', function ($app) {
            return (new FormBuilder(
                $app->make('html'), $app->make('url'), $app->make('view'), $app->make('request')
            ))->setSessionStore($app->make('session.store'));
        });
    }

protected function registerFormBuilder ( ) : void { $ this -> app -> singleton ( 'form' , function ( $ app ) { return ( new FormBuilder ( $ app -> make ( 'html' ) , $ app -> make ( 'url' ) , $ app -> make ( 'view' ) , $ app -> make ( 'request' ) ) ) -> setSessionStore ( $ app -> make ( 'session.store' ) ) ; } ) ; }

Register the form builder instance.

@return void


public function search(string $name, ?string $value = null, array $options = []): Htmlable
    {
        return $this->input('search', $name, $value, $options);
    }

public function search ( string $ name , ? string $ value = null , array $ options = [ ] ) : Htmlable { return $ this -> input ( 'search' , $ name , $ value , $ options ) ; }

Create a search input field.

@param  string $name
@param  string|null  $value
@param  array  $options

@return \Illuminate\Contracts\Support\Htmlable


public function datetime(string $name, $value = null, array $options = []): Htmlable
    {
        if ($value instanceof DateTime) {
            $value = $value->format(DateTime::RFC3339);
        }

        return $this->input('datetime', $name, $value, $options);
    }

public function datetime ( string $ name , $ value = null , array $ options = [ ] ) : Htmlable { if ( $ value instanceof DateTime ) { $ value = $ value -> format ( DateTime :: RFC3339 ) ; } return $ this -> input ( 'datetime' , $ name , $ value , $ options ) ; }

Create a datetime input field.

@param  string $name
@param  \DateTime|string|null  $value
@param  array  $options

@return \Illuminate\Contracts\Support\Htmlable


public function file(string $name, array $options = []): Htmlable
    {
        return $this->input('file', $name, null, $options);
    }

public function file ( string $ name , array $ options = [ ] ) : Htmlable { return $ this -> input ( 'file' , $ name , null , $ options ) ; }

Create a file input field.

@param  string  $name
@param  array   $options

@return \Illuminate\Contracts\Support\Htmlable


protected function removeXmlFirstLine($str)
    {
        $first = '<?xml version="1.0"?>';
        if (Str::startsWith($str, $first)) {
            return trim(substr($str, strlen($first)));
        }

        return $str;
    }

protected
function
removeXmlFirstLine
(
$
str
)
{
$
first
=
'<?xml version="1.0"?>'
;
if
(
Str
::
startsWith
(
$
str
,
$
first
)
)
{
return
trim
(
substr
(
$
str
,
strlen
(
$
first
)
)
)
;
}
return
$
str
;
}

remove the first line of xml string
@param string $str
@return string


public function load($locale)
    {
        $locale           = $this->unifyLocale($locale);
        $file             = self::$fileLocation . DIRECTORY_SEPARATOR . $locale . '.ini';
        $this->dictionary = array();
        if (! file_exists(realpath($file))) {
            return $this;
        }
        foreach (parse_ini_file($file) as $key => $val) {
            $this->dictionary[str_replace('@:', '', $key)] = $val;
        }

        return $this;
    }

public function load ( $ locale ) { $ locale = $ this -> unifyLocale ( $ locale ) ; $ file = self :: $ fileLocation . DIRECTORY_SEPARATOR . $ locale . '.ini' ; $ this -> dictionary = array ( ) ; if ( ! file_exists ( realpath ( $ file ) ) ) { return $ this ; } foreach ( parse_ini_file ( $ file ) as $ key => $ val ) { $ this -> dictionary [ str_replace ( '@:' , '' , $ key ) ] = $ val ; } return $ this ; }

Load a given locale-file as base for the dictionary

@param string $locale Load the file for the given locale

@return Dictionary

Load a given locale - file as base for the dictionary


public static function parseFile($locale)
    {
        $path = self::$fileLocation . DIRECTORY_SEPARATOR;
        $file = $path . 'hyph_' . $locale . '.dic';
        if (! file_Exists($file)) {
            throw new \Org\Heigl\Hyphenator\Exception\PathNotFoundException('The given Path does not exist');
        }

        $items = file($file);
        $source = trim($items[0]);
        if (0===strpos($source, 'ISO8859')) {
            $source = str_Replace('ISO8859', 'ISO-8859', $source);
        }
        unset($items[0]);
        $fh = fopen($path . $locale . '.ini', 'w+');
        foreach ($items as $item) {
            // Remove comment-lines starting with '#' or '%'.
            if (in_array(mb_substr($item, 0, 1), array('#', '%'))) {
                continue;
            }
            // Ignore empty lines.
            if ('' == trim($item)) {
                continue;
            }
            // Remove all Upper-case items as they are OOo-specific
            if ($item === mb_strtoupper($item)) {
                continue;
            }
            // Ignore lines containing an '=' sign as these are specific
            // instructions for non-standard-hyphenations. These will be
            // implemented later.
            if (false !== mb_strpos($item, '=')) {
                continue;
            }
            $item = mb_convert_Encoding($item, 'UTF-8', $source);
            $result = Pattern::factory($item);
            $string = '@:' . $result->getText() . ' = "' . $result->getPattern() . '"' . "\n";
            fwrite($fh, $string);
        }
        fclose($fh);

        return $path . $locale . '.ini';
    }

parse a dictionary-file to create an ini-file from it.

@param string $locale Parse the file for the given locale

@throws \Org\Heigl\Hyphenator\Exception\PathNotFoundException
@return string

parse a dictionary - file to create an ini - file from it .


public function getPatternsForWord($word)
    {
        $return = array();
        $word = '.' . $word . '.';
        $strlen = mb_strlen($word);
        for ($i = 0; $i <= $strlen; $i ++) {
            for ($j = 2; $j <= ($strlen-$i); $j++) {
                $substr = mb_substr($word, $i, $j);
                if (! isset($this->dictionary[$substr])) {
                    continue;
                }
                $return[$substr] = $this->dictionary[$substr];
            }
        }

        return $return;
    }

public function getPatternsForWord ( $ word ) { $ return = array ( ) ; $ word = '.' . $ word . '.' ; $ strlen = mb_strlen ( $ word ) ; for ( $ i = 0 ; $ i <= $ strlen ; $ i ++ ) { for ( $ j = 2 ; $ j <= ( $ strlen - $ i ) ; $ j ++ ) { $ substr = mb_substr ( $ word , $ i , $ j ) ; if ( ! isset ( $ this -> dictionary [ $ substr ] ) ) { continue ; } $ return [ $ substr ] = $ this -> dictionary [ $ substr ] ; } } return $ return ; }

Get all patterns for a given word.

@param string $word The word to get the patterns for.

@return array


private function unifyLocale($locale)
    {
        if (2 == strlen($locale)) {
            return strtolower($locale);
        }
        if (preg_match('/([a-zA-Z]{2})[^a-zA-Z]+([a-zA-Z]{2})/i', $locale, $result)) {
            return strtolower($result[1]) . '_' . strtoupper($result[2]);
        }

        return (string) $locale;
    }

Unify the given locale to a default format.

For that in a 2 by 2 format the whole string is splited, the first part
lowercased, the sewcond part upercased and concatenated with n under-
score.

a 2letter locae will simply be lowercased.

everything else will be returned AS IS

@param string $locale The locale to unify

@return string

Unify the given locale to a default format .


public function tokenize($string)
    {
        if (! $string instanceof TokenRegistry) {
            $wt = new WordToken($string);
            $string = new TokenRegistry();
            $string->add($wt);
        }
        foreach ($this as $tokenizer) {
            $string = $tokenizer->run($string);
        }

        return $string;
    }

public function tokenize ( $ string ) { if ( ! $ string instanceof TokenRegistry ) { $ wt = new WordToken ( $ string ) ; $ string = new TokenRegistry ( ) ; $ string -> add ( $ wt ) ; } foreach ( $ this as $ tokenizer ) { $ string = $ tokenizer -> run ( $ string ) ; } return $ string ; }

Pass the given string through the given tokenizers

@param string $string The String to be tokenized

@return \Org\Heigl\Hyphenator\TokenRegistry


public function run($input)
    {
        if ($input instanceof TokenRegistry) {
            // Tokenize a TokenRegistry
            $f = clone($input);
            foreach ($input as $token) {
                if (! $token instanceof WordToken) {
                    continue;
                }
                $newTokens = $this->tokenize($token->get());
                $f->replace($token, $newTokens);
            }

            return $f ;
        }

        // Tokenize a simple string.
        $array =  $this->tokenize($input);
        $registry = new TokenRegistry();
        foreach ($array as $item) {
            $registry->add($item);
        }

        return $registry;
    }

public
function
run
(
$
input
)
{
if
(
$
input
instanceof
TokenRegistry
)
{
// Tokenize a TokenRegistry
$
f
=
clone
(
$
input
)
;
foreach
(
$
input
as
$
token
)
{
if
(
!
$
token
instanceof
WordToken
)
{
continue
;
}
$
newTokens
=
$
this
->
tokenize
(
$
token
->
get
(
)
)
;
$
f
->
replace
(
$
token
,
$
newTokens
)
;
}
return
$
f
;
}
// Tokenize a simple string.
$
array
=
$
this
->
tokenize
(
$
input
)
;
$
registry
=
new
TokenRegistry
(
)
;
foreach
(
$
array
as
$
item
)
{
$
registry
->
add
(
$
item
)
;
}
return
$
registry
;
}

Split the given input into tokens using punktuation marks as splitter

The input can be a string or a tokenRegistry. If the input is a
TokenRegistry, each item will be tokenized.

@param string|\Org\Heigl\Hyphenator\Tokenizer\TokenRegistry $input The
input to be tokenized

@return \Org\Heigl\Hyphenator\Tokenizer\TokenRegistry


public function setOptions(\Org\Heigl\Hyphenator\Options $options)
    {
        $this->options =$options;

        return $this;
    }

public function setOptions ( \ Org \ Heigl \ Hyphenator \ Options $ options ) { $ this -> options = $ options ; return $ this ; }

Set the options-object for this filter

@param \Org\Heigl\Hyphenator\Options $options The options to set

@return Filter

Set the options - object for this filter


public function add(Dictionary $dict)
    {
        if (! in_array($dict, $this->registry)) {
            $this->registry[] = $dict;
        }

        return $this;
    }

public function add ( Dictionary $ dict ) { if ( ! in_array ( $ dict , $ this -> registry ) ) { $ this -> registry [ ] = $ dict ; } return $ this ; }

Add an item to the registry.

@param Dictionary $dict The Dictionary to add to the registry

@return DictionaryRegistry


public function getHyphenationPattterns($word)
    {
        $pattern = array();
        foreach ($this as $dictionary) {
            $pattern = array_merge($pattern, $dictionary->getPatternsForWord($word));
        }

        return $pattern;
    }

public function getHyphenationPattterns ( $ word ) { $ pattern = array ( ) ; foreach ( $ this as $ dictionary ) { $ pattern = array_merge ( $ pattern , $ dictionary -> getPatternsForWord ( $ word ) ) ; } return $ pattern ; }

Get an array of hyphenation-patterns for a given word.

@param string $word The word to get the patterns for.

@return array

Get an array of hyphenation - patterns for a given word .


public function setFilters($filters)
    {
        $this->filters = array();
        if (! is_array($filters)) {
            $filters = explode(',', $filters);
        }
        foreach ($filters as $filter) {
            $this->addFilter($filter);
        }

        return $this;
    }

public function setFilters ( $ filters ) { $ this -> filters = array ( ) ; if ( ! is_array ( $ filters ) ) { $ filters = explode ( ',' , $ filters ) ; } foreach ( $ filters as $ filter ) { $ this -> addFilter ( $ filter ) ; } return $ this ; }

Set the filters

@param string|array $filters The filters to use as comma separated list
or array

@return \Org\Heigl\Hyphenator\Options


public function addFilter($filter)
    {
        if (is_string($filter)) {
            $filter = trim($filter);
        } elseif (! $filter instanceof Filter) {
            throw new \UnexpectedValueException('Expceted instanceof Org\Heigl\Hyphenator\Filter\Filter or string');
        }
        if (! $filter) {
            return $this;
        }
        $this->filters[] = $filter;

        return $this;
    }

Add a filter to the options-array

@param string|Filter $filter The filter to be added

@throws \UnexpectedValueException
@return \Org\Heigl\Hyphenator\Options


public function setTokenizers($tokenizers)
    {
        $this->tokenizers = array();
        if (! is_array($tokenizers)) {
            $tokenizers = explode(',', $tokenizers);
        }
        foreach ($tokenizers as $tokenizer) {
            $this->addTokenizer($tokenizer);
        }

        return $this;
    }

public function setTokenizers ( $ tokenizers ) { $ this -> tokenizers = array ( ) ; if ( ! is_array ( $ tokenizers ) ) { $ tokenizers = explode ( ',' , $ tokenizers ) ; } foreach ( $ tokenizers as $ tokenizer ) { $ this -> addTokenizer ( $ tokenizer ) ; } return $ this ; }

Set the tokenizers to use

@param string|array $tokenizers The Tokenizers to use

@return \Org\Heigl\Hyphenator\Options


public function addTokenizer($tokenizer)
    {
        if (is_string($tokenizer)) {
            $tokenizer = trim($tokenizer);
        } elseif (! $tokenizer instanceof Tokenizer) {
            throw new \UnexpectedValueException(
                'Expceted instanceof Org\Heigl\Hyphenator\Tokenizer\Tokenizer or string'
            );
        }

        if (! $tokenizer) {
            return $this;
        }
        $this->tokenizers[] = $tokenizer;

        return $this;
    }

Add a tokenizer to the tomeizer-list

@param string|Tokenizer $tokenizer The tokenizer to add

@return \Org\Heigl\Hyphenator\Options


public static function factory($file)
    {
        if (! file_Exists($file)) {
            $file = $file . '.dist';
            if (! file_exists($file)) {
                throw new \Org\Heigl\Hyphenator\Exception\PathNotFoundException($file);
            }
        }
        $params = parse_ini_file($file);
        if (! is_array($params) || 1 > count($params)) {
            throw new \Org\Heigl\Hyphenator\Exception\InvalidArgumentException($file . ' is not a parseable file');
        }

        $option = new Options();
        foreach ($params as $key => $val) {
            if (! method_Exists($option, 'set' . $key)) {
                continue;
            }
            call_user_Func(array($option,'set' . $key), $val);
        }

        return $option;
    }

public
static
function
factory
(
$
file
)
{
if
(
!
file_Exists
(
$
file
)
)
{
$
file
=
$
file
.
'.dist'
;
if
(
!
file_exists
(
$
file
)
)
{
throw
new
\
Org
\
Heigl
\
Hyphenator
\
Exception
\
PathNotFoundException
(
$
file
)
;
}
}
$
params
=
parse_ini_file
(
$
file
)
;
if
(
!
is_array
(
$
params
)
||
1
>
count
(
$
params
)
)
{
throw
new
\
Org
\
Heigl
\
Hyphenator
\
Exception
\
InvalidArgumentException
(
$
file
.
' is not a parseable file'
)
;
}
$
option
=
new
Options
(
)
;
foreach
(
$
params
as
$
key
=>
$
val
)
{
if
(
!
method_Exists
(
$
option
,
'set'
.
$
key
)
)
{
continue
;
}
call_user_Func
(
array
(
$
option
,
'set'
.
$
key
)
,
$
val
)
;
}
return
$
option
;
}

Create an Option-Object by parsing a given file.

@param string $file The config-file to be parsed

@throws \Org\Heigl\Hyphenator\Exception\PathNotFoundException
@throws \Org\Heigl\Hyphenator\Exception\InvalidArgumentException
@return \Org\Heigl\Hyphenator\Options

Create an Option - Object by parsing a given file .


public function getText()
    {
        if (! $this->text) {
            throw new \Org\Heigl\Hyphenator\Exception\NoPatternSetException('No Pattern set');
        }

        return $this->text;
    }

public
function
getText
(
)
{
if
(
!
$
this
->
text
)
{
throw
new
\
Org
\
Heigl
\
Hyphenator
\
Exception
\
NoPatternSetException
(
'No Pattern set'
)
;
}
return
$
this
->
text
;
}

Get the text of the pattern

@throws \Org\Heigl\Hyphenator\Exception\NoPatternSetException
@return string


public function getPattern()
    {
        if (! $this->pattern) {
            throw new \Org\Heigl\Hyphenator\Exception\NoPatternSetException('No Pattern set');
        }

        return $this->pattern;
    }

public
function
getPattern
(
)
{
if
(
!
$
this
->
pattern
)
{
throw
new
\
Org
\
Heigl
\
Hyphenator
\
Exception
\
NoPatternSetException
(
'No Pattern set'
)
;
}
return
$
this
->
pattern
;
}

Get the pattern of this instance

@throws \Org\Heigl\Hyphenator\Exception\NoPatternSetException
@return string


public function setOptions(Options $options)
    {
        $this->options = $options;
        $this->tokenizers->cleanup();
        foreach ($this->options->getTokenizers() as $tokenizer) {
            $this->addTokenizer($tokenizer);
        }

        return $this;
    }

public function setOptions ( Options $ options ) { $ this -> options = $ options ; $ this -> tokenizers -> cleanup ( ) ; foreach ( $ this -> options -> getTokenizers ( ) as $ tokenizer ) { $ this -> addTokenizer ( $ tokenizer ) ; } return $ this ; }

Set the Options

@param \Org\Heigl\Hyphenator\Options $options The options to set

@return \Org\Heigl\Hyphenator\Hyphenator


public function getOptions()
    {
        if (null === $this->options) {
            $optFile = $this->getHomePath() . DIRECTORY_SEPARATOR . 'Hyphenator.properties';
            $this->setOptions(Options::factory($optFile));
        }

        return $this->options;
    }

public function getOptions ( ) { if ( null === $ this -> options ) { $ optFile = $ this -> getHomePath ( ) . DIRECTORY_SEPARATOR . 'Hyphenator.properties' ; $ this -> setOptions ( Options :: factory ( $ optFile ) ) ; } return $ this -> options ; }

Get the Options

@return \Org\Heigl\Hyphenator\Options


public function addDictionary($dictionary)
    {
        if (! $dictionary instanceof \Org\Heigl\Hyphenator\Dictionary\Dictionary) {
            \Org\Heigl\Hyphenator\Dictionary\Dictionary::setFileLocation($this->getHomePath() . '/files/dictionaries');
            $dictionary = \Org\Heigl\Hyphenator\Dictionary\Dictionary::factory($dictionary);
        }
        $this->dicts->add($dictionary);

        return $this;
    }

public function addDictionary ( $ dictionary ) { if ( ! $ dictionary instanceof \ Org \ Heigl \ Hyphenator \ Dictionary \ Dictionary ) { \ Org \ Heigl \ Hyphenator \ Dictionary \ Dictionary :: setFileLocation ( $ this -> getHomePath ( ) . '/files/dictionaries' ) ; $ dictionary = \ Org \ Heigl \ Hyphenator \ Dictionary \ Dictionary :: factory ( $ dictionary ) ; } $ this -> dicts -> add ( $ dictionary ) ; return $ this ; }

Add a Dictionary to the Hyphenator

@param \Org\Heigl\Hyphenator\Dictionary\Dictionary $dictionary The
Dictionary wit hyphenation-Patterns to add to this Hyphenator

@return Org\Heigl\Hyphenator\Hyphenator


public function addFilter($filter)
    {
        if (! $filter instanceof \Org\Heigl\Hyphenator\Filter\Filter) {
            $filter = '\\Org\\Heigl\\Hyphenator\\Filter\\' . ucfirst($filter) . 'Filter';
            $filter = new $filter();
        }
        $filter->setOptions($this->getOptions());
        $this->filters->add($filter);

        return $this;
    }

public function addFilter ( $ filter ) { if ( ! $ filter instanceof \ Org \ Heigl \ Hyphenator \ Filter \ Filter ) { $ filter = '\\Org\\Heigl\\Hyphenator\\Filter\\' . ucfirst ( $ filter ) . 'Filter' ; $ filter = new $ filter ( ) ; } $ filter -> setOptions ( $ this -> getOptions ( ) ) ; $ this -> filters -> add ( $ filter ) ; return $ this ; }

Add a Filter to the Hyphenator

@param \Org\Heigl\Hyphenator\Filter\Filter|string $filter The Filter with
non-standard-hyphenation-patterns

@link http://hunspell.sourceforge.net/tb87nemeth.pdf
@return Org\Heigl\Hyphenator\Hyphenator