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
111bf275
Commit
111bf275
authored
Feb 19, 2016
by
difox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable Drag&Drop
parent
27361ee6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
36 deletions
+64
-36
backend/web/css/site.css
backend/web/css/site.css
+10
-1
common/modules/school/controllers/CoursesAdminController.php
common/modules/school/controllers/CoursesAdminController.php
+21
-13
common/modules/school/forms/CourseForm.php
common/modules/school/forms/CourseForm.php
+24
-21
common/modules/school/models/Courses.php
common/modules/school/models/Courses.php
+9
-1
No files found.
backend/web/css/site.css
View file @
111bf275
...
...
@@ -120,4 +120,13 @@ a.desc:after {
.file-widget
{
margin-bottom
:
20px
;
}
.control-label
{
min-width
:
100px
;}
\ No newline at end of file
.control-label
{
min-width
:
100px
;}
.file-drop-zone
{
height
:
auto
;
}
.file-drop-zone-title
{
padding
:
35px
10px
;
}
.file-preview-image
{
height
:
100px
!important
;
}
\ No newline at end of file
common/modules/school/controllers/CoursesAdminController.php
View file @
111bf275
...
...
@@ -62,20 +62,28 @@ class CoursesAdminController extends AdminController
];
if
(
$model
->
load
(
Yii
::
$app
->
request
->
post
())
&&
$model
->
validate
()){
//Try to get file info
$model
->
upload_image
=
\yii\web\UploadedFile
::
getInstance
(
$model
,
'upload_image'
);
//If received, then I get the file name and asign it to $model->image in order to store it in db
if
(
!
empty
(
$model
->
upload_image
)){
$image_name
=
$model
->
upload_image
->
name
;
$model
->
image
=
$image_name
;
if
(
$model
->
filename
)
{
$model
->
image
=
$model
->
filename
;
}
else
{
//Try to get file info
$model
->
upload_image
=
\yii\web\UploadedFile
::
getInstance
(
$model
,
'upload_image'
);
//If received, then I get the file name and asign it to $model->image in order to store it in db
if
(
!
empty
(
$model
->
upload_image
)){
$image_name
=
$model
->
upload_image
->
name
;
$model
->
image
=
$image_name
;
}
}
$model
->
save
();
//If all went OK, then I proceed to save the image in filesystem
if
(
!
empty
(
$model
->
upload_image
)){
$model
->
upload_image
->
saveAs
(
$model
->
getPath
()
.
$image_name
);
if
(
!
$model
->
filename
)
{
//If all went OK, then I proceed to save the image in filesystem
if
(
!
empty
(
$model
->
upload_image
)){
$model
->
upload_image
->
saveAs
(
$model
->
getPath
()
.
$image_name
);
}
}
return
$this
->
redirect
([
'view'
,
'id'
=>
$model
->
id
]);
}
else
...
...
@@ -170,7 +178,7 @@ class CoursesAdminController extends AdminController
public
function
actionUpload
()
{
$model
=
new
Courses
;
if
(
empty
(
$_FILES
[
'Courses'
]))
{
if
(
empty
(
$_FILES
[
'Courses'
]))
{
echo
json_encode
([
'error'
=>
'No files found for upload.'
]);
// or you can throw an exception
return
;
// terminate
...
...
@@ -184,10 +192,10 @@ class CoursesAdminController extends AdminController
$paths
=
[];
// get file names
$filename
=
$images
[
'name'
][
"upload_image"
];
//
$filename = $images['name']["upload_image"];
// loop and process files
$ext
=
explode
(
'.'
,
basename
(
$filename
));
$target
=
$model
->
getPath
()
.
md5
(
uniqid
())
.
"."
.
array_pop
(
$ext
);
//
$ext = explode('.', basename($filename));
$target
=
$model
->
getPath
()
.
$images
[
'name'
][
"upload_image"
];
//
md5(uniqid()) . "." . array_pop($ext);
if
(
move_uploaded_file
(
$images
[
'tmp_name'
][
"upload_image"
],
$target
))
{
$success
=
true
;
$paths
[]
=
$target
;
...
...
common/modules/school/forms/CourseForm.php
View file @
111bf275
...
...
@@ -8,29 +8,31 @@ use common\modules\school\models\Courses;
use
common\modules\testings\models\Test
;
if
(
$model
->
image
)
{
$image
=
"<div class='file-widget'>"
.
FileInput
::
widget
([
'model'
=>
$model
,
'attribute'
=>
'upload_image'
,
'language'
=>
'en'
,
'options'
=>
[
'multiple'
=>
false
,
'accept'
=>
'image/*'
],
'pluginOptions'
=>
[
/*'uploadUrl' => Url::to(['/school/courses-admin/upload']),*/
'showUpload'
=>
false
,
'initialPreview'
=>
[
Html
::
img
(
$model
->
getUrl
(
$model
->
image
))
],
'overwriteInitial'
=>
true
]
])
.
"</div>"
;
}
else
{
$image
=
"<div class='file-widget'>"
.
FileInput
::
widget
([
'model'
=>
$model
,
'attribute'
=>
'upload_image'
,
'language'
=>
'en'
,
'options'
=>
[
'multiple'
=>
false
,
'accept'
=>
'image/*'
],
'pluginOptions'
=>
[
/*'uploadUrl' => Url::to(['/school/courses-admin/upload']),*/
'showUpload'
=>
false
,
'overwriteInitial'
=>
true
]
])
.
"</div>"
;
$initialImages
[]
=
Html
::
img
(
$model
->
getUrl
(
$model
->
image
));
}
$image
=
"<div class='file-widget'>"
.
FileInput
::
widget
([
'model'
=>
$model
,
'attribute'
=>
'upload_image'
,
'language'
=>
'en'
,
'options'
=>
[
'multiple'
=>
false
,
'accept'
=>
'image/*'
],
'pluginOptions'
=>
[
'uploadUrl'
=>
Url
::
to
([
'/school/courses-admin/upload'
]),
'showUpload'
=>
false
,
'overwriteInitial'
=>
true
,
'initialPreview'
=>
$initialImages
,
],
'pluginEvents'
=>
[
'fileuploaded'
=>
"function(event, data, previewId, index) {
$(
\"
[name='Courses[filename]']
\"
).val(data.files[0].name);
}"
,
'fileclear'
=>
"function(event) {
$(
\"
[name='Courses[filename]']
\"
).val();
}"
,
],
])
.
"</div>"
;
$elements
=
[
'test_id'
=>
[
'type'
=>
'dropdownlist'
,
'items'
=>
ArrayHelper
::
map
(
Test
::
find
()
->
all
(),
'id'
,
'name'
,
'session.name'
),
'empty'
=>
'Не задан'
],
'title'
=>
[
'type'
=>
'text'
],
...
...
@@ -41,6 +43,7 @@ $elements = [
'items'
=>
Courses
::
$type_list
,
],
'spec_proposition'
=>
[
'type'
=>
'checkbox'
],
'filename'
=>
[
'type'
=>
'hidden'
],
'image'
=>
$image
,
];
...
...
common/modules/school/models/Courses.php
View file @
111bf275
...
...
@@ -20,6 +20,8 @@ class Courses extends \common\components\ActiveRecordModel
public
$upload_image
;
public
$filename
;
public
static
$type_list
=
[
self
::
TYPE_IT
=>
'Для сотрудников it-отрасли'
,
self
::
TYPE_IM
=>
'Для интернет-маркетологов'
,
...
...
@@ -60,7 +62,7 @@ class Courses extends \common\components\ActiveRecordModel
[[
'type'
,
'spec_proposition'
,
'test_id'
],
'integer'
],
[[
'title'
],
'string'
,
'max'
=>
150
],
[[
'image'
],
'string'
,
'max'
=>
100
],
[[
'description'
,
'description_for_course'
],
'safe'
],
[[
'description'
,
'description_for_course'
,
'filename'
],
'safe'
],
[[
'upload_image'
],
'file'
,
'skipOnEmpty'
=>
true
,
'extensions'
=>
'png, jpg, jpeg, gif'
],
];
}
...
...
@@ -88,6 +90,12 @@ class Courses extends \common\components\ActiveRecordModel
}
}
public
function
afterFind
()
{
$this
->
filename
=
$this
->
image
;
parent
::
afterFind
();
}
public
function
getLessons
()
{
return
$this
->
hasMany
(
Lessons
::
className
(),
[
'course_id'
=>
'id'
]);
...
...
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