Completed
Push — master ( 9a2ec2...11be6a )
by Nazar
04:00
created

Helpers::show_posts_list()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 37
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 37
rs 8.5806
cc 4
eloc 24
nc 2
nop 4
1
<?php
2
/**
3
 * @package   Blogs
4
 * @category  modules
5
 * @author    Nazar Mokrynskyi <[email protected]>
6
 * @copyright Copyright (c) 2015-2016, Nazar Mokrynskyi
7
 * @license   MIT License, see license.txt
8
 */
9
namespace cs\modules\Blogs;
10
use
11
	cs\Config,
12
	cs\Language\Prefix,
13
	cs\Page,
14
	cs\User,
15
	h;
16
17
class Helpers {
18
	/**
19
	 * Return HTML with posts list
20
	 *
21
	 * @param int[]  $posts
22
	 * @param int    $posts_count
23
	 * @param int    $page
24
	 * @param string $base_url
25
	 *
26
	 * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
27
	 */
28
	static function show_posts_list ($posts, $posts_count, $page, $base_url) {
29
		$module_data = Config::instance()->module('Blogs');
30
		$L           = new Prefix('blogs_');
31
		$Page        = Page::instance();
32
		$Page->content(
33
			h::cs_blogs_head_actions()
34
		);
35
		if (!$posts) {
36
			$Page->content(
37
				h::{'p.cs-text-center'}($L->no_posts_yet)
38
			);
39
			return;
40
		}
41
		$Page->content(
42
			h::{'section[is=cs-blogs-posts]'}(
43
				h::{'script[type=application/ld+json]'}(
44
					json_encode(
45
						Posts::instance()->get_as_json_ld($posts),
46
						JSON_UNESCAPED_UNICODE
47
					)
48
				),
49
				[
50
					'comments_enabled' => $module_data->enable_comments && functionality('comments')
51
				]
52
			).
53
			h::{'.cs-block-margin.cs-text-center.cs-margin nav[is=cs-nav-pagination]'}(
54
				pages(
55
					$page,
56
					ceil($posts_count / $module_data->posts_per_page),
57
					function ($page) use ($base_url) {
58
						return $base_url.($page > 1 ? "/$page" : '');
59
					},
60
					true
61
				)
62
			)
63
		);
64
	}
65
}
66