<?php
/**
 * This file is part of the sfSearch package.
 * (c) Carl Vondrick <carl.vondrick@symfony-project.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * A retort to generate a route.
 *
 * @package sfSearch
 * @subpackage Result
 * @author Carl Vondrick
 */
final class xfRetortDirectRoute implements xfRetort {
    /**
     * The method bound to
     *
     * @var string
     */
    private $method = 'getRoute';

    /**
     * Constructor
     *
     * @param string $template The route template
     */
    public function __construct()
    {
    }

    /**
     * The method to accept
     *
     * @param string $method
     */
    public function setMethod($method)
    {
        $this->method = $method;
    }

    /**
     *
     * @see xfRetort
     */
    public function can(xfDocumentHit $hit, $method, array $args = array())
    {
        return $this->method == $method;
    }

    /**
     *
     * @see xfRetort
     */
    public function respond(xfDocumentHit $hit, $method, array $args = array())
    {
		$ContentTree = ContentTree::instance();
    	$ContentTree->build();
//        $ContentTreeNode = $ContentTree->getContentTreeNodeById($hit->getDocument()->getField('id')->getValue());
        $ContentTreeNode = $ContentTree->getContentTreeNodeById($hit->getDocument()->getField('node_id')->getValue());
        return $ContentTreeNode->getUrl();
    }
}