예제 #1
0
    /**
     * Updates a particular model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id the ID of the model to be updated
     */
    public function actionUpdate($id)
    {
        $model = $this->loadModel($id);
        $messageModels = LanguageModel::model()->getAllLanguageModels($id);

        if (isset($_POST['SourceMessageModel'])) {
            $model->attributes = $_POST['SourceMessageModel'];
            if ($_POST['MessageModel']) {
                foreach ($_POST['MessageModel'] as $key => $value) {
                    if (!empty($value['translation'])) {
                        $messageModel = MessageModel::model()->findByAttributes(array('id' => $model->id, 'language' => $key));
                        if ($messageModel == null) {
                            $messageModel = new MessageModel;
                            $messageModel->language = $key;
                            $messageModel->id = $model->id;
                            $messageModel->setIsNewRecord(true);
                        } else {
                            $messageModel->setIsNewRecord(false);
                        }
                       // die($messageModel->isNewRecord);
                        $messageModel->attributes = $value;
                        $messageModel->save(false);
                    }
                }
            }
            if ($model->save())
                $this->redirect(array('index'));
        }

        $this->render('update', array(
            'model' => $model,
            'messageModels' => $messageModels,
        ));
    }
예제 #2
0
 /**
  * Load available languages.
  * @return LanguageModel collection
  */
 private function loadLanguages()
 {
     $model = LanguageModel::model()->cache(Yii::app()->controller->cacheTime)->findAll();
     foreach ($model as $lang) {
         $this->_languages[$lang->code] = $lang;
         if ($lang->default === '1') {
             $this->_default = $lang->code;
         }
     }
     return $this->_languages;
 }
예제 #3
0
 public function actionUpdate($new = false)
 {
     $this->topButtons = false;
     $model = $new === true ? new LanguageModel() : LanguageModel::model()->findByPk($_GET['id']);
     $this->breadcrumbs = array(Yii::t('app', 'LANGUAGES') => $this->createUrl('index'), $model->isNewRecord ? Yii::t('app', 'CREATED_LANG', 0) : CHtml::encode($model->name));
     $this->pageName = $model->isNewRecord ? Yii::t('app', 'CREATED_LANG', 0) : Yii::t('app', 'CREATED_LANG', 1);
     if (!$model) {
         throw new CHttpException(404, Yii::t('app', 'LANG_NOFIND'));
     }
     if (Yii::app()->request->isPostRequest) {
         $model->attributes = $_POST['LanguageModel'];
         if ($model->validate()) {
             $model->save();
             $this->redirect(array('index'));
         }
     }
     $this->render('update', array('model' => $model));
 }
예제 #4
0
 /**
  * @param $code
  * @return array|mixed|null
  */
 public static function getLanguageIdByCode($code)
 {
     $model = LanguageModel::model()->findByAttributes(array('code' => $code));
     return ($model !== null) ? $model->id : '';
 }
예제 #5
0
    function actionAddVariation() {
        if (isset($_GET['product_id']) && $_GET['product_id']) {
            $variation = new Variation();
            $variation->save();

            $variation_id = $variation->getPrimaryKey();

            $product2variation = new Product2variation();
            $product2variation->product_id = $_GET['product_id'];
            $product2variation->variation_id = $variation_id;
            $product2variation->save();

            $allLangs = LanguageModel::model()->findAll('1', array('order'=> 'id ASC'));
            foreach ($allLangs as $language) {
                $variation_description = new VariationDescription();
                $variation_description->variation_id = $variation_id;
                $variation_description->language_id = $language['id'];
                $variation_description->save();
            }
            $this->actionUpdate($_GET['product_id']);
            die();
        }
    }
예제 #6
0
파일: CMS.php 프로젝트: buildshop/bs-common
 /**
  * 
  * @return string
  */
 public static function autoDetectLanguage()
 {
     $sites = array();
     $languages = LanguageModel::model()->findAll();
     foreach ($languages as $lange) {
         //print_r($lange->code);
         $sites[$lange->code] = Yii::app()->request->hostInfo . "/" . $lange->code . '/';
     }
     $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
     if (!in_array($lang, array_keys($sites))) {
         $lang = Yii::app()->languageManager->default->code;
     }
     Yii::app()->language = $lang;
     // Yii::app()->controller->redirect($sites[$lang]);
     return $sites[$lang];
 }
예제 #7
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = LanguageModel::model()->findByPk($id);
     if ($model === null)
         throw new CHttpException(404, 'The requested page does not exist.');
     return $model;
 }