public function actionGetTranslationsByCategory()
 {
     if (Yii::app()->request->isAjaxRequest && isset($_POST['language']) && isset($_POST['category']) && isset($_POST['listId'])) {
         $sourceModel = new SourceMessages();
         $sourceModel->unsetAttributes();
         $sourceModel->category = $_POST['category'];
         $sourceModel->language = $_POST['language'];
         $languageModel = ExtLanguages::model()->findByAttributes(array('code2' => $_POST['language']));
         $this->renderPartial('_translations_by_category', array('sourceModel' => $sourceModel, 'languageModel' => $languageModel, 'listId' => $_POST['listId']));
     }
 }
 public function run()
 {
     if (!TsTranslation::model()->isAccessEnabled()) {
         echo 'Error 403. You have no permission to use this widget!';
     } else {
         $this->registerClientScript();
         $languageModel = new ExtLanguages();
         $languageModel->unsetAttributes();
         $allLanguages = AllLanguages::model()->findAll();
         $allLanguagesList = CHtml::listData($allLanguages, 'id', 'name');
         $sourceTableName = SourceMessages::model()->tableName();
         $sql = 'SELECT `category` FROM ' . $sourceTableName . ' GROUP BY `category`';
         $categoryArray = Yii::app()->db->createCommand($sql)->queryColumn();
         $this->render('_translation_list', array('id' => $this->_id, 'model' => $languageModel, 'type' => $this->type, 'allLanguagesList' => $allLanguagesList, 'listOptions' => $this->listOptions, 'htmlOptions' => $this->htmlOptions, 'categoryArray' => $categoryArray, 'showDynamicContent' => $this->showDynamicContent));
     }
 }
 /**
  * Returns array of default language attributes, or attribute $attribute of default language
  * 
  * @param string $attribute
  * @return array or string
  */
 public static function getDefaultLanguage($attribute = false)
 {
     if ($attribute === 'code2') {
         if (isset(Yii::app()->request->cookies['_defaultLang']) && !empty(Yii::app()->request->cookies['_defaultLang']->value)) {
             return Yii::app()->request->cookies['_defaultLang']->value;
         } else {
             $defaultLanguage = ExtLanguages::model()->findByAttributes(array('asDefault' => 1));
             Yii::app()->request->cookies['_defaultLang'] = new CHttpCookie('_defaultLang', $defaultLanguage->code2, array('path' => '/'));
             return $defaultLanguage->code2;
         }
     }
     $defaultLanguage = ExtLanguages::model()->findByAttributes(array('asDefault' => 1));
     if ($attribute) {
         return $defaultLanguage->{$attribute};
     }
     return $defaultLanguage;
 }