/** * Return a ConceptCollection containing the concepts that match the search * criteria described in the passed ConceptSearch object. It iterates through * each search group. This function only returns fields from the concept table. * It is intended to be followed by other functions to retrieve additional * concept info. * @param ConceptSearch $cs * @access private */ private function _loadConcepts(ConceptSearch $cs) { $cc = new ConceptCollection(); $csrg = null; $group_i = 0; // Iterate through ConceptSearchGroup objects, perform base query and // create the concepts for each foreach (array_keys($cs->arr_search_group) as $group_key) { $group_i++; $csg = $cs->arr_search_group[$group_key]; $csrg = new ConceptSearchResultsGroup($csg); $ctsc = $csg->getSearchTermCollection(); $cc->addGroup($csrg); // Get sql statements for this search group $coll_csg_sql = $this->_buildSqlFromConceptSearchGroup($cs, $csg); $csrg->coll_sql_obj = $coll_csg_sql; // Debug info for the search group if ($this->debug || $this->verbose) { echo '<p><b>Concept Search Group ' . $group_i . ':</b> ' . $csg->query . '<br><ul>'; } // Iterate through the sql collection and execute foreach ($coll_csg_sql->getKeys() as $key) { $sql_obj = $coll_csg_sql->Get($key); // Debug info for sql statements if ($this->debug || $this->verbose) { echo '</li><strong>' . $sql_obj->source->getKey(); if ($sql_obj->css_sub_list_dict) { echo ' - ' . $sql_obj->css_sub_list_dict->getKey(); } echo ' : </strong> '; if ($sql_obj->sql) { echo htmlentities($sql_obj->sql); } else { echo '<em>[[ EMPTY SEARCH QUERY ]]</em></li>'; } } // Skip if no sql if (!$sql_obj->sql) { continue; } // Get the connection and execute $css_dict = $sql_obj->getDictionarySource(); $conn = $css_dict->getConnection(); $rsc_search = mysql_query($sql_obj->sql, $conn); if (!$rsc_search) { trigger_error("could not query db in ConceptSearchFactory::_loadConcepts: " . mysql_error()); } // Create/get the concepts and add to the collection while ($row = mysql_fetch_assoc($rsc_search)) { // Create the concept if it does not already exist $c = null; if (!($c = $cc->getConcept($row['concept_id'], $css_dict))) { $c = new Concept($row['concept_id'], $row['retired'], $row['is_set'], $row['class_id'], $row['class_name'], $row['datatype_id'], $row['datatype_name']); $c->uuid = $row['uuid']; // keeping this separate to add version compatibility later if ($row['date_created']) { $c->setAttribute('Date created', $row['date_created']); } if ($row['retired_by']) { $c->setAttribute('Date Retired', $row['retired_by']); } if ($row['date_retired']) { $c->setAttribute('Retired by', $row['date_retired']); } if ($row['retire_reason']) { $c->setAttribute('Retire reason', $row['retire_reason']); } $c->css_dict = $css_dict; $cc->addConcept($c); } // Relevancy - assign Fulltext Search relevancy only for now $relevancy = null; if (isset($row['relevancy'])) { $relevancy = $row['relevancy']; } // Add to the search results group $csrg->addConcept($c, $relevancy); } // Debug/verbose info if ($this->debug || $this->verbose) { echo '<ul><li><strong>' . $csrg->getCount($css_dict) . ' concept(s) returned:</strong> ' . implode(', ', $csrg->getConceptIds($css_dict)); echo '</li></ul></li>'; } } // end ConceptSearchSqlCollection loop // End debug output if ($this->debug || $this->verbose) { echo '</ul></p>'; } } // end ConceptSearchGroup loop return $cc; }