Skip to content

Commit ac6e9c8

Browse files
committed
break up ideas class
1 parent deee005 commit ac6e9c8

15 files changed

Lines changed: 1027 additions & 646 deletions

File tree

config/services.yml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ services:
88
- '@auth'
99
- '@config'
1010
- '@controller.helper'
11-
- '@phpbb.ideas.ideas'
11+
- '@phpbb.ideas.manager'
1212
- '@language'
1313
- '@phpbb.ideas.linkhelper'
1414
- '@template'
@@ -17,6 +17,7 @@ services:
1717
tags:
1818
- { name: event.listener }
1919

20+
# ----- Controllers -----
2021
phpbb.ideas.admin.controller:
2122
class: phpbb\ideas\controller\admin_controller
2223
arguments:
@@ -36,7 +37,7 @@ services:
3637
- '@auth'
3738
- '@config'
3839
- '@controller.helper'
39-
- '@phpbb.ideas.ideas'
40+
- '@phpbb.ideas.manager'
4041
- '@language'
4142
- '@phpbb.ideas.linkhelper'
4243
- '@pagination'
@@ -66,7 +67,15 @@ services:
6667
class: phpbb\ideas\controller\livesearch_controller
6768
parent: phpbb.ideas.controller.base
6869

69-
phpbb.ideas.ideas:
70+
# ----- Idea Factory Classes -----
71+
phpbb.ideas.manager:
72+
class: phpbb\ideas\factory\manager
73+
arguments:
74+
- '@phpbb.ideas.idea'
75+
- '@phpbb.ideas.ideas'
76+
- '@phpbb.ideas.vote'
77+
78+
phpbb.ideas.base:
7079
class: phpbb\ideas\factory\ideas
7180
arguments:
7281
- '@auth'
@@ -79,12 +88,27 @@ services:
7988
- '%tables.topics%'
8089
- '%core.php_ext%'
8190

91+
phpbb.ideas.ideas:
92+
class: phpbb\ideas\factory\ideas
93+
parent: phpbb.ideas.base
94+
95+
phpbb.ideas.idea:
96+
class: phpbb\ideas\factory\idea
97+
parent: phpbb.ideas.base
98+
arguments:
99+
- '@phpbb.ideas.vote'
100+
101+
phpbb.ideas.vote:
102+
class: phpbb\ideas\factory\vote
103+
parent: phpbb.ideas.base
104+
82105
phpbb.ideas.linkhelper:
83106
class: phpbb\ideas\factory\linkhelper
84107
arguments:
85108
- '@controller.helper'
86109
- '@user_loader'
87110

111+
# ----- Twig extensions -----
88112
phpbb.ideas.twig.extension.ideas_status_icon:
89113
class: phpbb\ideas\template\twig\extension\ideas_status_icon
90114
tags:
@@ -95,7 +119,7 @@ services:
95119
class: phpbb\ideas\cron\prune_orphaned_ideas
96120
arguments:
97121
- '@config'
98-
- '@phpbb.ideas.ideas'
122+
- '@phpbb.ideas.manager'
99123
calls:
100124
- [set_name, [cron.task.prune_orphaned_ideas]]
101125
tags:

controller/base.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
use phpbb\auth\auth;
1414
use phpbb\config\config;
1515
use phpbb\controller\helper;
16-
use phpbb\ideas\factory\ideas;
16+
use phpbb\ideas\ext;
17+
use phpbb\ideas\factory\manager as ideas;
1718
use phpbb\ideas\factory\linkhelper;
1819
use phpbb\language\language;
1920
use phpbb\pagination;
@@ -144,7 +145,7 @@ protected function display_common_vars()
144145
'S_SEARCHBOX_ACTION' => append_sid("{$this->root_path}search.{$this->php_ext}"),
145146
'S_SEARCH_IDEAS_HIDDEN_FIELDS' => build_hidden_fields(['fid' => [$this->config['ideas_forum_id']]]),
146147

147-
'U_SEARCH_MY_IDEAS' => $this->helper->route('phpbb_ideas_list_controller', ['sort' => ideas::SORT_MYIDEAS, 'status' => '-1']),
148+
'U_SEARCH_MY_IDEAS' => $this->helper->route('phpbb_ideas_list_controller', ['sort' => ext::SORT_MYIDEAS, 'status' => '-1']),
148149
]);
149150
}
150151
}

controller/idea_controller.php

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace phpbb\ideas\controller;
1212

1313
use phpbb\exception\http_exception;
14-
use phpbb\ideas\factory\ideas;
14+
use phpbb\ideas\ext;
1515
use Symfony\Component\HttpFoundation\JsonResponse;
1616
use Symfony\Component\HttpFoundation\RedirectResponse;
1717

