<?php

require_once 'model/om/BaseSnippetSnippet.php';


/**
 * Skeleton subclass for representing a row from the 'sn_snippet' table.
 *
 * 
 *
 * You should add additional methods to this class to meet the
 * application requirements.  This class will only be generated as
 * long as it does not already exist in the output directory.
 *
 * @package model
 */	
class SnippetSnippet extends BaseSnippetSnippet
{
  public function getTags()
  {
    return $this->getAllTags();
  }

  public function setTags($phrase)
  {
    $con = Propel::getConnection();
    try
    {
      $con->begin();

      // remove old tags
      $c = new Criteria();
      $c->add(SnippetTagPeer::USER_ID, $this->getUserId());
      $c->add(SnippetTagPeer::SNIPPET_ID, $this->getId());
      SnippetTagPeer::doDelete($c);

      // add new tags
      $tags = TagTools::splitPhrase($phrase);
      foreach($tags as $word)
      {
        $tag = new SnippetTag();
        $tag->setUserId($this->getUserId());
        $tag->setSnippetSnippet($this);
        $tag->setName(TagTools::normalize($word));
        $tag->save($con);
      }

      $con->commit();

    }
    catch (Exception $e)
    {
      $con->rollback();
      throw $e;
    }
  }

  public function getItemFeedDescription()
  {
    return $this->getHtmlBody();
  }

  public function setBody($body)
  {
    parent::setBody($body);

    $this->setHtmlBody(myToolkit::transformToHtml($body));
  }
}

