list_controller   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Importance

Changes 13
Bugs 0 Features 0
Metric Value
wmc 15
eloc 52
c 13
b 0
f 0
dl 0
loc 106
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C ideas_list() 0 94 15
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\exception\http_exception;
14
use phpbb\ideas\ext;
15
16
class list_controller extends base
17
{
18
	/* @var \phpbb\ideas\factory\ideas */
19
	protected $entity;
20
21
	/**
22
	 * Controller for /list/{sort}
23
	 *
24
	 * @param $sort string The type of list to show (new|top|implemented)
25
	 * @throws http_exception
26
	 * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
27
	 */
28
	public function ideas_list($sort)
29
	{
30
		if (!$this->is_available())
31
		{
32
			throw new http_exception(404, 'IDEAS_NOT_AVAILABLE');
33
		}
34
35
		// Overwrite the $sort parameter if the url contains a sort query.
36
		// This is needed with the sort by options form at the footer of the list.
37
		$sort = $this->request->is_set('sort') ? (string) $this->request->variable('sort', ext::SORT_NEW) : $sort;
38
39
		// Get additional query values the url may contain
40
		$sort_direction = $this->request->variable('sd', 'd');
41
		$status = $this->request->variable('status', 0);
42
		$start = $this->request->variable('start', 0);
43
44
		// Store original query params for use in breadcrumbs & pagination
45
		$u_sort = $sort;
46
		$u_status = $status;
47
		$u_sort_direction = $sort_direction;
48
49
		// convert the sort direction to ASC or DESC
50
		$sort_direction = ($sort_direction === 'd') ? 'DESC' : 'ASC';
51
52
		// If sort by "new" we really use date
53
		if ($sort === ext::SORT_NEW)
54
		{
55
			$sort = ext::SORT_DATE;
56
		}
57
58
		// Set the name for displaying in the template
59
		$status_name = 'LIST_' . ($status > 0 ? ext::status_name($status) : strtoupper($sort));
60
		$status_name = $this->language->is_set($status_name) ? $this->language->lang($status_name) : '';
61
62
		// For special case where we want to request ALL ideas,
63
		// including the statuses normally hidden from lists.
64
		if ($status === -1)
65
		{
66
			$status = ext::$statuses;
67
			$status_name = $status_name ?: $this->language->lang('ALL_IDEAS');
68
		}
69
70
		// Generate ideas
71
		$ideas = $this->entity->get_ideas($this->config['posts_per_page'], $sort, $sort_direction, $status, $start);
72
		$this->assign_template_block_vars('ideas', $ideas);
73
74
		// Build list page template output
75
		$this->template->assign_vars(array(
76
			'U_LIST_ACTION'		=> $this->helper->route('phpbb_ideas_list_controller'),
77
			'U_POST_ACTION'		=> $this->helper->route('phpbb_ideas_post_controller'),
78
			'IDEAS_COUNT'       => $this->entity->get_idea_count(),
79
			'STATUS_NAME'       => $status_name ?: $this->language->lang('OPEN_IDEAS'),
80
			'STATUS_ARY'		=> ext::$statuses,
81
			'STATUS'			=> $u_status,
82
			'SORT_ARY'			=> array(ext::SORT_AUTHOR, ext::SORT_DATE, ext::SORT_SCORE, ext::SORT_TITLE, ext::SORT_TOP, ext::SORT_VOTES),
83
			'SORT'				=> $sort,
84
			'SORT_DIRECTION'	=> $sort_direction,
85
			'U_MCP' 			=> ($this->auth->acl_get('m_', $this->config['ideas_forum_id'])) ? append_sid("{$this->root_path}mcp.$this->php_ext", "f={$this->config['ideas_forum_id']}&amp;i=main&amp;mode=forum_view", true, $this->user->session_id) : '',
86
87
		));
88
89
		// Recreate the url parameters for the current list
90
		$params = array(
91
			'sort'		=> $u_sort ?: null,
92
			'status'	=> $u_status ?: null,
93
			'sd'		=> $u_sort_direction ?: null,
94
		);
95
96
		// Assign breadcrumb template vars
97
		$this->template->assign_block_vars_array('navlinks', array(
98
			array(
99
				'U_VIEW_FORUM'	=> $this->helper->route('phpbb_ideas_index_controller'),
100
				'FORUM_NAME'	=> $this->language->lang('IDEAS'),
101
			),
102
			array(
103
				'U_VIEW_FORUM'	=> $this->helper->route('phpbb_ideas_list_controller', $params),
104
				'FORUM_NAME'	=> $status_name ?: $this->language->lang('OPEN_IDEAS'),
105
			),
106
		));
107
108
		// Generate template pagination
109
		$this->pagination->generate_template_pagination(
110
			$this->helper->route('phpbb_ideas_list_controller', $params),
111
			'pagination',
112
			'start',
113
			$this->entity->get_idea_count(),
114
			$this->config['posts_per_page'],
115
			$start
116
		);
117
118
		// Display common ideas template vars
119
		$this->display_common_vars();
120
121
		return $this->helper->render('@phpbb_ideas/list_body.html', $this->language->lang('IDEA_LIST'));
122
	}
123
}
124