Model
Mcats versions
- 20210706 alasnome ~~cms/cats/models/Mcats.php
- 20200225 shanebow ~~cms/cats/models
- 20211216 sirijanda ~~cms/cats/models/Mcats.php
- 20210929 thaidrills ~~cms/cats/models/Mcats.php
Views
admin
cat-tree.php.content
!layout:admin
<title>Categories</title>
~~cms/cats/views/admin/cat-tree.view
old Mblogs
The old blog_cats
table was just a flat list of blog categories.
This is superseded by the new cats
table which stores all site categories
in a tree structure that includes the blog categories as one branch.
To ease the migration to the new style, we can keep the blogs branch to a single
level — Then fetching this branch can return a flat list similar to the
old mblogs->get_cats()
, below, which is pervasive in the Blog
controller:
.
public function get_cats($fields='cats.id,name,icon,cats.slug') {
return $this->db
->select($fields.',COUNT(blogs.cid) as numblogs')
->join('blogs', 'blogs.cid = cats.id','left outer')
->group_by('cats.id')
->get('blog_cats cats')
->result_array();
}
UI Category Tree (sidebar)
<div class="panel cattree" >
<h3>Categories</h3>
<ul class="tree">
<?= file_get_contents('assets/files/cattree2.div') ?>
</ul>
</div>
Let's build a tree editor. Our tree will be composed of Node
objects:
<li>
<input type="checkbox" id="about" />
<label for="about" class="tree_label"><a href="/page/category/about"><i class="icon-megaphone"></i> <b>About</b></a></label>
<ul>
<li ><a href="/page/category/contibutors" class="tree_label"><i class="icon-profile"></i> <b>Contributors</b></a></li>
<li ><a href="/page/category/policies" class="tree_label"><i class="icon-balance"></i> <b>Policies</b></a></li>
</ul>
</li>
<li ><a href="/page/category/shop" class="tree_label"><i class="icon-bag"></i> <b>Productions</b></a></li>
<li ><a href="/page/category/services" class="tree_label"><i class="icon-bowtie"></i> <b>Services</b></a></li>
<li >
<input type="checkbox" id="projects" />
<label for="projects" class="tree_label"><a href="/page/category/projects"><i class="icon-coffee"></i> <b>Projects</b></a></label>
<ul>
<li><a href="/page/category/rich-content" class="tree_label"><b>Rich Content</b></a></li>
<li><a href="/page/category/timelines" class="tree_label"><b>Timelines</b></a></li>
<li><a href="/page/category/learn-thai" class="tree_label"><b>Learn Thai</b></a></li>
<li><a href="/page/category/crossfit-f3" class="tree_label"><b>CrossFit F3</b></a></li>
<li><a href="/page/category/chef-nick" class="tree_label"><b>Chef Nick</b></a></li>
<li><a href="/page/category/trading-systems" class="tree_label"><b>Trading Systems</b></a></li>
<li><a href="/page/category/site-builder" class="tree_label"><b>Site Builder</b></a></li>
</ul>
</li>
<li >
<input type="checkbox" id="diy" />
<label for="diy" class="tree_label"><a href="/page/category/diy"><i class="icon-direction"></i> <b>DIY</b></a></label>
<ul>
<li><a href="/page/category/reference" class="tree_label"><i class="icon-library2"></i> <b>Reference</b></a></li>
<li><a href="/page/category/tutorials" class="tree_label"><i class="icon-strategy"></i> <b>Tutorials</b></a></li>
</ul>
</li>
<li>
<input type="checkbox" id="lab" />
<label for="lab" class="tree_label"><a href="/page/category/lab"><i class="icon-lab"></i> <b>Lab</b></a></label>
<ul>
<li><a href="/page/category/data-structures" class="tree_label"><i class="icon-code"></i> <b>Data Structures</b></a></li>
<li><a href="/page/category/math" class="tree_label"><i class="icon-wave2"></i> <b>Mathematics</b></a></li>
<li><a href="/page/category/music" class="tree_label"><i class="icon-music"></i> <b>Music</b></a></li>
<li><a href="/page/category/astronomy" class="tree_label"><i class="icon-stars"></i> <b>Astronomy</b></a></li>
<li><a href="/page/category/modeling" class="tree_label"><i class="icon-glasses-3d2"></i> <b>Modeling</b></a></li>
<li><a href="/page/category/ui" class="tree_label"><i class="icon-menu2"></i> <b>UI/UX</b></a></li>
</ul>
</li>
<li><a href="/page/category/account" class="tree_label"><i class="icon-user-tie"></i> <b>Account</b></a></li>