@@ -133,7 +133,7 @@ public function duplicate()
133133
*/
134134
public function removevote()
135135
{
136-
if ($this->data['idea_status'] === ideas::$statuses['IMPLEMENTED'] || $this->data['idea_status'] === ideas::$statuses['DUPLICATE'] || !check_link_hash($this->get_hash(), "removevote_{$this->data['idea_id']}"))
136+
if ($this->data['idea_status'] === ext::$statuses['IMPLEMENTED'] || $this->data['idea_status'] === ext::$statuses['DUPLICATE'] || !check_link_hash($this->get_hash(), "removevote_{$this->data['idea_id']}"))
137137
{
138138
return false;
139139
}
@@ -179,7 +179,7 @@ public function status()
179179

180180
if ($status && $this->is_mod() && check_link_hash($this->get_hash(), "status_{$this->data['idea_id']}"))
181181
{
182-
$this->ideas->change_status($this->data['idea_id'], $status);
182+
$this->ideas->set_status($this->data['idea_id'], $status);
183183
return true;
184184
}
185185

@@ -220,25 +220,6 @@ public function implemented()
220220
return false;
221221
}
222222

223-
/**
224-
* Title action (sets an idea's title)
225-
*
226-
* @return bool True if set, false if not
227-
* @access public
228-
*
229-
* @deprecated 2.1.0 (No longer used, may be removed one day)
230-
*/
231-
public function title()
232-
{
233-
if (($this->is_own() || $this->is_mod()) && check_link_hash($this->get_hash(), "title_{$this->data['idea_id']}"))
234-
{
235-
$title = $this->request->variable('title', '', true);
236-
return $this->ideas->set_title($this->data['idea_id'], $title);
237-
}
238-
239-
return false;
240-
}
241-
242223
/**
243224
* Vote action (sets an idea's vote)
244225
*
@@ -249,7 +230,7 @@ public function vote()
249230
{
250231
$vote = $this->request->variable('v', 1);
251232

252-
if ($this->data['idea_status'] === ideas::$statuses['IMPLEMENTED'] || $this->data['idea_status'] === ideas::$statuses['DUPLICATE'] || !check_link_hash($this->get_hash(), "vote_{$this->data['idea_id']}"))
233+
if ($this->data['idea_status'] === ext::$statuses['IMPLEMENTED'] || $this->data['idea_status'] === ext::$statuses['DUPLICATE'] || !check_link_hash($this->get_hash(), "vote_{$this->data['idea_id']}"))
253234
{
254235
return false;
255236
}

controller/index_controller.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111
namespace phpbb\ideas\controller;
1212

1313
use phpbb\exception\http_exception;
14-
use phpbb\ideas\factory\ideas;
14+
use phpbb\ideas\ext;
1515

1616
class index_controller extends base
1717
{
18-
const NUM_IDEAS = 5;
19-
2018
/**
2119
* Controller for /ideas
2220
*
@@ -31,21 +29,21 @@ public function index()
3129
}
3230

3331
// Generate latest ideas
34-
$ideas = $this->ideas->get_ideas(self::NUM_IDEAS, ideas::SORT_DATE, 'DESC');
32+
$ideas = $this->ideas->get_ideas(ext::NUM_IDEAS, ext::SORT_DATE, 'DESC');
3533
$this->assign_template_block_vars('latest_ideas', $ideas);
3634

3735
// Generate top ideas
38-
$ideas = $this->ideas->get_ideas(self::NUM_IDEAS, ideas::SORT_TOP, 'DESC');
36+
$ideas = $this->ideas->get_ideas(ext::NUM_IDEAS, ext::SORT_TOP, 'DESC');
3937
$this->assign_template_block_vars('top_ideas', $ideas);
4038

4139
// Generate recently implemented
42-
$ideas = $this->ideas->get_ideas(self::NUM_IDEAS, ideas::SORT_DATE, 'DESC', ideas::$statuses['IMPLEMENTED']);
40+
$ideas = $this->ideas->get_ideas(ext::NUM_IDEAS, ext::SORT_DATE, 'DESC', ext::$statuses['IMPLEMENTED']);
4341
$this->assign_template_block_vars('implemented_ideas', $ideas);
4442

4543
$this->template->assign_vars(array(
46-
'U_VIEW_TOP' => $this->helper->route('phpbb_ideas_list_controller', ['sort' => ideas::SORT_TOP]),
47-
'U_VIEW_LATEST' => $this->helper->route('phpbb_ideas_list_controller', ['sort' => ideas::SORT_NEW]),
48-
'U_VIEW_IMPLEMENTED'=> $this->helper->route('phpbb_ideas_list_controller', ['sort' => ideas::SORT_DATE, 'status' => ideas::$statuses['IMPLEMENTED']]),
44+
'U_VIEW_TOP' => $this->helper->route('phpbb_ideas_list_controller', ['sort' => ext::SORT_TOP]),
45+
'U_VIEW_LATEST' => $this->helper->route('phpbb_ideas_list_controller', ['sort' => ext::SORT_NEW]),
46+
'U_VIEW_IMPLEMENTED'=> $this->helper->route('phpbb_ideas_list_controller', ['sort' => ext::SORT_DATE, 'status' => ext::$statuses['IMPLEMENTED']]),
4947
'U_POST_ACTION' => $this->helper->route('phpbb_ideas_post_controller'),
5048
'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']}&i=main&mode=forum_view", true, $this->user->session_id) : '',
5149

controller/list_controller.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace phpbb\ideas\controller;
1212

1313
use phpbb\exception\http_exception;
14-
use phpbb\ideas\factory\ideas;
14+
use phpbb\ideas\ext;
1515

1616
class list_controller extends base
1717
{
@@ -31,7 +31,7 @@ public function ideas_list($sort)
3131

3232
// Overwrite the $sort parameter if the url contains a sort query.
3333
// This is needed with the sort by options form at the footer of the list.
34-
$sort = $this->request->is_set('sort') ? $this->request->variable('sort', ideas::SORT_NEW) : $sort;
34+
$sort = $this->request->is_set('sort') ? $this->request->variable('sort', ext::SORT_NEW) : $sort;
3535

3636
// Get additional query values the url may contain
3737
$sort_direction = $this->request->variable('sd', 'd');
@@ -47,20 +47,20 @@ public function ideas_list($sort)
4747
$sort_direction = ($sort_direction === 'd') ? 'DESC' : 'ASC';
4848

4949
// If sort by "new" we really use date
50-
if ($sort === ideas::SORT_NEW)
50+
if ($sort === ext::SORT_NEW)
5151
{
52-
$sort = ideas::SORT_DATE;
52+
$sort = ext::SORT_DATE;
5353
}
5454

5555
// Set the name for displaying in the template
56-
$status_name = 'LIST_' . strtoupper($status > 0 ? array_search($status, ideas::$statuses) : $sort);
56+
$status_name = 'LIST_' . strtoupper($status > 0 ? array_search($status, ext::$statuses) : $sort);
5757
$status_name = $this->language->is_set($status_name) ? $this->language->lang($status_name) : '';
5858

5959
// For special case where we want to request ALL ideas,
6060
// including the statuses normally hidden from lists.
6161
if ($status === -1)
6262
{
63-
$status = ideas::$statuses;
63+
$status = ext::$statuses;
6464
$status_name = $status_name ?: $this->language->lang('ALL_IDEAS');
6565
}
6666

@@ -74,9 +74,9 @@ public function ideas_list($sort)
7474
'U_POST_ACTION' => $this->helper->route('phpbb_ideas_post_controller'),
7575
'IDEAS_COUNT' => $this->ideas->get_idea_count(),
7676
'STATUS_NAME' => $status_name ?: $this->language->lang('OPEN_IDEAS'),
77-
'STATUS_ARY' => ideas::$statuses,
77+
'STATUS_ARY' => ext::$statuses,
7878
'STATUS' => $u_status,
79-
'SORT_ARY' => array(ideas::SORT_AUTHOR, ideas::SORT_DATE, ideas::SORT_SCORE, ideas::SORT_TITLE, ideas::SORT_TOP, ideas::SORT_VOTES),
79+
'SORT_ARY' => array(ext::SORT_AUTHOR, ext::SORT_DATE, ext::SORT_SCORE, ext::SORT_TITLE, ext::SORT_TOP, ext::SORT_VOTES),
8080
'SORT' => $sort,
8181
'SORT_DIRECTION' => $sort_direction,
8282
'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']}&i=main&mode=forum_view", true, $this->user->session_id) : '',

cron/prune_orphaned_ideas.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ class prune_orphaned_ideas extends \phpbb\cron\task\base
1818
/** @var \phpbb\config\config */
1919
protected $config;
2020

