PHP code example of innobraingmbh / onoffice-structure

1. Go to this page and download the library: Download innobraingmbh/onoffice-structure 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/ */

    

innobraingmbh / onoffice-structure example snippets


use Innobrain\OnOfficeAdapter\Dtos\OnOfficeApiCredentials;
use Innobrain\Structure\Enums\FieldConfigurationModule;
use Innobrain\Structure\Enums\Language;
use Innobrain\Structure\Facades\Structure;

$credentials = new OnOfficeApiCredentials('your-token', 'your-secret');

// Fetch all modules (defaults to German labels)
$modules = Structure::forClient($credentials)->getModules();

// Fetch specific modules in a specific language. Enum cases and plain keys
// both work; an unknown key throws an InvalidArgumentException.
$modules = Structure::forClient($credentials)->getModules(
    only: [FieldConfigurationModule::Address, 'estate'],
    language: Language::English,
);

// Iterate over modules and fields
foreach ($modules as $moduleKey => $module) {
    echo "Module: {$module->label} ({$module->key->value})\n";
    foreach ($module->fields as $fieldKey => $field) {
        echo "  Field: {$field->label} ({$field->key}) - Type: {$field->type->value}\n";
    }
}

$addressModule = $modules->get(FieldConfigurationModule::Address->value);

$filteredFields = $addressModule->fields
    ->whereMatchesFilters()
    ->where('Art', '2')       // only fields visible when Art = 2
    ->when($someCondition, fn ($builder) => $builder->where('ArtDaten', '1'))
    ->get();

$writable = $estateModule->fields->writable();

$objekttyp = $estateModule->fields->get('objekttyp')->withPermittedValuesFor('haus');
// $objekttyp->permittedValues now only contains house types such as "bungalow"

$field = $estateModule->field('ort');            // finds "Ort"
$field = $modules->module('estate')?->field('ort');

$objektart = $estateModule->field('objektart');

$objektart->permittedValueLabels();              // ['haus' => 'Haus', 'wohnung' => 'Wohnung', ...]
$objektart->labelFor('haus');                    // 'Haus'
$objektart->permittedValueKeyFor('Wohnung');     // 'wohnung'
$objektart->permits('villa');                    // false

$sanitized = $addressModule->fields->sanitize(collect([
    'Email' => '[email protected]',
    'unknownField' => 'value',      // removed: not in field collection
    'Beziehung' => ['1', '999'],    // '999' removed: not a permitted value
]));

foreach ($addressModule->fields->violations($input) as $violation) {
    Log::info("{$violation->fieldKey}: {$violation->reason->value}", ['value' => $violation->value]);
}

use Innobrain\Structure\Enums\Language;

$fields = Structure::forClient($credentials)->getSearchCriteriaFields(Language::English);

$kaufpreis = $fields->get('kaufpreis');

$kaufpreis->isRange;              // true
$kaufpreis->rangeFromKey();       // 'kaufpreis__von', the key the lower bound is written under
$kaufpreis->rangeToKey();         // 'kaufpreis__bis'
$kaufpreis->storedRangeKey();     // 'range_kaufpreis', the key a stored range is read back under
$kaufpreis->rangeFromLabel;       // 'min. Sales price'
$kaufpreis->mustMatchByDefault;   // the account presets the field as a knockout criterion
$kaufpreis->appliesTo->all();     // ['vermarktungsart' => ['kauf']], the classification values it is limited to

$fields->byCategory();            // fields grouped by category name
$fields->get('regionaler_zusatz')->isRegions();   // its values are region keys
$fields->get('objektart')->isClassification();    // one of vermarktungsart, nutzungsart, objektart
$fields->get('objektart')->permittedValueLabels(); // same helpers as on Field

'serializable_classes' => \Innobrain\Structure\Services\Structure::serializableClasses(),

use Innobrain\Structure\Converters\Array\ArrayConvertStrategy;

$strategy = new ArrayConvertStrategy(dropEmpty: true); // remove null/empty values

$allModulesArray = $modules->convert($strategy);
$moduleArray = $addressModule->convert($strategy);
$fieldArray = $addressModule->fields->get('Email')->convert($strategy);

use Innobrain\Structure\Converters\LaravelRules\LaravelRulesConvertStrategy;

// Pipe-separated strings with nullable (default)
$strategy = new LaravelRulesConvertStrategy(pipeSyntax: true, rtStrategy(pipeSyntax: false, iehung.*' => 'in:0,1,2,3'

use Innobrain\Structure\Converters\JsonSchema\JsonSchemaConvertStrategy;

$strategy = new JsonSchemaConvertStrategy(
    

use Innobrain\Structure\Contracts\ConvertStrategy;
use Innobrain\Structure\Dtos\Field;
use Innobrain\Structure\Dtos\Module;

final readonly class MyConvertStrategy implements ConvertStrategy
{
    public function convertModule(Module $module): mixed { /* ... */ }
    public function convertField(Field $field): mixed { /* ... */ }
}

$result = $module->convert(new MyConvertStrategy());

use Innobrain\Structure\Enums\FieldConfigurationModule;
use Innobrain\Structure\Facades\Structure;
use Innobrain\Structure\Testing\FieldFactory;
use Innobrain\Structure\Testing\ModuleFactory;

$fake = Structure::fake([
    ModuleFactory::new(FieldConfigurationModule::Estate)->fields(
        FieldFactory::new('Ort'),
        FieldFactory::singleSelect('objektart', ['haus' => 'Haus', 'wohnung' => 'Wohnung'])->default('haus'),
        FieldFactory::singleSelect('objekttyp', ['einfamilienhaus' => 'Einfamilienhaus'])
            ->dependencies(['einfamilienhaus' => 'haus']),
    )->make(),
]);

// ... run the code under test ...

$fake->assertRetrieved(FieldConfigurationModule::Estate);

use Innobrain\Structure\Enums\EstateClassification;
use Innobrain\Structure\Testing\SearchCriteriaFieldFactory;

$fake = Structure::fakeSearchCriteria([
    SearchCriteriaFieldFactory::singleSelect('vermarktungsart', ['kauf' => 'Kauf', 'miete' => 'Miete'])->mustMatchByDefault()->make(),
    SearchCriteriaFieldFactory::range('kaufpreis')->category('Preise')->appliesTo(EstateClassification::MarketingType, 'kauf')->make(),
    SearchCriteriaFieldFactory::regions()->make(),
]);

$fake->assertRetrieved();
bash
php artisan vendor:publish --provider="Innobrain\Structure\StructureServiceProvider" --tag="onoffice-structure-config"