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
7ec50275
Commit
7ec50275
authored
Feb 19, 2016
by
Олег Гиммельшпах
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
При публикации записи в Блог добавить поле Автор
parent
504b17b3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
1 deletion
+54
-1
common/modules/blog/models/Post.php
common/modules/blog/models/Post.php
+24
-1
common/modules/blog/views/post-admin/manage.php
common/modules/blog/views/post-admin/manage.php
+12
-0
console/migrations/m160219_112010_add_post_column.php
console/migrations/m160219_112010_add_post_column.php
+18
-0
No files found.
common/modules/blog/models/Post.php
View file @
7ec50275
...
@@ -7,6 +7,7 @@ use Yii;
...
@@ -7,6 +7,7 @@ use Yii;
use
common\modules\languages\models\Languages
;
use
common\modules\languages\models\Languages
;
use
common\modules\blog\models\PostLang
;
use
common\modules\blog\models\PostLang
;
use
common\modules\blog\models\PostTag
;
use
common\modules\blog\models\PostTag
;
use
common\modules\users\models\User
;
use
common\models\MetaTags
;
use
common\models\MetaTags
;
/**
/**
...
@@ -52,7 +53,7 @@ class Post extends \common\components\ActiveRecordModel
...
@@ -52,7 +53,7 @@ class Post extends \common\components\ActiveRecordModel
{
{
return
[
return
[
[[
'url'
,
'active'
],
'required'
],
[[
'url'
,
'active'
],
'required'
],
[[
'active'
,
'created_at'
,
'updated_at'
],
'integer'
],
[[
'active'
,
'created_at'
,
'updated_at'
,
'author_id'
],
'integer'
],
[[
'url'
],
'string'
,
'max'
=>
255
],
[[
'url'
],
'string'
,
'max'
=>
255
],
[[
'url'
],
'unique'
],
[[
'url'
],
'unique'
],
[[
'preview'
,
'unlinkFile'
,
'tags'
],
'safe'
],
[[
'preview'
,
'unlinkFile'
,
'tags'
],
'safe'
],
...
@@ -100,6 +101,7 @@ class Post extends \common\components\ActiveRecordModel
...
@@ -100,6 +101,7 @@ class Post extends \common\components\ActiveRecordModel
{
{
return
[
return
[
'id'
=>
'ID'
,
'id'
=>
'ID'
,
'author_id'
=>
'Автор'
,
'url'
=>
'Ссылка'
,
'url'
=>
'Ссылка'
,
'active'
=>
'Видимость'
,
'active'
=>
'Видимость'
,
'file'
=>
'Изображение'
,
'file'
=>
'Изображение'
,
...
@@ -173,10 +175,31 @@ class Post extends \common\components\ActiveRecordModel
...
@@ -173,10 +175,31 @@ class Post extends \common\components\ActiveRecordModel
return
$this
->
hasMany
(
PostTagAssign
::
className
(),
[
'post_id'
=>
'id'
]);
return
$this
->
hasMany
(
PostTagAssign
::
className
(),
[
'post_id'
=>
'id'
]);
}
}
/**
* @return \yii\db\ActiveQuery
*/
public
function
getAuthor
()
{
return
$this
->
hasOne
(
User
::
className
(),
[
'id'
=>
'author_id'
]);
}
public
function
getThumbnailUrl
()
public
function
getThumbnailUrl
()
{
{
$path
=
pathinfo
(
$this
->
preview
);
$path
=
pathinfo
(
$this
->
preview
);
return
$path
[
'dirname'
]
.
'/'
.
$path
[
'filename'
]
.
'.thumb.'
.
$path
[
'extension'
];
return
$path
[
'dirname'
]
.
'/'
.
$path
[
'filename'
]
.
'.thumb.'
.
$path
[
'extension'
];
}
}
public
function
beforeSave
(
$insert
)
{
if
(
parent
::
beforeSave
(
$insert
))
{
$this
->
author_id
=
Yii
::
$app
->
user
->
identity
->
id
;
return
true
;
}
else
{
return
false
;
}
}
}
}
common/modules/blog/views/post-admin/manage.php
View file @
7ec50275
...
@@ -61,6 +61,18 @@ $this->params['breadcrumbs'][] = $this->title;
...
@@ -61,6 +61,18 @@ $this->params['breadcrumbs'][] = $this->title;
return
null
;
return
null
;
}
}
],
],
[
'attribute'
=>
'author_id'
,
'value'
=>
function
(
$model
)
{
if
(
$model
->
author
)
{
return
$model
->
author
->
surname
.
' '
.
$model
->
author
->
name
;
}
return
null
;
}
],
[
[
'class'
=>
'common\components\ColorActionColumn'
,
'class'
=>
'common\components\ColorActionColumn'
,
...
...
console/migrations/m160219_112010_add_post_column.php
0 → 100644
View file @
7ec50275
<?php
use
yii\db\Schema
;
use
yii\db\Migration
;
class
m160219_112010_add_post_column
extends
Migration
{
// Use safeUp/safeDown to run migration code within a transaction
public
function
safeUp
()
{
$this
->
addColumn
(
'posts'
,
'author_id'
,
Schema
::
TYPE_INTEGER
.
'(11) NOT NULL AFTER `active`'
);
}
public
function
safeDown
()
{
$this
->
dropColumn
(
'posts'
,
'author_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