Skip to content

AVACloud demo in PHP to read, write, convert and create GAEB files

License

Notifications You must be signed in to change notification settings

Dangl-IT/avacloud-demo-php

Repository files navigation

avacloud-demo-php

AVACloud is a web based Software as a Service (SaaS) offering for GAEB files.
The GAEB standard is a widely used format to exchange tenderings, bills of quantities and contracts both in the construction industry and in regular commerce. AVACloud uses the GAEB & AVA .Net Libraries and makes them available to virtually all programming frameworks via a web service.

This project here contains example code in PHP to read and convert GAEB files. The client code is generated from the AVACloud Swagger Specification.

Client Libraries

The client libraries are available here:
https://github.com/Dangl-IT/Dangl.AVACloudClientGenerator/releases

The PHP client is available on Packagist: https://packagist.org/packages/dangl/avacloud

Installation

  1. Run composer install in the root directory.

Alternative Install with Source Code

Instead of importing the dependency via Composer, you can manually download the source from here: https://github.com/Dangl-IT/Dangl.AVACloudClientGenerator/releases. Just make sure to run composer install after unzipping the client code.

Run the Project

Simply run the PHP server in the root of this repository and navigate to /demo.php. The script will send the GAEB file GAEBXML_EN.X86 to the AVACloud API and print the converted project to the screen. Additionally, it will print the item numbers for all encountered positions in the project.

Please make sure that the $clientId and $clientSecret variables are set at the top of the demo.php. See the next section for details.

Create new GAEB Files with PHP

The /create-new-project.php file works similar to the regular demo. It uses the Dangl.AVA project format to create a GAEB file in PHP by sending an object to AVACloud. The returned GAEB file is printed to the screen.

Authentication

You will need to authenticate with AVACloud with your client secret and client id. These are the credentials of your Dangl.Identity OAuth2 client that is configured to access AVACloud.
If you don't have values for ClientId and ClientSecret yet, you can check out the documentation for instructions on how to register for AVACloud and create an OAuth2 client.

Example Code - Iterating over all Elements

The following PHP snippet displays how you can iterate recursively over all elements in a Dangl.AVA project:

$project = getProject();

$baseContainer = $project->serviceSpecifications[0];
$elements = getElementsInContainer($baseContainer);

foreach ($elements as $element) {
    if ($element->elementTypeDiscriminator == 'PositionDto') {
        // The 'elementTypeDiscriminator' identifies the kind of element,
        // in this case it's a position
        echo $element->itemNumber->stringRepresentation.'<br>';
        // You can also set the price for a position
        $element->unitPriceOverride = 200.0;
    }
}

function getElementsInContainer($container) {
    $elementsList = [];
    foreach ($container->elements as $element) {
        array_push($elementsList, $element);
        if ($element->elementTypeDiscriminator == 'ServiceSpecificationGroupDto') {
            $childElements = getElementsInContainer($element);
            foreach ($childElements as $childElement) {
                array_push($elementsList, $childElement);
            }
        }
    }

    return $elementsList;
}

To print the whole structure of the service specification, you can use code like this:

$result = $apiInstance->gaebConversionConvertToAva($gaebFile);
printElementTypes($result->getServiceSpecifications()[0]->getElements());

function printElementTypes($elements) {
    foreach ($elements as $element) {
        if ($element->getElementTypeDiscriminator() == 'ServiceSpecificationGroupDto') {
            echo 'Group start '.$element->getItemNumber()->getStringRepresentation()
            .' - '
            .$element->getShortText()
            .'<br>';
            // Groups have elements of their own
            printElementTypes($element->getElements());
            echo 'Group end '.$element->getItemNumber()->getStringRepresentation().'<br>';
        } else if ($element->getElementTypeDiscriminator() == 'PositionDto') {
            echo 'Position '.$element->getItemNumber()->getStringRepresentation()
            .' - '
            .$element->getShortText()
            .'<br>';
        } else if ($element->getElementTypeDiscriminator() == 'NoteTextDto') {
            echo 'Note Text<br>';
        } else if ($element->getElementTypeDiscriminator() == 'ExecutionDescriptionDto') {
            echo 'ExecutionDescription<br>';
        }
    }
}

License

About

AVACloud demo in PHP to read, write, convert and create GAEB files

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages