<?php

class suggestVideoSegmentTagListAction extends sfAction
{
  public function execute($request)
  {
    // Parse request
    $text = $request->getParameter('q');
    $limit = (int) $request->getParameter('limit', 10);

    // Retrieve video
    $query = Doctrine_Query::create()
      ->from('ThdTag')
      ->where("uniqueid like '{$text}%'")
      ->limit($limit);
    $tags = Array();

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

    $response = $this->getResponse();
    $response->clearHttpHeaders();
    $response->setContent(implode('\n', $tags));
    return sfView::NONE;
  }
}