Completed
Push — master ( a7b61e...4a7303 )
by Khoa
03:38
created

bbook_words_module::main()   B

Complexity

Conditions 1
Paths 1

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 27
Code Lines 14

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 2
1
<?php
2
/**
3
* This file is part of the VinaBB.vn package.
4
*
5
* @copyright (c) VinaBB <vinabb.vn>
6
* @license GNU General Public License, version 2 (GPL-2.0)
7
*/
8
9
namespace vinabb\web\acp;
10
11
/**
12
* ACP module: acp_bbook_words
13
*/
14
class bbook_words_module
15
{
16
	/** @var \vinabb\web\controllers\acp\bbook_words_interface $controller */
17
	protected $controller;
18
19
	/** @var \phpbb\language\language $language */
20
	protected $language;
21
22
	/** @var \phpbb\request\request $request */
23
	protected $request;
24
25
	/** @var string $module */
26
	protected $module;
27
28
	/** @var string $mode */
29
	protected $mode;
30
31
	/** @var string $tpl_name */
32
	public $tpl_name;
33
34
	/** @var string $page_title */
35
	public $page_title;
36
37
	/** @var string $u_action */
38
	public $u_action;
39
40
	/** @var string $action */
41
	private $action;
42
43
	/** @var int $word_id */
44
	private $word_id;
45
46
	/**
47
	* Main method of the module
48
	*
49
	* @param string	$id		Module basename
50
	* @param string	$mode	Module mode
51
	*/
52
	public function main($id, $mode)
53
	{
54
		global $phpbb_container;
55
56
		$this->controller = $phpbb_container->get('vinabb.web.acp.bbook_words');
57
		$this->language = $phpbb_container->get('language');
58
		$this->request = $phpbb_container->get('request');
59
		$this->module = $id;
60
		$this->mode = $mode;
61
62
		// ACP template file
63
		$this->tpl_name = 'acp_bbook_words';
64
		$this->page_title = $this->language->lang('ACP_BBOOK_WORDS');
65
66
		// Language
67
		$this->language->add_lang('acp_bbook', 'vinabb/web');
68
69
		// Requests
70
		$this->action = $this->request->variable('action', 'display');
71
		$this->word_id = $this->request->variable('id', 0);
72
73
		// Form data
74
		$this->controller->set_form_action($this->u_action);
75
76
		// Do actions via the controller
77
		$this->{'action_' . $this->action}();
78
	}
79
80
	/**
81
	* Module action: Display (Default)
82
	*/
83
	private function action_display()
84
	{
85
		$this->controller->display_words();
86
	}
87
88
	/**
89
	* Module action: Add
90
	*/
91
	private function action_add()
92
	{
93
		$this->tpl_name = 'acp_bbook_words_edit';
94
		$this->page_title = $this->language->lang('ADD_WORD');
95
		$this->controller->add_word();
96
	}
97
98
	/**
99
	* Module action: Edit
100
	*/
101
	private function action_edit()
102
	{
103
		$this->tpl_name = 'acp_bbook_words_edit';
104
		$this->page_title = $this->language->lang('EDIT_WORD');
105
		$this->controller->edit_word($this->word_id);
106
	}
107
108
	/**
109
	* Module action: Delete
110
	*/
111
	private function action_delete()
112
	{
113
		if (confirm_box(true))
114
		{
115
			$this->controller->delete_word($this->word_id);
116
		}
117
		else
118
		{
119
			confirm_box(false, $this->language->lang('CONFIRM_DELETE_WORD'));
120
		}
121
122
		$this->action_display();
123
	}
124
}
125