/** * test Keyword * @group IL_Init * @return */ public function testKeyword() { include_once './Services/MetaData/classes/class.ilMDKeyword.php'; include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php'; $con = new ilMDKeyword(1, 2, 'xxx'); $con->setKeyword('Easy'); $ret = $con->save(); $this->assertGreaterThan(0, $ret); $con->setKeyword('Medium'); $con->update(); $con->read(); $desc = $con->getKeyword(); $this->assertEquals('Medium', $desc); $con->delete(); }
public static function getKeywords($a_obj_id, $a_posting_id) { include_once "./Services/MetaData/classes/class.ilMDKeyword.php"; return ilMDKeyword::lookupKeywords($a_obj_id, $a_posting_id); }
function keywordAutocomplete() { $force_all = (bool) $_GET["fetchall"]; include_once "./Services/MetaData/classes/class.ilMDKeyword.php"; $res = ilMDKeyword::_getMatchingKeywords(ilUtil::stripSlashes($_GET["term"]), "blp", $this->getParentObjId()); include_once "./Services/Search/classes/class.ilSearchSettings.php"; $cut = (int) ilSearchSettings::getInstance()->getAutoCompleteLength(); $has_more = false; $result = array(); foreach ($res as $r) { if (!$force_all && sizeof($result["items"]) >= $cut) { $has_more = true; break; } $entry = new stdClass(); $entry->value = $r; $entry->label = $r; $result["items"][] = $entry; } $result["hasMoreResults"] = $has_more; include_once './Services/JSON/classes/class.ilJsonUtil.php'; echo ilJsonUtil::encode($result); exit; }
function toXML(&$writer) { $writer->xmlStartTag('General', array('Structure' => $this->getStructure() ? $this->getStructure() : 'Atomic')); // Identifier $first = true; $identifiers = array(); $identifiers = $this->getIdentifierIds(); foreach ($identifiers as $id) { $ide =& $this->getIdentifier($id); $ide->setExportMode($this->getExportMode()); $ide->toXML($writer); $first = false; } if (!count($identifiers)) { include_once 'Services/MetaData/classes/class.ilMDIdentifier.php'; $ide = new ilMDIdentifier($this->getRBACId(), $this->getObjId(), $this->getObjType()); // added type, alex, 31 Oct 2007 $ide->setExportMode(true); $ide->toXML($writer, true); } // Title $writer->xmlElement('Title', array('Language' => $this->getTitleLanguageCode() ? $this->getTitleLanguageCode() : 'en'), $this->getTitle()); // Language $languages = $this->getLanguageIds(); foreach ($languages as $id) { $lan =& $this->getLanguage($id); $lan->toXML($writer); } if (!count($languages)) { // Default include_once 'Services/MetaData/classes/class.ilMDLanguage.php'; $lan = new ilMDLanguage($this->getRBACId(), $this->getObjId()); $lan->toXML($writer); } // Description $descriptions = $this->getDescriptionIds(); foreach ($descriptions as $id) { $des =& $this->getDescription($id); $des->toXML($writer); } if (!count($descriptions)) { // Default include_once 'Services/MetaData/classes/class.ilMDDescription.php'; $des = new ilMDDescription($this->getRBACId(), $this->getObjId()); $des->toXML($writer); } // Keyword $keywords = $this->getKeywordIds(); foreach ($keywords as $id) { $key =& $this->getKeyword($id); $key->toXML($writer); } if (!count($keywords)) { // Default include_once 'Services/MetaData/classes/class.ilMDKeyword.php'; $key = new ilMDKeyword($this->getRBACId(), $this->getObjId()); $key->toXML($writer); } // Copverage if (strlen($this->getCoverage())) { $writer->xmlElement('Coverage', array('Language' => $this->getCoverageLanguageCode() ? $this->getCoverageLanguageCode() : 'en'), $this->getCoverage()); } $writer->xmlEndTag('General'); }
/** * Get keywords by language as string * * @access public * @static * * @param int rbac_id * @param int obj_id * @param string obj type */ public static function _getKeywordsByLanguageAsString($a_rbac_id, $a_obj_id, $a_type) { foreach (ilMDKeyword::_getKeywordsByLanguage($a_rbac_id, $a_obj_id, $a_type) as $lng_code => $keywords) { $key_string[$lng_code] = implode(",", $keywords); } return $key_string ? $key_string : array(); }
/** * Get media objects */ function getMediaObjects($a_title_filter = "", $a_format_filter = "", $a_keyword_filter = '', $a_caption_filter) { global $ilDB; $query = "SELECT DISTINCT mep_tree.*, object_data.* " . "FROM mep_tree JOIN mep_item ON (mep_tree.child = mep_item.obj_id) " . " JOIN object_data ON (mep_item.foreign_id = object_data.obj_id) "; if ($a_format_filter != "" or $a_caption_filter != '') { $query .= " JOIN media_item ON (media_item.mob_id = object_data.obj_id) "; } $query .= " WHERE mep_tree.mep_id = " . $ilDB->quote($this->getId(), "integer") . " AND object_data.type = " . $ilDB->quote("mob", "text"); // filter if (trim($a_title_filter) != "") { $query .= " AND " . $ilDB->like("object_data.title", "text", "%" . trim($a_title_filter) . "%"); } if ($a_format_filter != "") { $filter = $a_format_filter == "unknown" ? "" : $a_format_filter; $query .= " AND " . $ilDB->equals("media_item.format", $filter, "text", true); } if (trim($a_caption_filter)) { $query .= 'AND ' . $ilDB->like('media_item.caption', 'text', '%' . trim($a_caption_filter) . '%'); } $query .= " ORDER BY object_data.title"; $objs = array(); $set = $ilDB->query($query); while ($rec = $ilDB->fetchAssoc($set)) { $rec["foreign_id"] = $rec["obj_id"]; $rec["obj_id"] = ""; $objs[] = $rec; } // Keyword filter if ($a_keyword_filter) { include_once './Services/MetaData/classes/class.ilMDKeyword.php'; $res = ilMDKeyword::_searchKeywords($a_keyword_filter, 'mob', 0); foreach ($objs as $obj) { if (in_array($obj['foreign_id'], $res)) { $filtered[] = $obj; } } return (array) $filtered; } return $objs; }
function &getKeywordIds() { include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDKeyword.php'; return ilMDKeyword::_getIds($this->getRBACId(), $this->getObjId(), $this->getMetaId(), 'meta_classification'); }
function keywordAutocomplete() { include_once "./Services/MetaData/classes/class.ilMDKeyword.php"; $res = ilMDKeyword::_getMatchingKeywords(ilUtil::stripSlashes($_GET["term"]), "blp", $this->getParentObjId()); $result = array(); $cnt = 0; foreach ($res as $r) { if ($cnt++ > 19) { continue; } $entry = new stdClass(); $entry->value = $r; $entry->label = $r; $result[] = $entry; } include_once './Services/JSON/classes/class.ilJsonUtil.php'; echo ilJsonUtil::encode($result); exit; }
/** * update quick edit properties */ function updateQuickEdit() { include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php'; if (!trim($_POST['gen_title'])) { ilUtil::sendFailure($this->lng->txt('title_required')); $this->listQuickEdit(); return false; } // General values $this->md_section = $this->md_obj->getGeneral(); $this->md_section->setTitle(ilUtil::stripSlashes($_POST['gen_title'])); // $this->md_section->setTitleLanguage(new ilMDLanguageItem($_POST['gen_title_language'])); $this->md_section->update(); // Language if (is_array($_POST['gen_language'])) { foreach ($_POST['gen_language'] as $id => $data) { if ($id > 0) { $md_lan = $this->md_section->getLanguage($id); $md_lan->setLanguage(new ilMDLanguageItem($data['language'])); $md_lan->update(); } else { $md_lan = $this->md_section->addLanguage(); $md_lan->setLanguage(new ilMDLanguageItem($data['language'])); $md_lan->save(); } } } // Description if (is_array($_POST['gen_description'])) { foreach ($_POST['gen_description'] as $id => $data) { $md_des = $this->md_section->getDescription($id); $md_des->setDescription(ilUtil::stripSlashes($data['description'])); // $md_des->setDescriptionLanguage(new ilMDLanguageItem($data['language'])); $md_des->update(); } } // Keyword if (is_array($_POST["keywords"]["value"])) { include_once "./Services/MetaData/classes/class.ilMDKeyword.php"; ilMDKeyword::updateKeywords($this->md_section, $_POST["keywords"]["value"]); } $this->callListeners('General'); // Copyright //if($_POST['copyright_id'] or $_POST['rights_copyright']) if ($_POST['copyright']['sel'] || $_POST['copyright']['ta']) { if (!is_object($this->md_section = $this->md_obj->getRights())) { $this->md_section = $this->md_obj->addRights(); $this->md_section->save(); } if ($_POST['copyright']['sel']) { $this->md_section->setCopyrightAndOtherRestrictions("Yes"); $this->md_section->setDescription('il_copyright_entry__' . IL_INST_ID . '__' . (int) $_POST['copyright']['sel']); } else { $this->md_section->setCopyrightAndOtherRestrictions("Yes"); $this->md_section->setDescription(ilUtil::stripSlashes($_POST['copyright']['ta'])); } $this->md_section->update(); } else { if (is_object($this->md_section = $this->md_obj->getRights())) { $this->md_section->setCopyrightAndOtherRestrictions("No"); $this->md_section->setDescription(""); $this->md_section->update(); } } $this->callListeners('Rights'); //Educational... // Typical Learning Time if ($_POST['tlt']['mo'] or $_POST['tlt']['d'] or $_POST["tlt"]['h'] or $_POST['tlt']['m'] or $_POST['tlt']['s']) { if (!is_object($this->md_section = $this->md_obj->getEducational())) { $this->md_section = $this->md_obj->addEducational(); $this->md_section->save(); } $this->md_section->setPhysicalTypicalLearningTime((int) $_POST['tlt']['mo'], (int) $_POST['tlt']['d'], (int) $_POST['tlt']['h'], (int) $_POST['tlt']['m'], (int) $_POST['tlt']['s']); $this->md_section->update(); } else { if (is_object($this->md_section = $this->md_obj->getEducational())) { $this->md_section->setPhysicalTypicalLearningTime(0, 0, 0, 0, 0); $this->md_section->update(); } } $this->callListeners('Educational'); //Lifecycle... // Authors if ($_POST["life_authors"] != "") { if (!is_object($this->md_section = $this->md_obj->getLifecycle())) { $this->md_section = $this->md_obj->addLifecycle(); $this->md_section->save(); } // determine all entered authors $auth_arr = explode($this->md_settings->getDelimiter(), $_POST["life_authors"]); for ($i = 0; $i < count($auth_arr); $i++) { $auth_arr[$i] = trim($auth_arr[$i]); } $md_con_author = ""; // update existing author entries (delete if not entered) foreach ($ids = $this->md_section->getContributeIds() as $con_id) { $md_con = $this->md_section->getContribute($con_id); if ($md_con->getRole() == "Author") { foreach ($ent_ids = $md_con->getEntityIds() as $ent_id) { $md_ent = $md_con->getEntity($ent_id); // entered author already exists if (in_array($md_ent->getEntity(), $auth_arr)) { unset($auth_arr[array_search($md_ent->getEntity(), $auth_arr)]); } else { $md_ent->delete(); } } $md_con_author = $md_con; } } // insert enterd, but not existing authors if (count($auth_arr) > 0) { if (!is_object($md_con_author)) { $md_con_author = $this->md_section->addContribute(); $md_con_author->setRole("Author"); $md_con_author->save(); } foreach ($auth_arr as $auth) { $md_ent = $md_con_author->addEntity(); $md_ent->setEntity(ilUtil::stripSlashes($auth)); $md_ent->save(); } } } else { if (is_object($this->md_section = $this->md_obj->getLifecycle())) { foreach ($ids = $this->md_section->getContributeIds() as $con_id) { $md_con = $this->md_section->getContribute($con_id); if ($md_con->getRole() == "Author") { $md_con->delete(); } } } } $this->callListeners('Lifecycle'); // Redirect here to read new title and description // Otherwise ('Lifecycle' 'technical' ...) simply call listSection() ilUtil::sendInfo($this->lng->txt("saved_successfully"), true); $this->ctrl->redirect($this, 'listSection'); }
function toXML(&$writer) { $writer->xmlStartTag('Classification', array('Purpose' => $this->getPurpose() ? $this->getPurpose() : 'Idea')); // Taxon Path $taxs = $this->getTaxonPathIds(); foreach ($taxs as $id) { $tax =& $this->getTaxonPath($id); $tax->toXML($writer); } if (!count($taxs)) { include_once 'Services/MetaData/classes/class.ilMDTaxonPath.php'; $tax = new ilMDTaxonPath($this->getRBACId(), $this->getObjId()); $tax->toXML($writer); } // Description $writer->xmlElement('Description', array('Language' => $this->getDescriptionLanguageCode() ? $this->getDescriptionLanguageCode() : 'en'), $this->getDescription()); // Keyword $keys = $this->getKeywordIds(); foreach ($keys as $id) { $key =& $this->getKeyword($id); $key->toXML($writer); } if (!count($keys)) { include_once 'Services/MetaData/classes/class.ilMDKeyword.php'; $key = new ilMDKeyword($this->getRBACId(), $this->getObjId()); $key->toXML($writer); } $writer->xmlEndTag('Classification'); }
/** * Fill html meta tags * * @access public * @static * * @param int rbac_id * @param int obj_id * @param string obj type */ public static function _fillHTMLMetaTags($a_rbac_id, $a_obj_id, $a_type) { global $tpl, $ilObjDataCache; include_once 'Services/MetaData/classes/class.ilMDKeyword.php'; foreach (ilMDKeyword::_getKeywordsByLanguageAsString($a_rbac_id, $a_obj_id, $a_type) as $lng_code => $key_string) { $tpl->setCurrentBlock('mh_meta_item'); $tpl->setVariable('MH_META_NAME', 'keywords'); $tpl->setVariable('MH_META_LANG', $lng_code); $tpl->setVariable('MH_META_CONTENT', $key_string); $tpl->parseCurrentBlock(); } include_once 'Services/MetaData/classes/class.ilMDContribute.php'; foreach (ilMDContribute::_lookupAuthors($a_rbac_id, $a_obj_id, $a_type) as $author) { $tpl->setCurrentBlock('mh_meta_item'); $tpl->setVariable('MH_META_NAME', 'author'); $tpl->setVariable('MH_META_CONTENT', $author); $tpl->parseCurrentBlock(); } }
/** * get media info as html */ function _getMediaInfoHTML(&$a_mob) { global $lng; $tpl =& new ilTemplate("tpl.media_info.html", true, true, "Services/MediaObjects"); $types = array("Standard", "Fullscreen"); foreach ($types as $type) { if ($type == "Fullscreen" && !$a_mob->hasFullScreenItem()) { continue; } $med = $a_mob->getMediaItem($type); if (!$med) { return ""; } $tpl->setCurrentBlock("media_info"); if ($type == "Standard") { $tpl->setVariable("TXT_PURPOSE", $lng->txt("cont_std_view")); } else { $tpl->setVariable("TXT_PURPOSE", $lng->txt("cont_fullscreen")); } $tpl->setVariable("TXT_TYPE", $lng->txt("cont_" . strtolower($med->getLocationType()))); $tpl->setVariable("VAL_LOCATION", $med->getLocation()); if ($med->getLocationType() == "LocalFile") { $file = ilObjMediaObject::_getDirectory($med->getMobId()) . "/" . $med->getLocation(); if (is_file($file)) { $size = filesize($file); } else { $size = 0; } $tpl->setVariable("VAL_FILE_SIZE", " ({$size} " . $lng->txt("bytes") . ")"); } $tpl->setVariable("TXT_FORMAT", $lng->txt("cont_format")); $tpl->setVariable("VAL_FORMAT", $med->getFormat()); if ($med->getWidth() != "" && $med->getHeight() != "") { $tpl->setCurrentBlock("size"); $tpl->setVariable("TXT_SIZE", $lng->txt("size")); $tpl->setVariable("VAL_SIZE", $med->getWidth() . "x" . $med->getHeight()); $tpl->parseCurrentBlock(); } // original size if ($orig_size = $med->getOriginalSize()) { if ($orig_size["width"] != $med->getWidth() || $orig_size["height"] != $med->getHeight()) { $tpl->setCurrentBlock("orig_size"); $tpl->setVariable("TXT_ORIG_SIZE", $lng->txt("cont_orig_size")); $tpl->setVariable("ORIG_WIDTH", $orig_size["width"]); $tpl->setVariable("ORIG_HEIGHT", $orig_size["height"]); $tpl->parseCurrentBlock(); } } // output caption if ($med && strlen($med->getCaption())) { $tpl->setCurrentBlock('additional_info'); $tpl->setVariable('ADD_INFO', $lng->txt('cont_caption') . ': ' . $med->getCaption()); $tpl->parseCurrentBlock(); } // output keywords if ($type == "Standard") { include_once './Services/MetaData/classes/class.ilMDKeyword.php'; if (count($kws = ilMDKeyword::lookupKeywords(0, $med->getMobId()))) { $tpl->setCurrentBlock('additional_info'); $tpl->setVariable('ADD_INFO', $lng->txt('keywords') . ': ' . implode(', ', $kws)); $tpl->parseCurrentBlock(); } } $tpl->setCurrentBlock("media_info"); $tpl->parseCurrentBlock(); } return $tpl->get(); }
/** * Standard Version of Fill Row. Most likely to * be overwritten by derived class. */ protected function fillRow($a_set) { global $lng, $ilCtrl, $ilAccess; $this->tpl->setCurrentBlock("link"); switch ($a_set["type"]) { case "fold": $this->tpl->setVariable("TXT_TITLE", $a_set["title"]); $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $a_set["obj_id"]); $this->tpl->setVariable("LINK_VIEW", $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd)); $this->tpl->parseCurrentBlock(); if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) && $this->getMode() == ilMediaPoolTableGUI::IL_MEP_EDIT) { $this->tpl->setCurrentBlock("edit"); $this->tpl->setVariable("TXT_EDIT", $lng->txt("edit")); $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $a_set["obj_id"]); $this->tpl->setVariable("EDIT_LINK", $ilCtrl->getLinkTarget($this->parent_obj, "editFolder")); $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $_GET[$this->folder_par]); $this->tpl->parseCurrentBlock(); } $this->tpl->setCurrentBlock("tbl_content"); $this->tpl->setVariable("IMG", ilUtil::img(ilUtil::getImagePath("icon_" . $a_set["type"] . ".png"))); $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $this->current_folder); break; case "pg": $this->tpl->setVariable("TXT_NO_LINK_TITLE", $a_set["title"]); if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) && $this->getMode() == ilMediaPoolTableGUI::IL_MEP_EDIT) { $this->tpl->setCurrentBlock("edit"); $this->tpl->setVariable("TXT_EDIT", $lng->txt("edit")); $ilCtrl->setParameterByClass("ilmediapoolpagegui", "mepitem_id", $a_set["child"]); $this->tpl->setVariable("EDIT_LINK", $ilCtrl->getLinkTargetByClass("ilmediapoolpagegui", "edit")); $this->tpl->parseCurrentBlock(); } $this->tpl->setCurrentBlock("tbl_content"); $this->tpl->setVariable("IMG", ilUtil::img(ilUtil::getImagePath("icon_pg.png"))); $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $this->current_folder); break; case "mob": if ($this->getMode() == ilMediaPoolTableGUI::IL_MEP_SELECT || $this->getMode() == ilMediaPoolTableGUI::IL_MEP_SELECT_SINGLE) { $this->tpl->setVariable("TXT_NO_LINK_TITLE", $a_set["title"]); } else { $this->tpl->setVariable("TXT_TITLE", $a_set["title"]); $this->tpl->touchBlock("nf"); $ilCtrl->setParameterByClass("ilobjmediaobjectgui", "mepitem_id", $a_set["child"]); $ilCtrl->setParameter($this->parent_obj, "mob_id", $a_set["foreign_id"]); $this->tpl->setVariable("LINK_VIEW", $ilCtrl->getLinkTarget($this->parent_obj, "showMedia")); } // edit link if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId()) && $this->getMode() == ilMediaPoolTableGUI::IL_MEP_EDIT) { $this->tpl->setCurrentBlock("edit"); $this->tpl->setVariable("TXT_EDIT", $lng->txt("edit")); $this->tpl->setVariable("EDIT_LINK", $ilCtrl->getLinkTargetByClass("ilobjmediaobjectgui", "edit")); $this->tpl->parseCurrentBlock(); } $this->tpl->setCurrentBlock("link"); $this->tpl->setCurrentBlock("tbl_content"); // output thumbnail (or mob icon) if (ilObject::_lookupType($a_set["foreign_id"]) == "mob") { $mob = new ilObjMediaObject($a_set["foreign_id"]); $med = $mob->getMediaItem("Standard"); $target = $med->getThumbnailTarget(); if ($target != "") { $this->tpl->setVariable("IMG", ilUtil::img($target)); } else { $this->tpl->setVariable("IMG", ilUtil::img(ilUtil::getImagePath("icon_" . $a_set["type"] . ".png"))); } if (ilUtil::deducibleSize($med->getFormat()) && $med->getLocationType() == "Reference") { $size = @getimagesize($med->getLocation()); if ($size[0] > 0 && $size[1] > 0) { $wr = $size[0] / 80; $hr = $size[1] / 80; $r = max($wr, hr); $w = (int) ($size[0] / $r); $h = (int) ($size[1] / $r); $this->tpl->setVariable("IMG", ilUtil::img($med->getLocation(), "", $w, $h)); } } // output media info include_once "./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php"; $this->tpl->setVariable("MEDIA_INFO", ilObjMediaObjectGUI::_getMediaInfoHTML($mob)); $ilCtrl->setParameter($this->parent_obj, $this->folder_par, $this->current_folder); // output keywords include_once './Services/MetaData/classes/class.ilMDKeyword.php'; if (count($kws = ilMDKeyword::lookupKeywords(0, $a_set['foreign_id']))) { $this->tpl->setCurrentBlock('additional_info'); $this->tpl->setVariable('ADD_INFO', $lng->txt('keywords') . ': ' . implode(' ', $kws)); $this->tpl->parseCurrentBlock(); } // output caption if (strlen($med->getCaption())) { $this->tpl->setCurrentBlock('additional_info'); $this->tpl->setVariable('ADD_INFO', $lng->txt('cont_caption') . ': ' . $med->getCaption()); $this->tpl->parseCurrentBlock(); } } break; } if ($ilAccess->checkAccess("write", "", $this->media_pool->getRefId())) { if ($this->getMode() == ilMediaPoolTableGUI::IL_MEP_EDIT || $this->getMode() == ilMediaPoolTableGUI::IL_MEP_SELECT && $a_set["type"] == "mob" || $this->getMode() == ilMediaPoolTableGUI::IL_MEP_SELECT_CONTENT && $a_set["type"] == "pg") { $this->tpl->setCurrentBlock("chbox"); $this->tpl->setVariable("CHECKBOX_ID", $a_set["child"]); $this->tpl->parseCurrentBlock(); $this->tpl->setCurrentBlock("tbl_content"); } else { if ($this->getMode() == ilMediaPoolTableGUI::IL_MEP_SELECT_SINGLE && $a_set["type"] == "mob") { $this->tpl->setCurrentBlock("radio"); $this->tpl->setVariable("RADIO_ID", $a_set["child"]); $this->tpl->parseCurrentBlock(); $this->tpl->setCurrentBlock("tbl_content"); } } } }