瀏覽代碼

Added Tag filter to skill management - Refs #8318

José Loguercio 8 年之前
父節點
當前提交
56096966b1
共有 3 個文件被更改,包括 78 次插入1 次删除
  1. 23 0
      main/admin/skill_list.php
  2. 31 0
      main/inc/lib/extra_field.lib.php
  3. 24 1
      main/template/default/skill/list.tpl

+ 23 - 0
main/admin/skill_list.php

@@ -140,13 +140,36 @@ switch ($action) {
             ['title' => get_lang('BadgesManagement')]
         );
 
+        $extraField = new ExtraField('skill');
+        $arrayVals = $extraField->get_handler_field_info_by_tags('tags');
+        $tags = [];
+        foreach ($arrayVals['options'] as $value) {
+            $tags[] = $value;
+        }
+
         /* View */
         $skill = new Skill();
         $skillList = $skill->get_all();
 
+        $extraFieldSearchTagId = isset($_REQUEST['tag_id']) ? $_REQUEST['tag_id'] : 0;
+
+        if ($extraFieldSearchTagId) {
+            $skills = [];
+
+            $skillsFiltered = $extraField->getAllSkillPerTag($arrayVals['id'], $extraFieldSearchTagId);
+            foreach ($skillList as $index => $value) {
+                if (array_search($index, $skillsFiltered)) {
+                    $skills[$index] = $value;
+                }
+            }
+            $skillList = $skills;
+        }
+
         $tpl = new Template(get_lang('ManageSkills'));
         $tpl->assign('message', $message);
         $tpl->assign('skills', $skillList);
+        $tpl->assign('current_tag_id', $extraFieldSearchTagId);
+        $tpl->assign('tags', $tags);
 
         $content = $tpl->fetch('default/skill/list.tpl');
 

+ 31 - 0
main/inc/lib/extra_field.lib.php

@@ -2603,4 +2603,35 @@ JAVASCRIPT;
 
         return Database::store_result($result, 'ASSOC');
     }
+
+    /**
+     * @param int $fieldId
+     * @param int $tagId
+     *
+     * @return array
+     */
+    public function getAllSkillPerTag($fieldId, $tagId)
+    {
+        $skillTable = Database::get_main_table(TABLE_MAIN_SKILL);
+        $tagRelXtraTable = Database::get_main_table(TABLE_MAIN_EXTRA_FIELD_REL_TAG);
+        $fieldId = intval($fieldId);
+        $tagId = intval($tagId);
+
+        $sql = "SELECT s.id
+                FROM $skillTable s INNER JOIN $tagRelXtraTable t
+                ON t.item_id = s.id
+                WHERE tag_id = $tagId AND t.field_id = $fieldId;
+        ";
+
+        $result = Database::query($sql);
+        $result = Database::store_result($result, 'ASSOC');
+
+        $skillList = [];
+
+        foreach ($result as $index => $value) {
+            $skillList[$value['id']] = $value['id'];
+        }
+
+        return $skillList;
+    }
 }

+ 24 - 1
main/template/default/skill/list.tpl

@@ -1,7 +1,20 @@
 <legend>
     <h1>{{ "ManageSkills" | get_lang }}</h1>
 </legend>
-
+<div class="row">
+    <div class="col-md-3" >
+        <select id="tag-filter" class="form-control">
+            <option value="0">{{ 'PleaseSelectAChoice' | get_lang }}</option>
+            {% for tag in tags %}
+                <option value="{{ tag.id }}">{{ tag.tag }}</option>
+            {% endfor %}
+        </select>
+    </div>
+    <div class="col-md-3">
+        <a id="filter-button" class="btn btn-default">{{ 'FilterByTags' | get_lang }}</a>
+    </div>
+</div>
+<br />
 <div class="table table-responsive">
     <table class="table table-hover table-striped">
         <thead>
@@ -62,3 +75,13 @@
         </tbody>
     </table>
 </div>
+
+<script>
+    $(document).ready(function() {
+        $("#tag-filter").val("{{ current_tag_id }}");
+        $("#filter-button").click(function() {
+            var tagId = $( "#tag-filter option:selected" ).val();
+            $(location).attr('href', '{{ _p.web_main }}admin/skill_list.php?tag_id='+tagId);
+        });
+    });
+</script>