Skip to content

Commit 185fd84

Browse files
authored
Merge pull request #132 from iMattPro/experiment
Break Up The Big Idea
2 parents a4a81d6 + f3d2c4f commit 185fd84

36 files changed

Lines changed: 1031 additions & 847 deletions

config/services.yml

Lines changed: 25 additions & 3 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.idea'
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,6 @@ services:
3637
- '@auth'
3738
- '@config'
3839
- '@controller.helper'
39-
- '@phpbb.ideas.ideas'
4040
- '@language'
4141
- '@phpbb.ideas.linkhelper'
4242
- '@pagination'
@@ -49,10 +49,14 @@ services:
4949
phpbb.ideas.index_controller:
5050
class: phpbb\ideas\controller\index_controller
5151
parent: phpbb.ideas.controller.base
52+
calls:
53+
- [get_entity, ['@phpbb.ideas.ideas']]
5254

5355
phpbb.ideas.list_controller:
5456
class: phpbb\ideas\controller\list_controller
5557
parent: phpbb.ideas.controller.base
58+
calls:
59+
- [get_entity, ['@phpbb.ideas.ideas']]
5660

5761
phpbb.ideas.post_controller:
5862
class: phpbb\ideas\controller\post_controller
@@ -61,12 +65,17 @@ services:
6165
phpbb.ideas.idea_controller:
6266
class: phpbb\ideas\controller\idea_controller
6367
parent: phpbb.ideas.controller.base
68+
calls:
69+
- [get_entity, ['@phpbb.ideas.idea']]
6470

6571
phpbb.ideas.livesearch_controller:
6672
class: phpbb\ideas\controller\livesearch_controller
6773
parent: phpbb.ideas.controller.base
74+
calls:
75+
- [get_entity, ['@phpbb.ideas.livesearch']]
6876

69-
phpbb.ideas.ideas:
77+
# ----- Idea Factory Classes -----
78+
phpbb.ideas.base:
7079
class: phpbb\ideas\factory\ideas
7180
arguments:
7281
- '@auth'
@@ -79,12 +88,25 @@ 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+
99+
phpbb.ideas.livesearch:
100+
class: phpbb\ideas\factory\livesearch
101+
parent: phpbb.ideas.base
102+
82103
phpbb.ideas.linkhelper:
83104
class: phpbb\ideas\factory\linkhelper
84105
arguments:
85106
- '@controller.helper'
86107
- '@user_loader'
87108

109+
# ----- Twig extensions -----
88110
phpbb.ideas.twig.extension.ideas_status_icon:
89111
class: phpbb\ideas\template\twig\extension\ideas_status_icon
90112
tags:

controller/admin_controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function set_ideas_forum_options()
168168

169169
$forum_id = (int) $this->config['ideas_forum_id'];
170170

171-
$permission_helper = new \phpbb\ideas\factory\permission_helper($this->config, $this->db, $this->phpbb_root_path, $this->php_ext);
171+
$permission_helper = new \phpbb\ideas\factory\permission_helper($this->db, $this->phpbb_root_path, $this->php_ext);
172172
$permission_helper->set_ideas_forum_permissions($forum_id);
173173

174174
// Disable auto-pruning for ideas forum

controller/base.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
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;
1717
use phpbb\ideas\factory\linkhelper;
1818
use phpbb\language\language;
1919
use phpbb\pagination;
@@ -32,8 +32,8 @@ abstract class base
3232
/* @var helper */
3333
protected $helper;
3434

35-
/* @var ideas */
36-
protected $ideas;
35+
/* @var \phpbb\ideas\factory\base */
36+
protected $entity;
3737

