<?php

/**
 * This class has been auto-generated by the Doctrine ORM Framework
 */
class ThdTag extends BaseThdTag
{
  /*
   * Add new tag and returns the new tag object
   * If already exists returns tag object
   */
  public static function addTag($tag) {
    $tagUid = ThdUtil::normalizeText($tag);

    // Search tag
    $query = Doctrine_Query::create()
      ->from('ThdTag')
      ->where("uniqueid = '{$tagUid}'");
    $obj = $query->execute()->getFirst();
    if ($obj) return $obj;

    // Tag does not exist so create it
    $obj = new ThdTag();
    $obj->setTag($tag);
    $obj->setUniqueid($tagUid);
    $obj->save();
    return $obj;
  }
}