public function actionDemo() { //Нужно найти проект с пометкой демо //Создать на основе него копию //И сделать редирект на его edit if (Yii::$app->user->isGuest) { $this->redirect(Url::toRoute(['intro/index'])); return; } $photobooks = Photobook::find()->where(['user_id' => Yii::$app->user->identity->getId(), 'status' => Photobook::STATUS_DEMO])->all(); if (count($photobooks) > 0) { $photobook = $photobooks[0]; $this->redirect(Url::toRoute(['photobooks/edit', 'ref' => AlphaId::id($photobook->user_id), 'id' => AlphaId::id($photobook->id)])); return; } $settingForm = new SettingForm(); $demo_account_id = $settingForm->getValue('demo_account_id', 0); $photobooks = Photobook::find()->where(['user_id' => $demo_account_id, 'status' => Photobook::STATUS_NEW])->all(); if (count($photobooks) > 0) { $photobook = $photobooks[0]; $photobookForm = new PhotobookForm(); if ($photobookForm->loadById($photobook->id)) { $result = $photobookForm->copyToUser(Yii::$app->user->identity->getId(), Photobook::STATUS_DEMO); if (!empty($result['response'])) { $pb_id = $result['response']['id']; $user_id = $result['response']['user_id']; $this->redirect(Url::toRoute(['photobooks/edit', 'ref' => AlphaId::id($user_id), 'id' => AlphaId::id($pb_id)])); return; } else { $this->redirect(Url::toRoute(['photobooks/index'])); return; } } else { $this->redirect(Url::toRoute(['photobooks/index'])); return; } } else { $this->redirect(Url::toRoute(['photobooks/index'])); return; } }
public function actionCopyToUser() { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $ref = Yii::$app->request->get('ref'); $id = Yii::$app->request->get('id'); $to_user_id = Yii::$app->request->get('user_id'); if (!empty($ref) && !empty($id)) { $user_id = AlphaId::id($ref, true); $pb_id = AlphaId::id($id, true); $model = new PhotobookForm(); if ($model->loadById($pb_id)) { return $model->copyToUser($to_user_id); } else { return ['error' => ['msg' => Yii::t('app', 'Фотокнига не найдена')]]; } } else { return ['error' => ['msg' => Yii::t('app', 'Фотокнига не найдена')]]; } }