Completed
Push — develop ( 755a17...843010 )
by Daniel
07:33
created

portal::get_index_template()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2013 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\content\services\views\driver;
11
12
class portal extends base_view
13
{
14
	/** @var \phpbb\config\config */
15
	protected $config;
16
17
	/** @var \blitze\content\services\types */
18
	protected $content_types;
19
20
	/**
21
	 * Constructor
22
	 *
23
	 * @param \phpbb\event\dispatcher_interface			$phpbb_dispatcher	Event dispatcher object
24
	 * @param \phpbb\language\language					$language			Language Object
25
	 * @param \phpbb\pagination							$pagination			Pagination object
26
	 * @param \phpbb\template\template					$template			Template object
27
	 * @param \blitze\content\services\fields			$fields				Content fields object
28
	 * @param \blitze\sitemaker\services\forum\data		$forum				Forum Data object
29
	 * @param \blitze\content\services\helper			$helper				Content helper object
30
	 * @param \blitze\content\services\quickmod			$quickmod			Quick moderator tools
31
	 * @param string									$phpbb_root_path	Path to the phpbb includes directory.
32
	 * @param string									$php_ext			php file extension
33
	 * @param \phpbb\config\config						$config				Config object
34
	 * @param \blitze\content\services\types			$content_types		Content types object
35
	*/
36
	public function __construct(\phpbb\event\dispatcher_interface $phpbb_dispatcher, \phpbb\language\language $language, \phpbb\pagination $pagination, \phpbb\template\template $template, \blitze\content\services\fields $fields, \blitze\sitemaker\services\forum\data $forum, \blitze\content\services\helper $helper, \blitze\content\services\quickmod $quickmod, $phpbb_root_path, $php_ext, \phpbb\config\config $config, \blitze\content\services\types $content_types)
37
	{
38
		parent::__construct($phpbb_dispatcher, $language, $pagination, $template, $fields, $forum, $helper, $quickmod, $phpbb_root_path, $php_ext);
39
40
		$this->config = $config;
41
		$this->content_types = $content_types;
42
	}
43
44
	/**
45
	 * @inheritdoc
46
	 */
47
	public function get_name()
48
	{
49
		return 'portal';
50
	}
51
52
	/**
53
	 * @inheritdoc
54
	 */
55
	public function get_langname()
56
	{
57
		return 'CONTENT_DISPLAY_PORTAL';
58
	}
59
60
	/**
61
	 * @inheritdoc
62
	 */
63
	public function get_index_template()
64
	{
65
		return 'views/portal.html';
66
	}
67
68
	/**
69
	 * {@inheritdoc}
70
	 */
71
	public function render_filter($filter_type, $filter_value, $page)
72
	{
73
		$this->build_index_query($filter_type, $filter_value);
74
75
		$total_topics = $this->forum->get_topics_count();
76
		$items_per_page = $this->config['topics_per_page'];
77
		$start = ($page - 1) * $items_per_page;
78
		$topics_data = $this->forum->get_topic_data($items_per_page, $start);
79
		$this->generate_pagination('summary', $total_topics, $start, $items_per_page, array(
80
			'filter_type'	=> $filter_type,
81
			'filter_value'	=> $filter_value,
82
		));
83
84
		if (sizeof($topics_data))
85
		{
86
			$posts_data = $this->forum->get_post_data('first');
87
			$users_cache = $this->forum->get_posters_info();
88
89
			$forums_data = array();
90
			foreach ($posts_data as $topic_id => $row)
91
			{
92
				$post = current($row);
93
				$forums_data[$post['forum_id']][$topic_id] = $post;
94
			}
95
96
			$this->display_filtered_topics($forums_data, $topics_data, $users_cache);
97
		}
98
	}
99
100
	/**
101
	 * @param array $forums_data
102
	 * @return void
103
	 */
104
	protected function display_filtered_topics(array $forums_data, array $topics_data, array $users_cache)
105
	{
106
		$update_count = array();
107
		foreach ($forums_data as $forum_id => $posts_data)
108
		{
109
			$content_type = $this->content_types->get_forum_type($forum_id);
110
			$entity = $this->content_types->get_type($content_type);
0 ignored issues
show
Bug introduced by
It seems like $content_type defined by $this->content_types->get_forum_type($forum_id) on line 109 can also be of type boolean; however, blitze\content\services\types::get_type() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
111
			$this->template->assign_vars($entity->to_array());
112
113
			$this->fields->prepare_to_show($entity, array_keys($posts_data), $entity->get_summary_tags(), $entity->get_summary_tpl(), 'summary');
0 ignored issues
show
Security Bug introduced by
It seems like $entity defined by $this->content_types->get_type($content_type) on line 110 can also be of type false; however, blitze\content\services\fields::prepare_to_show() does only seem to accept object<blitze\content\model\entity\type>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
114
115
			$topic_tracking_info = $this->forum->get_topic_tracking_info($forum_id);
116
			$attachments = $this->forum->get_attachments($forum_id);
117
118
			foreach ($posts_data as $topic_id => $post_data)
119
			{
120
				$topic_data	= $topics_data[$topic_id];
121
				$topic = $this->fields->show($content_type, $topic_data, $post_data, $users_cache, $attachments, $update_count, $topic_tracking_info);
1 ignored issue
show
Bug introduced by
It seems like $content_type defined by $this->content_types->get_forum_type($forum_id) on line 109 can also be of type boolean; however, blitze\content\services\fields::show() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
122
123
				$this->template->assign_block_vars('topicrow', $topic);
124
			}
125
		}
126
	}
127
}
128