Passed
Push — develop ( 20d485...b34a14 )
by Daniel
03:01
created

mcp_post::modify_post_data()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 12
nc 3
nop 1
dl 0
loc 19
rs 9.2
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2018 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_post 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_post_template_data'	=> 'modify_post_data',
56
		);
57
	}
58
59
	/**
60
	 * @param \phpbb\event\data $event
61
	 * @return void
62
	 */
63
	public function modify_post_data(\phpbb\event\data $event)
64
	{
65
		$type = (string) $this->content_types->get_forum_type($event['post_info']['forum_id']);
66
		if ($type && $event['post_info']['post_id'] === $event['post_info']['topic_first_post_id'])
67
		{
68
			$entity = $this->content_types->get_type($type);
69
70
			$this->fields->prepare_to_show($entity, array($event['post_info']['topic_id']), $entity->get_summary_fields(), $entity->get_summary_tpl(), 'summary');
71
			$users_cache = $attachments = $topic_tracking_info = $update_count = array();
72
73
			$post_data = $topic_data = (array) $event['post_info'];
74
			$users_cache[$post_data['poster_id']] = array();
75
76
			$tpl_data = $this->fields->get_summary_template_data($type, $topic_data, $post_data, $users_cache, $attachments, $topic_tracking_info, $update_count);
77
			$content = $this->fields->build_content($tpl_data);
78
79
			$mcp_post_template_data = $event['mcp_post_template_data'];
80
			$mcp_post_template_data['POST_PREVIEW'] = isset($content['CUSTOM_DISPLAY']) ? $content['CUSTOM_DISPLAY'] : join('', $content['FIELDS']['all']);
81
			$event['mcp_post_template_data'] = $mcp_post_template_data;
82
		}
83
	}
84
}
85