public function run()
 {
     if ($this->checkAccess) {
         call_user_func($this->checkAccess, $this->id);
     }
     $params = Yii::$app->request->post();
     if (!isset($params['language'])) {
         throw new HttpException(404, Yii::t('cza', 'Language ({s1}) Not Found!', ['s1' => $params['language']]));
     }
     if (isset($params['src_model_id'])) {
         $model = $this->controller->retrieveModel($params['src_model_id']);
     } else {
         throw new HttpException(404, Yii::t('cza', 'Srouce model not found!'));
     }
     $translationModel = $model->getTranslation($params['language']);
     // handle cms media fields
     if ($this->controller instanceof \cza\base\components\controllers\backend\CmsController) {
         $cmsFields = $this->controller->getCmsFields();
         $translationModel->attachBehavior('CmsMediaBehavior', ['class' => CmsMediaBehavior::className(), 'fields' => $cmsFields, 'options' => ['isTranslation' => true]]);
     }
     if ($translationModel->load($params) && $translationModel->save()) {
         $responseData = \cza\base\models\statics\ResponseDatum::getSuccessDatum($_POST, array('message' => Yii::t('cza', 'Operation completed successfully!')));
     } else {
         $responseData = \cza\base\models\statics\ResponseDatum::getErrorDatum($_POST, array('message' => $translationModel->getFirstErrors()));
     }
     return \Yii::createObject(['class' => 'yii\\web\\Response', 'format' => \yii\web\Response::FORMAT_JSON, 'data' => $responseData]);
 }
Пример #2
0
 /**
  * 
  * @param type $id
  * @param type $allowReturnNew
  * @return \cza\base\components\controllers\backend\modelClass
  * @throws NotFoundHttpException
  */
 public function retrieveModel($id = null, $allowReturnNew = true)
 {
     $model = parent::retrieveModel($id, $allowReturnNew);
     $model->attachBehavior('BlameableBehavior', ['class' => BlameableBehavior::className()]);
     $cmsFields = $this->getCmsFields();
     if (!empty($cmsFields)) {
         $model->attachBehavior('CmsMediaBehavior', ['class' => CmsMediaBehavior::className(), 'fields' => $cmsFields]);
     }
     return $model;
 }