Initial import
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\models;
|
||||
|
||||
use yii\base\BaseObject;
|
||||
|
||||
/**
|
||||
* Class Expositions
|
||||
* @package app\models
|
||||
* @property $id
|
||||
* @property $name
|
||||
* @property $annotation
|
||||
* @property $description
|
||||
* @property $info_center
|
||||
* @property $info_center_address
|
||||
* @property $ts_en_name
|
||||
* @property $ts_en_annotation
|
||||
* @property $ts_en_description
|
||||
* @property $ts_en_info_center
|
||||
* @property $ts_en_info_center_address
|
||||
* @property $media_key
|
||||
* @property $publish_date
|
||||
* @property $category_id
|
||||
* @property $partner_id
|
||||
* @property $is_for_publish
|
||||
* @property \app\models\ExpositionsTagsExpositions[] $expositionsTags
|
||||
* @property \app\models\ExpositionsObjects[] $objectList
|
||||
*/
|
||||
class Expositions extends _Base
|
||||
{
|
||||
public function getExpositionsTags() {
|
||||
return $this->hasMany(ExpositionsTagsExpositions::class, ['exposition_id' => 'id']);
|
||||
}
|
||||
|
||||
public function getObjectList() {
|
||||
return $this->hasMany(ExpositionsObjects::class, ['exposition_id' => 'id']);
|
||||
}
|
||||
|
||||
public function getTagList() {
|
||||
$selected = [];
|
||||
foreach ($this->expositionsTags as $expositionsTag) {
|
||||
$selected[] = $expositionsTag->exposition_tag_id;
|
||||
}
|
||||
$tags = [];
|
||||
foreach (ExpositionsTags::find()->all() as $objectTemplate) {
|
||||
$tags[] = [
|
||||
'id' => $objectTemplate->id,
|
||||
'name' => $objectTemplate->name,
|
||||
'selected' => in_array($objectTemplate->id, $selected) ? 'selected' : ''
|
||||
];
|
||||
}
|
||||
return $tags;
|
||||
}
|
||||
|
||||
public function updateExpositionTags($tag_list = []) {
|
||||
$related = ExpositionsTagsExpositions::find()->where(['exposition_id' => $this->id])->all();
|
||||
$remain = [];
|
||||
foreach ($related as $etx) {
|
||||
if(in_array($etx->id, $tag_list)) {
|
||||
$remain[] = $etx->id;
|
||||
} else {
|
||||
$etx->delete();
|
||||
}
|
||||
}
|
||||
foreach ($tag_list as $id) {
|
||||
if(!in_array($id, $remain)) {
|
||||
$new = new ExpositionsTagsExpositions();
|
||||
$new->exposition_id = $this->id;
|
||||
$new->exposition_tag_id = $id;
|
||||
$new->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user