-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConceptSearchTermCollection.inc.php
executable file
·133 lines (121 loc) · 4.15 KB
/
ConceptSearchTermCollection.inc.php
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
require_once(MCL_ROOT . 'ConceptSearchTerm.inc.php');
/**
* Object containing an array of ConceptSearchTerm objects or other
* ConceptSearchTermCollection objects. Objects are "glued" together by
* either an OR or AND operator.
*/
class ConceptSearchTermCollection
{
/**
* Determines whether search objects are glued together by OR or AND.
*/
public $glue = MCL_CONCEPT_SEARCH_GLUE_AND;
/**
* Array of ConceptSearchTermCollection and ConceptSearchTerm objects.
*/
public $arr_search_object = array();
/**
* Constructor
*/
public function ConceptSearchTermCollection($glue = MCL_CONCEPT_SEARCH_GLUE_AND)
{
$this->glue = $glue;
}
/**
* Returns the number of search objects contained in this collection.
* NOTE: This does count through the hierarchy.
*/
public function Count()
{
$i = 0;
foreach (array_keys($this->arr_search_object) as $k) {
if ($this->arr_search_object[$k] instanceof ConceptSearchTermCollection) {
$i += $this->arr_search_object[$k]->Count();
} else {
$i++;
}
}
return $i;
}
/**
* Adds a ConceptSearchTerm object to the collection.
*/
public function addSearchTerm(ConceptSearchTerm $search_term)
{
$this->arr_search_object[] = $search_term;
}
/**
* Adds a ConceptSearchTermCollection object to the collection.
*/
public function addSearchTermCollection(ConceptSearchTermCollection $search_term_collection)
{
$this->arr_search_object[] = $search_term_collection;
}
/**
* Returns an array of references to ConceptSearchTerm objects contained by
* this collection that match the specified criteria. If is_int is null (default),
* the criteria is not applied. If recursive is true, matching terms for child
* CSTCs are also returned. Recursion is false by default.
* @param mixed $arr_term_type MCL_SEARCH_TERM_TYPE constant or an array of such constants
* @param mixed $is_integer If bool, the search must be or not be an integer. If null, can be anything.
* @param bool $recurive If true, the function recursively calls child ConceptSearchTermCollection objects
*/
public function getSearchTerms($arr_term_type, $is_integer = null, $recursive = false)
{
if (!is_array($arr_term_type)) $arr_term_type = array($arr_term_type);
$arr_search_term = array();
foreach (array_keys($this->arr_search_object) as $key)
{
$search_object = $this->arr_search_object[$key];
if ($search_object instanceof ConceptSearchTermCollection)
{
// Add if a match
if (array_search(MCL_SEARCH_TERM_TYPE_COLLECTION, $arr_term_type, true) !== false) {
$arr_search_term[] = $search_object;
}
// If recursion is true, check for matches in the child collection
if ($recursive) {
$arr_search_term = array_merge($arr_search_term,
$search_object->getSearchTerms($arr_term_type, $is_integer, $recursive));
}
} else if ( ( $search_object instanceof ConceptSearchTerm ) &&
( array_search($search_object->term_type, $arr_term_type, true) !== false ) )
{
// Add if a match
if (is_null($is_integer) || $is_integer == $search_object->isInteger()) {
$arr_search_term[] = $search_object;
}
}
}
return $arr_search_term;
}
/**
* Returns the search terms that match the passed Concept matches.
* @param Concept $c
* @return array Array of search term objects that match the passed Concept object
*/
public function getMatchingSearchTerms(Concept $c)
{
$arr_search_term = array();
foreach ( array_keys($this->arr_search_object) as $key )
{
$search_object = $this->arr_search_object[$key];
if ( $search_object instanceof ConceptSearchTermCollection )
{
// Check for matches in the child collection
$arr_search_term = array_merge(
$arr_search_term,
$search_object->getMatchingSearchTerms( $c )
);
}
elseif ( ( $search_object instanceof ConceptSearchTerm ) &&
( $search_object->isMatch($c) ) )
{
$arr_search_term[] = $search_object;
}
}
return $arr_search_term;
}
}
?>