HoltBosse / Alba

Basic developer oriented CMS system
7 stars 2 forks source link

Add to core tag.php? #85

Open bobmitch opened 3 years ago

bobmitch commented 3 years ago


public static function get_all_tags_by_depth_and_content_type ($parent=0, $depth=-1, $content_type_id=null) {
        $depth = $depth+1;
        $result=array();
        $children = DB::fetchall("select * from tags where state>-1 and parent=? ORDER BY title ASC", array($parent));

        if ($content_type_id!==null) {
            $applicable1 = DB::fetchall("select id from tags where state>0 and filter=2 and id in (select tag_id from tag_content_type where content_type_id=?)", array($content_type_id));
            $applicable2 = DB::fetchall("select id from tags where state>0 and filter=1 and id not in (select tag_id from tag_content_type where content_type_id=?)", array($content_type_id));
            $applicable_ids = array_merge ($applicable1,$applicable2);
        }

        //CMS::pprint_r ($applicable_ids);

        foreach ($children as $child) {
            if ($content_type_id) {
                $applicable = false;
                for($n=0; $n<sizeof($applicable_ids); $n++) {
                    //echo "<p>comparing " . $child->id . " to " . $applicable_ids[$n]->id . "</p>";
                    if ($child->id==$applicable_ids[$n]->id) {
                        $applicable=true;
                        break;
                    }
                }
            }
            else {
                $applicable=true;
            }
            if (!$applicable) {
                continue;
            }
            $child->depth = $depth;
            $result[] = $child;
            $result = array_merge ($result, Tag::get_all_tags_by_depth_and_content_type($child->id, $depth, $content_type_id));
        }
        return $result;
    }
bobmitch commented 3 years ago

Discussion: Now that tags are hierarchical, if a tag selection is presented, should an option's ancestors applicability to the current content type prevent it from being shown, or should ancestors/hierarchy be shown with inapplicable ancestors presented greyed-out and unselectable?

The function above will prune entire tag branches if it encounters a node that is not applicable for a given content type.