Example #1
0
 /**
  * Get terms related to the query.
  *
  * @return array
  */
 public function getTerms()
 {
     // Extract the first search term from the search object:
     $search = $this->searchObject->getParams()->getQuery();
     $lookfor = $search instanceof Query ? $search->getString() : '';
     // Get terminology information:
     $terms = $this->worldCatUtils->getRelatedTerms($lookfor, $this->vocab);
     // Wipe out any empty or unexpected sections of the related terms array;
     // this will make it easier to only display content in the template if
     // we have something worth displaying.
     if (is_array($terms)) {
         $desiredKeys = ['exact', 'broader', 'narrower'];
         foreach ($terms as $key => $value) {
             if (empty($value) || !in_array($key, $desiredKeys)) {
                 unset($terms[$key]);
             }
         }
     }
     return $terms;
 }