Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taskonsite-архив-перенесен
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitry Korolev
taskonsite-архив-перенесен
Commits
9a707a6d
Commit
9a707a6d
authored
Feb 25, 2016
by
Олег Гиммельшпах
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#1032 - Доработка модуля bids drag and drop
parent
d7069127
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
218 additions
and
71 deletions
+218
-71
common/modules/bids/controllers/BidController.php
common/modules/bids/controllers/BidController.php
+47
-25
common/modules/bids/models/Bid.php
common/modules/bids/models/Bid.php
+11
-27
common/modules/bids/models/BidFile.php
common/modules/bids/models/BidFile.php
+91
-0
common/modules/bids/models/SearchBid.php
common/modules/bids/models/SearchBid.php
+1
-2
common/modules/bids/views/bid-admin/manage.php
common/modules/bids/views/bid-admin/manage.php
+10
-2
common/modules/bids/views/bid/mail-all.php
common/modules/bids/views/bid/mail-all.php
+10
-2
console/migrations/m160224_162315_upgrade_bids_files.php
console/migrations/m160224_162315_upgrade_bids_files.php
+34
-0
frontend/views/layouts/footer-index.php
frontend/views/layouts/footer-index.php
+3
-4
frontend/views/site/contacts.php
frontend/views/site/contacts.php
+3
-5
frontend/web/js/connect-form.js
frontend/web/js/connect-form.js
+3
-0
frontend/web/js/upload-files.js
frontend/web/js/upload-files.js
+5
-4
No files found.
common/modules/bids/controllers/BidController.php
View file @
9a707a6d
...
...
@@ -10,6 +10,7 @@ use yii\web\Response;
use
yii\web\UploadedFile
;
use
common\modules\bids\models\Bid
;
use
common\modules\bids\models\BidFile
;
/**
* BidAdminController implements the CRUD actions for Bid model.
...
...
@@ -30,28 +31,35 @@ class BidController extends \common\components\BaseController
*/
public
function
actionAdd
()
{
Yii
::
$app
->
response
->
format
=
Response
::
FORMAT_JSON
;
$model
=
new
Bid
;
$model
->
scenario
=
Yii
::
$app
->
request
->
post
(
'scenario'
);
if
(
Yii
::
$app
->
request
->
isAjax
)
if
(
Yii
::
$app
->
request
->
isAjax
&&
$model
->
load
(
Yii
::
$app
->
request
->
post
())
)
{
$model
->
load
(
Yii
::
$app
->
request
->
post
());
$model
->
file
=
UploadedFile
::
getInstance
(
$model
,
'file'
);
$transaction
=
Yii
::
$app
->
db
->
beginTransaction
();
Yii
::
$app
->
response
->
format
=
Response
::
FORMAT_JSON
;
$model
->
filename
=
$_POST
[
'file_name'
];
if
(
$model
->
validate
())
try
{
/*if($model->file
)
if
(
$model
->
save
()
)
{
$model->upload();
$model->file = null;
}*/
// Yii::$app->user->identity->afterSubscribe(12);
if
(
$model
->
file
)
{
foreach
(
$model
->
file
as
$filename
)
{
$file
=
new
BidFile
;
$file
->
bid_id
=
$model
->
id
;
$file
->
filename
=
$filename
;
$file
->
save
();
}
}
$model
->
save
();
$model
->
send
();
$transaction
->
commit
();
return
[
'success'
=>
true
];
}
else
...
...
@@ -59,6 +67,12 @@ class BidController extends \common\components\BaseController
return
ActiveForm
::
validate
(
$model
);
}
}
catch
(
Exception
$e
)
{
$transaction
->
rollBack
();
throw
$e
;
}
}
else
{
throw
new
NotFoundHttpException
(
'The requested page does not exist.'
);
...
...
@@ -68,16 +82,24 @@ class BidController extends \common\components\BaseController
public
function
actionUploadFiles
()
{
$model
=
new
Bid
();
if
(
!
empty
(
$_FILES
))
{
Yii
::
$app
->
response
->
format
=
Response
::
FORMAT_JSON
;
$model
=
new
BidFile
;
$model
->
file
=
UploadedFile
::
getInstanceByName
(
'file'
);
$tempFile
=
$_FILES
[
'file'
][
'tmp_name'
];
if
(
$model
->
file
)
{
if
(
!
file_exists
(
BidFile
::
path
()))
{
mkdir
(
BidFile
::
path
(),
0777
,
true
);
}
$
targetPath
=
$model
->
getPath
()
;
$
targetFile
=
$targetPath
.
$_FILES
[
'file'
][
'name'
];
$
model
->
filename
=
date
(
'dmYHis-'
)
.
uniqid
()
.
'.'
.
$model
->
file
->
extension
;
$
model
->
file
->
saveAs
(
BidFile
::
path
()
.
$model
->
filename
);
move_uploaded_file
(
$tempFile
,
$targetFile
);
return
$_FILES
[
'file'
][
'name'
];
return
[
'filename'
=>
$model
->
filename
];
}
}
}
common/modules/bids/models/Bid.php
View file @
9a707a6d
...
...
@@ -30,10 +30,6 @@ class Bid extends \common\components\ActiveRecordModel
const
TAG_INVOLVEMENT
=
'Вовлечение'
;
const
TAG_TREATMENT
=
'Обращение'
;
const
FILE_FOLDER
=
'/uploads/bids/'
;
public
$file
;
public
static
$form_titles
=
[
self
::
FORM_PROJECT
=>
'Расчитать проект'
,
self
::
FORM_CALLBACK
=>
'Обратный звонок'
,
...
...
@@ -46,6 +42,8 @@ class Bid extends \common\components\ActiveRecordModel
self
::
FORM_SUBSCRIBE
=>
'Ошибки'
,
];
public
$file
;
/**
* @inheritdoc
*/
...
...
@@ -81,12 +79,13 @@ class Bid extends \common\components\ActiveRecordModel
[[
'email'
],
'required'
,
'on'
=>
self
::
SCENARIO_SUBSCRIBE
],
[[
'file'
],
'file'
,
'skipOnEmpty'
=>
true
,
'extensions'
=>
'png, jpg, jpeg, gif, xls, xlsx, doc, docx, pdf'
],
[[
'text'
],
'string'
],
[[
'name'
],
'string'
,
'max'
=>
100
],
[[
'phone'
],
'string'
,
'max'
=>
30
],
[[
'email'
],
'string'
,
'max'
=>
70
],
[[
'filename'
,
'form'
],
'string'
,
'max'
=>
50
],
[[
'form'
],
'string'
,
'max'
=>
50
],
[[
'file'
],
'safe'
],
];
}
...
...
@@ -100,8 +99,6 @@ class Bid extends \common\components\ActiveRecordModel
'name'
=>
'Имя'
,
'phone'
=>
'Телефон'
,
'email'
=>
'Email'
,
'filename'
=>
'Прикрепленный файл'
,
'file'
=>
'Прикрепленный файл'
,
'text'
=>
'Сообщение'
,
'form'
=>
'Форма отправки'
,
'created_at'
=>
'Дата добавления'
,
...
...
@@ -109,25 +106,12 @@ class Bid extends \common\components\ActiveRecordModel
];
}
public
function
getUrl
()
{
return
Yii
::
$app
->
params
[
'frontUrl'
]
.
self
::
FILE_FOLDER
.
$this
->
filename
;
}
public
function
getPath
()
{
return
Yii
::
getAlias
(
'@frontend/web'
)
.
self
::
FILE_FOLDER
;
}
public
function
upload
()
{
if
(
!
file_exists
(
$this
->
getPath
()))
/**
* @return \yii\db\ActiveQuery
*/
public
function
getFiles
()
{
mkdir
(
$this
->
getPath
(),
0777
,
true
);
}
$this
->
filename
=
date
(
'dmYHis-'
)
.
uniqid
()
.
'.'
.
$this
->
file
->
extension
;
$this
->
file
->
saveAs
(
$this
->
getPath
()
.
$this
->
filename
);
return
$this
->
hasMany
(
BidFile
::
className
(),
[
'bid_id'
=>
'id'
]);
}
public
function
send
()
...
...
common/modules/bids/models/BidFile.php
0 → 100644
View file @
9a707a6d
<?php
namespace
common\modules\bids\models
;
use
Yii
;
/**
* This is the model class for table "bids_files".
*
* @property integer $id
* @property integer $bid_id
* @property string $filename
*
* @property Bids $bid
*/
class
BidFile
extends
\common\components\ActiveRecordModel
{
const
FILE_FOLDER
=
'/uploads/bids/'
;
public
$file
;
/**
* @inheritdoc
*/
public
static
function
tableName
()
{
return
'bids_files'
;
}
/**
* @inheritdoc
*/
public
function
name
()
{
return
'Файл заявки'
;
}
/**
* @inheritdoc
*/
public
function
behaviors
()
{
return
[
];
}
/**
* @inheritdoc
*/
public
function
rules
()
{
return
[
[[
'bid_id'
],
'required'
],
[[
'bid_id'
],
'integer'
],
[[
'filename'
],
'string'
,
'max'
=>
100
],
[[
'file'
],
'file'
,
'skipOnEmpty'
=>
true
,
'extensions'
=>
'png, jpg, jpeg, gif, xls, xlsx, doc, docx, pdf'
,
'maxFiles'
=>
4
],
[[
'bid_id'
],
'exist'
,
'skipOnError'
=>
true
,
'targetClass'
=>
Bid
::
className
(),
'targetAttribute'
=>
[
'bid_id'
=>
'id'
]],
];
}
/**
* @inheritdoc
*/
public
function
attributeLabels
()
{
return
[
'id'
=>
'ID'
,
'file'
=>
'Прикрепленный файл'
,
'bid_id'
=>
'Заявка'
,
'filename'
=>
'Файл'
,
];
}
/**
* @return \yii\db\ActiveQuery
*/
public
function
getBid
()
{
return
$this
->
hasOne
(
Bid
::
className
(),
[
'id'
=>
'bid_id'
]);
}
public
function
getUrl
()
{
return
Yii
::
$app
->
params
[
'frontUrl'
]
.
self
::
FILE_FOLDER
.
$this
->
filename
;
}
public
static
function
path
()
{
return
Yii
::
getAlias
(
'@frontend/web'
)
.
self
::
FILE_FOLDER
;
}
}
common/modules/bids/models/SearchBid.php
View file @
9a707a6d
...
...
@@ -19,7 +19,7 @@ class SearchBid extends Bid
{
return
[
[[
'id'
],
'integer'
],
[[
'name'
,
'phone'
,
'email'
,
'
filename'
,
'
text'
,
'created_at'
,
'form'
],
'safe'
],
[[
'name'
,
'phone'
,
'email'
,
'text'
,
'created_at'
,
'form'
],
'safe'
],
];
}
...
...
@@ -67,7 +67,6 @@ class SearchBid extends Bid
$query
->
andFilterWhere
([
'like'
,
'name'
,
$this
->
name
])
->
andFilterWhere
([
'like'
,
'phone'
,
$this
->
phone
])
->
andFilterWhere
([
'like'
,
'email'
,
$this
->
email
])
->
andFilterWhere
([
'like'
,
'filename'
,
$this
->
filename
])
->
andFilterWhere
([
'like'
,
'text'
,
$this
->
text
]);
return
$dataProvider
;
...
...
common/modules/bids/views/bid-admin/manage.php
View file @
9a707a6d
...
...
@@ -26,11 +26,19 @@ $this->params['breadcrumbs'][] = $this->title;
'phone'
,
'email:email'
,
[
'
attribute'
=>
'filename
'
,
'
header'
=>
'Файлы
'
,
'format'
=>
'html'
,
'value'
=>
function
(
$model
)
{
return
(
$model
->
filename
?
Html
::
a
(
$model
->
filename
,
$model
->
getUrl
())
:
null
);
$files
=
[];
if
(
$model
->
files
)
{
foreach
(
$model
->
files
as
$file
)
{
$files
[]
=
Html
::
a
(
$file
->
filename
,
$file
->
getUrl
());
}
}
return
implode
(
'<br>'
,
$files
);
}
],
'text:ntext'
,
...
...
common/modules/bids/views/bid/mail-all.php
View file @
9a707a6d
<?php
use
yii\helpers\Html
;
use
common\modules\bids\models\Bid
;
use
common\modules\bids\models\Bid
File
;
?>
Имя:
<?=
$model
->
name
?>
<br>
...
...
@@ -12,7 +12,15 @@ Email: <?=$model->email?><br>
Сообщение:
<?=
$model
->
text
?>
<br>
Файл:
<?=
(
$model
->
filename
?
Html
::
a
(
$model
->
filename
,
\Yii
::
$app
->
params
[
'frontUrl'
]
.
Bid
::
FILE_FOLDER
.
$model
->
filename
)
:
''
)
?>
<br>
<?php
if
(
$model
->
files
)
:
?>
<hr>
Файлы:
<?php
foreach
(
$model
->
files
as
$file
)
{
echo
Html
::
a
(
$file
->
filename
,
\Yii
::
$app
->
params
[
'frontUrl'
]
.
BidFile
::
FILE_FOLDER
.
$file
->
filename
)
.
'<br>'
;
}
?>
<hr>
<?php
endif
;
?>
Дата добавления заявки:
<?=
date
(
'd.m.Y H:i:s'
,
$model
->
created_at
)
?>
<br>
...
...
console/migrations/m160224_162315_upgrade_bids_files.php
0 → 100644
View file @
9a707a6d
<?php
use
yii\db\Schema
;
use
yii\db\Migration
;
class
m160224_162315_upgrade_bids_files
extends
Migration
{
// Use safeUp/safeDown to run migration code within a transaction
public
function
safeUp
()
{
$this
->
createTable
(
'bids_files'
,
[
'id'
=>
Schema
::
TYPE_PK
,
'bid_id'
=>
Schema
::
TYPE_INTEGER
.
'(11) NOT NULL'
,
'filename'
=>
Schema
::
TYPE_STRING
.
'(100) DEFAULT NULL'
]);
$this
->
dropColumn
(
'bids'
,
'filename'
);
$this
->
addForeignKey
(
'fk_bids_files_bid_id_bids_id'
,
'bids_files'
,
'bid_id'
,
'bids'
,
'id'
);
}
public
function
safeDown
()
{
$this
->
dropForeignKey
(
'fk_bids_files_bid_id_bids_id'
,
'bids_files'
);
$this
->
dropTable
(
'bids_files'
);
$this
->
addColumn
(
'bids'
,
'filename'
,
Schema
::
TYPE_STRING
.
'(50) DEFAULT NULL'
);
}
}
frontend/views/layouts/footer-index.php
View file @
9a707a6d
...
...
@@ -75,9 +75,6 @@ FileUploadBundle::register($this);
<div
class=
"file_upload_bt"
>
<div
class=
"file-upload"
>
<label>
<?php
/* echo $form->field($model, 'file', [
'template' => '<div class="row"><div class="col-sm-4">{input}</div></div>'
])->fileInput();*/
?>
<span>
Выбрать файл
</span>
</label>
</div>
...
...
@@ -85,7 +82,9 @@ FileUploadBundle::register($this);
<div
class=
"file_drop"
>
Перетащите файл в данную область
<br/>
или выберите файл с компьютера
</div>
</div>
</div>
<input
type=
"hidden"
name=
"file_name"
id=
'file_name'
value=
""
/>
<div
id=
"files-zone"
>
</div>
<?php
echo
Html
::
submitButton
(
'Рассчитать проект'
,
[
'class'
=>
'btn-default save-button'
]);
?>
<?php
ActiveForm
::
end
();
?>
...
...
frontend/views/site/contacts.php
View file @
9a707a6d
...
...
@@ -129,17 +129,15 @@ FileUploadBundle::register($this);
<div
class=
"file_upload_bt_cs"
>
<div
class=
"file-upload_cs"
>
<label>
<?php
/*echo $form->field($model, 'file', [
'template' => '<div class="row"><div class="col-sm-4">{input}</div></div>'
])->fileInput(); */
?>
<span>
Выбрать файл
</span>
</label>
</div>
<!--<input type="text" id="filename" class="filename_cs" disabled>-->
<div
class=
"file_drop_cs"
>
Перетащите файл в данную область
<br/>
или выберите файл с компьютера
</div>
</div>
</div>
<input
type=
"hidden"
name=
"file_name"
id=
'file_name'
value=
""
/>
<div
id=
"files-zone"
>
</div>
<?php
echo
Html
::
submitButton
(
'Отправить'
,
[
'class'
=>
'btn-default save-button'
]);
?>
...
...
frontend/web/js/connect-form.js
View file @
9a707a6d
...
...
@@ -39,6 +39,9 @@ $('form.bids-form').on('beforeSubmit', function(e) {
form
.
find
(
'
input:not(.not_clear), textarea
'
).
val
(
''
);
$
(
'
.send_secce
'
).
show
();
form
.
find
(
'
#files-zone
'
).
html
(
''
);
$
(
'
.dz-preview.dz-processing
'
).
remove
();
dataLayer
.
push
({
'
event
'
:
'
UA_event
'
,
'
Catagory
'
:
form
.
data
(
'
tag
'
),
...
...
frontend/web/js/upload-files.js
View file @
9a707a6d
...
...
@@ -6,15 +6,16 @@ $(document).ready(function() {
// var myDropzone = new Dropzone("div#block_upload", {url: "/bids/bid/upload-files", maxFiles: 1});
Dropzone
.
options
.
blockUpload
=
{
url
:
"
/bids/bid/upload-files
"
,
maxFiles
:
1
,
maxFiles
:
4
,
addRemoveLinks
:
true
,
dictRemoveFile
:
'
Удалить
'
,
/*accept: function(file, done) {
$('#file_name').val(file.name);
done();
},*/
success
:
function
(
first
,
response
)
{
$
(
'
#file_name
'
).
val
(
response
);
success
:
function
(
first
,
response
)
{
$
(
'
#files-zone
'
).
append
(
'
<input type="hidden" name="Bid[file][]" value="
'
+
response
.
filename
+
'
" />
'
);
$
(
'
.file_drop
'
).
hide
();
$
(
'
.file_drop_cs
'
).
hide
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment