Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace Drupal\search_api_glossary;
/**
* Search Api GlossaryAZ Helper class.
*
* @package Drupal\search_api_glossary
*/
class GlossaryHelper {
/**
* Getter callback for title_az_glossary property.
*/
public function glossaryGetter($source_value, $glossary_az_grouping) {
$first_letter = strtoupper(substr(trim($source_value), 0, 1));
return $this->glossaryGetterHelper($first_letter, array_values($glossary_az_grouping));
}
/**
* Getter Helper for Alpha Numeric Keys.
*/
public function glossaryGetterHelper($first_letter, $glossary_az_grouping) {
// Is it Alpha?
if (ctype_alpha($first_letter)) {
// Do we have Alpha grouping?
if (in_array('grouping_az', $glossary_az_grouping, TRUE)) {
$first_letter = "A-Z";
}
return $first_letter;
}
// Is it a number?
elseif (ctype_digit($first_letter)) {
// Do we have Numeric grouping?
if (in_array('grouping_09', $glossary_az_grouping, TRUE)) {
$first_letter = "0-9";
}
return $first_letter;
}
// Catch non alpha numeric.
// Do we have Non Alpha Numeric grouping?
elseif (in_array('grouping_other', $glossary_az_grouping, TRUE)) {
$first_letter = "#";
return $first_letter;
}
}
/**
* Facet Helper for to check glossary field.
*/
public static function glossaryFacetFieldCheker($facet) {
// Load up the search index and processor.
$glossary_processor = $facet->getFacetSource()->getIndex()->getProcessor('glossary');
// Resolve fields.
$glossary_field_id = $facet->getFieldIdentifier();
// Check if chosen field is glossary or not.
return $glossary_processor->checkFieldName($glossary_field_id);
}
}