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

bbook_chapters_module::action_move_down()   A

Complexity

Conditions 1
Paths 1

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 5
Code Lines 3

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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_chapters
13
*/
14
class bbook_chapters_module
15
{
16
	/** @var \vinabb\web\controllers\acp\bbook_books_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 $parent_id */
44
	private $parent_id;
45
46
	/** @var int $chapter_id */
47
	private $chapter_id;
48
49
	/**
50
	* Main method of the module
51
	*
52
	* @param string	$id		Module basename
53
	* @param string	$mode	Module mode
54
	*/
55
	public function main($id, $mode)
56
	{
57
		global $phpbb_container;
58
59
		$this->controller = $phpbb_container->get('vinabb.web.acp.bbook_chapters');
60
		$this->language = $phpbb_container->get('language');
61
		$this->request = $phpbb_container->get('request');
62
		$this->module = $id;
63
		$this->mode = $mode;
64
65
		// ACP template file
66
		$this->tpl_name = 'acp_bbook_chapters';
67
		$this->page_title = $this->language->lang('ACP_BBOOK_CHAPTERS');
68
69
		// Language
70
		$this->language->add_lang('acp_bbook', 'vinabb/web');
71
72
		// Requests
73
		$this->action = $this->request->variable('action', 'display');
74
		$this->parent_id = $this->request->variable('parent_id', 0);
75
		$this->chapter_id = $this->request->variable('id', 0);
76
77
		// Form data
78
		$this->controller->set_form_action($this->u_action);
79
80
		// Do actions via the controller
81
		$this->{'action_' . $this->action}();
82
	}
83
84
	/**
85
	* Module action: Display (Default)
86
	*/
87
	private function action_display()
88
	{
89
		$this->controller->display_chapters($this->parent_id);
90
	}
91
92
	/**
93
	* Module action: Add
94
	*/
95
	private function action_add()
96
	{
97
		$this->tpl_name = 'acp_bbook_chapters_edit';
98
		$this->page_title = $this->language->lang('ADD_CHAPTER');
99
		$this->controller->add_chapter($this->parent_id);
100
	}
101
102
	/**
103
	* Module action: Edit
104
	*/
105
	private function action_edit()
106
	{
107
		$this->tpl_name = 'acp_bbook_chapters_edit';
108
		$this->page_title = $this->language->lang('EDIT_CHAPTER');
109
		$this->controller->edit_chapter($this->chapter_id);
110
	}
111
112
	/**
113
	* Module action: Move Down
114
	*/
115
	private function action_move_down()
116
	{
117
		$this->controller->move_chapter($this->chapter_id, 'down');
118
		$this->action_display();
119
	}
120
121
	/**
122
	* Module action: Move Up
123
	*/
124
	private function action_move_up()
125
	{
126
		$this->controller->move_chapter($this->chapter_id, 'up');
127
		$this->action_display();
128
	}
129
130
	/**
131
	* Module action: Delete
132
	*/
133
	private function action_delete()
134
	{
135
		if (confirm_box(true))
136
		{
137
			$this->controller->delete_chapter($this->chapter_id);
138
		}
139
		else
140
		{
141
			confirm_box(false, $this->language->lang('CONFIRM_DELETE_CHAPTER'));
142
		}
143
144
		$this->action_display();
145
	}
146
}
147