PHP code example of katalam / laravel-onoffice-adapter

1. Go to this page and download the library: Download katalam/laravel-onoffice-adapter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

katalam / laravel-onoffice-adapter example snippets


return [
    /**
     * The base URL of the OnOffice API.
     * Change that if you are using a different version of the API.
     */
    'base_url' => 'https://api.onoffice.de/api/stable/api.php',

    /**
     * The headers to be sent with the request.
     * Override this if you need to send additional headers.
     */
    'headers' => [
        'Content-Type' => 'application/json',
        'Accept' => 'application/json',
    ],

    /**
     * Retry
     */
    'retry' => [
        'count' => 3,
        'delay' => 200,
        'only_on_connection_error' => true,
    ],

    /**
     * The token and secret to be used for authentication with the OnOffice API.
     */
    'token' => env('ON_OFFICE_TOKEN', ''),
    'secret' => env('ON_OFFICE_SECRET', ''),
];

$estates = EstateRepository::query()
    ->select('Id')
    ->where('status', 1)
    ->where('kaufpreis', '<', 30_000)
    ->orderBy('kaufpreis')
    ->orderByDesc('warmmiete')
    ->get();

$users = UserRepository::query()
    ->select([
        'Anrede',
        'Vorname',
        'Nachname',
        'Mobil',
    ])
    ->where('Nr', $this->userId)
    ->get();

$success = MarketplaceRepository::query()
    ->unlockProvider($parameterCacheId, $extendedClaim);

$tmpUploadId = FileRepository::upload()
    ->save(base64_encode($fileContent));
$success = FileRepository::upload()->link($tmpUploadId, [
    'module' => 'estate',
    'relatedRecordId' => '12345',
]);

// or

$success = FileRepository::upload()
    ->uploadInBlocks()
    ->saveAndLink(base64_encode($fileContent), [
        'module' => 'estate',
        'relatedRecordId' => '12345',
    ]);

ActivityRepository::query()
    ->recordIds($recordIds)
    ->recordIdsAsAddress()
    ->create([
        'datetime' => $event->getDateFormatted(),
        'actionkind' => 'Newsletter',
        'actiontype' => 'Hard Bounce',
        'note' => $message,
    ]);

Config::set('onoffice.token', 'token');
Config::set('onoffice.secret', 'secret');
Config::set('onoffice.api_claim', 'api_claim');

use Illuminate\Support\Facades\Log;
use Innobrain\OnOfficeAdapter\Facades\BaseRepository;

BaseRepository::query()
    ->before(static function (OnOfficeRequest $request) {
        Log::info('About to send request', [
            'request' => $request->toArray(),
        ]);
    })
    ->call(new OnOfficeRequest(
        OnOfficeAction::Read,
        OnOfficeResourceType::Estate,
    ));

use Innobrain\OnOfficeAdapter\Facades\BaseRepository;

BaseRepository::query()
    ->dd()
    ->call(new OnOfficeRequest(
        OnOfficeAction::Read,
        OnOfficeResourceType::Estate,
    ));

use Innobrain\OnOfficeAdapter\Facades\BaseRepository;

BaseRepository::record();

BaseRepository::query()
    ->call(new OnOfficeRequest(
        OnOfficeAction::Read,
        OnOfficeResourceType::Estate,
    ));

$result = BaseRepository::lastRecorded();

/*
    $result = [
        OnOfficeRequest,
        OnOfficeResponse,
    ];
*/

use Innobrain\OnOfficeAdapter\Facades\EstateRepository;
use Innobrain\OnOfficeAdapter\Services\OnOfficeService;

$estates = EstateRepository::query()
    ->select(OnOfficeService::DEFAULT_ESTATE_INFO_FIELDS)
    ->get();

use Innobrain\OnOfficeAdapter\Facades\EstateRepository;
use Innobrain\OnOfficeAdapter\Services\OnOfficeService;
 
$estates = EstateRepository::query()
    ->select(OnOfficeService::DEFAULT_ESTATE_INFO_FIELDS)
    ->get();
    
// will leave out fields with empty values like "", "0.00", [], or null.
$estates = clean_elements($estates);

use Innobrain\OnOfficeAdapter\Facades\EstateRepository;

EstateRepository::fake(EstateRepository::response([
    EstateRepository::page(recordFactories: [
        EstateFactory::make()
            ->id(1),
    ]),
]));

$response = EstateRepository::query()->get();

expect($response->count())->toBe(1)
    ->and($response->first()['id'])->toBe(1);

EstateRepository::assertSentCount(1);

use Innobrain\OnOfficeAdapter\Facades\EstateRepository;

EstateRepository::fake(EstateRepository::response([
    EstateRepository::page(recordFactories: [
        EstateFactory::make()
            ->id(1),
    ]),
    EstateRepository::page(recordFactories: [
        EstateFactory::make()
            ->id(2),
    ]),
]));

$response = EstateRepository::query()->get();

expect($response->count())->toBe(2)
    ->and($response->first()['id'])->toBe(1)
    ->and($response->last()['id'])->toBe(2);

EstateRepository::assertSentCount(2);

use Innobrain\OnOfficeAdapter\Facades\EstateRepository;

EstateRepository::preventStrayRequests();
EstateRepository::fake([
    EstateRepository::response([
        EstateRepository::page(recordFactories: [
            EstateFactory::make()
                ->id(1),
        ]),
        EstateRepository::page(recordFactories: [
            EstateFactory::make()
                ->id(2),
        ]),
    ]),
    EstateRepository::response([
        EstateRepository::page(recordFactories: [
            EstateFactory::make()
                ->id(3),
        ]),
        EstateRepository::page(recordFactories: [
            EstateFactory::make()
                ->id(4),
        ]),
    ]),
]);

$response = EstateRepository::query()->get();

expect($response->count())->toBe(2)
    ->and($response->first()['id'])->toBe(1)
    ->and($response->last()['id'])->toBe(2);

$response = EstateRepository::query()->get();

expect($response->count())->toBe(2)
    ->and($response->first()['id'])->toBe(3)
    ->and($response->last()['id'])->toBe(4);

EstateRepository::assertSentCount(4);

$response = EstateRepository::query()->get(); // throws StrayRequestException

use Innobrain\OnOfficeAdapter\Facades\EstateRepository;

EstateRepository::preventStrayRequests();
EstateRepository::fake(EstateRepository::sequence(
    EstateRepository::response([
        EstateRepository::page(recordFactories: EstateFactory::times(20)),
    ]),
    times: 30,
));

for ($i = 0; $i < 30; ++$i) {
    $response = EstateRepository::query()->get();

    expect($response->count())->toBe(20);
}
bash
php artisan vendor:publish --tag="laravel-onoffice-adapter-config"