Ejemplo n.º 1
0
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     $uploadFile = new UploadForm();
     $uploadImg = new UploadForm();
     if (Yii::$app->request->isPost) {
         $uploadFile->file = UploadedFile::getInstance($uploadFile, 'file');
         $uploadImg->img = UploadedFile::getInstance($uploadImg, 'img');
         if ($uploadFile->file && $uploadFile->validate()) {
             $uploadFile->file->saveAs('uploads/' . Yii::$app->translater->translit($uploadFile->file->baseName) . '.' . $uploadFile->file->extension);
         } elseif ($uploadImg->img && $uploadImg->validate()) {
             $uploadImg->img->saveAs('uploads/' . Yii::$app->translater->translit($uploadImg->img->baseName) . '.' . $uploadImg->img->extension);
         } else {
             print_r($uploadFile->getErrors());
         }
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->text = Yii::$app->request->post('Items')['text'];
         $model->tags = Yii::$app->request->post('Items')['tags'];
         $model->title = Yii::$app->request->post('Items')['title'];
         $model->cens = Yii::$app->request->post('Items')['cens'];
         //$model->cat_id = Yii::$app->request->post('Items')['cat_id'];
         if (Categories::find()->where(['title' => Yii::$app->request->post('Items')['cat_title']])->one()) {
             $model->cat_id = Categories::find()->where(['title' => Yii::$app->request->post('Items')['cat_title']])->one()->id;
         }
         $model->audio_link = Yii::$app->request->post('Items')['audio_link'];
         $model->in_work_prim = Yii::$app->request->post('Items')['in_work_prim'];
         //$model->play_status = 1;
         Tag::addTags($model->tags, $id);
         //if(isset(Yii::$app->request->post('Items')['source_id']))$model->source_id = Yii::$app->request->post('Items')['source_id'];
         //else $model->source_id = 2;
         if (Source::find()->where(['title' => Yii::$app->request->post('Items')['source_title']])->one()) {
             $model->source_id = Source::find()->where(['title' => Yii::$app->request->post('Items')['source_title']])->one()->id;
         } else {
             $model->source_id = 2;
         }
         if (isset($uploadFile->file)) {
             $model->audio = Url::base() . 'uploads/' . Yii::$app->translater->translit($uploadFile->file->baseName) . '.' . $uploadFile->file->extension;
         }
         if (isset($uploadImg->img)) {
             $model->img = Url::base() . 'uploads/' . Yii::$app->translater->translit($uploadImg->img->baseName) . '.' . $uploadImg->img->extension;
         }
         $model->save(false);
         return $this->redirect(Url::toRoute('item/index'));
     } else {
         return $this->render('_form', ['model' => $model, 'uploadFile' => $uploadFile, 'uploadImg' => $uploadImg]);
     }
 }
Ejemplo n.º 2
0
 /**
  * Запись айтема
  * @return string|void
  */
 public function actionRecordItem()
 {
     if (Yii::$app->getRequest()->getQueryParam('user')) {
         $user = MarkUser::findOne(Yii::$app->getRequest()->getQueryParam('user'));
         if (Yii::$app->getRequest()->getQueryParam('source') && Yii::$app->getRequest()->getQueryParam('tags') && Yii::$app->getRequest()->getQueryParam('cat') && Yii::$app->getRequest()->getQueryParam('txt') && Yii::$app->getRequest()->getQueryParam('title')) {
             // return nl2br(Yii::$app->getRequest()->getQueryParam('txt'));
             $act = new DiaryActs();
             $act->model_id = 7;
             $act->user_id = $user->id;
             $act->mark = 1;
             if ($act->save(false)) {
                 $item = new Items();
                 $item->text = Yii::$app->getRequest()->getQueryParam('txt');
                 $item->tags = Yii::$app->getRequest()->getQueryParam('tags');
                 $item->title = Yii::$app->getRequest()->getQueryParam('title');
                 $item->cens = Yii::$app->getRequest()->getQueryParam('cens');
                 // return var_dump($item);
                 if (Yii::$app->getRequest()->getQueryParam('old_data')) {
                     $item->old_data = Yii::$app->getRequest()->getQueryParam('old_data');
                 }
                 if (Categories::find()->where("name like '" . trim(Yii::$app->getRequest()->getQueryParam('cat') . "'"))->one()) {
                     //  return var_dump(Categories::find()->where(['name' => Yii::$app->getRequest()->getQueryParam('cat')])->one()->id);
                     $item->cat_id = Categories::find()->where("name like '" . trim(Yii::$app->getRequest()->getQueryParam('cat') . "'"))->one()->id;
                 } else {
                     return "Категория!";
                 }
                 $item->in_work_prim = '';
                 $item->play_status = 1;
                 if (Source::find()->where("title like '" . Yii::$app->getRequest()->getQueryParam('source') . "'")->one()) {
                     // return var_dump(Source::find()->where(['title' => Yii::$app->getRequest()->getQueryParam('source')])->one()->id);
                     $item->source_id = Source::find()->where("title like '" . trim(Yii::$app->getRequest()->getQueryParam('source') . "'"))->one()->id;
                 } else {
                     return var_dump($item);
                 }
                 $item->act_id = $act->id;
                 //return var_dump($item);
                 if ($item->save(false)) {
                     Tag::addTags($item->tags, $item->id);
                 }
             }
             return "<p>Сохранено!</p>";
         }
         return $this->renderPartial('add_item');
     }
 }