Ejemplo n.º 1
0
 /**
  * Query data for given object records
  *
  * @param
  * @return
  */
 public static function queryForRecords($a_obj_id, $a_subtype, $a_records, $a_obj_id_key, $a_obj_subid_key, array $a_amet_filter = null)
 {
     $result = array();
     if (!is_array($a_obj_id)) {
         $a_obj_id = array($a_obj_id);
     }
     $sub_obj_ids = array();
     foreach ($a_records as $rec) {
         $sub_obj_ids[] = $rec[$a_obj_subid_key];
     }
     // preload adv data for object id(s)
     ilADTFactory::getInstance()->initActiveRecordByType();
     ilADTActiveRecordByType::preloadByPrimary("adv_md_values", array("obj_id" => array("integer", $a_obj_id), "sub_type" => array("text", $a_subtype), "sub_id" => array("integer", $sub_obj_ids)));
     $record_groups = array();
     foreach ($a_records as $rec) {
         $obj_id = $rec[$a_obj_id_key];
         $sub_id = $rec[$a_obj_subid_key];
         // only active amet records for glossary
         foreach (ilAdvancedMDRecord::_getSelectedRecordsByObject(ilObject::_lookupType($obj_id), $obj_id, $a_subtype) as $adv_record) {
             $record_id = $adv_record->getRecordId();
             if (!isset($record_groups[$record_id])) {
                 $defs = ilAdvancedMDFieldDefinition::getInstancesByRecordId($record_id);
                 $record_groups[$record_id] = ilAdvancedMDFieldDefinition::getADTGroupForDefinitions($defs);
                 $record_groups[$record_id] = ilADTFactory::getInstance()->getDBBridgeForInstance($record_groups[$record_id]);
                 $record_groups[$record_id]->setTable("adv_md_values");
             }
             // prepare ADT group for record id
             $record_groups[$record_id]->setPrimary(array("obj_id" => array("integer", $obj_id), "sub_type" => array("text", $a_subtype), "sub_id" => array("integer", $sub_id)));
             // multi-enum fakes single in adv md
             foreach ($record_groups[$record_id]->getElements() as $element) {
                 if ($element->getADT()->getType() == "MultiEnum") {
                     $element->setFakeSingle(true);
                 }
             }
             // read (preloaded) data
             $active_record = new ilADTActiveRecordByType($record_groups[$record_id]);
             $active_record->setElementIdColumn("field_id", "integer");
             $active_record->read();
             $adt_group = $record_groups[$record_id]->getADT();
             // filter against amet values
             if ($a_amet_filter) {
                 foreach ($a_amet_filter as $field_id => $element) {
                     if ($adt_group->hasElement($field_id)) {
                         if (!$element->isInCondition($adt_group->getElement($field_id))) {
                             continue 3;
                         }
                     }
                 }
             }
             // add amet values to glossary term record
             foreach ($adt_group->getElements() as $element_id => $element) {
                 if (!$element->isNull()) {
                     // we are reusing the ADT group for all $a_records, so we need to clone
                     $pb = ilADTFactory::getInstance()->getPresentationBridgeForInstance(clone $element);
                     $rec["md_" . $element_id] = $pb->getSortable();
                     $rec["md_" . $element_id . "_presentation"] = $pb;
                 } else {
                     $rec["md_" . $element_id] = null;
                 }
             }
         }
         $results[] = $rec;
     }
     return $results;
 }