get_item_hierarchy()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 2
nc 1
nop 2
1
<?php
2
/**
3
 * Hierarchical breadcrumb item locator
4
 *
5
 * @package carbon-breadcrumbs
6
 */
7
8
/**
9
 * Abstract breadcrumb item locator class for hierarchical types.
10
 *
11
 * Used as a base for taxonomy, post type and other hierarchical locators.
12
 */
13
abstract class Carbon_Breadcrumb_Locator_Hierarchical extends Carbon_Breadcrumb_Locator {
14
15
	/**
16
	 * Retrieve the items, found by this locator.
17
	 *
18
	 * @access public
19
	 *
20
	 * @param int $id The object ID, used to go up the item tree.
21
	 * @param int $priority The priority of the located items.
22
	 * @return array $items The items hierarchy.
23
	 */
24
	public function get_item_hierarchy( $id, $priority ) {
25
		$items = array();
26
27
		do {
28
			$item = Carbon_Breadcrumb_Item::factory( $this->get_type(), $priority );
29
			$item->set_id( $id );
30
			$item->set_subtype( $this->get_subtype() );
31
			$item->setup();
32
33
			$items[] = $item;
34
35
			$id = $this->get_parent_id( $id );
36
		} while ( $id );
37
38
		return array_reverse( $items );
39
	}
40
41
	/**
42
	 * Get the parent ID of a specific item ID
43
	 *
44
	 * @access public
45
	 *
46
	 * @param int $id The ID of the item to retrieve the parent of.
47
	 */
48
	abstract public function get_parent_id( $id );
49
50
}
51