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
c445fe54
Commit
c445fe54
authored
Jul 12, 2016
by
andre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#1302
parent
cac0c014
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
171 additions
and
9 deletions
+171
-9
common/components/activeRecordBehaviors/CaseMetaTagBehavior.php
.../components/activeRecordBehaviors/CaseMetaTagBehavior.php
+127
-0
common/modules/cases/models/CaseContent.php
common/modules/cases/models/CaseContent.php
+44
-9
No files found.
common/components/activeRecordBehaviors/CaseMetaTagBehavior.php
0 → 100644
View file @
c445fe54
<?php
namespace
common\components\activeRecordBehaviors
;
use
Yii
;
use
yii\base\Behavior
;
use
yii\db\ActiveRecord
;
use
\common\models\MetaTags
;
use
common\modules\languages\models\Languages
;
class
CaseMetaTagBehavior
extends
Behavior
{
public
$meta
;
public
$actions
=
[];
public
function
events
()
{
return
[
ActiveRecord
::
EVENT_INIT
=>
'eventInit'
,
ActiveRecord
::
EVENT_AFTER_FIND
=>
'eventFind'
,
ActiveRecord
::
EVENT_AFTER_UPDATE
=>
'eventSave'
,
ActiveRecord
::
EVENT_AFTER_INSERT
=>
'eventInsert'
,
ActiveRecord
::
EVENT_BEFORE_DELETE
=>
'eventDelete'
,
];
}
public
function
eventInit
(
$event
)
{
if
(
Yii
::
$app
->
controller
&&
in_array
(
Yii
::
$app
->
controller
->
action
->
id
,
$this
->
actions
))
{
$langs
=
Languages
::
find
()
->
all
();
foreach
(
$langs
as
$lang
)
{
$mt
=
new
MetaTags
;
$mt
->
lang_id
=
$lang
->
id
;
$this
->
meta
[
$lang
->
id
]
=
$mt
;
}
}
}
public
function
eventFind
(
$event
)
{
if
(
Yii
::
$app
->
controller
&&
in_array
(
Yii
::
$app
->
controller
->
action
->
id
,
$this
->
actions
))
{
$langs
=
Languages
::
find
()
->
all
();
foreach
(
$langs
as
$lang
)
{
$mt
=
$this
->
owner
->
getMetaTags
(
$lang
->
id
)
->
one
();
if
(
!
$mt
)
{
$mt
=
new
MetaTags
;
$mt
->
lang_id
=
$lang
->
id
;
}
$this
->
meta
[
$lang
->
id
]
=
$mt
;
}
}
}
public
function
eventSave
(
$event
)
{
$meta
=
\Yii
::
$app
->
request
->
post
(
'MetaTags'
);
if
(
$meta
)
{
foreach
(
$meta
as
$lang_id
=>
$attributes
)
{
$meta_tag
=
MetaTags
::
find
()
->
where
([
'object_id'
=>
$this
->
owner
->
id
,
'model_id'
=>
$this
->
owner
->
parentClass
,
'lang_id'
=>
$lang_id
,
])
->
one
();
if
(
!
$meta_tag
)
{
$meta_tag
=
new
MetaTags
;
}
$attributes
[
'object_id'
]
=
$this
->
owner
->
id
;
$attributes
[
'model_id'
]
=
$this
->
owner
->
parentClass
;
$attributes
[
'lang_id'
]
=
$lang_id
;
$meta_tag
->
setAttributes
(
$attributes
);
if
(
!
$meta_tag
->
save
())
die
(
print_r
(
$meta_tag
->
errors
));
}
}
return
true
;
}
public
function
eventInsert
(
$event
)
{
$meta
=
\Yii
::
$app
->
request
->
post
(
'MetaTags'
);
if
(
$meta
)
{
foreach
(
$meta
as
$lang_id
=>
$attributes
)
{
$meta_tag
=
new
MetaTags
;
$attributes
[
'object_id'
]
=
$this
->
owner
->
id
;
$attributes
[
'model_id'
]
=
$this
->
owner
->
parentClass
;
$attributes
[
'lang_id'
]
=
$lang_id
;
$meta_tag
->
setAttributes
(
$attributes
);
$meta_tag
->
save
(
false
);
}
}
return
true
;
}
public
function
eventDelete
(
$event
)
{
if
(
$this
->
owner
->
metaTags
)
{
foreach
(
$this
->
owner
->
metaTags
as
$meta
)
{
$meta
->
delete
();
}
}
return
true
;
}
}
common/modules/cases/models/CaseContent.php
View file @
c445fe54
...
...
@@ -25,6 +25,50 @@ class CaseContent extends CoContent
{
public
$parentClass
=
'common\modules\content\models\CoContent'
;
public
function
behaviors
()
{
return
[
'meta'
=>
[
'class'
=>
'common\components\activeRecordBehaviors\CaseMetaTagBehavior'
,
'actions'
=>
[
'create'
,
'update'
,
'copy'
,
'createcase'
,
'createproject'
]
],
'langs'
=>
[
'class'
=>
'common\modules\languages\components\LanguageHelperBehavior'
,
'field'
=>
'content_id'
,
'langClass'
=>
'common\modules\content\models\CoContentLang'
,
'actions'
=>
[
'create'
,
'update'
,
'copy'
,
'createcase'
,
'createproject'
]
],
'file'
=>
[
'class'
=>
'common\components\activeRecordBehaviors\FileUploadBehavior'
,
'path'
=>
'@frontend/web'
,
'folder'
=>
'/uploads/content/'
,
'field'
=>
'preview'
],
'timestamp'
=>
[
'class'
=>
TimestampBehavior
::
className
(),
'createdAtAttribute'
=>
'created_at'
,
'updatedAtAttribute'
=>
'updated_at'
,
'value'
=>
time
(),
],
'sitemap'
=>
[
'class'
=>
SitemapBehavior
::
className
(),
'scope'
=>
function
(
$model
)
{
/** @var \yii\db\ActiveQuery $model */
$model
->
select
([
'url'
,
'updated_at'
,
'priority'
]);
$model
->
andWhere
([
'active'
=>
1
]);
},
'dataClosure'
=>
function
(
$model
)
{
return
[
'loc'
=>
Url
::
to
(
$model
->
url
),
'lastmod'
=>
date
(
'c'
,
$model
->
updated_at
),
'changefreq'
=>
SitemapBehavior
::
CHANGEFREQ_DAILY
,
'priority'
=>
$model
->
priority
];
}
],
];
}
public
function
getPreviewType
()
{
return
$this
->
hasOne
(
CasesPreviewType
::
className
(),
[
'content_id'
=>
'id'
])
->
one
();
...
...
@@ -71,15 +115,6 @@ class CaseContent extends CoContent
$previewType
->
attributes
=
Yii
::
$app
->
request
->
post
(
'CasesPreviewType'
);
$previewType
->
content_id
=
$this
->
id
;
$previewType
->
save
();
$metatags
=
MetaTags
::
find
()
->
where
([
'model_id'
=>
get_class
(
$this
)])
->
all
();
foreach
(
$metatags
as
$metatag
)
{
$metatag
->
model_id
=
$this
->
parentClass
;
$metatag
->
save
();
}
}
// public function __construct(array $config)
...
...
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