Completed
Push — master ( 2f6701...a7b61e )
by Khoa
05:19
created

nestedset_bbook_chapters   A

Coupling/Cohesion

Components 0
Dependencies 0

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 50
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 1
A get_cat_data() 0 4 2
A add_to_nestedset() 0 4 1
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\operators;
10
11
/**
12
* Nestedset class for BBook chapters
13
*/
14
class nestedset_bbook_chapters extends \phpbb\tree\nestedset
15
{
16
	/**
17
	* Construct
18
	*
19
	* @param \phpbb\db\driver\driver_interface	$db			Database object
20
	* @param \phpbb\lock\db						$lock		Lock the table when moving entities around
21
	* @param string								$table_name	Table name
22
	*/
23
	public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\lock\db $lock, $table_name)
24
	{
25
		parent::__construct(
26
			$db,
27
			$lock,
28
			$table_name,
29
			'NESTEDSET_BBOOK_CHAPTERS_',
30
			'',
31
			[],
32
			[
33
				'item_id'		=> 'chapter_id',
34
				'parent_id'		=> 'parent_id',
35
				'left_id'		=> 'left_id',
36
				'right_id'		=> 'right_id',
37
				'item_parents'	=> 'chapter_parents'
38
			]
39
		);
40
	}
41
42
	/**
43
	* Get the category data from the database
44
	*
45
	* @param int $parent_id Parent to display categories from, 0 for all
46
	* @return array
47
	*/
48
	public function get_cat_data($parent_id)
49
	{
50
		return $parent_id ? $this->get_subtree_data($parent_id, true, false) : $this->get_all_tree_data();
51
	}
52
53
	/**
54
	* Update the tree for an item inserted in the database
55
	*
56
	* @param int $item_id The item to be added
57
	* @return array
58
	*/
59
	public function add_to_nestedset($item_id)
60
	{
61
		return $this->add_item_to_nestedset($item_id);
62
	}
63
}
64