Implement is_strict and options fields

This commit is contained in:
Kijin Sung 2024-10-08 21:46:56 +09:00
parent 8fd72747fc
commit db4103b732
7 changed files with 104 additions and 11 deletions

View file

@ -174,8 +174,14 @@ class DocumentAdminController extends Document
$var_idx = Context::get('var_idx');
$name = Context::get('name');
$type = Context::get('type');
$is_required = Context::get('is_required');
$default = Context::get('default');
$is_required = Context::get('is_required') === 'Y' ? 'Y' : 'N';
$is_strict = Context::get('is_strict') === 'Y' ? 'Y' : 'N';
$default = trim(utf8_clean(Context::get('default')));
$options = trim(utf8_clean(Context::get('options')));
if ($options !== '')
{
$options = array_map('trim', explode("\n", $options));
}
$desc = Context::get('desc') ? Context::get('desc') : '';
$search = Context::get('search');
$eid = Context::get('eid');
@ -201,8 +207,11 @@ class DocumentAdminController extends Document
}
// insert or update
$oDocumentController = getController('document');
$output = $oDocumentController->insertDocumentExtraKey($module_srl, $var_idx, $name, $type, $is_required, $search, $default, $desc, $eid);
$oDocumentController = DocumentController::getInstance();
$output = $oDocumentController->insertDocumentExtraKey(
$module_srl, $var_idx, $name, $type, $is_required, $search,
$default, $desc, $eid, $is_strict, $options
);
if(!$output->toBool()) return $output;
$this->setMessage('success_registed');

View file

@ -1611,11 +1611,16 @@ class DocumentController extends Document
* @param string $var_default
* @param string $var_desc
* @param int $eid
* @param string $var_is_strict
* @param array $var_options
* @return object
*/
function insertDocumentExtraKey($module_srl, $var_idx, $var_name, $var_type, $var_is_required = 'N', $var_search = 'N', $var_default = '', $var_desc = '', $eid = 0)
function insertDocumentExtraKey($module_srl, $var_idx, $var_name, $var_type, $var_is_required = 'N', $var_search = 'N', $var_default = '', $var_desc = '', $eid = 0, $var_is_strict = 'N', $var_options = null)
{
if(!$module_srl || !$var_idx || !$var_name || !$var_type || !$eid) return new BaseObject(-1, 'msg_invalid_request');
if (!$module_srl || !$var_idx || !$var_name || !$var_type || !$eid)
{
return new BaseObject(-1, 'msg_invalid_request');
}
$obj = new stdClass();
$obj->module_srl = $module_srl;
@ -1623,8 +1628,10 @@ class DocumentController extends Document
$obj->var_name = $var_name;
$obj->var_type = $var_type;
$obj->var_is_required = $var_is_required=='Y'?'Y':'N';
$obj->var_is_strict = $var_is_strict=='Y'?'Y':'N';
$obj->var_search = $var_search=='Y'?'Y':'N';
$obj->var_default = $var_default;
$obj->var_options = $var_options ? json_encode($var_options, \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES) : null;
$obj->var_desc = $var_desc;
$obj->eid = $eid;
@ -3653,7 +3660,7 @@ Content;
{
foreach($documentExtraKeys AS $extraItem)
{
$this->insertDocumentExtraKey($value, $extraItem->idx, $extraItem->name, $extraItem->type, $extraItem->is_required , $extraItem->search , $extraItem->default , $extraItem->desc, $extraItem->eid) ;
$this->insertDocumentExtraKey($value, $extraItem->idx, $extraItem->name, $extraItem->type, $extraItem->is_required , $extraItem->search , $extraItem->default , $extraItem->desc, $extraItem->eid, $extraItem->is_strict, $extraItem->options);
}
}
}

View file

