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
b25bf125
Commit
b25bf125
authored
Jul 13, 2016
by
andre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#1302
parent
d34b3a86
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
200 additions
and
4 deletions
+200
-4
common/components/activeRecordBehaviors/MFileUploadBehavior.php
.../components/activeRecordBehaviors/MFileUploadBehavior.php
+139
-0
common/modules/cases/models/CaseContent.php
common/modules/cases/models/CaseContent.php
+8
-1
common/modules/cases/views/cases-admin/_form.php
common/modules/cases/views/cases-admin/_form.php
+8
-1
common/modules/content/models/CoContent.php
common/modules/content/models/CoContent.php
+1
-0
console/migrations/m160713_083810_add_column_to_co_content.php
...le/migrations/m160713_083810_add_column_to_co_content.php
+23
-0
frontend/views/layouts/block/cases.php
frontend/views/layouts/block/cases.php
+4
-1
frontend/views/layouts/main.php
frontend/views/layouts/main.php
+1
-1
frontend/web/css/screen.css
frontend/web/css/screen.css
+16
-0
No files found.
common/components/activeRecordBehaviors/MFileUploadBehavior.php
0 → 100644
View file @
b25bf125
<?php
namespace
common\components\activeRecordBehaviors
;
use
Yii
;
use
yii\base\Behavior
;
use
yii\db\ActiveRecord
;
use
yii\web\UploadedFile
;
use
yii\imagine\Image
;
/**
* Class MFileUploadBehavior
* @package common\components\activeRecordBehaviors
*
* Тоже самое что и FileUploadBehavior, только
* использует $this->field, т.е. атрибут хранящий файл, в методах save и insert
* соотв и в форме нужно указывать этот атрибут, а не 'file'
*/
class
MFileUploadBehavior
extends
Behavior
{
public
$path
;
public
$folder
;
public
$file
;
public
$unlinkFile
=
false
;
public
$field
;
public
$thumb
=
false
;
public
$thumbSize
=
[
'100'
,
'100'
];
public
function
events
()
{
return
[
ActiveRecord
::
EVENT_BEFORE_UPDATE
=>
'Save'
,
ActiveRecord
::
EVENT_BEFORE_INSERT
=>
'Insert'
,
ActiveRecord
::
EVENT_BEFORE_DELETE
=>
'Delete'
,
];
}
private
function
getAbsolutePath
()
{
return
Yii
::
getAlias
(
$this
->
path
);
}
private
function
uploadFile
()
{
if
(
!
file_exists
(
$this
->
getAbsolutePath
()
.
$this
->
folder
))
{
mkdir
(
$this
->
getAbsolutePath
()
.
$this
->
folder
,
0777
,
true
);
}
$field
=
$this
->
field
;
$filename
=
date
(
'dmYHis-'
)
.
uniqid
();
$this
->
owner
->
$field
=
$this
->
folder
.
$filename
.
'.'
.
$this
->
file
->
extension
;
$this
->
file
->
saveAs
(
$this
->
getAbsolutePath
()
.
$this
->
owner
->
$field
);
if
(
$this
->
thumb
)
{
list
(
$width
,
$height
)
=
$this
->
thumbSize
;
try
{
Image
::
$driver
=
[
Image
::
DRIVER_GD2
];
Image
::
thumbnail
(
$this
->
path
.
$this
->
owner
->
$field
,
$width
,
$height
)
->
save
(
$this
->
getAbsolutePath
()
.
$this
->
folder
.
$filename
.
'.thumb.'
.
$this
->
file
->
extension
,
[
'quality'
=>
80
]);
}
catch
(
Exception
$e
)
{
throw
$e
;
}
}
}
private
function
deleteFile
()
{
$field
=
$this
->
field
;
if
(
$this
->
owner
->
$field
)
{
// Удаление Thumbnail если есть
$path
=
pathinfo
(
Yii
::
getAlias
(
$this
->
path
.
$this
->
owner
->
$field
));
$thumb
=
$path
[
'dirname'
]
.
'/'
.
$path
[
'filename'
]
.
'.thumb.'
.
$path
[
'extension'
];
if
(
file_exists
(
$thumb
))
{
unlink
(
$thumb
);
}
// Удаление файла
if
(
file_exists
(
$this
->
getAbsolutePath
()
.
$this
->
owner
->
$field
))
{
unlink
(
$this
->
getAbsolutePath
()
.
$this
->
owner
->
$field
);
}
$this
->
owner
->
$field
=
null
;
}
}
public
function
Save
(
$event
)
{
$this
->
file
=
UploadedFile
::
getInstance
(
$this
->
owner
,
$this
->
field
);
if
(
$this
->
owner
->
unlinkFile
||
$this
->
file
)
{
$this
->
deleteFile
();
}
if
(
$this
->
file
)
{
$this
->
uploadFile
();
}
return
true
;
}
public
function
Insert
(
$event
)
{
$this
->
file
=
UploadedFile
::
getInstance
(
$this
->
owner
,
$this
->
field
);
if
(
$this
->
file
)
{
$this
->
uploadFile
();
}
return
true
;
}
public
function
Delete
(
$event
)
{
$this
->
deleteFile
();
return
true
;
}
}
common/modules/cases/models/CaseContent.php
View file @
b25bf125
...
@@ -25,6 +25,7 @@ class CaseContent extends CoContent
...
@@ -25,6 +25,7 @@ class CaseContent extends CoContent
{
{
public
$parentClass
=
'common\modules\content\models\CoContent'
;
public
$parentClass
=
'common\modules\content\models\CoContent'
;
public
function
behaviors
()
public
function
behaviors
()
{
{
return
[
return
[
...
@@ -39,11 +40,17 @@ class CaseContent extends CoContent
...
@@ -39,11 +40,17 @@ class CaseContent extends CoContent
'actions'
=>
[
'create'
,
'update'
,
'copy'
,
'createcase'
,
'createproject'
]
'actions'
=>
[
'create'
,
'update'
,
'copy'
,
'createcase'
,
'createproject'
]
],
],
'file'
=>
[
'file'
=>
[
'class'
=>
'common\components\activeRecordBehaviors\FileUploadBehavior'
,
'class'
=>
'common\components\activeRecordBehaviors\
M
FileUploadBehavior'
,
'path'
=>
'@frontend/web'
,
'path'
=>
'@frontend/web'
,
'folder'
=>
'/uploads/content/'
,
'folder'
=>
'/uploads/content/'
,
'field'
=>
'preview'
'field'
=>
'preview'
],
],
'file_mob'
=>
[
'class'
=>
'common\components\activeRecordBehaviors\MFileUploadBehavior'
,
'path'
=>
'@frontend/web'
,
'folder'
=>
'/uploads/content/'
,
'field'
=>
'preview_mob'
],
'timestamp'
=>
[
'timestamp'
=>
[
'class'
=>
TimestampBehavior
::
className
(),
'class'
=>
TimestampBehavior
::
className
(),
'createdAtAttribute'
=>
'created_at'
,
'createdAtAttribute'
=>
'created_at'
,
...
...
common/modules/cases/views/cases-admin/_form.php
View file @
b25bf125
...
@@ -90,7 +90,14 @@ $blocks = \common\modules\content\models\CoBlocks::find()->all();
...
@@ -90,7 +90,14 @@ $blocks = \common\modules\content\models\CoBlocks::find()->all();
echo
Html
::
img
(
\Yii
::
$app
->
params
[
'frontUrl'
]
.
$model
->
preview
);
echo
Html
::
img
(
\Yii
::
$app
->
params
[
'frontUrl'
]
.
$model
->
preview
);
}
?>
}
?>
<?=
$form
->
field
(
$model
,
'file'
)
->
fileInput
()
?>
<?=
$form
->
field
(
$model
,
'preview'
)
->
fileInput
()
?>
<?php
if
(
$model
->
preview_mob
)
{
echo
Html
::
img
(
\Yii
::
$app
->
params
[
'frontUrl'
]
.
$model
->
preview_mob
);
}
?>
<?=
$form
->
field
(
$model
,
'preview_mob'
)
->
fileInput
()
?>
<ul
class=
"nav nav-pills"
>
<ul
class=
"nav nav-pills"
>
<?php
$c
=
0
;
foreach
(
$model
->
getLangsHelper
()
as
$i
=>
$content
)
:
$c
++
;
?>
<?php
$c
=
0
;
foreach
(
$model
->
getLangsHelper
()
as
$i
=>
$content
)
:
$c
++
;
?>
...
...
common/modules/content/models/CoContent.php
View file @
b25bf125
...
@@ -141,6 +141,7 @@ class CoContent extends \common\components\ActiveRecordModel
...
@@ -141,6 +141,7 @@ class CoContent extends \common\components\ActiveRecordModel
'url'
=>
Yii
::
t
(
'content'
,
'Url'
),
'url'
=>
Yii
::
t
(
'content'
,
'Url'
),
'name'
=>
Yii
::
t
(
'content'
,
'Name'
),
'name'
=>
Yii
::
t
(
'content'
,
'Name'
),
'file'
=>
'Превью'
,
'file'
=>
'Превью'
,
'preview_mob'
=>
'Превью для моб. версии'
,
'custom'
=>
'Заголовок'
,
'custom'
=>
'Заголовок'
,
'priority'
=>
'Приоритет в Sitemap'
,
'priority'
=>
'Приоритет в Sitemap'
,
'title'
=>
Yii
::
t
(
'content'
,
'Title'
),
'title'
=>
Yii
::
t
(
'content'
,
'Title'
),
...
...
console/migrations/m160713_083810_add_column_to_co_content.php
0 → 100644
View file @
b25bf125
<?php
use
yii\db\Migration
;
use
yii\db\Schema
;
/**
* Handles adding column to table `co_content`.
*/
class
m160713_083810_add_column_to_co_content
extends
Migration
{
/**
* @inheritdoc
*/
public
function
safeUp
()
{
$this
->
addColumn
(
'co_content'
,
'preview_mob'
,
Schema
::
TYPE_STRING
.
'(100) AFTER preview'
);
}
public
function
safeDown
()
{
$this
->
dropColumn
(
'co_content'
,
'preview_mob'
);
}
}
frontend/views/layouts/block/cases.php
View file @
b25bf125
...
@@ -44,7 +44,10 @@ $models = CaseContent::find()
...
@@ -44,7 +44,10 @@ $models = CaseContent::find()
<?
elseif
(
$model
->
previewType
->
type
==
CasesPreviewType
::
PREVIEW_RECTANGLE
)
:
?>
<?
elseif
(
$model
->
previewType
->
type
==
CasesPreviewType
::
PREVIEW_RECTANGLE
)
:
?>
<div
class=
"col-md-12 col-xs-12 col-sm-12"
>
<div
class=
"col-md-12 col-xs-12 col-sm-12"
>
<a
href=
"
<?=
Url
::
to
([
'/'
.
$model
->
url
])
?>
"
class=
"keys_block_small big"
>
<a
href=
"
<?=
Url
::
to
([
'/'
.
$model
->
url
])
?>
"
class=
"keys_block_small big"
>
<img
src=
"
<?=
$model
->
preview
?>
"
height=
"338"
width=
"940"
>
<img
class=
"img_lg"
src=
"
<?=
$model
->
preview
?>
"
height=
"338"
width=
"940"
>
<?
if
(
$model
->
preview_mob
)
:
?>
<img
class=
"img_sm"
src=
"
<?=
$model
->
preview_mob
?>
"
height=
"338"
width=
"455"
>
<?
endif
?>
<div
class=
"keys_small_title"
<?
if
(
$model
->
custom
==
CoContent
::
CUSTOM_WHITE
){
?>
style=
"color:#fff;"
<?
}
?>
>
<?=
$model
->
lang
->
title
?>
</div>
<div
class=
"keys_small_title"
<?
if
(
$model
->
custom
==
CoContent
::
CUSTOM_WHITE
){
?>
style=
"color:#fff;"
<?
}
?>
>
<?=
$model
->
lang
->
title
?>
</div>
<div
class=
"keys_small_foot"
>
<div
class=
"keys_small_foot"
>
<div
class=
"keys_small_btn_more"
>
<div
class=
"keys_small_btn_more"
>
...
...
frontend/views/layouts/main.php
View file @
b25bf125
...
@@ -21,7 +21,7 @@ AppAsset::register($this);
...
@@ -21,7 +21,7 @@ AppAsset::register($this);
<?php
$this
->
head
()
?>
<?php
$this
->
head
()
?>
<?php
echo
$this
->
render
(
'head'
)
?>
<?php
echo
$this
->
render
(
'head'
)
?>
</head>
</head>
<body
class=
"responsiv_100pr"
>
<body
<?
/* class="responsiv_100pr"*/
?>
>
<?php
echo
$this
->
render
(
'htmlcodes'
)
?>
<?php
echo
$this
->
render
(
'htmlcodes'
)
?>
<?php
$this
->
beginBody
()
?>
<?php
$this
->
beginBody
()
?>
...
...
frontend/web/css/screen.css
View file @
b25bf125
...
@@ -15435,4 +15435,20 @@ h2.subsc_blog_title{
...
@@ -15435,4 +15435,20 @@ h2.subsc_blog_title{
.subsc_blog
.save-button
{
.subsc_blog
.save-button
{
margin-top
:
0
!important
;
margin-top
:
0
!important
;
}
/*--*/
.img_sm
{
display
:
none
;
}
@media
only
screen
and
(
max-width
:
768px
)
{
.img_lg
{
display
:
none
;
}
.img_sm
{
display
:
block
;
}
}
}
\ No newline at end of file
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