intermediate commit
This commit is contained in:
@ -2,6 +2,10 @@
|
||||
|
||||
namespace backend\modules\document\controllers;
|
||||
|
||||
use common\models\DocumentField;
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\Shared\ZipArchive;
|
||||
use PhpOffice\PhpWord\TemplateProcessor;
|
||||
use Yii;
|
||||
use backend\modules\document\models\Document;
|
||||
use backend\modules\document\models\DocumentSearch;
|
||||
@ -10,6 +14,8 @@ use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
|
||||
use common\services\DocumentService;
|
||||
|
||||
/**
|
||||
* DocumentController implements the CRUD actions for Document model.
|
||||
*/
|
||||
@ -138,4 +144,70 @@ class DocumentController extends Controller
|
||||
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
|
||||
|
||||
public function actionCreateDocument($id)
|
||||
{
|
||||
$model = Document::findOne($id);
|
||||
|
||||
$file_title = $model->title;
|
||||
$template_title = $model->template->template_file_name;
|
||||
|
||||
|
||||
|
||||
$fieldaValueArr = $model->documentFieldValues;
|
||||
|
||||
foreach ($fieldaValueArr as $tmp) {
|
||||
echo $tmp['value'];
|
||||
}
|
||||
|
||||
die();
|
||||
|
||||
|
||||
// var_dump($file_title);
|
||||
// var_dump($template_title);
|
||||
// var_dump($fieldsArray);
|
||||
// die;
|
||||
// //, $template_name, [] $fields
|
||||
|
||||
|
||||
$documentService = new DocumentService($file_title, $template_title, $fieldsArray);
|
||||
$documentService->save();
|
||||
|
||||
|
||||
// $outputFile = 'review_full222.docx';
|
||||
//
|
||||
//
|
||||
// $PhpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
// $document = $PhpWord->loadTemplate('/var/www/guild.loc/backend/web/upload/templates/tets template.docx'); //шаблон
|
||||
// $document->setValue('FIO', '8888888888' );
|
||||
// $document->setValue('INN', '999999999999999999');
|
||||
//
|
||||
// $document->saveAs($outputFile);
|
||||
//
|
||||
// // Имя скачиваемого файла
|
||||
// $downloadFile = $outputFile;
|
||||
//
|
||||
// // Контент-тип означающий скачивание
|
||||
// header("Content-Type: application/octet-stream");
|
||||
//
|
||||
// // Размер в байтах
|
||||
// header("Accept-Ranges: bytes");
|
||||
//
|
||||
// // Размер файла
|
||||
// header("Content-Length: ".filesize($downloadFile));
|
||||
//
|
||||
// // Расположение скачиваемого файла
|
||||
// header("Content-Disposition: attachment; filename=".$downloadFile);
|
||||
//
|
||||
// // Прочитать файл
|
||||
// readfile($downloadFile);
|
||||
//
|
||||
//
|
||||
//
|
||||
// unlink($outputFile);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace backend\modules\document\controllers;
|
||||
|
||||
use common\helpers\TransliteratorHelper;
|
||||
use Yii;
|
||||
use backend\modules\document\models\DocumentField;
|
||||
use backend\modules\document\models\DocumentFieldSearch;
|
||||
|
@ -83,21 +83,8 @@ class TemplateController extends Controller
|
||||
{
|
||||
$model = new Template();
|
||||
|
||||
if ($model->load(Yii::$app->request->post())) {
|
||||
$model->template = UploadedFile::getInstance($model, 'template');
|
||||
|
||||
if (!empty($model->template)) {
|
||||
$pathToTemplates = Yii::getAlias('@templates');
|
||||
$model->template_file_name = date('mdyHis') . '_' . $model->template->name;
|
||||
|
||||
if ($model->save()) {
|
||||
if (FileHelper::createDirectory($pathToTemplates, $mode = 0775, $recursive = true)) {
|
||||
$model->template->saveAs($pathToTemplates . '/' . $model->template_file_name);
|
||||
}
|
||||
return $this->redirect(['template-document-field/create', 'template_id' => $model->id]);
|
||||
}
|
||||
return $this->render('create', ['model' => $model]);
|
||||
}
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['template-document-field/create', 'template_id' => $model->id]);
|
||||
}
|
||||
|
||||
return $this->render('create', [
|
||||
@ -115,34 +102,11 @@ class TemplateController extends Controller
|
||||
public function actionUpdate($id)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
// $pathToFile = Yii::getAlias('@templates') . '/' . $model->template_file_name;
|
||||
|
||||
// if ($model->load(Yii::$app->request->post())) {
|
||||
// $template = UploadedFile::getInstance($model, 'template');
|
||||
//
|
||||
// if (!empty($template)) {
|
||||
// $path = Yii::getAlias('@frontend') . '/web/upload/documents/templates';
|
||||
//
|
||||
// $model->template = $template;
|
||||
// $model->template_file_name = $model->template->name;
|
||||
// $model->template_path = $path . '/' . $model->template->name;
|
||||
//
|
||||
// if (!$model->template->saveAs($path . '/' . $model->template->name)) {
|
||||
// return $this->render('update', [
|
||||
// 'model' => $model,
|
||||
// ]);
|
||||
// }
|
||||
// }
|
||||
// if ($model->save()) {
|
||||
// return $this->redirect(['view', 'id' => $model->id]);
|
||||
// }
|
||||
// }
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
// $model->template = UploadedFile::getInstance($model, $pathToFile); // file($pathToFile);
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
]);
|
||||
|
Reference in New Issue
Block a user