3838
/** @var language */
3939
protected $language;
@@ -63,7 +63,6 @@ abstract class base
6363
* @param auth $auth
6464
* @param config $config
6565
* @param helper $helper
66-
* @param ideas $ideas
6766
* @param language $language
6867
* @param linkhelper $link_helper
6968
* @param pagination $pagination
@@ -73,12 +72,11 @@ abstract class base
7372
* @param string $root_path
7473
* @param string $php_ext
7574
*/
76-
public function __construct(auth $auth, config $config, helper $helper, ideas $ideas, language $language, linkhelper $link_helper, pagination $pagination, request $request, template $template, user $user, $root_path, $php_ext)
75+
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)
7776
{
7877
$this->auth = $auth;
7978
$this->config = $config;
8079
$this->helper = $helper;
81-
$this->ideas = $ideas;
8280
$this->language = $language;
8381
$this->link_helper = $link_helper;
8482
$this->pagination = $pagination;
@@ -91,6 +89,16 @@ public function __construct(auth $auth, config $config, helper $helper, ideas $i
9189
$this->language->add_lang('common', 'phpbb/ideas');
9290
}
9391

92+
/**
93+
* Set the Ideas entity
94+
*
95+
* @param \phpbb\ideas\factory\base $entity
96+
*/
97+
public function get_entity($entity)
98+
{
99+
$this->entity = $entity;
100+
}
101+
94102
/**
95103
* Check if Ideas is properly configured after installation
96104
* Ideas is available only after forum settings have been set in ACP
@@ -144,7 +152,7 @@ protected function display_common_vars()
144152
'S_SEARCHBOX_ACTION' => append_sid("{$this->root_path}search.{$this->php_ext}"),
145153
'S_SEARCH_IDEAS_HIDDEN_FIELDS' => build_hidden_fields(['fid' => [$this->config['ideas_forum_id']]]),
146154

147-
'U_SEARCH_MY_IDEAS' => $this->helper->route('phpbb_ideas_list_controller', ['sort' => ideas::SORT_MYIDEAS, 'status' => '-1']),
155+
'U_SEARCH_MY_IDEAS' => $this->helper->route('phpbb_ideas_list_controller', ['sort' => ext::SORT_MYIDEAS, 'status' => '-1']),
148156
]);
149157
}
150158
}

controller/idea_controller.php

Lines changed: 15 additions & 31 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

@@ -20,6 +20,9 @@ class idea_controller extends base
2020
/** @var array of idea data */
2121
protected $data;
2222

23+
/* @var \phpbb\ideas\factory\idea */
24+
protected $entity;
25+
2326
/**
2427
* Controller for /idea/{idea_id}
2528
*
@@ -34,7 +37,7 @@ public function idea($idea_id)
3437
throw new http_exception(404, 'IDEAS_NOT_AVAILABLE');
3538
}
3639

37-
$this->data = $this->ideas->get_idea($idea_id);
40+
$this->data = $this->entity->get_idea($idea_id);
3841
if (!$this->data)
3942
{
4043
throw new http_exception(404, 'IDEA_NOT_FOUND');
@@ -80,7 +83,7 @@ public function delete()
8083
if (confirm_box(true))
8184
{
8285
include $this->root_path . 'includes/functions_admin.' . $this->php_ext;
83-
$this->ideas->delete($this->data['idea_id'], $this->data['topic_id']);
86+
$this->entity->delete($this->data['idea_id'], $this->data['topic_id']);
8487

8588
$redirect = $this->helper->route('phpbb_ideas_index_controller');
8689
$message = $this->language->lang('IDEA_DELETED') . '<br /><br />' . $this->language->lang('RETURN_IDEAS', '<a href="' . $redirect . '">', '</a>');
@@ -119,7 +122,7 @@ public function duplicate()
119122
if ($this->is_mod() && check_link_hash($this->get_hash(), "duplicate_{$this->data['idea_id']}"))
120123
{
121124
$duplicate = $this->request->variable('duplicate', 0);
122-
return $this->ideas->set_duplicate($this->data['idea_id'], $duplicate);
125+
return $this->entity->set_duplicate($this->data['idea_id'], $duplicate);
123126
}
124127

125128
return false;
@@ -133,14 +136,14 @@ public function duplicate()
133136
*/
134137
public function removevote()
135138
{
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']}"))
139+
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']}"))
137140
{
138141
return false;
139142
}
140143

141144
if ($this->auth->acl_get('f_vote', (int) $this->config['ideas_forum_id']))
142145
{
143-
$result = $this->ideas->remove_vote($this->data, $this->user->data['user_id']);
146+
$result = $this->entity->remove_vote($this->data, $this->user->data['user_id']);
144147
}
145148
else
146149
{
@@ -161,7 +164,7 @@ public function rfc()
161164
if (($this->is_own() || $this->is_mod()) && check_link_hash($this->get_hash(), "rfc_{$this->data['idea_id']}"))
162165
{
163166
$rfc = $this->request->variable('rfc', '');
164-
return $this->ideas->set_rfc($this->data['idea_id'], $rfc);
167+
return $this->entity->set_rfc($this->data['idea_id'], $rfc);
165168
}
166169

167170
return false;
@@ -179,7 +182,7 @@ public function status()
179182

180183
if ($status && $this->is_mod() && check_link_hash($this->get_hash(), "status_{$this->data['idea_id']}"))
181184
{
182-
$this->ideas->change_status($this->data['idea_id'], $status);
185+
$this->entity->set_status($this->data['idea_id'], $status);
183186
return true;
184187
}
185188

@@ -197,7 +200,7 @@ public function ticket()
197200
if (($this->is_own() || $this->is_mod()) && check_link_hash($this->get_hash(), "ticket_{$this->data['idea_id']}"))
198201
{
199202
$ticket = $this->request->variable('ticket', 0);
200-
return $this->ideas->set_ticket($this->data['idea_id'], $ticket);
203+
return $this->entity->set_ticket($this->data['idea_id'], $ticket);
201204
}
202205

203206
return false;
@@ -214,26 +217,7 @@ public function implemented()
214217
if ($this->is_mod() && check_link_hash($this->get_hash(), "implemented_{$this->data['idea_id']}"))
215218
{
216219
$version = $this->request->variable('implemented', '');
217-
return $this->ideas->set_implemented($this->data['idea_id'], $version);
218-
}
219-
220-
return false;
221-
}
222-
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);
220+
return $this->entity->set_implemented($this->data['idea_id'], $version);
237221
}
238222

