-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathBlogTagUtil.php
More file actions
48 lines (41 loc) · 1.17 KB
/
Copy pathBlogTagUtil.php
File metadata and controls
48 lines (41 loc) · 1.17 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace Module\Blog\Util;
use Illuminate\Support\Facades\Cache;
use ModStart\Core\Dao\ModelUtil;
use ModStart\Core\Util\ArrayUtil;
use ModStart\Core\Util\TagUtil;
use Module\Blog\Model\Blog;
class BlogTagUtil
{
public static function clearCache()
{
Cache::forget('BlogTags');
}
public static function all()
{
return Cache::rememberForever('BlogTags', function () {
$blogs = Blog::published()->get(['tag'])->toArray();
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;
});
}
public static function records()
{
$all = self::all();
$records = array_build($all, function ($k, $v) {
return [$k, ['name' => $k, 'count' => $v]];
});
$records = ArrayUtil::sortByKey($records, 'count', 'desc');
return $records;
}
}