@ -49,6 +49,14 @@
<label class="x_inline" for="is_required_n"><input type="radio" name="is_required" id="is_required_n" value="N" checked="checked"|cond="$selected_var->is_required != 'Y'" /> {$lang->not}</label>
</div>
</div>
<div class="x_control-group">
<label class="x_control-label">{$lang->extra_vars_is_strict}</label>
<div class="x_controls">
<label class="x_inline" for="is_strict_y"><input type="radio" name="is_strict" id="is_strict_y" value="Y" checked="checked"|cond="$selected_var->is_strict == 'Y'" /> {$lang->yes}</label>
<label class="x_inline" for="is_strict_n"><input type="radio" name="is_strict" id="is_strict_n" value="N" checked="checked"|cond="$selected_var->is_strict != 'Y'" /> {$lang->not}</label>
<p class="x_help-block">{$lang->about_extra_vars_is_strict}</p>
</div>
</div>
<div class="x_control-group">
<label class="x_control-label" for="default">{$lang->default_value}</label>
<div class="x_controls">
@ -56,6 +64,13 @@
<p class="x_help-block">{$lang->about_extra_vars_default_value}</p>
</div>
</div>
<div class="x_control-group">
<label class="x_control-label" for="default">{$lang->extra_vars_options}</label>
<div class="x_controls">
<textarea type="text" name="options" id="options">{implode("\n", $selected_var->getOptions())}</textarea>
<p class="x_help-block">{$lang->about_extra_vars_options}</p>
</div>
</div>
<div class="x_control-group">
<label class="x_control-label" for="lang_desc">{$lang->description}</label>
<div class="x_controls">

View file

