public function actionAddLanguage() { $ok = 0; $message = 'Your request is invalid'; $redirectUrl = null; if (Yii::app()->request->isAjaxRequest && isset($_POST['id'])) { $id = intval($_POST['id']); $model = AllLanguages::model()->findByPk($id); if ($model) { $existedLanguage = ExtLanguages::model()->findByAttributes(array('code2' => $model->code2)); if ($existedLanguage) { $message = 'Language "' . $existedLanguage->name . '" already exists!'; } else { $newLanguage = new ExtLanguages(); $newLanguage->unsetAttributes(); $newLanguage->attributes = $model->attributes; $newLanguage->status = 1; $newLanguage->asDefault = 0; if ($newLanguage->save()) { $ok = 1; $message = 'New languge added successfully.'; $redirectUrl = Yii::app()->request->urlReferrer; } else { $message = 'Error! languge not added'; } } } } echo json_encode(array('ok' => $ok, 'message' => $message, 'redirectUrl' => $redirectUrl)); Yii::app()->end(); }
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)); } }