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

mcp_topic::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 5
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\event;
11
12
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
13
14
class mcp_topic implements EventSubscriberInterface
15
{
16
	/** @var \phpbb\db\driver\driver_interface */
17
	protected $db;
18
19
	/* @var \blitze\content\services\types */
20
	protected $content_types;
21
22
	/* @var \blitze\content\services\fields */
23
	protected $fields;
24
25
	/** @var string */
26
	protected $phpbb_root_path;
27
28
	/** @var string */
29
	protected $php_ext;
30
31
	/**
32
	 * Constructor
33
	 *
34
	 * @param \phpbb\db\driver\driver_interface		$db					Database object
35
	 * @param \blitze\content\services\types		$content_types		Content types object
36
	 * @param \blitze\content\services\fields		$fields				Content fields object
37
	 * @param string								$phpbb_root_path	Path to the phpbb includes directory.
38
	 * @param string								$php_ext			php file extension
39
	*/
40
	public function __construct(\phpbb\db\driver\driver_interface $db, \blitze\content\services\types $content_types, \blitze\content\services\fields $fields, $phpbb_root_path, $php_ext)
41
	{
42
		$this->db = $db;
43
		$this->content_types = $content_types;
44
		$this->fields = $fields;
45
		$this->phpbb_root_path = $phpbb_root_path;
46
		$this->php_ext = $php_ext;
47
	}
48
49
	/**
50
	 * @return array
51
	 */
52
	static public function getSubscribedEvents()
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
53
	{
54
		return array(
55
			'core.mcp_topic_modify_post_data'	=> 'modify_post_data',
56
			'core.mcp_topic_review_modify_row'	=> 'modify_review_row',
57
			'core.mcp_view_forum_modify_sql'	=> 'modify_forum_sql',
58
			'core.mcp_queue_get_posts_for_topics_query_before'	=> 'modify_topic_queue_sql',
59
			'core.mcp_front_queue_unapproved_total_before'		=> 'modify_forumlist',
60
			'core.mcp_front_view_queue_postid_list_after'		=> 'modify_forumlist',
61
		);
62
	}
63
64
	/**
65
	 * @param \phpbb\event\data $event
66
	 * @return void
67
	 */
68
	public function modify_post_data(\phpbb\event\data $event)
69
	{
70
		// We use $event['rowset'][0]['forum_id'] instead of $event['forum_id'] because forum_id is not guaranteed
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
71
		// as it is only retrieved from url parameters on topic view but links from pagination does not include forumid
72
		$this->type = $this->content_types->get_forum_type($event['rowset'][0]['forum_id']);
73
	}
74
75
	/**
76
	 * @param \phpbb\event\data $event
77
	 * @return void
78
	 */
79
	public function modify_review_row(\phpbb\event\data $event)
80
	{
81
		if ($event['row']['post_id'] === $event['topic_info']['topic_first_post_id'] && $this->type)
82
		{
83
			$entity = $this->content_types->get_type($this->type);
84
			$this->fields->prepare_to_show($this->type, 'summary', $entity->get_summary_tags(), $entity->get_content_fields(), $entity->get_summary_tpl());
0 ignored issues
show
Documentation introduced by
'summary' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
85
86
			$post_row = $event['post_row'];
87
			$content = $this->fields->build_content($post_row);
88
			$post_row['MESSAGE'] = isset($content['SEQ_DISPLAY']) ? $content['SEQ_DISPLAY'] : $content['CUSTOM_DISPLAY'];
89
90
			$event['post_row'] = $post_row;
91
		}
92
	}
93
94
	/**
95
	 * @param \phpbb\event\data $event
96
	 * @return void
97
	 */
98
	public function modify_forum_sql(\phpbb\event\data $event)
99
	{
100
		$types = $this->content_types->get_forum_types();
101
102
		if ($types[$event['forum_id']])
103
		{
104
			redirect(append_sid("{$this->phpbb_root_path}mcp.$this->php_ext"));
105
		}
106
	}
107
108
	/**
109
	 * @param \phpbb\event\data $event
110
	 * @return void
111
	 */
112
	public function modify_topic_queue_sql(\phpbb\event\data $event)
113
	{
114
		$forum_list = $event['forum_list'];
115
		$forum_list = is_array($forum_list) ? $forum_list : array($forum_list);
116
117
		$sql = 'SELECT t.forum_id, t.topic_id, t.topic_title, t.topic_title AS post_subject, t.topic_time AS post_time, t.topic_poster AS poster_id, t.topic_first_post_id AS post_id, t.topic_attachment AS post_attachment, t.topic_first_poster_name AS username, t.topic_first_poster_colour AS user_colour
118
			FROM ' . TOPICS_TABLE . ' t
119
			WHERE ' . $this->db->sql_in_set('forum_id', $this->get_forum_list($forum_list)) . '
120
				AND  ' . $this->db->sql_in_set('topic_visibility', $event['visibility_const']) . "
121
				AND topic_delete_user <> 0
122
				{$event['limit_time_sql']}
123
			ORDER BY {$event['sort_order_sql']}";
124
125
		$event['sql'] = $sql;
126
	}
127
128
	/**
129
	 * @param \phpbb\event\data $event
130
	 * @return void
131
	 */
132
	public function modify_forumlist(\phpbb\event\data $event)
133
	{
134
		$event['forum_list'] = $this->get_forum_list($event['forum_list']);
135
	}
136
137
	/**
138
	 * @param array
139
	 * @return array
140
	 */
141
	protected function get_forum_list(array $forum_list)
142
	{
143
		$types = $this->content_types->get_forum_types();
144
		$forum_ids = array_diff($forum_list, array_keys($types));
145
146
		return sizeof($forum_ids) ? $forum_ids : array(0);
147
	}
148
}
149