Merge branch 'rhymix:develop' into develop

This commit is contained in:
Lastorder 2024-10-12 16:08:02 +09:00 committed by GitHub
commit 88b5281094
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
111 changed files with 2542 additions and 405 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

@ -109,6 +109,10 @@ class Document extends ModuleObject
if(!$oDB->isColumnExists('document_categories', 'is_default')) return true;
if(!$oDB->isIndexExists('document_categories', 'idx_list_order')) return true;
// 2024.10.08 Add columns to document_extra_keys table
if(!$oDB->isColumnExists('document_extra_keys', 'var_is_strict')) return true;
if(!$oDB->isColumnExists('document_extra_keys', 'var_options')) return true;
return false;
}
@ -219,6 +223,16 @@ class Document extends ModuleObject
{
$oDB->addIndex('document_categories', 'idx_list_order', array('list_order'));
}
// 2024.10.08 Add columns to document_extra_keys table
if(!$oDB->isColumnExists('document_extra_keys', 'var_is_strict'))
{
$oDB->addColumn('document_extra_keys', 'var_is_strict', 'char', '1', 'N', true, 'var_is_required');
}
if(!$oDB->isColumnExists('document_extra_keys', 'var_options'))
{
$oDB->addColumn('document_extra_keys', 'var_options', 'text', '', '', false, 'var_default');
}
}
/**

View file

@ -818,7 +818,11 @@ class DocumentController extends Document
if(isset($obj->{'extra_vars'.$idx}))
{
$tmp = $obj->{'extra_vars'.$idx};
if(is_array($tmp))
if ($extra_item->type === 'file')
{
$value = $tmp;
}
elseif (is_array($tmp))
{
$value = implode('|@|', $tmp);
}
@ -831,7 +835,37 @@ class DocumentController extends Document
{
$value = trim($obj->{$extra_item->name});
}
if($value == NULL) continue;
// Validate and process the extra value.
if ($value == NULL && $manual_inserted)
{
continue;
}
else
{
if (!$manual_inserted)
{
$ev_output = $extra_item->validate($value);
if ($ev_output && !$output->toBool())
{
$oDB->rollback();
return $ev_output;
}
}
// Handle extra vars that support file upload.
if ($extra_item->type === 'file' && is_array($value))
{
$ev_output = $extra_item->uploadFile($value, $obj->document_srl, 'doc');
if (!$ev_output->toBool())
{
$oDB->rollback();
return $ev_output;
}
$value = $ev_output->get('file_srl');
}
}
$extra_vars[$extra_item->name] = $value;
$this->insertDocumentExtraVar($obj->module_srl, $obj->document_srl, $idx, $value, $extra_item->eid);
}
@ -1153,7 +1187,10 @@ class DocumentController extends Document
$extra_vars = array();
if(Context::get('act')!='procFileDelete')
{
// Get a copy of current extra vars before deleting all existing data.
$old_extra_vars = DocumentModel::getExtraVars($obj->module_srl, $obj->document_srl);
$this->deleteDocumentExtraVars($source_obj->get('module_srl'), $obj->document_srl, null, Context::getLangType());
// Insert extra variables if the document successfully inserted.
$extra_keys = DocumentModel::getExtraKeys($obj->module_srl);
if(count($extra_keys))
@ -1164,13 +1201,98 @@ class DocumentController extends Document
if(isset($obj->{'extra_vars'.$idx}))
{
$tmp = $obj->{'extra_vars'.$idx};
if(is_array($tmp))
if ($extra_item->type === 'file')
{
$value = $tmp;
}
elseif (is_array($tmp))
{
$value = implode('|@|', $tmp);
}
else
{
$value = trim($tmp);
}
}
elseif (isset($obj->{$extra_item->name}))
{
$value = trim($obj->{$extra_item->name});
}
// Validate and process the extra value.
if ($value == NULL && $manual_updated && $extra_item->type !== 'file')
{
continue;
}
else
{
// Check for required and strict values.
if (!$manual_updated)
{
$ev_output = $extra_item->validate($value, $old_extra_vars[$idx]->value ?? null);
if ($ev_output && !$ev_output->toBool())
{
$oDB->rollback();
return $ev_output;
}
}
// Handle extra vars that support file upload.
if ($extra_item->type === 'file')
{
// New upload
if (is_array($value) && isset($value['name']))
{
// Delete old file
if (isset($old_extra_vars[$idx]->value))
{
$fc_output = FileController::getInstance()->deleteFile($old_extra_vars[$idx]->value);
if (!$fc_output->toBool())
{
$oDB->rollback();
return $fc_output;
}
}
// Insert new file
$ev_output = $extra_item->uploadFile($value, $obj->document_srl, 'doc');
if (!$ev_output->toBool())
{
$oDB->rollback();
return $ev_output;
}
$value = $ev_output->get('file_srl');
}
// Delete current file
elseif (isset($obj->{'_delete_extra_vars'.$idx}) && $obj->{'_delete_extra_vars'.$idx} === 'Y')
{
if (isset($old_extra_vars[$idx]->value))
{
// Check if deletion is allowed
$ev_output = $extra_item->validate(null);
if (!$ev_output->toBool())
{
$oDB->rollback();
return $ev_output;
}
// Delete old file
$fc_output = FileController::getInstance()->deleteFile($old_extra_vars[$idx]->value);
if (!$fc_output->toBool())
{
$oDB->rollback();
return $fc_output;
}
}
}
// Leave current file unchanged
elseif (!$value)
{
if (isset($old_extra_vars[$idx]->value))
{
$value = $old_extra_vars[$idx]->value;
}
}
}
}
else if(isset($obj->{$extra_item->name})) $value = trim($obj->{$extra_item->name});
if($value == NULL) continue;
$extra_vars[$extra_item->name] = $value;
$this->insertDocumentExtraVar($obj->module_srl, $obj->document_srl, $idx, $value, $extra_item->eid);
}
@ -1611,11 +1733,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 +1750,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;
@ -2554,8 +2683,6 @@ class DocumentController extends Document
$js_code[] = 'var validator = xe.getApp("validator")[0];';
$js_code[] = 'if(!validator) return false;';
$logged_info = Context::get('logged_info');
foreach($extra_keys as $idx => $val)
{
$idx = $val->idx;
@ -2563,9 +2690,11 @@ class DocumentController extends Document
{
$idx .= '[]';
}
$name = str_ireplace(array('<script', '</script'), array('<scr" + "ipt', '</scr" + "ipt'), $val->name);
$js_code[] = sprintf('validator.cast("ADD_MESSAGE", ["extra_vars%s","%s"]);', $idx, $name);
if($val->is_required == 'Y') $js_code[] = sprintf('validator.cast("ADD_EXTRA_FIELD", ["extra_vars%s", { required:true }]);', $idx);
$js_code[] = sprintf('validator.cast("ADD_MESSAGE", ["extra_vars%s", %s]);', $idx, var_export($val->name, true));
if($val->is_required == 'Y' && $val->type !== 'file')
{
$js_code[] = sprintf('validator.cast("ADD_EXTRA_FIELD", ["extra_vars%s", { required:true }]);', $idx);
}
}
$js_code[] = '})(jQuery);';
@ -3654,7 +3783,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

@ -965,7 +965,7 @@ class DocumentItem extends BaseObject
return $this->get('comment_count');
}
function getComments()
function getComments(?int $page = null)
{
if(!$this->getCommentCount())
{
@ -979,7 +979,7 @@ class DocumentItem extends BaseObject
// cpage is a number of comment pages
$cpageStr = sprintf('%d_cpage', $this->document_srl);
$cpage = Context::get($cpageStr);
$cpage = $page ? $page : Context::get($cpageStr);
if(!$cpage)
{
$cpage = Context::get('cpage');

View file

@ -8,10 +8,12 @@
<column name="var_name" alias="name" />
<column name="var_type" alias="type" />
<column name="var_is_required" alias="is_required" />
<column name="var_is_strict" alias="is_strict" />
<column name="var_search" alias="search" />
<column name="var_default" alias="default" />
<column name="var_options" alias="options" />
<column name="var_desc" alias="desc" />
<column name="eid" alias="eid" />
<column name="eid" alias="eid" />
</columns>
<conditions>
<condition operation="equal" column="module_srl" var="module_srl" filter="number" notnull="notnull" />

View file

@ -1,16 +1,18 @@
<query id="insertDocumentExtraKey" action="insert">
<tables>
<table name="document_extra_keys" />
</tables>
<columns>
<column name="module_srl" var="module_srl" filter="number" notnull="notnull" />
<column name="var_idx" var="var_idx" filter="number" notnull="notnull" />
<column name="var_name" var="var_name" notnull="notnull" />
<column name="var_type" var="var_type" notnull="notnull" />
<column name="var_is_required" var="var_is_required" default="N" notnull="notnull" />
<column name="var_search" var="var_search" default="N" notnull="notnull" />
<column name="var_default" var="var_default" />
<column name="var_desc" var="var_desc" />
<column name="eid" var="eid" notnull="notnull" />
</columns>
<tables>
<table name="document_extra_keys" />
</tables>
<columns>
<column name="module_srl" var="module_srl" filter="number" notnull="notnull" />
<column name="var_idx" var="var_idx" filter="number" notnull="notnull" />
<column name="var_name" var="var_name" notnull="notnull" />
<column name="var_type" var="var_type" notnull="notnull" />
<column name="var_is_required" var="var_is_required" default="N" notnull="notnull" />
<column name="var_is_strict" var="var_is_strict" default="N" notnull="notnull" />
<column name="var_search" var="var_search" default="N" notnull="notnull" />
<column name="var_default" var="var_default" />
<column name="var_options" var="var_options" />
<column name="var_desc" var="var_desc" />
<column name="eid" var="eid" notnull="notnull" />
</columns>
</query>

View file

@ -1,18 +1,20 @@
<query id="updateDocumentExtraKey" action="update">
<tables>
<table name="document_extra_keys" />
</tables>
<columns>
<column name="var_name" var="var_name" notnull="notnull" />
<column name="var_type" var="var_type" notnull="notnull" />
<column name="var_is_required" var="var_is_required" default="N" notnull="notnull" />
<column name="var_search" var="var_search" default="N" notnull="notnull" />
<column name="var_default" var="var_default" default="" />
<column name="var_desc" var="var_desc" />
<column name="eid" var="eid" notnull="notnull" />
</columns>
<conditions>
<condition operation="equal" column="module_srl" var="module_srl" filter="number" notnull="notnull" />
<condition operation="equal" column="var_idx" var="var_idx" filter="number" notnull="notnull" pipe="and" />
</conditions>
<tables>
<table name="document_extra_keys" />
</tables>
<columns>
<column name="var_name" var="var_name" notnull="notnull" />
<column name="var_type" var="var_type" notnull="notnull" />
<column name="var_is_required" var="var_is_required" default="N" notnull="notnull" />
<column name="var_is_strict" var="var_is_strict" default="N" notnull="notnull" />
<column name="var_search" var="var_search" default="N" notnull="notnull" />
<column name="var_default" var="var_default" default="" />
<column name="var_options" var="var_options" default="" />
<column name="var_desc" var="var_desc" />
<column name="eid" var="eid" notnull="notnull" />
</columns>
<conditions>
<condition operation="equal" column="module_srl" var="module_srl" filter="number" notnull="notnull" />
<condition operation="equal" column="var_idx" var="var_idx" filter="number" notnull="notnull" pipe="and" />
</conditions>
</query>

View file

@ -4,8 +4,10 @@
<column name="var_name" type="varchar" size="250" notnull="notnull" />
<column name="var_type" type="varchar" size="50" notnull="notnull" />
<column name="var_is_required" type="char" size="1" default="N" notnull="notnull" />
<column name="var_is_strict" type="char" size="1" default="N" notnull="notnull" />
<column name="var_search" type="char" size="1" default="N" notnull="notnull" />
<column name="var_default" type="text" />
<column name="var_options" type="text" />
<column name="var_desc" type="text" />
<column name="eid" type="varchar" size="40" />
</table>

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">{$selected_var ? 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">