21-
/** @var \phpbb\ideas\factory\ideas */
21+
/** @var \phpbb\ideas\factory\manager */
2222
protected $ideas;
2323

2424
/**
2525
* Constructor
2626
*
27-
* @param \phpbb\config\config $config Config object
28-
* @param \phpbb\ideas\factory\ideas $ideas Ideas factory object
27+
* @param \phpbb\config\config $config Config object
28+
* @param \phpbb\ideas\factory\manager $ideas Ideas factory object
2929
* @access public
3030
*/
31-
public function __construct(\phpbb\config\config $config, \phpbb\ideas\factory\ideas $ideas)
31+
public function __construct(\phpbb\config\config $config, \phpbb\ideas\factory\manager $ideas)
3232
{
3333
$this->config = $config;
3434
$this->ideas = $ideas;

event/listener.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
use phpbb\auth\auth;
1414
use phpbb\config\config;
1515
use phpbb\controller\helper;
16-
use phpbb\ideas\factory\ideas;
16+
use phpbb\ideas\ext;
17+
use phpbb\ideas\factory\manager as ideas;
1718
use phpbb\ideas\factory\linkhelper;
1819
use phpbb\language\language;
1920
use phpbb\template\template;
@@ -53,7 +54,7 @@ class listener implements EventSubscriberInterface
5354
* @param \phpbb\auth\auth $auth
5455
* @param \phpbb\config\config $config
5556
* @param \phpbb\controller\helper $helper
56-
* @param \phpbb\ideas\factory\ideas $ideas
57+
* @param \phpbb\ideas\factory\manager $ideas
5758
* @param \phpbb\language\language $language
5859
* @param \phpbb\ideas\factory\linkhelper $link_helper
5960
* @param \phpbb\template\template $template
@@ -154,7 +155,7 @@ public function show_idea($event)
154155

155156
if ($mod)
156157
{
157-
$this->template->assign_var('STATUS_ARY', ideas::$statuses);
158+
$this->template->assign_var('STATUS_ARY', ext::$statuses);
158159

159160
// Add quick mod option for deleting an idea
160161
$this->template->alter_block_array('quickmod', array(
@@ -165,8 +166,8 @@ public function show_idea($event)
165166
}
166167

167168
$points = $idea['idea_votes_up'] - $idea['idea_votes_down'];
168-
$can_vote = (bool) ($idea['idea_status'] != ideas::$statuses['IMPLEMENTED'] &&
169-
$idea['idea_status'] != ideas::$statuses['DUPLICATE'] &&
169+
$can_vote = (bool) ($idea['idea_status'] != ext::$statuses['IMPLEMENTED'] &&
170+
$idea['idea_status'] != ext::$statuses['DUPLICATE'] &&
170171
$this->auth->acl_get('f_vote', (int) $this->config['ideas_forum_id']) &&
171172
$event['topic_data']['topic_status'] != ITEM_LOCKED);
172173

@@ -222,7 +223,7 @@ public function show_idea($event)
222223
'U_IDEA_VOTE' => $this->link_helper->get_idea_link($idea['idea_id'], 'vote', true),
223224
'U_IDEA_DUPLICATE' => $this->link_helper->get_idea_link($idea['duplicate_id']),
224225
'U_IDEA_STATUS_LINK'=> $this->helper->route('phpbb_ideas_list_controller', ['status' => $idea['idea_status']]),
225-
'U_SEARCH_MY_IDEAS' => $this->helper->route('phpbb_ideas_list_controller', ['sort' => ideas::SORT_MYIDEAS, 'status' => '-1']),
226+
'U_SEARCH_MY_IDEAS' => $this->helper->route('phpbb_ideas_list_controller', ['sort' => ext::SORT_MYIDEAS, 'status' => '-1']),
226227
'U_TITLE_LIVESEARCH'=> $this->helper->route('phpbb_ideas_livesearch_controller'),
227228
));
228229

ext.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@
2020
*/
2121
class ext extends \phpbb\extension\base
2222
{
23+
public const SORT_AUTHOR = 'author';
24+
public const SORT_DATE = 'date';
25+
public const SORT_NEW = 'new';
26+
public const SORT_SCORE = 'score';
27+
public const SORT_TITLE = 'title';
28+
public const SORT_TOP = 'top';
29+
public const SORT_VOTES = 'votes';
30+
public const SORT_MYIDEAS = 'egosearch';
31+
public const SUBJECT_LENGTH = 120;
32+
public const NUM_IDEAS = 5;
33+
34+
/** @var array Idea status names and IDs */
35+
public static $statuses = array(
36+
'NEW' => 1,
37+
'IN_PROGRESS' => 2,
38+
'IMPLEMENTED' => 3,
39+
'DUPLICATE' => 4,
40+
'INVALID' => 5,
41+
);
42+
2343
/**
2444
* Check whether or not the extension can be enabled.
2545
*

0 commit comments

Comments
 (0)