/** * Creates a new RramatDocfiles model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (Yii::$app->request->isAjax && Yii::$app->request->isPost) { $UploadFile = new UploadDocFile(); $UploadFile->docFile = UploadedFile::getInstance($UploadFile, 'docFile'); $UploadTrigger = $UploadFile->upload(); if ($UploadTrigger['success']) { $Docfiles = new Docfiles(); $Docfiles->docfiles_hash = $UploadTrigger['savedhashfilename_utf8']; $Docfiles->docfiles_name = $UploadTrigger['savedfilename']; $Docfiles->docfiles_ext = $UploadTrigger['fileextension']; if ($Docfiles->save()) { $RramatDocfiles = new RramatDocfiles(); $RramatDocfiles->id_docfiles = $Docfiles->primaryKey; $RramatDocfiles->id_recoveryrecieveaktmat = $_POST['id_recoveryrecieveaktmat']; if ($RramatDocfiles->save()) { echo json_encode(['ok']); } else { throw new HttpException(500, Proc::ActiveRecordErrorsToString($RramatDocfiles)); } } else { throw new HttpException(500, Proc::ActiveRecordErrorsToString($Docfiles)); } } else { throw new HttpException(500, 'Ошибка при загрузке файла'); } } else { throw new HttpException(500, 'Ошибка запроса'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Docfiles::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['docfiles_id' => $this->docfiles_id]); $query->andFilterWhere(['like', 'docfiles_name', $this->docfiles_name])->andFilterWhere(['like', 'docfiles_hash', $this->docfiles_hash])->andFilterWhere(['like', 'docfiles_ext', $this->docfiles_ext]); return $dataProvider; }
/** * Finds the Docfiles model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Docfiles the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Docfiles::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getIdDocfiles() { return $this->hasOne(Docfiles::className(), ['docfiles_id' => 'id_docfiles'])->from(['idDocfiles' => Docfiles::tableName()]); }
public static function DeleteDocFile($docfile_id) { if (!empty($docfile_id)) { $existdb1 = RraDocfiles::find()->andWhere(['id_docfiles' => $docfile_id])->count(); $existdb2 = RramatDocfiles::find()->andWhere(['id_docfiles' => $docfile_id])->count(); if (empty($existdb1) && empty($existdb2)) { $Docfiles = Docfiles::findOne($docfile_id); if (!empty($Docfiles)) { $hash = Yii::$app->basePath . '/docs/' . $Docfiles->docfiles_hash; $fileroot = DIRECTORY_SEPARATOR === '/' ? $hash : mb_convert_encoding($hash, 'Windows-1251', 'UTF-8'); if ($Docfiles->delete() && file_exists($fileroot)) { return unlink($fileroot); } } } } return false; }