QuestionController.php
1.72 KB
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
<?php
class QuestionController extends NodeSiteController
{
    /** @var QuestionRoot */
    public $questionRoot;
    public function init()
    {
        parent::init();
        $this->questionRoot = QuestionRoot::model()->findByPk($this->getNode()->data_id);
        $this->headerGalleryId = $this->questionRoot->header_gallery_id;
    }
    public function actionIndex($category = null)
    {
        $questionCategories = QuestionCategory::model()->with('i18n')->findAll(array(
            'order' => 'rank asc',
            'condition'=>'question_root_id = '. $this->getNode()->data_id,
        ));
        if (isset($category)) {
            /** @var $currentCategory QuestionCategory */
            $currentCategory = QuestionCategory::model()->findByAttributes(array(
                'link' => $category,
            ));
            if (empty($currentCategory)) throw new CHttpException(404);
            $this->sectionGalleryId = $currentCategory->gallery_id;
        } else {
            $currentCategory = $questionCategories[0];
        }
        $questions = Question::model()->with('i18n')->findAll(array(
            'condition' => 'question_category_id=' . $currentCategory->id
        ));
        $this->pageName = $currentCategory->i18n->page_name;
        $this->setSEOParams($currentCategory->i18n->title, $currentCategory->i18n->keywords, $currentCategory->i18n->description);
        $this->setContacts(explode(',',$currentCategory->contacts_data));
        $this->setContacts(explode(',',$this->questionRoot->contacts_data));
        $this->render('index', array(
            'questionCategories' => $questionCategories,
            'questions' => $questions,
            'currentCategory' => $currentCategory,
        ));
    }
}