<?php

/**
 * reflex actions.
 *
 * @package    thd
 * @subpackage reflex
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class reflexActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
  	///reflex/:film_uniqueid/:tag/:direction
  	// Parse request parameters
    $format = $request->getRequestFormat();
    $this->film_uniqueid = (string) $request->getParameter('film_uniqueid');   
    $this->tag = (string) $request->getParameter('tag');
    $this->direction = (string) $request->getParameter('direction');
    $this->distance = (int)$request->getParameter('distance');
    
    $this->distance = $this->distance * ($this->direction=='more'?1.0:-1.0) / 100.0;

    $sonyengine = SonyengineClient::getInstance();
    $result = $client->engineFind($this->film_uniqueid,$this->tag,$this->distance,true);
    foreach($results as $res)
    {
      $primaryKeys[] = $res['id'];
    }

    if(!empty($primaryKeys))
    {
      $this->mostTaggedFilms = Doctrine::getTable('ThdFilm')->findByScoredId($primaryKeys);       
    }
    else
    {
      $this->mostTaggedFilms = array();
    }
    
    return sfView::SUCCESS;
  }
}
