src/Api/Controller/Customer.php
public function getSearch()
    {
        if (!userHasPermission('admin:invoice:customer:manage')) {
            throw new ApiException('You are not authorised to search customers.', 401);
        }

        $oInput         = Factory::service('Input');
        $sKeywords      = $oInput->get('keywords');
        $oCustomerModel = Factory::model('Customer', 'nails/module-invoice');

        if (strlen($sKeywords) < 3) {
            throw new ApiException('Search term must be 3 characters or longer.', 400);
        }

        $oResult = $oCustomerModel->search($sKeywords);
        $aOut    = [];

        foreach ($oResult->data as $oCustomer) {
            $aOut[] = $this->formatCustomer($oCustomer);
        }

        return Factory::factory('ApiResponse', 'nails/module-api')
                      ->setData($aOut);
    }
public function getSearch()
    {
        if (!userHasPermission('admin:invoice:customer:manage')) {
            throw new ApiException('You are not authorised to search customers.', 401);
        }

        $oInput         = Factory::service('Input');
        $sKeywords      = $oInput->get('keywords');
        $oCustomerModel = Factory::model('Customer', 'nails/module-invoice');

        if (strlen($sKeywords) < 3) {
            throw new ApiException('Search term must be 3 characters or longer.', 400);
        }

        $oResult = $oCustomerModel->search($sKeywords);
        $aOut    = [];

        foreach ($oResult->data as $oCustomer) {
            $aOut[] = $this->formatCustomer($oCustomer);
        }

        return Factory::factory('ApiResponse', 'nails/module-api')
                      ->setData($aOut);
    }
public function getSearch ( ) { if ( ! userHasPermission ( 'admin:invoice:customer:manage' ) ) { throw new ApiException ( 'You are not authorised to search customers.' , 401 ) ; } $ oInput = Factory :: service ( 'Input' ) ; $ sKeywords = $ oInput -> get ( 'keywords' ) ; $ oCustomerModel = Factory :: model ( 'Customer' , 'nails/module-invoice' ) ; if ( strlen ( $ sKeywords ) < 3 ) { throw new ApiException ( 'Search term must be 3 characters or longer.' , 400 ) ; } $ oResult = $ oCustomerModel -> search ( $ sKeywords ) ; $ aOut = [ ] ; foreach ( $ oResult -> data as $ oCustomer ) { $ aOut [ ] = $ this -> formatCustomer ( $ oCustomer ) ; } return Factory :: factory ( 'ApiResponse' , 'nails/module-api' ) -> setData ( $ aOut ) ; }
Search for a customer
Search for a customer