@ -25,7 +25,9 @@ class Value
public $name = '';
public $desc = '';
public $default = null;
public $options = null;
public $is_required = 'N';
public $is_strict = 'N';
public $is_disabled = 'N';
public $is_readonly = 'N';
public $search = 'N';
@ -55,6 +57,15 @@ class Value
'kr_zip' => true,
];
/**
* List of types that can have options.
*/
public const OPTION_TYPES = [
'checkbox' => true,
'radio' => true,
'select' => true,
];
/**
* Constructor for compatibility with legacy ExtraItem class.
*
@ -68,8 +79,11 @@ class Value
* @param string $search (Y, N)
* @param string $value
* @param string $eid
* @param string $parent_type
* @param string $is_strict
* @param string $options
*/
function __construct(int $module_srl, int $idx, string $name, string $type = 'text', $default = null, $desc = '', $is_required = 'N', $search = 'N', $value = null, string $eid = '')
function __construct(int $module_srl, int $idx, string $name, string $type = 'text', $default = null, $desc = '', $is_required = 'N', $search = 'N', $value = null, $eid = '', $parent_type = 'document', $is_strict = '', $options = null)
{
if (!$idx)
{
@ -80,11 +94,14 @@ class Value
$this->idx = $idx;
$this->eid = $eid;
$this->type = $type;
$this->parent_type = $parent_type;
$this->value = $value;
$this->name = $name;
$this->desc = $desc;
$this->default = $default;
$this->options = $options ? json_decode($options) : null;
$this->is_required = $is_required;
$this->is_strict = $is_strict;
$this->search = $search;
}
@ -133,12 +150,49 @@ class Value
'type' => $this->type,
'value' => self::_getTypeValue($this->type, $this->value),
'default' => self::_getTypeValue($this->type, $this->default),
'options' => $this->getOptions(),
'input_name' => $this->parent_type === 'document' ? ('extra_vars' . $this->idx) : ($this->input_name ?: $this->eid),
'input_id' => $this->input_id ?: '',
]);
return $template->compile();
}
/**
* Check if the current value can have options.
*
* @return bool
*/
public function canHaveOptions(): bool
{
return isset(self::OPTION_TYPES[$this->type]);
}
/**
* Get options specified by the administrator.
*
* @return array
*/
public function getOptions(): array
{
if (!$this->canHaveOptions())
{
return [];
}
if (is_array($this->options))
{
return $this->options;
}
elseif ($this->default)
{
return explode(',', $this->default);
}
else
{
return [];
}
}
/**
* Get the next temporary ID.
*

View file

@ -50,7 +50,7 @@ class ValueCollection
foreach ($keys as $val)
{
$this->keys[$val->idx] = new Value($val->module_srl, $val->idx, $val->name, $val->type, $val->default, $val->desc, $val->is_required, $val->search, $val->value ?? null, $val->eid, $val->parent_type ?? 'document');
$this->keys[$val->idx] = new Value($val->module_srl, $val->idx, $val->name, $val->type, $val->default, $val->desc, $val->is_required, $val->search, $val->value ?? null, $val->eid, $val->parent_type ?? 'document', $val->is_strict, $val->options);
}
}

View file

@ -97,7 +97,11 @@ $lang->about_mobile_page_count = 'You can set the number of page links to move p
$lang->about_admin_id = 'You can grant someone permission to manage this module. Please enter the user ID or email address of the person you wish to add.';
$lang->about_grant_deatil = 'Registered users mean users who signed-up to the virtual sites (e.g., cafeXE).';
$lang->about_module = 'Rhymix consists of modules except the basic library. [Module Manage] module will show all installed modules and help you to manage them.';
$lang->about_extra_vars_default_value = 'If you need to provide multiple choices, you can separate them with a comma.';
$lang->extra_vars_is_strict = 'Specified values only';
$lang->extra_vars_options = 'Options';
$lang->about_extra_vars_is_strict = 'In single and multiple choice fields, only allow the values specified below. If you change the allowed values, it may affect previous posts.';
$lang->about_extra_vars_default_value = 'In single and multiple choice fields, the default value should be one of the values specified below.';
$lang->about_extra_vars_options = 'In single and multiple choice fields, please enter the options one in each line.';
$lang->about_search_virtual_site = 'Enter domain of virtual sites. To search modules of non-virtual site, search with blank';
$lang->about_extra_vars_eid_value = 'This is the unique ID for this field.<br>You can use a combination of Latin alphabets, numbers and underscore(_), as long as it starts with an alphabet.';
$lang->about_extra_vars_column_name = 'This is the name that is actually shown to users.';

View file

@ -96,7 +96,11 @@ $lang->about_mobile_page_count = '목록 하단, 페이지를 이동하는 링
$lang->about_admin_id = '특정 회원에게 이 모듈의 관리 권한을 부여할 수 있습니다. 권한을 부여할 회원의 아이디 또는 이메일 주소를 입력해 주세요.';
$lang->about_grant_deatil = '가입한 사용자는 cafeXE 등 분양형 가상 사이트에 가입을 한 로그인 사용자를 의미합니다.';
$lang->about_module = 'Rhymix는 기본 라이브러리를 제외한 나머지는 모두 모듈로 구성되어 있습니다. 모듈 관리 모듈은 설치된 모든 모듈을 보여주고 관리를 돕습니다.';
$lang->about_extra_vars_default_value = '다중/단일 선택 등 여러 선택지가 주어지는 경우 &#39;,&#39;(쉼표)로 구분하면 됩니다.';
$lang->extra_vars_is_strict = '임의입력 금지';
$lang->extra_vars_options = '선택지';
$lang->about_extra_vars_is_strict = '단일/다중 선택에서 미리 주어진 선택지만 입력할 수 있도록 합니다. 선택지를 변경할 경우 기존 게시물에 영향을 줄 수 있습니다.';
$lang->about_extra_vars_default_value = '단일/다중 선택의 경우, 아래에 입력한 선택지 중 하나여야 합니다.';
$lang->about_extra_vars_options = '단일/다중 선택 등 여러 선택지가 주어지는 경우, 한 줄에 하나씩 입력하십시오.<br><span style="color:red">구 버전과 달리, 쉼표로 구분하지 않으니 주의하십시오.</span>';
$lang->about_search_virtual_site = '가상 사이트(예:cafeXE) 도메인을 입력한 후 검색하세요. 가상 사이트 이외의 모듈은 내용을 비우고 검색하면 됩니다. (http:// 는 제외)';
$lang->about_extra_vars_eid_value = '시스템 내에서 이 변수를 식별하기 위한 ID값입니다. 예: school<br>영문, 숫자, _를 조합해서 사용할 수 있으며 첫 글자는 영문이어야 합니다.';
$lang->about_extra_vars_column_name = '사용자에게 보여지는 입력 항목 이름입니다. 예: 학교';