DerDu/SPHERE-Framework

View on GitHub
Application/Api/Billing/Accounting/ApiCauser.php

Summary

Maintainability
A
55 mins
Test Coverage
<?php
namespace SPHERE\Application\Api\Billing\Accounting;

use SPHERE\Application\Api\ApiTrait;
use SPHERE\Application\Api\Dispatcher;
use SPHERE\Application\Billing\Accounting\Causer\Causer;
use SPHERE\Application\IApiInterface;
use SPHERE\Common\Frontend\Ajax\Emitter\ServerEmitter;
use SPHERE\Common\Frontend\Ajax\Pipeline;
use SPHERE\Common\Frontend\Ajax\Receiver\ModalReceiver;
use SPHERE\Common\Frontend\Form\Repository\Button\Close;
use SPHERE\System\Extension\Extension;

/**
 * Class ApiCauser
 * @package SPHERE\Application\Api\Billing\Accounting
 */
class ApiCauser extends Extension implements IApiInterface
{

    // registered method
    use ApiTrait;

    public function exportApi($Method = '')
    {
        $Dispatcher = new Dispatcher(__CLASS__);
        $Dispatcher->registerMethod('showCauserHistory');

        return $Dispatcher->callMethod($Method);
    }

    /**
     * @param string $Header
     *
     * @return ModalReceiver
     */
    public static function receiverModal()
    {

        return (new ModalReceiver(null, new Close()))->setIdentifier('CauserModal');
    }

    /**
     * @param string $PersonId
     *
     * @return Pipeline
     */
    public static function pipelineOpenCauserModal($PersonId = '')
    {

        $Receiver = self::receiverModal();
        $Pipeline = new Pipeline();
        $Emitter = new ServerEmitter($Receiver, self::getEndpoint());
        $Emitter->setGetPayload(array(
            self::API_TARGET => 'showCauserHistory'
        ));
        $Emitter->setPostPayload(array(
            'PersonId' => $PersonId
        ));
        $Pipeline->appendEmitter($Emitter);

        return $Pipeline;
    }

    /**
     * @param $PersonId
     *
     * @return string
     */
    public function showCauserHistory($PersonId = '')
    {

        return Causer::useFrontend()->getHistoryByPerson($PersonId);
    }
}