[WeCenter Secondary Development] Use different categories for your questions, articles and activities

Original link: https://www.wingrower.cn/archives/611/

There are three parts to accomplish this function:
1. Management – category management
2. List of articles, questions, activities
3. Select categories when publishing articles, questions, and activities.

The first part: background-category management content setting in the background-“category management realizes the function of adding and modifying categories, the modification function will not be changed, only the adding function will be changed. (That is, the module to which the classification belongs will not be modified.)
Involved files:
app/admin/category.php app/admin/ajax.php
view/default/admin/category/list.tpl.htm

First, file one needs to get the list of categories. Line37 and so on are modified to: (question deleted)

 TPL::assign('list', json_decode($this->model('system')->build_category_json(''), true)); TPL::assign('category_option', $this->model('system')->build_category_html('', 0, 0, null, false)); TPL::assign('target_category', $this->model('system')->build_category_html('', 0, null));

Then the list is displayed in list.tpl.htm, modify the form for adding categories, and add the module display and selection to which the categories belong. Added a “Module Owns” column to the list.
File 3 line 19 or so, change to:

 <th><?php _e('所属模块'); ?></th><!--添加了此行--> <th><?php _e('分类标题'); ?></th> <th><?php _e('排序'); ?></th> <th><?php _e('操作'); ?></th>

For about line 29, change to:

 <td><?php echo $val['type']; ?></td><!--此行为新增--> <td> <a href="<?php echo $val['type']; ?>/category-<?php echo ($val['url_token']) ? $val['url_token'] : $val['id']; ?>"><?php echo $val['title']; ?></a> </td><!--此行被修改-->

After the modification, it was found that the new column was added as an output variable, and the methods fetch_category() and build_category_html() used in model/system.php were modified, and ‘type’ => $val[‘ was added to the two arrays in the two methods type’] member, changed to:
line 76

 $category_list[$val['id']] = array( 'id' => $val['id'], 'title' => $val['title'], 'type' => $val['type'], 'icon' => $val['icon'], 'description' => $val['description'], 'parent_id' => $val['parent_id'], 'sort' => $val['sort'], 'url_token' => $val['url_token'] );

line 148

 $data[] = array( 'id' => $category_id, 'title' => $_prefix . $val['title'], 'type' => $val['type'], 'description' => $val['description'], 'sort' => $val['sort'], 'parent_id' => $val['parent_id'], 'url_token' => $val['url_token'] );

Add the module selection drop-down box, roughly in the 52-line form element. Adjusted the layout and added a drop-down box selection module, after modifying the form code:

 <form id="add_category_form" action="admin/ajax/save_category/" method="post" onsubmit="return false"> <div class="form-group col-sm-4"> <span class="col-sm-3 col-xs-12 mod-category-foot"><?php _e('分类标题'); ?></span> <div class="col-sm-6 col-xs-12"> <input type="text" class="form-control" name="title" /> </div> </div> <div class="form-group col-sm-4"> <span class="col-sm-3 col-xs-12 mod-category-foot"><?php _e('所属模块') ?>:</span> <div class="col-sm-6 col-xs-12"> <select name="category_type" class="form-control"> <option value="question"><?php _e('问题'); ?></option> <option value="article"><?php _e('文章'); ?></option> <option value="project"><?php _e('活动'); ?></option> </select> </div> </div> <div class="form-group col-sm-4"> <span class="col-sm-3 col-xs-12 mod-category-foot"><?php _e('父级分类') ?>:</span> <div class="col-sm-6 col-xs-12"> <select name="parent_id" class="form-control"> <option value="0"><?php _e('无'); ?></option> <?php echo $this->category_option; ?> </select> </div> </div> <div class="col-sm-1 col-xs-12"> <a onclick="AWS.ajax_post($('#add_category_form'));" class="btn-primary btn"><?php _e('添加分类'); ?></a>

This article is transferred from: https://www.wingrower.cn/archives/611/
This site is only for collection, and the copyright belongs to the original author.