base::get_entity()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 *
4
 * Ideas extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\ideas\controller;
12
13
use phpbb\auth\auth;
14
use phpbb\config\config;
15
use phpbb\controller\helper;
16
use phpbb\ideas\factory\linkhelper;
17
use phpbb\language\language;
18
use phpbb\pagination;
19
use phpbb\request\request;
20
use phpbb\template\template;
21
use phpbb\user;
22
23
abstract class base
24
{
25
	/** @var auth */
26
	protected $auth;
27
28
	/* @var config */
29
	protected $config;
30
31
	/* @var helper */
32
	protected $helper;
33
34
	/* @var \phpbb\ideas\factory\base */
35
	protected $entity;
36
37
	/** @var language  */
38
	protected $language;
39
40
	/* @var linkhelper */
41
	protected $link_helper;
42
43
	/** @var pagination */
44
	protected $pagination;
45
46
	/* @var request */
47
	protected $request;
48
49
	/* @var template */
50
	protected $template;
51
52
	/* @var user */
53
	protected $user;
54
55
	/** @var string */
56
	protected $root_path;
57
58
	/** @var string */
59
	protected $php_ext;
60
61
	/**
62
	 * @param auth       $auth
63
	 * @param config     $config
64
	 * @param helper     $helper
65
	 * @param language   $language
66
	 * @param linkhelper $link_helper
67
	 * @param pagination $pagination
68
	 * @param request    $request
69
	 * @param template   $template
70
	 * @param user       $user
71
	 * @param string     $root_path
72
	 * @param string     $php_ext
73
	 */
74
	public function __construct(auth $auth, config $config, helper $helper, language $language, linkhelper $link_helper, pagination $pagination, request $request, template $template, user $user, $root_path, $php_ext)
75
	{
76
		$this->auth = $auth;
77
		$this->config = $config;
78
		$this->helper = $helper;
79
		$this->language = $language;
80
		$this->link_helper = $link_helper;
81
		$this->pagination = $pagination;
82
		$this->request = $request;
83
		$this->template = $template;
84
		$this->user = $user;
85
		$this->root_path = $root_path;
86
		$this->php_ext = $php_ext;
87
88
		$this->language->add_lang('common', 'phpbb/ideas');
89
	}
90
91
	/**
92
	 * Set the Ideas entity
93
	 *
94
	 * @param \phpbb\ideas\factory\base $entity
95
	 */
96
	public function get_entity($entity)
97
	{
98
		$this->entity = $entity;
99
	}
100
101
	/**
102
	 * Check if Ideas is properly configured after installation
103
	 * Ideas is available only after forum settings have been set in ACP
104
	 *
105
	 * @return bool Depending on whether the extension is properly configured
106
	 */
107
	public function is_available()
108
	{
109
		return (bool) $this->config['ideas_forum_id'];
110
	}
111
112
	/**
113
	 * Assign idea lists template variables
114
	 *
115
	 * @param string $block The template block var name
116
	 * @param array  $rows  The Idea row data
117
	 *
118
	 * @return void
119
	 */
120
	protected function assign_template_block_vars($block, $rows)
121
	{
122
		foreach ($rows as $row)
123
		{
124
			$this->template->assign_block_vars($block, array(
125
				'ID'         => $row['idea_id'], // (not currently implemented)
126
				'LINK'       => $this->link_helper->get_idea_link($row['idea_id']),
127
				'TITLE'      => $row['idea_title'],
128
				'AUTHOR'     => $this->link_helper->get_user_link($row['idea_author']),
129
				'DATE'       => $this->user->format_date($row['idea_date']),
130
				'READ'       => $row['read'],
131
				'VOTES_UP'   => $row['idea_votes_up'],
132
				'VOTES_DOWN' => $row['idea_votes_down'],
133
				'USER_VOTED' => $row['u_voted'],
134
				'POINTS'     => $row['idea_votes_up'] - $row['idea_votes_down'], // (not currently implemented)
135
				'STATUS'     => $row['idea_status'], // for status icons (not currently implemented)
136
				'LOCKED'     => $row['topic_status'] == ITEM_LOCKED,
137
				'U_UNAPPROVED_IDEA'	=> (($row['topic_visibility'] == ITEM_UNAPPROVED || $row['topic_visibility'] == ITEM_REAPPROVE) && $this->auth->acl_get('m_approve', $this->config['ideas_forum_id'])) ? append_sid("{$this->root_path}mcp.$this->php_ext", 'i=queue&amp;mode=approve_details&amp;t=' . $row['topic_id'], true, $this->user->session_id) : '',
138
			));
139
		}
140
	}
141
142
	/**
143
	 * Assign common template variables for Ideas pages
144
	 *
145
	 * @return void
146
	 */
147
	protected function display_common_vars()
148
	{
149
		$this->template->assign_vars([
150
			'S_DISPLAY_SEARCHBOX'	=> $this->auth->acl_get('u_search') && $this->auth->acl_get('f_search', $this->config['ideas_forum_id']) && $this->config['load_search'],
151
			'S_SEARCHBOX_ACTION'	=> append_sid("{$this->root_path}search.$this->php_ext"),
152
			'S_SEARCH_IDEAS_HIDDEN_FIELDS'	=> build_hidden_fields(['fid' => [$this->config['ideas_forum_id']]]),
153
		]);
154
	}
155
}
156