diff --git a/modules/document/document.class.php b/modules/document/document.class.php index 0d2eef81d..5a2fe043c 100644 --- a/modules/document/document.class.php +++ b/modules/document/document.class.php @@ -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')); + } } /** diff --git a/modules/document/document.controller.php b/modules/document/document.controller.php index d4e93ede4..73019c943 100644 --- a/modules/document/document.controller.php +++ b/modules/document/document.controller.php @@ -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="" url=%s expand=%s color=%s description="" document_count="%d" ', + 'mid="%s" module_srl="%d" node_srl="%d" parent_srl="%d" category_srl="%d" text="" url=%s expand=%s is_default=%s color=%s description="" 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, diff --git a/modules/document/document.model.php b/modules/document/document.model.php index 3195eef51..a3c2932da 100644 --- a/modules/document/document.model.php +++ b/modules/document/document.model.php @@ -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) { diff --git a/modules/document/lang/en.php b/modules/document/lang/en.php index 4aa9befd0..281cfba03 100644 --- a/modules/document/lang/en.php +++ b/modules/document/lang/en.php @@ -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\'.'; diff --git a/modules/document/lang/ko.php b/modules/document/lang/ko.php index b4a7f1f98..1253281a2 100644 --- a/modules/document/lang/ko.php +++ b/modules/document/lang/ko.php @@ -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 스킨이 기본값으로 출력됩니다.'; diff --git a/modules/document/queries/insertCategory.xml b/modules/document/queries/insertCategory.xml index 442ac1e1b..a18bbcb73 100644 --- a/modules/document/queries/insertCategory.xml +++ b/modules/document/queries/insertCategory.xml @@ -5,15 +5,16 @@ + + + + + - - - - diff --git a/modules/document/queries/updateCategory.xml b/modules/document/queries/updateCategory.xml index 9180af6cb..aa1fae47b 100644 --- a/modules/document/queries/updateCategory.xml +++ b/modules/document/queries/updateCategory.xml @@ -5,12 +5,13 @@ - - - - + + + + + diff --git a/modules/document/queries/updateCategoryIsDefault.xml b/modules/document/queries/updateCategoryIsDefault.xml new file mode 100644 index 000000000..193e8dd43 --- /dev/null +++ b/modules/document/queries/updateCategoryIsDefault.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/modules/document/schemas/document_categories.xml b/modules/document/schemas/document_categories.xml index 179d1e50e..7b9f404c7 100644 --- a/modules/document/schemas/document_categories.xml +++ b/modules/document/schemas/document_categories.xml @@ -3,12 +3,13 @@ - - - - - + - + + + + + +
diff --git a/modules/document/tpl/category_list.html b/modules/document/tpl/category_list.html index e1aa8b36d..80783686b 100644 --- a/modules/document/tpl/category_list.html +++ b/modules/document/tpl/category_list.html @@ -83,6 +83,12 @@ +
+ +
+ +
+