122 lines
4.1 KiB
PHP
122 lines
4.1 KiB
PHP
<?php
|
|
|
|
|
|
namespace app\models;
|
|
|
|
/**
|
|
* Class ObjectTemplateField
|
|
* @package app\models
|
|
* @property $ot_id
|
|
* @property $parent_id
|
|
* @property $rr_otf_id
|
|
* @property $rr_otf_option_id
|
|
* @property $name
|
|
* @property $ts_en_name
|
|
* @property $user_interface_type
|
|
* @property $common_field_id
|
|
* @property $data_type
|
|
* @property $order_index
|
|
* @property $is_filter
|
|
* [Relations]
|
|
* @property ObjectTemplate $objectTemplate
|
|
* @property ObjectTemplateField[] $fieldOptions
|
|
* @property CommonFields $commonField
|
|
*/
|
|
class ObjectTemplateField extends _Base
|
|
{
|
|
public function getObjectTemplate()
|
|
{
|
|
return $this->hasOne(ObjectTemplate::class, ['id' => 'ot_id']);
|
|
}
|
|
|
|
public function getCommonField() {
|
|
return $this->hasOne(CommonFields::class, ['id' => 'common_field_id']);
|
|
}
|
|
|
|
public function getFieldOptions()
|
|
{
|
|
return $this->hasMany(ObjectTemplateField::class, ['parent_id' => 'id']);
|
|
}
|
|
|
|
public function fieldOptionsAsJson($fieldOptions)
|
|
{
|
|
if (!empty($fieldOptions)) {
|
|
$data = [];
|
|
/** @var \app\models\ObjectTemplateField $fieldOption */
|
|
foreach ($fieldOptions as $fieldOption) {
|
|
$data[] = [
|
|
'id' => $fieldOption->id,
|
|
'bg' => $fieldOption->name,
|
|
'en' => $fieldOption->ts_en_name
|
|
];
|
|
}
|
|
return json_encode($data);
|
|
}
|
|
|
|
return '[]';
|
|
}
|
|
|
|
public static function dataType($id, $value = null, $html = true, $optionOnly = false)
|
|
{
|
|
$types = [
|
|
'string' => 'текстов низ',
|
|
'int' => 'числова стойност',
|
|
];
|
|
|
|
if ($html) {
|
|
$select = !$optionOnly ? '<select name="sub[' . $id . '][data_type]">' : '';
|
|
foreach ($types as $key => $val) {
|
|
$select .= '<option ' . ($value == $key ? 'selected' : '') . ' value="' . $key . '">' . $val . '</option>';
|
|
}
|
|
$select .= !$optionOnly ? '</select>' : '';
|
|
return $select;
|
|
}
|
|
if ($value) return $types[$value];
|
|
|
|
return $types;
|
|
}
|
|
|
|
public static function userInterfaceType($value = null, $html = true, $id = null, $optionOnly = null)
|
|
{
|
|
$types = [
|
|
'year' => 'Запис на година',
|
|
'date' => 'Запис на дата',
|
|
'geo_coordinates' => 'Географски кординати',
|
|
'map'=>'Запис на локация по карта',
|
|
'settlements_data' => 'Избор от списък с градове и села',
|
|
'input_simple' => 'Поле (без превод)',
|
|
'input' => 'Поле (двуезично)',
|
|
'text' => 'Текст (двуезично)',
|
|
'text_redactor' => 'Текст с редактор (двуезично)',
|
|
'list_simple' => 'Избор с опции (без превод)',
|
|
'list' => 'Избор с опции (двуезично)'
|
|
];
|
|
|
|
foreach (CommonFields::find()->where(['IS', 'parent_id', NULL])->all() as $commonField) {
|
|
$types[$commonField->id] = "(Общи номенклатури) ". $commonField->name;
|
|
}
|
|
|
|
$select = $optionOnly ? '' : '<select data-id="' . $id . '" class="type-value-selector" name="sub[' . $id . '][user_interface_type]">';
|
|
$select .= '<option selected disabled value="">-- Избери тип --</option>';
|
|
foreach ($types as $key => $text) {
|
|
$selected = $value && $value == $key ? 'selected' : '';
|
|
$select .= '<option ' . $selected . ' value="' . $key . '">' . $text . '</option>';
|
|
}
|
|
$select .= $optionOnly ? '' : '</select>';
|
|
|
|
if ($html)
|
|
return $select;
|
|
if ($value)
|
|
return $types[$value];
|
|
|
|
return $types;
|
|
}
|
|
|
|
|
|
public static function getNextOrderIndex($ot_id)
|
|
{
|
|
$last = self::find()->where(['ot_id' => $ot_id])->orderBy(['order_index' => SORT_DESC])->one();
|
|
return $last && $last->order_index ? $last->order_index + 1 : 1;
|
|
}
|
|
}
|