/**
  * Get all advanced metadata fields
  */
 function getAllFields()
 {
     $fields = array();
     include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php';
     $recs = ilAdvancedMDRecord::_getSelectedRecordsByObject("glo", $this->glo_id, "term");
     foreach ($recs as $record_obj) {
         include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php';
         foreach (ilAdvancedMDFieldDefinition::getInstancesByRecordId($record_obj->getRecordId()) as $def) {
             $fields[$def->getFieldId()] = array("id" => $def->getFieldId(), "title" => $def->getTitle(), "type" => $def->getType());
         }
     }
     return $fields;
 }
 /**
  * Fill row
  *
  * @access public
  * @param
  * 
  */
 public function fillRow($a_set)
 {
     foreach (ilAdvancedMDRecord::_getAssignableObjectTypes(true) as $obj_type) {
         $this->tpl->setCurrentBlock('ass_obj_types');
         $this->tpl->setVariable('VAL_OBJ_TYPE', $obj_type["text"]);
         $this->tpl->setVariable('ASS_ID', $a_set['id']);
         $this->tpl->setVariable('ASS_NAME', $obj_type["obj_type"] . ":" . $obj_type["sub_type"]);
         foreach ($a_set['obj_types'] as $t) {
             if ($obj_type["obj_type"] == $t["obj_type"] && $obj_type["sub_type"] == $t["sub_type"]) {
                 $this->tpl->setVariable('ASS_CHECKED', 'checked="checked"');
             }
         }
         if (!$a_set["perm"][ilAdvancedMDPermissionHelper::ACTION_RECORD_EDIT_PROPERTY][ilAdvancedMDPermissionHelper::SUBACTION_RECORD_OBJECT_TYPES]) {
             $this->tpl->setVariable('ASS_DISABLED', 'disabled="disabled"');
         }
         $this->tpl->parseCurrentBlock();
     }
     $this->tpl->setVariable('VAL_ID', $a_set['id']);
     $this->tpl->setVariable('VAL_TITLE', $a_set['title']);
     if (strlen($a_set['description'])) {
         $this->tpl->setVariable('VAL_DESCRIPTION', $a_set['description']);
     }
     $defs = ilAdvancedMDFieldDefinition::getInstancesByRecordId($a_set['id']);
     if (!count($defs)) {
         $this->tpl->setVariable('TXT_FIELDS', $this->lng->txt('md_adv_no_fields'));
     }
     foreach ($defs as $definition_obj) {
         $this->tpl->setCurrentBlock('field_entry');
         $this->tpl->setVariable('FIELD_NAME', $definition_obj->getTitle() . ": " . $this->lng->txt($definition_obj->getTypeTitle()));
         $this->tpl->parseCurrentBlock();
     }
     $this->tpl->setVariable('ACTIVE_CHECKED', $a_set['active'] ? ' checked="checked" ' : '');
     $this->tpl->setVariable('ACTIVE_ID', $a_set['id']);
     if (!$a_set["perm"][ilAdvancedMDPermissionHelper::ACTION_RECORD_TOGGLE_ACTIVATION]) {
         $this->tpl->setVariable('ACTIVE_DISABLED', 'disabled="disabled"');
     }
     $this->ctrl->setParameter($this->parent_obj, 'record_id', $a_set['id']);
     if ($a_set["perm"][ilAdvancedMDPermissionHelper::ACTION_RECORD_EDIT]) {
         $this->tpl->setVariable('EDIT_LINK', $this->ctrl->getLinkTarget($this->parent_obj, 'editRecord'));
         $this->tpl->setVariable('TXT_EDIT_RECORD', $this->lng->txt('edit'));
     }
     if ($a_set["perm"][ilAdvancedMDPermissionHelper::ACTION_RECORD_EDIT_FIELDS]) {
         $this->tpl->setVariable('EDIT_FIELDS_LINK', $this->ctrl->getLinkTarget($this->parent_obj, 'editFields'));
         $this->tpl->setVariable('TXT_EDIT_FIELDS', $this->lng->txt('md_adv_field_table'));
     }
 }
 /**
  * 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;
 }
 /**
  * To Xml.
  * This method writes only the subset Record (including all fields)
  * Use class.ilAdvancedMDRecordXMLWriter to generate a complete xml presentation.
  *
  * @access public
  * @param object ilXmlWriter
  * 
  */
 public function toXML(ilXmlWriter $writer)
 {
     $writer->xmlStartTag('Record', array('active' => $this->isActive() ? 1 : 0, 'id' => $this->generateImportId()));
     $writer->xmlElement('Title', null, $this->getTitle());
     $writer->xmlElement('Description', null, $this->getDescription());
     foreach ($this->getAssignedObjectTypes() as $obj_type) {
         if ($obj_type["sub_type"] == "") {
             $writer->xmlElement('ObjectType', null, $obj_type["obj_type"]);
         } else {
             $writer->xmlElement('ObjectType', null, $obj_type["obj_type"] . ":" . $obj_type["sub_type"]);
         }
     }
     include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php';
     foreach (ilAdvancedMDFieldDefinition::getInstancesByRecordId($this->getRecordId()) as $definition) {
         $definition->toXML($writer);
     }
     $writer->xmlEndTag('Record');
 }
 /**
  * Parse property for filter (table)
  *
  * @access private
  * 
  */
 private function parseFilter()
 {
     include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php';
     if ($this->getSelectedOnly()) {
         $recs = ilAdvancedMDRecord::_getSelectedRecordsByObject($this->obj_type, $this->obj_id, $this->sub_type);
     } else {
         $recs = ilAdvancedMDRecord::_getActivatedRecordsByObjectType($this->obj_type, $this->sub_type);
     }
     $this->adt_search = array();
     include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php';
     foreach ($recs as $record_obj) {
         $record_id = $record_obj->getRecordId();
         $defs = ilAdvancedMDFieldDefinition::getInstancesByRecordId($record_id);
         foreach ($defs as $def) {
             // :TODO: not all types supported yet
             if (!in_array($def->getType(), array(ilAdvancedMDFieldDefinition::TYPE_TEXT, ilAdvancedMDFieldDefinition::TYPE_SELECT, ilAdvancedMDFieldDefinition::TYPE_SELECT_MULTI, ilAdvancedMDFieldDefinition::TYPE_DATE, ilAdvancedMDFieldDefinition::TYPE_DATETIME))) {
                 continue;
             }
             /* :TODO:
             			if($this->handleECSDefinitions($def))
              			{
              				continue;
              			}
             			*/
             $this->adt_search[$def->getFieldId()] = ilADTFactory::getInstance()->getSearchBridgeForDefinitionInstance($def->getADTDefinition(), true, false);
             $this->adt_search[$def->getFieldId()]->setTableGUI($this->table_gui);
             $this->adt_search[$def->getFieldId()]->setTitle($def->getTitle());
             $this->adt_search[$def->getFieldId()]->setElementId('md_' . $def->getFieldId());
             $this->adt_search[$def->getFieldId()]->loadFilter();
             $this->adt_search[$def->getFieldId()]->addToForm();
         }
     }
 }
 /**
  * Update fields 
  *
  * @access public
  * 
  */
 public function updateFields()
 {
     $this->ctrl->saveParameter($this, 'record_id');
     if (!isset($_GET['record_id']) or !$_GET['record_id']) {
         ilUtil::sendFailure($this->lng->txt('select_one'));
         $this->editFields();
         return false;
     }
     include_once './Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php';
     $fields = ilAdvancedMDFieldDefinition::getInstancesByRecordId($_GET['record_id']);
     if ($this->getPermissions()->hasPermission(ilAdvancedMDPermissionHelper::CONTEXT_RECORD, $_GET['record_id'], ilAdvancedMDPermissionHelper::ACTION_RECORD_FIELD_POSITIONS)) {
         if (!isset($_POST['position']) or !is_array($_POST['position'])) {
             $this->editFields();
             return false;
         }
         // sort by position
         asort($_POST['position'], SORT_NUMERIC);
         $positions = array_flip(array_keys($_POST['position']));
         foreach ($fields as $field) {
             $field->setPosition($positions[$field->getFieldId()]);
             $field->update();
         }
     }
     foreach ($fields as $field) {
         if ($this->getPermissions()->hasPermission(ilAdvancedMDPermissionHelper::CONTEXT_FIELD, $field->getFieldId(), ilAdvancedMDPermissionHelper::ACTION_FIELD_EDIT_PROPERTY, ilAdvancedMDPermissionHelper::SUBACTION_FIELD_SEARCHABLE)) {
             $field->setSearchable(isset($_POST['searchable'][$field->getFieldId()]) ? true : false);
             $field->update();
         }
     }
     ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
     $this->ctrl->redirect($this, "editFields");
 }
 protected function findPages($a_list_id)
 {
     global $ilDB;
     $list_values = $this->getFieldValues($a_list_id);
     $wiki_id = $this->getPage()->getWikiId();
     $found_result = array();
     // only search in active fields
     $found_ids = null;
     $recs = ilAdvancedMDRecord::_getSelectedRecordsByObject("wiki", $wiki_id, "wpg");
     foreach ($recs as $record) {
         foreach (ilAdvancedMDFieldDefinition::getInstancesByRecordId($record->getRecordId(), true) as $field) {
             if (isset($list_values[$field->getFieldId()])) {
                 $field_form = ilADTFactory::getInstance()->getSearchBridgeForDefinitionInstance($field->getADTDefinition(), true, false);
                 $field->setSearchValueSerialized($field_form, $list_values[$field->getFieldId()]);
                 $found_pages = $field->searchSubObjects($field_form, $wiki_id, "wpg");
                 if (is_array($found_ids)) {
                     $found_ids = array_intersect($found_ids, $found_pages);
                 } else {
                     $found_ids = $found_pages;
                 }
             }
         }
     }
     if (sizeof($found_ids)) {
         $sql = "SELECT id,title FROM il_wiki_page" . " WHERE " . $ilDB->in("id", $found_ids, "", "integer") . " ORDER BY title";
         $set = $ilDB->query($sql);
         while ($row = $ilDB->fetchAssoc($set)) {
             $found_result[$row["id"]] = $row["title"];
         }
     }
     return $found_result;
 }
 /**
  * Return an array of all meta data fields
  */
 public static function getFields()
 {
     global $lng;
     $lng->loadLanguageModule('meta');
     $fields['lom_content'] = $lng->txt('content');
     include_once './Services/Search/classes/class.ilSearchSettings.php';
     if (ilSearchSettings::getInstance()->enabledLucene()) {
         $fields['general_offline'] = $lng->txt('lucene_offline_filter');
     }
     //'lom_type'					= $lng->txt('type');
     $fields['lom_language'] = $lng->txt('language');
     $fields['lom_keyword'] = $lng->txt('meta_keyword');
     $fields['lom_coverage'] = $lng->txt('meta_coverage');
     $fields['lom_structure'] = $lng->txt('meta_structure');
     $fields['lom_status'] = $lng->txt('meta_status');
     $fields['lom_version'] = $lng->txt('meta_version');
     $fields['lom_contribute'] = $lng->txt('meta_contribute');
     $fields['lom_format'] = $lng->txt('meta_format');
     $fields['lom_operating_system'] = $lng->txt('meta_operating_system');
     $fields['lom_browser'] = $lng->txt('meta_browser');
     $fields['lom_interactivity'] = $lng->txt('meta_interactivity_type');
     $fields['lom_resource'] = $lng->txt('meta_learning_resource_type');
     $fields['lom_level'] = $lng->txt('meta_interactivity_level');
     $fields['lom_density'] = $lng->txt('meta_semantic_density');
     $fields['lom_user_role'] = $lng->txt('meta_intended_end_user_role');
     $fields['lom_context'] = $lng->txt('meta_context');
     $fields['lom_difficulty'] = $lng->txt('meta_difficulty');
     $fields['lom_costs'] = $lng->txt('meta_cost');
     $fields['lom_copyright'] = $lng->txt('meta_copyright_and_other_restrictions');
     $fields['lom_purpose'] = $lng->txt('meta_purpose');
     $fields['lom_taxon'] = $lng->txt('meta_taxon');
     // Append all advanced meta data fields
     include_once './Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php';
     include_once './Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php';
     foreach (ilAdvancedMDRecord::_getRecords() as $record) {
         foreach (ilAdvancedMDFieldDefinition::getInstancesByRecordId($record->getRecordId(), true) as $def) {
             $fields['adv_' . $def->getFieldId()] = $def->getTitle();
         }
     }
     return $fields;
 }