Completed
Push — master ( 561264...fd44b1 )
by Khoa
14:56
created

nestedset_bbook_chapters::set_sql_where()   A

Complexity

Conditions 1
Paths 1

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 4
Code Lines 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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
	* Update $this->sql_where to display chapters by the book ID
44
	*
45
	* @param int $book_id Book ID
46
	*/
47
	public function set_sql_where($book_id)
48
	{
49
		$this->sql_where = 'book_id = ' . (int) $book_id;
50
	}
51
52
	/**
53
	* Get the chapter data from the database
54
	*
55
	* @param int $parent_id Parent to display chapters from, 0 for all
56
	* @return array
57
	*/
58
	public function get_chapter_data($parent_id)
59
	{
60
		return $parent_id ? $this->get_subtree_data($parent_id, true, false) : $this->get_all_tree_data();
61
	}
62
63
	/**
64
	* Update the tree for an item inserted in the database
65
	*
66
	* @param int $item_id The item to be added
67
	* @return array
68
	*/
69
	public function add_to_nestedset($item_id)
70
	{
71
		return $this->add_item_to_nestedset($item_id);
72
	}
73
}
74