PHP code example of juanparati / podium

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

    

juanparati / podium example snippets


$client = new \Juanparati\Podium\Podium(
        session: '12346',
        clientId: 'myClientId',
        clientSecret: 'myClientSecret'
);

$client->authenticate(
    new \Juanparati\Podium\Auths\AppAuth(
        appId: '987654',      
        appToken: 'myAppToken'
    )
);

$item = (new \Juanparati\Podium\Requests\ItemRequest($client))->get(itemId: 11111111);

$models = (new \Juanparati\Podium\Requests\ItemRequest($client))->filter(appId: 987654);

$models =  (new \Juanparati\Podium\Models\ItemFilterModel([], $client))           
        ->setSortBy('last_edit_on')
        ->setSortDesc(true)
        ->setLimit(5);

$itemNum = 0;

foreach ($models->items() as $item) {
    print_r($item->originalValues())
    
    // The setLimit options indicate the limit of items per page to the request,
    // but the generator will automatically request the next page.
    // In order to limit the number of results we should manually limit the results.
    if ($itemNum === 10)
        break;
        
    $itemNum++;   
}

$item->originalValues();

$item->decodeValue();

// Accessing to the fields
$item->fields->decodeValue();

// Accessing to specific values
$item->fields->title;
$item->fields->{'my-custom-field'};

// Accessing to specific values
$item->fields->title = "My new title";
$item->save(silent: false, hook: true); // Will perform silent update calling the bounded hooks 

$attr = [
    'title' => 'My new title'
    'revenue' => ['currency' => 'DKK', 'value' => 123.34];
];

(new \Juanparati\Podium\Requests\ItemRequest($client))->create(
    appId: 987654,
    attr: $attr,
    silent: false,
    hook: false
);

$item = (new \Juanparati\Podium\Requests\ItemRequest($client))->get(itemId: 11111111);
echo $item->fields->{'my-long-named-field'};

$item->setOptions([
    \Juanparati\Podium\Models\ItemFieldModel::class => [
        \Juanparati\Podium\Models\ItemFieldModel::OPTION_KEY_AS => \Juanparati\Podium\Models\ItemFieldModel::KEY_AS_SNAKECASE,
    ]
);

echo $item->fields->my_long_named_field;

$item->setOptions([
    \Juanparati\Podium\Models\ItemFieldModel::class => [
        \Juanparati\Podium\Models\ItemFieldModel::OPTION_KEY_AS => \Juanparati\Podium\Models\ItemFieldModel::KEY_AS_FIELD_ID,
    ]
);

echo $item->fields->{'12345567'};

$item = (new \Juanparati\Podium\Requests\ItemRequest($client))->get(itemId: 11111111);

$item->setOptions([
    \Juanparati\Podium\Models\ItemFieldModel::class => [
        \Juanparati\Podium\Models\ItemFields\DateItemField::class => [
            \Juanparati\Podium\Models\ItemFields\DateItemField::OPTION_TIMEZONE => 'Europe/Copenhagen',
            \Juanparati\Podium\Models\ItemFields\DateItemField::OPTION_FORMAT => \Juanparati\Podium\Models\ItemFields\DateItemField::FORMAT_TIMESTAMP
        ]
    ]
);