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
d3f88425
Commit
d3f88425
authored
Feb 17, 2016
by
Виталий Мурашко
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload lesson documents
parent
37ac2dd5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
161 additions
and
0 deletions
+161
-0
common/modules/school/models/LessonImage.php
common/modules/school/models/LessonImage.php
+73
-0
common/modules/school/models/Lessons.php
common/modules/school/models/Lessons.php
+57
-0
console/migrations/m160217_095148_create_school_lessons_image.php
...migrations/m160217_095148_create_school_lessons_image.php
+31
-0
No files found.
common/modules/school/models/LessonImage.php
0 → 100644
View file @
d3f88425
<?php
namespace
common\modules\school\models
;
use
Yii
;
use
common\modules\school\models\Lessons
;
/**
* This is the model class for table "testings_questions_image".
*
* @property integer $id
* @property integer $question_id
* @property string $filename
*/
class
LessonImage
extends
\common\components\ActiveRecordModel
{
/**
* @inheritdoc
*/
public
static
function
tableName
()
{
return
'school_lessons_image'
;
}
public
function
name
()
{
return
'Документы для уроков'
;
}
/**
* @inheritdoc
*/
public
function
rules
()
{
return
[
[[
'lesson_id'
,
'filename'
],
'required'
],
[[
'lesson_id'
],
'integer'
],
[[
'filename'
],
'string'
,
'max'
=>
50
],
];
}
/**
* @inheritdoc
*/
public
function
attributeLabels
()
{
return
[
'id'
=>
'ID'
,
'lesson_id'
=>
'Урок'
,
'filename'
=>
'Документ'
,
];
}
/**
* @inheritdoc
*/
public
function
behaviors
()
{
return
[
];
}
public
function
getLesson
()
{
return
$this
->
hasOne
(
Lessons
::
className
(),
[
'id'
=>
'lesson_id'
]);
}
public
function
getUrl
()
{
return
Yii
::
$app
->
params
[
'frontUrl'
]
.
Lessons
::
IMAGES_FOLDER
.
$this
->
filename
;
}
}
common/modules/school/models/Lessons.php
View file @
d3f88425
...
@@ -17,6 +17,9 @@ class Lessons extends \common\components\ActiveRecordModel
...
@@ -17,6 +17,9 @@ class Lessons extends \common\components\ActiveRecordModel
{
{
const
PAGE_SIZE
=
10
;
const
PAGE_SIZE
=
10
;
const
IMAGES_FOLDER
=
'/uploads/lessons_docs/'
;
public
$filesUpload
;
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
...
@@ -41,6 +44,7 @@ class Lessons extends \common\components\ActiveRecordModel
...
@@ -41,6 +44,7 @@ class Lessons extends \common\components\ActiveRecordModel
[[
'video_id'
],
'string'
,
'max'
=>
100
],
[[
'video_id'
],
'string'
,
'max'
=>
100
],
[[
'course_id'
,
'number'
],
'integer'
],
[[
'course_id'
,
'number'
],
'integer'
],
[[
'text'
],
'safe'
],
[[
'text'
],
'safe'
],
[[
'filesUpload'
],
'file'
,
'skipOnEmpty'
=>
true
,
'extensions'
=>
'png, jpg, jpeg, gif, rar, ai, ppt, doc, docx'
],
];
];
}
}
...
@@ -99,4 +103,57 @@ class Lessons extends \common\components\ActiveRecordModel
...
@@ -99,4 +103,57 @@ class Lessons extends \common\components\ActiveRecordModel
return
false
;
return
false
;
}
}
}
}
public
function
getFiles
()
{
return
$this
->
hasMany
(
LessonImage
::
className
(),
[
'lesson_id'
=>
'id'
]);
}
public
function
getPath
()
{
return
Yii
::
getAlias
(
'@frontend/web'
)
.
self
::
IMAGES_FOLDER
;
}
public
function
upload
()
{
if
(
$this
->
validate
())
{
if
(
!
file_exists
(
$this
->
getPath
()))
{
mkdir
(
$this
->
getPath
(),
0777
,
true
);
}
foreach
(
$this
->
filesUpload
as
$file
)
{
$filename
=
date
(
'dmYHis-'
)
.
uniqid
()
.
'.'
.
$file
->
extension
;
$file
->
saveAs
(
$this
->
getPath
()
.
$filename
);
$image
=
new
LessonImage
;
$image
->
lesson_id
=
$this
->
id
;
$image
->
filename
=
$filename
;
$image
->
save
();
}
return
true
;
}
else
{
return
false
;
}
}
public
function
deleteFiles
()
{
if
(
$this
->
files
)
{
foreach
(
$this
->
files
as
$file
)
{
if
(
file_exists
(
$this
->
getPath
()
.
$file
->
filename
))
{
unlink
(
$this
->
getPath
()
.
$file
->
filename
);
}
$file
->
delete
();
}
}
}
}
}
console/migrations/m160217_095148_create_school_lessons_image.php
0 → 100644
View file @
d3f88425
<?php
use
yii\db\Schema
;
use
yii\db\Migration
;
class
m160217_095148_create_school_lessons_image
extends
Migration
{
public
function
safeUp
()
{
$tableOptions
=
null
;
if
(
$this
->
db
->
driverName
===
'mysql'
)
{
$tableOptions
=
'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB'
;
}
// Структура таблицы `school_lessons_image`
$this
->
createTable
(
'school_lessons_image'
,
[
'id'
=>
Schema
::
TYPE_PK
,
'filename'
=>
Schema
::
TYPE_STRING
.
'(50) NOT NULL'
,
'lesson_id'
=>
Schema
::
TYPE_INTEGER
.
'(11) NOT NULL'
,
],
$tableOptions
);
$this
->
createIndex
(
'FK_school_lessons_image_lessons'
,
'school_lessons_image'
,
'lesson_id'
);
}
public
function
safeDown
()
{
$this
->
dropTable
(
'school_lessons_image'
);
}
}
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