Ejemplo n.º 1
0
 /**
  * Get all terms for given set of glossary ids.
  * 
  * @param 	integer/array	array of glossary ids for meta glossaries
  * @param	string			searchstring
  * @param	string			first letter
  * @return	array			array of terms 
  */
 static function getTermList($a_glo_id, $searchterm = "", $a_first_letter = "", $a_def = "", $a_tax_node = 0, $a_add_amet_fields = false, $a_amet_filter = "")
 {
     global $ilDB;
     $terms = array();
     // get all term ids under taxonomy node (if given)
     if ($a_tax_node > 1) {
         include_once "./Services/Taxonomy/classes/class.ilObjTaxonomy.php";
         $tax_ids = ilObjTaxonomy::getUsageOfObject($a_glo_id);
         if (count($tax_ids) > 0) {
             $items = ilObjTaxonomy::getSubTreeItems("glo", $a_glo_id, "term", $tax_ids[0], $a_tax_node);
             $sub_tree_ids = array();
             foreach ($items as $i) {
                 $sub_tree_ids[] = $i["item_id"];
             }
             $in = " AND " . $ilDB->in("gt.id", $sub_tree_ids, false, "integer");
         }
     }
     if ($a_def != "") {
         $join = " JOIN glossary_definition gd ON (gd.term_id = gt.id)" . " JOIN page_object ON (" . "page_object.parent_id = " . $ilDB->quote($a_glo_id, "integer") . " AND page_object.parent_type = " . $ilDB->quote("gdf", "text") . " AND page_object.page_id = gd.id" . " AND " . $ilDB->like("page_object.content", "text", "%" . $a_def . "%") . ")";
     }
     $searchterm = !empty($searchterm) ? " AND " . $ilDB->like("term", "text", "%" . $searchterm . "%") . " " : "";
     if ($a_first_letter != "") {
         $searchterm .= " AND " . $ilDB->upper($ilDB->substr("term", 1, 1)) . " = " . $ilDB->upper($ilDB->quote($a_first_letter, "text")) . " ";
     }
     // meta glossary
     if (is_array($a_glo_id)) {
         $where = $ilDB->in("glo_id", $a_glo_id, false, "integer");
     } else {
         $where = " glo_id = " . $ilDB->quote($a_glo_id, "integer") . " ";
     }
     $where .= $in;
     $q = "SELECT gt.term, gt.id, gt.glo_id, gt.language FROM glossary_term gt " . $join . " WHERE " . $where . $searchterm . " ORDER BY term";
     $term_set = $ilDB->query($q);
     //var_dump($q);
     while ($term_rec = $ilDB->fetchAssoc($term_set)) {
         $terms[] = array("term" => $term_rec["term"], "language" => $term_rec["language"], "id" => $term_rec["id"], "glo_id" => $term_rec["glo_id"]);
     }
     // add advanced metadata
     if ($a_add_amet_fields || is_array($a_amet_filter)) {
         include_once "./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php";
         $terms = ilAdvancedMDValues::queryForRecords($a_glo_id, "term", $terms, "glo_id", "id", $a_amet_filter);
     }
     return $terms;
 }