Fix #2335 allow selecting a category as default

This commit is contained in:
Kijin Sung 2024-05-04 20:21:09 +09:00
parent d3415b5e01
commit 684b86a636
11 changed files with 106 additions and 29 deletions

View file

@ -105,6 +105,10 @@ class Document extends ModuleObject
// 2017.12.21 Add an index for nick_name
if(!$oDB->isIndexExists('documents', 'idx_nick_name')) return true;
// 2024.05.04 Add default category
if(!$oDB->isColumnExists('document_categories', 'is_default')) return true;
if(!$oDB->isIndexExists('document_categories', 'idx_list_order')) return true;
return false;
}
@ -205,6 +209,16 @@ class Document extends ModuleObject
{
$oDB->addIndex('documents', 'idx_nick_name', array('nick_name'));
}
// 2024.05.04 Add default category
if(!$oDB->isColumnExists('document_categories', 'is_default'))
{
$oDB->addColumn('document_categories', 'is_default', 'char', '1', 'N', true, 'expand');
}
if(!$oDB->isIndexExists('document_categories', 'idx_list_order'))
{
$oDB->addIndex('document_categories', 'idx_list_order', array('list_order'));
}
}
/**

View file

@ -2565,26 +2565,33 @@ class DocumentController extends Document
function procDocumentInsertCategory($args = null)
{
// List variables
if(!$args) $args = Context::gets('module_srl','category_srl','parent_srl','category_title','category_description','expand','group_srls','category_color','mid');
if(!$args) $args = Context::gets('module_srl','category_srl','parent_srl','category_title','category_description','expand','is_default','group_srls','category_color','mid');
$args->title = trim($args->category_title);
$args->description = trim($args->category_description);
$args->color = $args->category_color;
$args->expand = (isset($args->expand) && $args->expand === 'Y') ? 'Y' : 'N';
$args->is_default = (isset($args->is_default) && $args->is_default === 'Y') ? 'Y' : 'N';
if(!$args->module_srl && $args->mid)
{
$mid = $args->mid;
unset($args->mid);
$args->module_srl = $this->module_srl;
}
// Check permissions
$columnList = array('module_srl', 'module');
$module_info = ModuleModel::getModuleInfoByModuleSrl($args->module_srl, $columnList);
$grant = ModuleModel::getGrant($module_info, Context::get('logged_info'));
if(!$grant->manager) return new BaseObject(-1, 'msg_not_permitted');
if($args->expand !="Y") $args->expand = "N";
if(!is_array($args->group_srls)) $args->group_srls = str_replace('|@|',',',$args->group_srls);
else $args->group_srls = implode(',', $args->group_srls);
if (!is_array($args->group_srls))
{
$args->group_srls = str_replace('|@|',',',$args->group_srls);
}
else
{
$args->group_srls = implode(',', $args->group_srls);
}
$args->parent_srl = (int)$args->parent_srl;
$oDB = DB::getInstance();
@ -2596,6 +2603,7 @@ class DocumentController extends Document
$category_info = DocumentModel::getCategory($args->category_srl);
if($category_info->category_srl != $args->category_srl) $args->category_srl = null;
}
// Update if exists
if($args->category_srl)
{
@ -2616,6 +2624,16 @@ class DocumentController extends Document
return $output;
}
}
// If set as default, set other categories as not default.
if ($args->is_default === 'Y')
{
$output = executeQuery('document.updateCategoryIsDefault', [
'module_srl' => $args->module_srl,
'except_category_srl' => $args->category_srl,
]);
}
// Update the xml file and get its location
$xml_file = $this->makeCategoryFile($args->module_srl);
@ -2890,7 +2908,8 @@ class DocumentController extends Document
$child_buff = $this->getXmlTree($tree[$category_srl], $tree, $site_srl, $xml_header_buff);
}
// List variables
$expand = ($node->expand) ? $node->expand : 'N';
$expand = isset($node->expand) ? $node->expand : 'N';
$is_default = isset($node->is_default) ? $node->is_default : 'N';
$group_srls = ($node->group_srls) ? $node->group_srls : '';
$mid = ($node->mid) ? $node->mid : '';
$module_srl = ($node->module_srl) ? $node->parent_srl : '';
@ -2923,7 +2942,7 @@ class DocumentController extends Document
}
$attribute = sprintf(
'mid="%s" module_srl="%d" node_srl="%d" parent_srl="%d" category_srl="%d" text="<?php echo (%s?($_titles[%d][$lang_type]):"")?>" url=%s expand=%s color=%s description="<?php echo (%s?($_descriptions[%d][$lang_type]):"")?>" document_count="%d" ',
'mid="%s" module_srl="%d" node_srl="%d" parent_srl="%d" category_srl="%d" text="<?php echo (%s?($_titles[%d][$lang_type]):"")?>" url=%s expand=%s is_default=%s color=%s description="<?php echo (%s?($_descriptions[%d][$lang_type]):"")?>" document_count="%d" ',
$mid,
$module_srl,
$category_srl,
@ -2933,6 +2952,7 @@ class DocumentController extends Document
$category_srl,
str_replace("'", '"', var_export(getUrl('','mid',$node->mid,'category',$category_srl), true)),
str_replace("'", '"', var_export($expand, true)),
str_replace("'", '"', var_export($is_default, true)),
str_replace("'", '"', var_export(escape($color, false), true)),
$group_check_code,
$category_srl,
@ -2988,7 +3008,8 @@ class DocumentController extends Document
// List variables
$selected = '"' . implode('","', $child_output['category_srl_list']) . '"';
$child_buff = $child_output['buff'];
$expand = $node->expand;
$expand = $node->expand ?? 'N';
$is_default = $node->is_default ?? 'N';
$title = $node->title;
$description = $node->description;
@ -3027,7 +3048,7 @@ class DocumentController extends Document
// Create attributes(Use the category_srl_list to check whether to belong to the menu's node. It seems to be tricky but fast fast and powerful;)
$attribute = sprintf(
'"mid" => "%s", "module_srl" => "%d","node_srl"=>"%d","category_srl"=>"%d","parent_srl"=>"%d","text"=>$_titles[%d][$lang_type],"selected"=>(in_array(Context::get("category"),array(%s))?1:0),"expand"=>%s,"color"=>%s,"description"=>$_descriptions[%d][$lang_type],"list"=>array(%s),"document_count"=>"%d","grant"=>%s?true:false',
'"mid" => "%s", "module_srl" => "%d","node_srl"=>"%d","category_srl"=>"%d","parent_srl"=>"%d","text"=>$_titles[%d][$lang_type],"selected"=>(in_array(Context::get("category"),array(%s))?1:0),"expand"=>%s,"is_default"=>%s,"color"=>%s,"description"=>$_descriptions[%d][$lang_type],"list"=>array(%s),"document_count"=>"%d","grant"=>%s?true:false',
$node->mid,
$node->module_srl,
$node->category_srl,
@ -3036,6 +3057,7 @@ class DocumentController extends Document
$node->category_srl,
$selected,
var_export($expand, true),
var_export($is_default, true),
var_export($node->color, true),
$node->category_srl,
$child_buff,

View file

@ -813,7 +813,8 @@ class DocumentModel extends Document
$obj->parent_srl = $val['parent_srl'];
$obj->title = $obj->text = $val['text'];
$obj->description = $val['description'];
$obj->expand = $val['expand']=='Y'?true:false;
$obj->expand = isset($val['expand']) && $val['expand'] === 'Y';
$obj->is_default = isset($val['is_default']) && $val['is_default'] === 'Y';
$obj->color = $val['color'];
$obj->document_count = $val['document_count'];
$obj->depth = $depth;
@ -821,10 +822,19 @@ class DocumentModel extends Document
$obj->childs = array();
$obj->grant = $val['grant'];
if(Context::get('mid') == $obj->mid && Context::get('category') == $obj->category_srl) $selected = true;
else $selected = false;
$obj->selected = $selected;
$selected_category = Context::get('category');
if (Context::get('mid') == $obj->mid && $selected_category == $obj->category_srl)
{
$obj->selected = true;
}
elseif (!isset($selected_category) && $obj->is_default)
{
$obj->selected = true;
}
else
{
$obj->selected = false;
}
$list_order[$idx++] = $obj->category_srl;
// If you have a parent category of child nodes apply data
@ -833,7 +843,10 @@ class DocumentModel extends Document
$parent_srl = $obj->parent_srl;
$document_count = $obj->document_count;
$expand = $obj->expand;
if($selected) $expand = true;
if ($obj->selected)
{
$expand = true;
}
while($parent_srl)
{

View file

@ -16,12 +16,14 @@ $lang->parent_category_title = 'Parent Category';
$lang->category_title = 'Category';
$lang->category_color = 'Category Font Color';
$lang->expand = 'Expand';
$lang->is_default_category = 'Default Category';
$lang->category_group_srls = 'Allowed Groups';
$lang->cmd_make_child = 'Add Child Category';
$lang->cmd_enable_move_category = 'Change category position (Select a category and drag it to the position you want.)';
$lang->about_category_title = 'Please enter a category name.';
$lang->about_view_count_option = 'This option controls whether to count multiple views by the same user. Different methods will try to detect duplicates in different ways.';
$lang->about_expand = 'Select this option, and they will stay expanded.';
$lang->about_default_category = 'Automatically select this category when writing a new post.';
$lang->about_category_group_srls = 'Only the selected group will be able to write posts in this category. If none is selected, everyone is allowed.';
$lang->about_category_color = 'You can set the font color of the category. e.g.) red or #ff0000';
$lang->about_cmd_pc_icon_setting = 'Select the icon set to display next to new or updated articles. The default is \'default\'.';

View file

@ -16,12 +16,14 @@ $lang->parent_category_title = '상위 분류 명';
$lang->category_title = '분류 명';
$lang->category_color = '분류 폰트 색깔';
$lang->expand = '펼침';
$lang->is_default_category = '기본 분류';
$lang->category_group_srls = '작성 허용 그룹';
$lang->cmd_make_child = '하위 분류 추가';
$lang->cmd_enable_move_category = '분류 위치 변경 (선택 후 위 메뉴를 드래그하세요.)';
$lang->about_category_title = '분류 이름을 입력해주세요.';
$lang->about_view_count_option = '조회 수 설정에 따라 중복 조회 수 카운트를 할 수 있도록 도와줍니다. 각 옵션에 따라 조회 수를 기록하는 방식이 달라집니다.';
$lang->about_expand = '선택하면 늘 펼쳐진 상태로 있게 합니다.';
$lang->about_default_category = '글 작성시 이 분류가 기본으로 선택되도록 합니다.';
$lang->about_category_group_srls = '이 분류를 사용하여 글을 작성할 수 있는 그룹을 제한합니다. 선택하지 않을 경우 모든 사용자에게 허용합니다.';
$lang->about_category_color = '분류 폰트 색깔을 지정합니다. 예) red 또는 #ff0000';
$lang->about_cmd_pc_icon_setting = '새로운 글이 등록되었거나 수정되었을 때 출력하는 아이콘입니다. 기본값은 default입니다. 사용 안 함을 선택할 경우 default 스킨이 기본값으로 출력됩니다.';

View file

@ -5,15 +5,16 @@
<columns>
<column name="category_srl" var="category_srl" filter="number" notnull="notnull" />
<column name="module_srl" var="module_srl" filter="number" default="0" notnull="notnull" />
<column name="parent_srl" var="parent_srl" filter="number" default="0" />
<column name="title" var="title" notnull="notnull" minlength="1" maxlength="250" />
<column name="description" var="description" maxlength="2000"/>
<column name="group_srls" var="group_srls" />
<column name="color" var="color" />
<column name="expand" var="expand" />
<column name="is_default" var="is_default" />
<column name="document_count" var="document_count" default="0" />
<column name="regdate" var="regdate" default="curdate()" />
<column name="expand" var="expand" />
<column name="parent_srl" var="parent_srl" filter="number" default="0" />
<column name="group_srls" var="group_srls" />
<column name="last_update" var="last_update" default="curdate()" />
<column name="list_order" var="list_order" default="0" />
<column name="color" var="color" />
</columns>
</query>

View file

@ -5,12 +5,13 @@
<columns>
<column name="title" var="title" />
<column name="description" var="description" />
<column name="list_order" var="list_order" />
<column name="last_update" var="last_update" default="curdate()" />
<column name="expand" var="expand" />
<column name="parent_srl" var="parent_srl" filter="number" />
<column name="group_srls" var="group_srls" />
<column name="color" var="color" />
<column name="expand" var="expand" />
<column name="is_default" var="is_default" />
<column name="last_update" var="last_update" default="curdate()" />
<column name="list_order" var="list_order" />
<column name="parent_srl" var="parent_srl" filter="number" />
</columns>
<conditions>
<condition operation="equal" column="category_srl" var="category_srl" filter="number" notnull="notnull" />

View file

@ -0,0 +1,12 @@
<query id="updateCategoryIsDefault" action="update">
<tables>
<table name="document_categories" />
</tables>
<columns>
<column name="is_default" var="is_default" default="N" />
</columns>
<conditions>
<condition operation="equal" column="module_srl" var="module_srl" filter="number" notnull="notnull" />
<condition operation="notequal" column="category_srl" var="except_category_srl" filter="number" />
</conditions>
</query>

View file

@ -3,12 +3,13 @@
<column name="module_srl" type="number" notnull="notnull" index="idx_module_srl" />
<column name="parent_srl" type="number" notnull="notnull" />
<column name="title" type="varchar" size="250" />
<column name="expand" type="char" size="1" default="N" />
<column name="document_count" type="number" default="0" notnull="notnull" />
<column name="regdate" type="date" index="idx_regdate" />
<column name="last_update" type="date" />
<column name="list_order" type="number" notnull="notnull" />
<column name="description" type="varchar" size="200" />
<column name="group_srls" type="text" />
<column name="color" type="varchar" size="11" />
<column name="description" type="varchar" size="200" />
<column name="expand" type="char" size="1" default="N" notnull="notnull" />
<column name="is_default" type="char" size="1" default="N" notnull="notnull" />
<column name="document_count" type="number" default="0" notnull="notnull" />
<column name="regdate" type="date" notnull="notnull" index="idx_regdate" />
<column name="last_update" type="date" />
<column name="list_order" type="number" notnull="notnull" index="idx_list_order" />
</table>

View file

@ -83,6 +83,12 @@
<label class="x_inline" for="expand"><input type="checkbox" name="expand" value="Y" id="expand" /> {$lang->about_expand}</label>
</div>
</div>
<div class="x_control-group">
<label class="x_control-label">{$lang->is_default_category}</label>
<div class="x_controls">
<label class="x_inline" for="is_default_category"><input type="checkbox" name="is_default" value="Y" id="is_default_category" /> {$lang->about_default_category}</label>
</div>
</div>
</div>
<div class="x_modal-footer">
<button type="button" class="x_btn x_pull-left" data-hide="#__category_info">{$lang->cmd_close}</button>

View file

@ -210,6 +210,9 @@ function modifyNode(node,e){
if(data.category_info.expand == 'Y'){
$w.find('input[name="expand"]').attr('checked', 'checked');
}
if(data.category_info.is_default == 'Y'){
$w.find('input[name="is_default"]').attr('checked', 'checked');
}
});
$('#__parent_category_info').hide().next('.x_control-group').css('borderTop','0');