Completed
Push — develop ( da46c8...85331c )
by Daniel
07:12
created

mcp_topic::modify_review_row()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 14
cp 0
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 8
nc 4
nop 1
crap 30
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
	public static function getSubscribedEvents()
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
		$this->type = $this->content_types->get_forum_type($event['rowset'][0]['forum_id']);
71
	}
72
73
	/**
74
	 * @param \phpbb\event\data $event
75
	 * @return void
76
	 */
77
	public function modify_review_row(\phpbb\event\data $event)
78
	{
79
		if ($event['row']['post_id'] === $event['topic_info']['topic_first_post_id'] && $this->type)
80
		{
81
			if (($entity = $this->content_types->get_type($this->type)) !== false)
82
			{
83
				$this->fields->prepare_to_show($entity, array($event['topic_info']['topic_id']), $entity->get_summary_tags(), $entity->get_summary_tpl(), 'summary');
84
	
85
				$post_row = $event['post_row'];
86
				$content = $this->fields->build_content($post_row);
87
				$post_row['MESSAGE'] = isset($content['SEQ_DISPLAY']) ? $content['SEQ_DISPLAY'] : $content['CUSTOM_DISPLAY'];
88
	
89
				$event['post_row'] = $post_row;
90
			}
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