Skip to content

[Suggestion] Allow manual setting on Track layer order #5

@ghost

Description

Just a suggestion, but it would be great to have the ability to manually set each Tracks order, rather than only having the option of array index.

For example, I've found I need to add layers out of order, so I've had to create a middleware that allows me to re-order the Tracks before committing them to the SDK.

If Track had an order attribute and setter available, which fell-back/defaulted to the upstream Timeline array priority that would be incredible.

eg:

<?php
namespace Shotstack\Client\Model;
class Track implements ModelInterface, ArrayAccess
{
  //...
   public function setOrder(int $order)
    {
        $this->container['order'] = $order;

        return $this;
    }

    public function getOrder()
    {
        return $this->container['order'] ?? null;
    }
}
<?php
namespace Shotstack\Client\Model;
class Timeline implements ModelInterface, ArrayAccess
{
  //...
  public function getTracks()
    {
       $originalTracks = $this->container['tracks'];
        $orderedTracks = [];
        $tracks = [];
        foreach($originalTracks as $track) {
           if($track->getOrder()) {
               $orderedTracks[] = $track;
           } else { 
              $tracks[] = $track;
           }
        }
        // I'm using a third-party library here to pull all the ...
        array_unshift($orderedTracks, $tracks);
        
        return $tracks;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions