1 | <?php |
||
7 | abstract class Carbon_Breadcrumb_Locator extends Carbon_Breadcrumb_Factory { |
||
8 | |||
9 | /** |
||
10 | * Breadcrumb item locator type. |
||
11 | * |
||
12 | * @access protected |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $type = ''; |
||
16 | |||
17 | /** |
||
18 | * Breadcrumb item locator subtype. |
||
19 | * |
||
20 | * @access protected |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $subtype = ''; |
||
24 | |||
25 | /** |
||
26 | * Build a new breadcrumb item locator of the selected type. |
||
27 | * |
||
28 | * @static |
||
29 | * @access public |
||
30 | * |
||
31 | * @param string $type Type of the breadcrumb item locator. |
||
32 | * @param string $subtype Subtype of the breadcrumb item locator. |
||
33 | * @return Carbon_Breadcrumb_Locator $locator The new breadcrumb item locator. |
||
34 | */ |
||
35 | 3 | public static function factory( $type, $subtype = '' ) { |
|
41 | |||
42 | /** |
||
43 | * Constructor. |
||
44 | * |
||
45 | * Creates and configures a new breadcrumb item locator with the provided settings. |
||
46 | * |
||
47 | * @access public |
||
48 | * |
||
49 | * @param string $type Type of the breadcrumb item locator. |
||
50 | * @param string $subtype Subtype of the breadcrumb item locator. |
||
51 | */ |
||
52 | 1 | public function __construct( $type, $subtype ) { |
|
56 | |||
57 | /** |
||
58 | * Generate a set of breadcrumb items that found by the current type and the provided subtypes. |
||
59 | * |
||
60 | * @access public |
||
61 | * |
||
62 | * @param array $subtypes The subtypes to generate items for. |
||
63 | * @return array $items The items, generated by this locator. |
||
64 | */ |
||
65 | 3 | public function generate_items_for_subtypes( $subtypes ) { |
|
66 | 3 | $all_items = array(); |
|
67 | |||
68 | 3 | foreach ( $subtypes as $subtype ) { |
|
69 | 3 | $locator = Carbon_Breadcrumb_Locator::factory( $this->get_type(), $subtype ); |
|
70 | 3 | if ( $locator->is_included() ) { |
|
71 | 3 | $items = $locator->get_items(); |
|
72 | 3 | $all_items = array_merge( $all_items, $items ); |
|
73 | 3 | } |
|
74 | 3 | } |
|
75 | |||
76 | 3 | return $all_items; |
|
77 | } |
||
78 | |||
79 | /** |
||
80 | * Retrieve the type of this locator. |
||
81 | * |
||
82 | * @access public |
||
83 | * |
||
84 | * @return string $type The type of this locator. |
||
85 | */ |
||
86 | 1 | public function get_type() { |
|
89 | |||
90 | /** |
||
91 | * Modify the type of this locator. |
||
92 | * |
||
93 | * @access public |
||
94 | * |
||
95 | * @param string $type The new locator type. |
||
96 | */ |
||
97 | 1 | public function set_type( $type ) { |
|
100 | |||
101 | /** |
||
102 | * Retrieve the subtype of this locator. |
||
103 | * |
||
104 | * @access public |
||
105 | * |
||
106 | * @return string $subtype The subtype of this locator. |
||
107 | */ |
||
108 | 1 | public function get_subtype() { |
|
111 | |||
112 | /** |
||
113 | * Modify the subtype of this locator. |
||
114 | * |
||
115 | * @access public |
||
116 | * |
||
117 | * @param string $subtype The new locator subtype. |
||
118 | */ |
||
119 | 1 | public function set_subtype( $subtype ) { |
|
122 | |||
123 | /** |
||
124 | * Whether this the items of this locator should be included in the trail. |
||
125 | * |
||
126 | * @abstract |
||
127 | * @access public |
||
128 | */ |
||
129 | abstract public function is_included(); |
||
130 | |||
131 | /** |
||
132 | * Get the breadcrumb items, found by this locator. |
||
133 | * |
||
134 | * @abstract |
||
135 | * @access public |
||
136 | * |
||
137 | * @param int $priority The priority of the located items. |
||
138 | * @param int $id The ID of the item to get items for. Optional. |
||
139 | */ |
||
140 | abstract public function get_items( $priority = 1000, $id = 0 ); |
||
141 | |||
142 | /** |
||
143 | * Generate a set of breadcrumb items that found by this locator type and any subtype. |
||
144 | * |
||
145 | * @abstract |
||
146 | * @access public |
||
147 | */ |
||
148 | abstract public function generate_items(); |
||
149 | |||
150 | } |