<?php
class videoComponents extends sfComponents
{
    public function executeVideo(sfWebRequest $request)
    {
        $this->culture = $this->getUser()->getCulture();
        if ($request->getParameter('alias')) {
            $productTags = Doctrine::getTable('Product')->findOneByAlias($request->getParameter('alias'))->getProductTags();
            $idsTags = array();
            foreach ($productTags as $tag) {
                $idsTags[] = $tag->getTagId();
            }

            if (count($idsTags) > 0) {
                $q = Doctrine_Query::create()
                    ->select("v.*, t.*")
                    ->from("Video v")
                    ->innerJoin("v.Translation t")
                    ->where("t.lang = ?", $this->getUser()->getCulture())
                    ->andWhere("t.available = 1")
                    ->innerJoin('v.VideoTags vt')
                    ->andWhereIn('vt.tag_id', $idsTags);

                if (isset($this->limit) && $this->limit) {
                    $q->limit($this->limit);
                }
                $this->videos = $q->fetchArray();
            } else {
                $q = array();
            }
        }else
        {
            $this->videos = Doctrine_Query::create()
                ->select("v.*, t.*")
                ->from("Video v")
                ->innerJoin("v.Translation t")
                ->where("t.lang = ?", $this->getUser()->getCulture())
                ->andWhere("t.available = 1")
                ->fetchArray();
        }
        //print_r($request->getParameter('alias'));
    }
}