Initial import
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace app\models;
|
||||
|
||||
/**
|
||||
* Class ObjectTemplate
|
||||
* @package app\models
|
||||
* @property $id
|
||||
* @property $heritage_type
|
||||
* @property $name
|
||||
* @property $ts_en_name
|
||||
* @property $rr_ot_id
|
||||
* [Relations]
|
||||
* @property ObjectTemplateField[] $objectTemplateFields
|
||||
* @property CategoriesOt[] $categoryOts
|
||||
* @property array $categoryIds
|
||||
* @property string $categoryConcatList
|
||||
*/
|
||||
class ObjectTemplate extends _Base
|
||||
{
|
||||
|
||||
public function getCategoryOts()
|
||||
{
|
||||
return $this->hasMany(CategoriesOt::class, ['ot_id' => 'id']);
|
||||
}
|
||||
|
||||
public function getCategoryConcatList()
|
||||
{
|
||||
$categories = [];
|
||||
$index = 1;
|
||||
foreach ($this->categoryOts as $categoriesOt) {
|
||||
$main = $categoriesOt->category->mainCategory->name;
|
||||
$sub = $categoriesOt->category->name;
|
||||
$categories[] = '<div style="display: flex; background: #FFFFFF; padding: 3px; margin: 2px"><div>' . $index . '.</div><div>' . $main . ' - ' . $sub . '</div></div>';
|
||||
$index++;
|
||||
}
|
||||
return implode('', $categories);
|
||||
}
|
||||
|
||||
public function getCategoryIds()
|
||||
{
|
||||
$ids = [];
|
||||
foreach ($this->categoryOts as $cOt) {
|
||||
$ids[] = $cOt->sc_id;
|
||||
}
|
||||
return $ids;
|
||||
}
|
||||
|
||||
public function getObjectTemplateFields()
|
||||
{
|
||||
return $this->hasMany(ObjectTemplateField::class, ['ot_id' => 'id'])->orderBy(['order_index' => SORT_ASC])->all();
|
||||
}
|
||||
|
||||
public static function heritageTypes($id = null)
|
||||
{
|
||||
$types = [
|
||||
1 => 'Недвижимо наследсвто',
|
||||
2 => 'Движимо материално наследство',
|
||||
3 => 'Движимо нематериално наследство',
|
||||
4 => 'Природно наследство',
|
||||
];
|
||||
if ($id)
|
||||
return $types[$id];
|
||||
return $types;
|
||||
}
|
||||
|
||||
public static function heritageTypesByCategory()
|
||||
{
|
||||
$subCategoryId = null;
|
||||
if (!empty($_GET['q'])) {
|
||||
$f = explode('|', $_GET['q']);
|
||||
foreach ($f as $fkv) {
|
||||
$filter = explode(':', $fkv);
|
||||
if ($filter[0] == 'sc_id' && !empty($filter[1]))
|
||||
$subCategoryId = $filter[1];
|
||||
}
|
||||
}
|
||||
if ($subCategoryId) {
|
||||
$heritage_types = [];
|
||||
$CategoriesOts = CategoriesOt::find()->where(['sc_id' => $subCategoryId])->all();
|
||||
foreach ($CategoriesOts as $CategoriesOt) {
|
||||
$htId = $CategoriesOt->objectTemplate->heritage_type;
|
||||
if (!isset($heritage_type[$htId])) {
|
||||
$heritage_types[$htId] = self::heritageTypes($htId);
|
||||
}
|
||||
}
|
||||
return $heritage_types;
|
||||
}
|
||||
return self::heritageTypes();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user