/**
  * Creates a new Gallery model.
  * For ajax request will return json object
  * and for non-ajax request if creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $request = Yii::$app->request;
     $model = new Gallery();
     if ($request->isAjax) {
         /*
          *   Process for ajax request
          */
         Yii::$app->response->format = Response::FORMAT_JSON;
         if ($request->isGet) {
             return ['title' => "Create Gallery", 'content' => $this->renderPartial('create', ['model' => $model])];
         } else {
             if ($model->load($request->post()) && $model->validate()) {
                 $model->name = Html::encode($model->name);
                 $model->date = date('Y-m-d H:i:s');
                 if ($model->save()) {
                     $alias = Yii::getAlias('@app/web/img/gallery/' . Translator::rus2translit($model->name));
                     try {
                         //если создавать рекурсивно, то работает через раз хз почему.
                         $old = umask(0);
                         mkdir($alias, 0777, true);
                         chmod($alias, 0777);
                         mkdir($alias . '/thumb', 0777);
                         chmod($alias . '/thumb', 0777);
                         umask($old);
                     } catch (\Exception $e) {
                         return 'Не удалось создать директорию ' . $alias . ' - ' . $e->getMessage();
                     }
                     return ['forceReload' => true, 'forceClose' => true, 'hideActionButton' => true, 'title' => "Create Gallery", 'content' => '<span class="text-success">Success!</span>'];
                 } else {
                     return ['title' => "Create Gallery", 'content' => $this->renderPartial('create', ['model' => $model])];
                 }
             } else {
                 return ['title' => "Create Gallery", 'content' => $this->renderPartial('create', ['model' => $model])];
             }
         }
     } else {
         /*
          *   Process for non-ajax request
          */
         if ($model->load($request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->gallery_id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     }
 }