PHP code example of salamek / moje-olomouc

1. Go to this page and download the library: Download salamek/moje-olomouc 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/ */

    

salamek / moje-olomouc example snippets


use Salamek\MojeOlomouc\MojeOlomouc;
use Salamek\MojeOlomouc\Model\ImportantMessage;
use Salamek\MojeOlomouc\Model\Identifier;
use Salamek\MojeOlomouc\Enum\ImportantMessageSeverityEnum;
use Salamek\MojeOlomouc\Enum\ImportantMessageTypeEnum;

$apiKey = 'YOUR_API_KEY';
$isProduction = false;
$mojeOlomouc = new MojeOlomouc($apiKey, $isProduction);

$importantMessage = new ImportantMessage(
    'Warning',
    new \DateTime('2018-11-10'),
    ImportantMessageTypeEnum::TRAFFIC_SITUATION,
    ImportantMessageSeverityEnum::WARNING,
    new \DateTime('2018-11-12')
);

// Create new important-message
$response = $mojeOlomouc->importantMessages->create([$importantMessage]);
if (!$response->isError())
{
    echo 'SUCCESS'.PHP_EOL;
    print_r($response->getData());
    echo 'New important message have ID: '.$importantMessage->getId();
}
else
{
    echo 'ERROR'.PHP_EOL;
    echo $response->getMessage().PHP_EOL;
}

// Update important-message
$importantMessage->setExpireAt(new \DateTime('2018-11-20'));
$response = $mojeOlomouc->importantMessages->update([$importantMessage]);
if (!$response->isError())
{
    echo 'SUCCESS'.PHP_EOL;
    print_r($response->getData());
}
else
{
    echo 'ERROR'.PHP_EOL;
    echo $response->getMessage().PHP_EOL;
}

// Delete important-message
$response = $mojeOlomouc->importantMessages->delete([$importantMessage]);
if (!$response->isError())
{
    echo 'SUCCESS'.PHP_EOL;
    print_r($response->getData());
}
else
{
    echo 'ERROR'.PHP_EOL;
    echo $response->getMessage().PHP_EOL;
}

// Or
$idToDelete = 10;
$response = $mojeOlomouc->importantMessages->delete([new Identifier($idToDelete)]);
if (!$response->isError())
{
    echo 'SUCCESS'.PHP_EOL;
    print_r($response->getData());
}
else
{
    echo 'ERROR'.PHP_EOL;
    echo $response->getMessage().PHP_EOL;
}