Skip to content

Commit df8230f

Browse files
author
Charles THIBAULT
committed
[APIPHP-29] Add support for retrieving facet tags
1 parent f5975c8 commit df8230f

File tree

2 files changed

+77
-4
lines changed

2 files changed

+77
-4
lines changed

AFS/SEARCH/TEST/facetHelperTest.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,65 @@ public function testRetrieveLabelsWhenNoLabelsExists() {
8585
$this->assertEquals("FOO", $helper->get_label());
8686
}
8787

88+
public function testRetrieveTags() {
89+
$input = json_decode('{
90+
"afs:t": "FacetTree",
91+
"tags": "tag1 tag2 tag3",
92+
"node": [
93+
{
94+
"key": "false",
95+
"labels": [
96+
{
97+
"label": "BAD"
98+
}
99+
],
100+
"items": 67
101+
}
102+
],
103+
"layout": "TREE",
104+
"type": "BOOL",
105+
"id": "FOO",
106+
"labels": [
107+
{
108+
"label": "String facet"
109+
}
110+
],
111+
"sticky": "true" }');
112+
113+
$config = new AfsHelperConfiguration();
114+
$helper = new AfsFacetHelper($input, new AfsQuery(), $config);
115+
$this->assertEquals(array('tag1', 'tag2', 'tag3'), $helper->get_tags());
116+
}
117+
118+
public function testNotags() {
119+
$input = json_decode('{
120+
"afs:t": "FacetTree",
121+
"node": [
122+
{
123+
"key": "false",
124+
"labels": [
125+
{
126+
"label": "BAD"
127+
}
128+
],
129+
"items": 67
130+
}
131+
],
132+
"layout": "TREE",
133+
"type": "BOOL",
134+
"id": "FOO",
135+
"labels": [
136+
{
137+
"label": "String facet"
138+
}
139+
],
140+
"sticky": "true" }');
141+
142+
$config = new AfsHelperConfiguration();
143+
$helper = new AfsFacetHelper($input, new AfsQuery(), $config);
144+
$this->assertEquals(array(), $helper->get_tags());
145+
}
146+
88147
public function testRetrieveStickyness()
89148
{
90149
$input = json_decode('{

AFS/SEARCH/afs_facet_helper.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class AfsFacetHelper extends AfsHelperBase
1212
{
1313
private $id = null;
1414
private $labels = null;
15+
private $tags = null;
1516
private $layout = null;
1617
private $type = null;
1718
private $sticky = null;
@@ -26,12 +27,13 @@ class AfsFacetHelper extends AfsHelperBase
2627
public function __construct($facet, AfsQuery $query, AfsHelperConfiguration $config, $feed=null)
2728
{
2829
$this->id = $facet->id;
29-
if (property_exists($facet, 'labels') && ! empty($facet->labels)
30-
&& property_exists($facet->labels[0], 'label')) {
30+
if (property_exists($facet, 'labels') && ! empty($facet->labels)) {
3131
$this->labels = $facet->labels;
32-
} else {
33-
$this->labels = null;
3432
}
33+
if (property_exists($facet, 'tags')) {
34+
$this->tags = $facet->tags;
35+
}
36+
3537
$this->layout = $facet->layout;
3638
$this->type = $facet->type;
3739
if (property_exists($facet, 'sticky')
@@ -83,6 +85,18 @@ public function get_labels() {
8385
return $labels;
8486
}
8587

88+
/** @brief Retrieve current facet tags
89+
*
90+
* @return tags as a string array or empty array if current facet have no tags
91+
*/
92+
public function get_tags() {
93+
if (! is_null($this->tags)) {
94+
return explode(' ', $this->tags);
95+
}
96+
97+
return array();
98+
}
99+
86100
/** @brief Retrieves facet id.
87101
*
88102
* This value is not necessary unless specific query should be created

0 commit comments

Comments
 (0)