actions.class.php 2.59 KB
Newer Older
Яков's avatar
first  
Яков committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php

/**
 * video actions.
 *
 * @package    sf
 * @subpackage video
 * @author     Atma
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class videoActions extends sfActions
{
    /**
     * Executes index action
     *
     * @param sfRequest $request A request object
     */
    public function executeIndex(sfWebRequest $request)
    {
        $this->culture = $this->getUser()->getCulture();

        $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();

        $count_videos = count($this->videos);

        if ($request->getParameter('tag_id'))
        {
            $this->tag_id = $request->getParameter('tag_id');
        }else
        {
            $this->tag_id = 'all';
        }


        $tags = Doctrine_Query::create()
            ->select('t.*, tt.*, vt.*')
            ->from('Tag t')
            ->leftJoin('t.Translation tt WITH tt.lang = ?', $this->culture)
            ->leftJoin('t.VideoTags vt WITH vt.tag_id = t.id')
            ->fetchArray();

        $this->videos_tags = array();

        foreach ($tags as $tag)
        {
            if (count($tag['VideoTags']) > 0 )
            {
                $this->videos_tags[] = $tag;
            }
        }

        if ($request->getParameter('tag_id') && $request->getParameter('tag_id') != 'all' && $count_videos >= sfConfig::get('app_view_count_tag')) {
            unset($this->videos);

            $videos = Doctrine_Query::create()
                ->select('')
                ->from('Tag t')
                ->where('t.id = ?', $request->getParameter('tag_id'))
                ->leftJoin('t.VideoTags at WITH t.id = at.tag_id')
                ->leftJoin('at.Video a WITH at.video_id = a.id')
                ->innerJoin("a.Translation ta")
                ->andwhere("ta.lang = ?", $this->culture)
                ->andWhere("ta.available = 1")
                ->fetchArray();
            $this->videos = array();
            foreach ($videos[0]['VideoTags'] as $video) {
                $this->videos[] = $video['Video'];
            }
            $this->forward404Unless($this->videos);

        }

        if ($request->getParameter('tag_id') && $request->getParameter('ajax'))
        {
            sfContext::getInstance()->getConfiguration()->loadHelpers('Partial');
            echo include_partial('video/video', array('videos' => $this->videos, 'die' => true));
        }
    }
}