<?php

/**
 * This class has been auto-generated by the Doctrine ORM Framework
 */
class ThdSegment extends BaseThdSegment
{


  public function preInsert($event) {
    $this->uniqueid = UUID::generate(UUID::UUID_TIME, UUID::FMT_STRING,     "mosatags");
    $this->creation_date = strftime('%Y-%m-%d %H:%M:%S');
  }

  public function getTags() {
    $tags = Array();

    // Create query
    $query = Doctrine_Query::create()
      ->select("ST.*, T.*")
      ->from('ThdSegmentTag ST')
      ->leftJoin('ST.ThdTag T')
      ->leftJoin('ST.ThdSegment S')
      ->where("S.id='{$this->getId()}'");

    foreach ($query->execute() as $item) {
      $tags[] = $item->getThdTag()->getTag();
    }

    return $tags;
  }

  public function getDistinctTags() {
    $tags = Array();

    foreach ($this->getTags() as $tag) {
      if (in_array($tag, $tags)) continue;
      $tags[] = $tag;
    }

    return $tags;
  }

}