239223
return false;
@@ -249,14 +233,14 @@ public function vote()
249233
{
250234
$vote = $this->request->variable('v', 1);
251235

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']}"))
236+
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']}"))
253237
{
254238
return false;
255239
}
256240

257241
if ($this->auth->acl_get('f_vote', (int) $this->config['ideas_forum_id']))
258242
{
259-
$result = $this->ideas->vote($this->data, $this->user->data['user_id'], $vote);
243+
$result = $this->entity->vote($this->data, $this->user->data['user_id'], $vote);
260244
}
261245
else
262246
{

controller/index_controller.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
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;
18+
/* @var \phpbb\ideas\factory\ideas */
19+
protected $entity;
1920

2021
/**
2122
* Controller for /ideas
@@ -31,21 +32,21 @@ public function index()
3132
}
3233

3334
// Generate latest ideas
34-
$ideas = $this->ideas->get_ideas(self::NUM_IDEAS, ideas::SORT_DATE, 'DESC');
35+
$ideas = $this->entity->get_ideas(ext::NUM_IDEAS, ext::SORT_DATE, 'DESC');
3536
$this->assign_template_block_vars('latest_ideas', $ideas);
3637

3738
// Generate top ideas
38-
$ideas = $this->ideas->get_ideas(self::NUM_IDEAS, ideas::SORT_TOP, 'DESC');
39+
$ideas = $this->entity->get_ideas(ext::NUM_IDEAS, ext::SORT_TOP, 'DESC');
3940
$this->assign_template_block_vars('top_ideas', $ideas);
4041

4142
// Generate recently implemented
42-
$ideas = $this->ideas->get_ideas(self::NUM_IDEAS, ideas::SORT_DATE, 'DESC', ideas::$statuses['IMPLEMENTED']);
43+
$ideas = $this->entity->get_ideas(ext::NUM_IDEAS, ext::SORT_DATE, 'DESC', ext::$statuses['IMPLEMENTED']);
4344
$this->assign_template_block_vars('implemented_ideas', $ideas);
4445

4546
$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']]),
47+
'U_VIEW_TOP' => $this->helper->route('phpbb_ideas_list_controller', ['sort' => ext::SORT_TOP]),
48+
'U_VIEW_LATEST' => $this->helper->route('phpbb_ideas_list_controller', ['sort' => ext::SORT_NEW]),
49+
'U_VIEW_IMPLEMENTED'=> $this->helper->route('phpbb_ideas_list_controller', ['sort' => ext::SORT_DATE, 'status' => ext::$statuses['IMPLEMENTED']]),
4950
'U_POST_ACTION' => $this->helper->route('phpbb_ideas_post_controller'),
5051
'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) : '',
5152

0 commit comments

Comments
 (0)