You are here

class Timeline in Views TimelineJS integration 8.3

Defines a TimelineJS3 timeline.

Hierarchy

Expanded class hierarchy of Timeline

1 file declares its use of Timeline
TimelineJS.php in src/Plugin/views/style/TimelineJS.php

File

src/TimelineJS/Timeline.php, line 8

Namespace

Drupal\views_timelinejs\TimelineJS
View source
class Timeline implements TimelineInterface {

  /**
   * The timeline scale.
   *
   * @var string
   */
  protected $scale = 'human';

  /**
   * The timeline's title slide.
   *
   * @var \Drupal\views_timelinejs\TimelineJS\SlideInterface
   */
  protected $titleSlide;

  /**
   * The timeline's array of event slides.
   *
   * @var \Drupal\views_timelinejs\TimelineJS\SlideInterface[]
   */
  protected $events = [];

  /**
   * The timeline's array of eras.
   *
   * @var \Drupal\views_timelinejs\TimelineJS\EraInterface[]
   */
  protected $eras = [];

  /**
   * {@inheritdoc}
   */
  public function setTitleSlide(SlideInterface $slide) {
    $this->titleSlide = $slide;
  }

  /**
   * {@inheritdoc}
   */
  public function getTitleSlide() {
    return $this->titleSlide;
  }

  /**
   * {@inheritdoc}
   */
  public function addEvent(SlideInterface $slide) {
    $this->events[] = $slide;
  }

  /**
   * {@inheritdoc}
   */
  public function getEvents() {
    return $this->events;
  }

  /**
   * {@inheritdoc}
   */
  public function addEra(EraInterface $era) {
    $this->eras[] = $era;
  }

  /**
   * {@inheritdoc}
   */
  public function getEras() {
    return $this->eras;
  }

  /**
   * {@inheritdoc}
   */
  public function setScaleToHuman() {
    $this->scale = 'human';
  }

  /**
   * {@inheritdoc}
   */
  public function setScaleToCosomological() {
    $this->scale = 'cosomological';
  }

  /**
   * {@inheritdoc}
   */
  public function getScale() {
    return $this->scale;
  }

  /**
   * {@inheritdoc}
   */
  public function buildArray() {
    $timeline = [
      'scale' => $this->scale,
    ];
    if (!empty($this->titleSlide)) {
      $timeline['title'] = $this->titleSlide
        ->buildArray();
    }
    foreach ($this->events as $event) {
      $timeline['events'][] = $event
        ->buildArray();
    }
    foreach ($this->eras as $era) {
      $timeline['eras'][] = $era
        ->buildArray();
    }
    return $timeline;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Timeline::$eras protected property The timeline's array of eras.
Timeline::$events protected property The timeline's array of event slides.
Timeline::$scale protected property The timeline scale.
Timeline::$titleSlide protected property The timeline's title slide.
Timeline::addEra public function Adds a new era to the timeline's eras array. Overrides TimelineInterface::addEra
Timeline::addEvent public function Adds a new slide to the timeline's events array. Overrides TimelineInterface::addEvent
Timeline::buildArray public function Creates an array representing the TimelineJS javascript object. Overrides ObjectInterface::buildArray
Timeline::getEras public function Returns the timeline's array of eras. Overrides TimelineInterface::getEras
Timeline::getEvents public function Returns the timeline's array of event slides. Overrides TimelineInterface::getEvents
Timeline::getScale public function Returns the timeline's scale. Overrides TimelineInterface::getScale
Timeline::getTitleSlide public function Returns the timeline's title slide. Overrides TimelineInterface::getTitleSlide
Timeline::setScaleToCosomological public function Sets the timeline's scale to cosmological. Overrides TimelineInterface::setScaleToCosomological
Timeline::setScaleToHuman public function Sets the timeline's scale to human. Overrides TimelineInterface::setScaleToHuman
Timeline::setTitleSlide public function Sets the timeline's title slide. Overrides TimelineInterface::setTitleSlide