forked from modstart/ModStartBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlogTagUtil.php
More file actions
36 lines (30 loc) · 828 Bytes
/
Copy pathBlogTagUtil.php
File metadata and controls
36 lines (30 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
namespace Module\Blog\Util;
use Illuminate\Support\Facades\Cache;
use ModStart\Core\Dao\ModelUtil;
use ModStart\Core\Util\TagUtil;
class BlogTagUtil
{
public static function clearCache()
{
Cache::forget('BlogTags');
}
public static function all()
{
return Cache::rememberForever('BlogTags', function () {
$blogs = ModelUtil::all('blog', [], ['tag']);
TagUtil::recordsString2Array($blogs, 'tag');
$tags = [];
foreach ($blogs as $blog) {
foreach ($blog['tag'] as $t) {
if (isset($tags[$t])) {
$tags[$t]++;
} else {
$tags[$t] = 1;
}
}
}
return $tags;
});
}
}