Completed
Push — develop ( 613db1...73b4e9 )
by Daniel
05:02
created

author_contents::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 4
crap 2
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\services\topic\driver;
11
12
class author_contents implements block_interface
13
{
14
	/** @var\phpbb\language\language */
15
	protected $language;
16
17
	/** @var \phpbb\template\template */
18
	protected $template;
19
20
	/* @var \blitze\content\services\fields */
21
	protected $fields;
22
23
	/** @var \blitze\sitemaker\services\forum\data */
24
	protected $forum;
25
26
	/**
27
	 * Constructor
28
	 *
29
	 * @param \phpbb\language\language					$language			Language Object
30
	 * @param \phpbb\template\template					$template			Template object
31
	 * @param \blitze\content\services\fields			$fields				Content fields object
32
	 * @param \blitze\sitemaker\services\forum\data		$forum				Forum Data object
33
	*/
34
	public function __construct(\phpbb\language\language $language, \phpbb\template\template $template, \blitze\content\services\fields $fields, \blitze\sitemaker\services\forum\data $forum)
35
	{
36
		$this->language = $language;
37
		$this->template = $template;
38
		$this->fields = $fields;
39
		$this->forum = $forum;
40
	}
41
42
	/**
43
	 * @inheritdoc
44
	 */
45
	public function get_name()
46
	{
47
		return 'author_contents';
48
	}
49
50
	/**
51
	 * @inheritdoc
52
	 */
53
	public function get_langname()
54
	{
55
		return 'AUTHOR_CONTENTS';
56
	}
57
58
	/**
59
	 * @param \blitze\content\model\entity\type $entity
60
	 * @param array $topic_data
61
	 * @param array $post_data
62
	 * @param array $user_cache
63
	 * @return void
64
	 */
65
	public function show_block(\blitze\content\model\entity\type $entity, array $topic_data, array $post_data, array $user_cache)
66
	{
67
		$this->forum->query()
68
			->fetch_forum($topic_data['forum_id'])
69
			->fetch_topic_poster($topic_data['topic_poster'])
70
			->fetch_custom(array(
71
				'WHERE' => array('t.topic_id <> ' . (int) $topic_data['topic_id'])
72
			))->build(true, true, false);
73
74
		$topics_data = $this->forum->get_topic_data(5);
75
		$topic_tracking_info = $this->forum->get_topic_tracking_info($topic_data['forum_id']);
76
		$content_type = $entity->get_content_name();
77
78
		$topics = array();
79
		foreach ($topics_data as $row)
80
		{
81
			$topics[] = $this->fields->get_min_topic_info($content_type, $row, $topic_tracking_info);
82
		}
83
84
		$this->template->assign_block_vars('topic_blocks', array(
85
			'TITLE'		=> $this->language->lang('AUTHOR_CONTENTS', $entity->get_content_langname(), $topic_data['topic_first_poster_name']),
86
			'TPL_NAME'	=> '@blitze_content/author_contents.html',
87
			'TOPICS'	=> $topics,
88
		));
89
	}
90
}
91