154 lines
8.4 KiB
PHP
154 lines
8.4 KiB
PHP
<?php
|
|
|
|
namespace app\models;
|
|
|
|
/**
|
|
* Class ObjectsField
|
|
* @package app\models
|
|
* @property $object_id
|
|
* @property $object_tf_id
|
|
* @property $option_tf_id
|
|
* @property $value
|
|
* @property $value_en
|
|
* @property $date
|
|
* @property $geo_lon
|
|
* @property $geo_lat
|
|
* @property $settlement_id
|
|
* @property $common_field_id
|
|
* [RELATION]
|
|
* @property Objects $object
|
|
* @property ObjectTemplateField $objectTemplateField
|
|
* @property ObjectTemplateField $optionTemplateField
|
|
*/
|
|
class ObjectsField extends _Base
|
|
{
|
|
public function getObject()
|
|
{
|
|
return $this->hasOne(Objects::class, ['id' => 'object_id']);
|
|
}
|
|
|
|
public function getObjectTemplateField()
|
|
{
|
|
return $this->hasOne(ObjectTemplateField::class, ['id' => 'object_tf_id']);
|
|
}
|
|
|
|
public function getOptionTemplateField()
|
|
{
|
|
return $this->hasOne(ObjectTemplateField::class, ['id' => 'option_tf_id']);
|
|
}
|
|
|
|
public function getUserInterface()
|
|
{
|
|
$objectTemplateField = $this->objectTemplateField;
|
|
if ($objectTemplateField) {
|
|
switch ($objectTemplateField->user_interface_type) {
|
|
case 'input_simple':
|
|
return '<div class="flex row"><div class="c6 right10"><label>' . $objectTemplateField->name . '</label><input name="obf['.$this->id.'][value]" value="'.$this->value.'"></div></div>';
|
|
case 'input':
|
|
return '
|
|
<label>' . $objectTemplateField->name . '</label>
|
|
<div class="flex row row-panel">
|
|
<div class="c6 right10"><label>[bg]</label><input name="obf['.$this->id.'][value]" value="'.$this->value.'"></div>
|
|
<div class="c6"><label>[en]</label><input name="obf['.$this->id.'][value_en]" value="'.$this->value.'"></div>
|
|
</div>';
|
|
case 'list':
|
|
case 'list_simple':
|
|
$html = '<div class="flex row">';
|
|
$html .= '<div class="c6 right10">';
|
|
$html .= '<label>' . $objectTemplateField->name . '</label>';
|
|
$html .= '<select name="obf['.$this->id.'][option_tf_id]">';
|
|
$html .= '<option value="">-- Избери ' . mb_strtolower($objectTemplateField->name) . ' --</option>';
|
|
foreach ($objectTemplateField->fieldOptions as $option) {
|
|
$html .= '<option '.($option->id == $this->option_tf_id ? 'selected' : '').' value="' . $option->id . '">' . $option->name . '</option>';
|
|
}
|
|
$html .= '</select>';
|
|
$html .= '</div>';
|
|
$html .= '</div>';
|
|
return $html;
|
|
|
|
case 'language':
|
|
$html = '<div class="flex row">';
|
|
$html .= '<div class="c6 right10">';
|
|
$html .= '<label>' . $objectTemplateField->name . '</label>';
|
|
$html .= '<select name="obf['.$this->id.'][language_id]">';
|
|
$html .= '<option value="">-- Избери ' . mb_strtolower($objectTemplateField->name) . ' --</option>';
|
|
$html .= '<option value="1">Български</option>';
|
|
$html .= '<option value="2">Английски</option>';
|
|
$html .= '<option value="3">Руски</option>';
|
|
$html .= '</select>';
|
|
$html .= '</div>';
|
|
$html .= '</div>';
|
|
return $html;
|
|
case 'text':
|
|
$html = '<label>' . $objectTemplateField->name . '</label>';
|
|
$html .= '<div class="flex row row-panel">';
|
|
$html .= '<div class="c6 right10">';
|
|
$html .= '<label>[bg]</label>';
|
|
$html .= '<textarea name="obf[' . $this->id . '][value]">'.$this->value.'</textarea>';
|
|
$html .= '</div>';
|
|
$html .= '<div class="c6">';
|
|
$html .= '<label>[en]</label>';
|
|
$html .= '<textarea name="obf[' . $this->id . '][value_en]">'.$this->value_en.'</textarea>';
|
|
$html .= '</div>';
|
|
$html .= '</div>';
|
|
return $html;
|
|
case 'text_redactor':
|
|
$html = '<label>' . $objectTemplateField->name . '</label>';
|
|
$html .= '<div class="flex row row-panel">';
|
|
$html .= '<div class="c6 right10">';
|
|
$html .= '<label>[bg]</label>';
|
|
$html .= '<textarea class="ckEditor" name="obf[' . $this->id . '][value]">'.$this->value.'</textarea>';
|
|
$html .= '</div>';
|
|
$html .= '<div class="c6">';
|
|
$html .= '<label>[en]</label>';
|
|
$html .= '<textarea class="ckEditor" name="obf[' . $this->id . '][value_en]">'.$this->value_en.'</textarea>';
|
|
$html .= '</div>';
|
|
$html .= '</div>';
|
|
return $html;
|
|
case 'year':
|
|
return '<div class="flex row"><div class="c6 right10"><label>' . $objectTemplateField->name . '</label><input data-format="integer" data-max="'.date('Y').'" name="obf[' . $this->id . '][value]" value="'.$this->value.'"></div></div>';
|
|
case 'date':
|
|
return '<div class="flex row"><div class="c6 right10"><label>' . $objectTemplateField->name . '</label><input type="hidden" data-format="date" name="obf[' . $this->id . '][date]" value="'.$this->date.'"></div></div>';
|
|
case 'geo_coordinates':
|
|
return '
|
|
<label>' . $objectTemplateField->name . '</label>
|
|
<div class="flex row row-panel">
|
|
<div class="c6 right10"><label>Географска дължина [lon]</label><input data-format="double" name="obf['.$this->id.'][geo_lon]" value="'.$this->geo_lon.'"></div>
|
|
<div class="c6"><label>Географска ширина [lat]</label><input data-format="double" name="obf['.$this->id.'][geo_lat]" value="'.$this->geo_lat.'"></div>
|
|
</div>';
|
|
case 'map':
|
|
return
|
|
'<div class="row">
|
|
<div class="c8 right10" style="position: relative">
|
|
<label>' . $objectTemplateField->name . '</label><input placeholder="Избери ' . $objectTemplateField->name . '" class="sbr" data-sbr-name="obf[' . $this->id . '][settlement_id]" data-sbr-value="' . $this->settlement_id . '"><i style="position: absolute; right: 5px; top: 33px; font-size: 23px; ; color: var(--base-background-dark)" class="la la-map-marked"></i>
|
|
</div>
|
|
<div class="c12 top15"><div class="map" style="width: 100%; height: 350px; background: #cccccc"></div></div>
|
|
</div>';
|
|
case 'settlements_data':
|
|
return '<div class="flex row"><div class="c6 right10" style="position: relative"><label>' . $objectTemplateField->name . '</label><input placeholder="Избери '.$objectTemplateField->name.'" class="sbr" data-sbr-name="obf[' . $this->id . '][settlement_id]" data-sbr-value="'.$this->settlement_id.'"><i style="position: absolute; right: 5px; top: 33px; font-size: 23px; ; color: var(--base-background-dark)" class="la la-map-marked"></i></div></div>';
|
|
|
|
default:
|
|
//return '';
|
|
}
|
|
|
|
if($objectTemplateField->common_field_id) {
|
|
$html = '<div class="flex row">';
|
|
$html .= '<div class="c6 right10">';
|
|
$html .= '<label>' . $objectTemplateField->name . '</label>';
|
|
$html .= '<select name="obf['.$this->id.'][common_field_id]">';
|
|
$html .= '<option value="">-- Избери ' . mb_strtolower($objectTemplateField->name) . ' --</option>';
|
|
|
|
foreach ($objectTemplateField->commonField->options as $option) {
|
|
$html .= '<option '.($option->id == $this->common_field_id ? 'selected' : '').' value="'.$option->id.'">'.$option->name.'</option>';
|
|
}
|
|
|
|
$html .= '</select>';
|
|
$html .= '</div>';
|
|
$html .= '</div>';
|
|
return $html;
|
|
}
|
|
return '';
|
|
}
|
|
}
|
|
}
|