Exemplo n.º 1
0
 /**
  * True if this search term object matches the passed Concept; false otherwise.
  * @param Concept $c
  * @param mixed $search_term_type One of the MCL_SEARCH_TERM_TYPE_* constants. Use to force a specific type of comparison
  * @return bool
  */
 public function isMatch(Concept $c, $search_term_type = null)
 {
     // Prepare the search term type for comparison
     if (is_null($search_term_type)) {
         $search_term_type = $this->term_type;
     }
     // Now do the comparison
     if ($search_term_type == MCL_SEARCH_TERM_TYPE_ALL) {
         return true;
     } elseif ($search_term_type == MCL_SEARCH_TERM_TYPE_CONCEPT_ID) {
         if ($this->needle == $c->concept_id) {
             return true;
         }
     } elseif ($search_term_type == MCL_SEARCH_TERM_TYPE_CONCEPT_ID_RANGE) {
         list($min, $max) = explode('-', $this->needle);
         if ($c->concept_id >= $min && $c->concept_id <= $max) {
             return true;
         }
     } elseif ($search_term_type == MCL_SEARCH_TERM_TYPE_MAP_CODE) {
         foreach ($c->getConceptMappingIds() as $mapcode_id) {
             $subject = $c->getConceptMapping($mapcode_id)->source_code;
             if (preg_match('/\\b' . addslashes($this->needle) . '/i', $subject)) {
                 return true;
             }
         }
     } elseif ($search_term_type == MCL_SEARCH_TERM_TYPE_MAP_CODE_RANGE) {
         // TODO: MCL_SEARCH_TERM_TYPE_MAP_CODE_RANGE
     } elseif ($search_term_type == MCL_SEARCH_TERM_TYPE_TEXT) {
         foreach ($c->getConceptNameIds() as $name_id) {
             $subject = $c->getConceptName($name_id)->name;
             if (preg_match('/\\b' . addslashes($this->needle) . '/i', $subject)) {
                 return true;
             }
         }
         foreach ($c->getConceptDescriptionIds() as $desc_id) {
             $subject = $c->getConceptDescription($desc_id)->description;
             if (preg_match('/\\b' . addslashes($this->needle) . '/i', $subject)) {
                 return true;
             }
         }
     } elseif ($search_term_type == MCL_SEARCH_TERM_TYPE_CONCEPT_NAME) {
         foreach ($c->getConceptNameIds() as $name_id) {
             $subject = $c->getConceptName($name_id)->name;
             if (preg_match('/\\b' . addslashes($this->needle) . '/i', $subject)) {
                 return true;
             }
         }
     } elseif ($search_term_type == MCL_SEARCH_TERM_TYPE_CONCEPT_DESCRIPTION) {
         foreach ($c->getConceptDescriptionIds() as $desc_id) {
             $subject = $c->getConceptDescription($desc_id)->description;
             if (preg_match('/\\b' . addslashes($this->needle) . '/i', $subject)) {
                 return true;
             }
         }
     } elseif ($search_term_type == MCL_SEARCH_TERM_TYPE_UUID) {
         if (strtolower($this->needle) == strtolower(substr($c->uuid, 0, strlen($this->needle)))) {
             return true;
         }
     } elseif ($search_term_type == MCL_SEARCH_TERM_TYPE_LIST) {
         // TODO: MCL_SEARCH_TERM_TYPE_LIST
     } elseif ($search_term_type == MCL_SEARCH_TERM_TYPE_MAP_SOURCE) {
         // TODO: MCL_SEARCH_TERM_TYPE_MAP_SOURCE
     }
     return false;
 }
 /**
  * Render the definitions column
  */
 protected function _renderColumn_Definitions(ConceptSearchResultsGroup $csrg, Concept $c, $group_i, $i)
 {
     echo "\n<td class=\"col_4\">\n\t";
     // Get the search terms
     $arr_term_type = array(MCL_SEARCH_TERM_TYPE_TEXT, MCL_SEARCH_TERM_TYPE_CONCEPT_DESCRIPTION);
     $arr_search_term = $csrg->csg->getSearchTermCollection()->getSearchTerms($arr_term_type, null, true);
     // Definitions
     foreach ($c->getConceptDescriptionIds() as $_desc_i) {
         $cd = $c->getConceptDescription($_desc_i);
         $desc = htmlentities($cd->description);
         foreach ($arr_search_term as $search_term) {
             $desc = preg_replace('/\\b(' . addslashes($search_term->needle) . ')/i', '<span class="h">$1</span>', $desc);
         }
         echo '<div class="concept_def"><span class="concept_def_header">[' . $cd->locale . ']</span> ' . $desc . "</div>";
     }
     /**
      * Answers - Only the first CSRR::num_display_qa_results answers are visible; set to zero to make 
      * all visible by default.
      */
     if ($c->hasAnswers()) {
         echo "<div style=\"margin-bottom:15px;\">This concept is a question with the following answer(s):\n";
         echo '<ul class="qa_set" style="margin-bottom:0;padding-bottom:0;">';
         $_i = 0;
         $num_results = $c->getNumberAnswers();
         foreach ($c->getAnswerIds() as $_answer_id) {
             $ca = $this->cc->getConcept($_answer_id, $c->css_dict);
             echo '<li>' . htmlentities($ca->getPreferredName()) . ' (<a href="' . $this->getSearchUrl('id:' . $_answer_id, array('source' => $c->css_dict->dict_db)) . '">' . $_answer_id . '</a>)</li>';
             $_i++;
             if ($_i == $this->num_display_qa_results && $num_results > $this->num_display_qa_results) {
                 $ul_toggle_id = 'ul_answer_toggle_' . $c->css_dict->dict_id . '_' . $group_i . '_' . $c->concept_id;
                 $ul_more_id = 'ul_answer_more_' . $c->css_dict->dict_id . '_' . $group_i . '_' . $c->concept_id;
                 $num_more_results = $num_results - $this->num_display_qa_results;
                 echo "</ul>\n" . '<ul id="' . $ul_toggle_id . '" style="padding-left:24px;margin-top:6px;padding-top:0;list-style-type:none;">' . '<li><a href="javascript:toggleElementVisibility(\'' . $ul_toggle_id . '\');toggleElementVisibility(\'' . $ul_more_id . '\');">' . 'See ' . $num_more_results . ' more...</a></li></ul>' . "\n";
                 echo '<ul class="qa_set" id="' . $ul_more_id . '" style="display:none;margin-top:0;padding-top:0;margin-bottom:0;padding-bottom:0;">';
             }
         }
         echo '</ul></div>';
     }
     /**
      * Questions - Only the first CSRR::num_display_qa_results questions are visible; 
      * set to zero to make all visible by default.
      */
     if ($c->hasQuestions()) {
         echo "<div style=\"margin-bottom:15px;\">This concept is an answer for the following question(s):\n";
         echo '<ul class="qa_set" style="margin-bottom:0;padding-bottom:0;">';
         $_i = 0;
         $num_results = $c->getNumberQuestions();
         foreach ($c->getQuestionIds() as $_question_id) {
             $cq = $this->cc->getConcept($_question_id, $c->css_dict);
             echo '<li>' . htmlentities($cq->getPreferredName()) . ' (<a href="' . $this->getSearchUrl('id:' . $_question_id, array('source' => $c->css_dict->dict_db)) . '">' . $_question_id . '</a>)</li>';
             $_i++;
             if ($_i == $this->num_display_qa_results && $num_results > $this->num_display_qa_results) {
                 echo "</ul>\n";
                 $ul_toggle_id = 'ul_question_toggle_' . $c->css_dict->dict_id . '_' . $c->concept_id;
                 $ul_more_id = 'ul_question_more_' . $c->css_dict->dict_id . '_' . $c->concept_id;
                 $num_more_results = $num_results - $this->num_display_qa_results;
                 echo '<ul id="' . $ul_toggle_id . '" style="padding-left:24px;margin-top:6px;padding-top:0;list-style-type:none;">' . '<li><a href="javascript:toggleElementVisibility(\'' . $ul_toggle_id . '\');toggleElementVisibility(\'' . $ul_more_id . '\');">' . 'See ' . $num_more_results . ' more...</a></li></ul>' . "\n";
                 echo '<ul class="qa_set" id="' . $ul_more_id . '" style="display:none;margin-top:0;padding-top:0;margin-bottom:0;padding-bottom:0;">';
             }
         }
         echo '</ul></div>';
     }
     // End of column 3
     echo '</td>';
 }