1<?php 2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */ 3 4include_once("./Services/Table/classes/class.ilTable2GUI.php"); 5 6/** 7 * Term list table 8 * 9 * @author Alex Killing <alex.killing@gmx.de> 10 * @version $Id$ 11 * 12 * @ingroup Services 13 */ 14class ilTermListTableGUI extends ilTable2GUI 15{ 16 /** 17 * @var ilObjGlossary 18 */ 19 protected $glossary; 20 21 /** 22 * @var ilGlossaryTermPermission 23 */ 24 protected $term_perm; 25 26 /** 27 * @var ilLanguage 28 */ 29 protected $lng; 30 31 /** 32 * @var ilCtrl 33 */ 34 protected $ctrl; 35 36 /** 37 * Constructor 38 */ 39 public function __construct($a_parent_obj, $a_parent_cmd, $a_tax_node) 40 { 41 global $DIC; 42 43 $this->glossary = $a_parent_obj->object; 44 $this->setId("glotl" . $this->glossary->getId()); 45 $this->tax_node = $a_tax_node; 46 47 $this->lng = $DIC->language(); 48 $this->ctrl = $DIC->ctrl(); 49 50 $this->selectable_cols = array(); 51 52 include_once("./Modules/Glossary/classes/class.ilGlossaryTermPermission.php"); 53 $this->term_perm = ilGlossaryTermPermission::getInstance(); 54 55 include_once("./Modules/Glossary/classes/class.ilGlossaryAdvMetaDataAdapter.php"); 56 $adv_ad = new ilGlossaryAdvMetaDataAdapter($this->glossary->getRefId()); 57 $this->adv_fields = $adv_ad->getAllFields(); 58 foreach ($this->adv_fields as $f) { 59 $this->selectable_cols["md_" . $f["id"]] = array( 60 "txt" => $f["title"], 61 "default" => false 62 ); 63 } 64 65 // selectable columns 66 $this->selectable_cols["language"] = array( 67 "txt" => $this->lng->txt("language"), 68 "default" => true); 69 $this->selectable_cols["usage"] = array( 70 "txt" => $this->lng->txt("cont_usage"), 71 "default" => true); 72 73 // selectable columns of advanced metadata 74 75 parent::__construct($a_parent_obj, $a_parent_cmd); 76 $this->setTitle($this->lng->txt("cont_terms")); 77 78 $this->addColumn("", "", "1", true); 79 //$this->addColumn($this->lng->txt("cont_term")); 80 81 include_once("./Modules/Glossary/classes/class.ilGlossaryAdvMetaDataAdapter.php"); 82 $adv_ap = new ilGlossaryAdvMetaDataAdapter($this->glossary->getRefId()); 83 $this->adv_cols_order = $adv_ap->getColumnOrder(); 84 $this->selected_cols = $this->getSelectedColumns(); 85 foreach ($this->adv_cols_order as $c) { 86 if ($c["id"] == 0) { 87 $this->addColumn($this->lng->txt("cont_term"), "term"); 88 } else { 89 if (in_array("md_" . $c["id"], $this->selected_cols)) { 90 $this->addColumn($c["text"], "md_" . $c["id"]); 91 } 92 } 93 } 94 95 foreach (array("language", "usage") as $c) { 96 if (in_array($c, $this->selected_cols)) { 97 $this->addColumn($this->selectable_cols[$c]["txt"]); 98 } 99 } 100 101 $this->setDefaultOrderDirection("asc"); 102 $this->setDefaultOrderField("term"); 103 $this->addColumn($this->lng->txt("cont_definitions")); 104 105 if ($this->showGlossaryColumn()) { 106 $this->addColumn($this->lng->txt("obj_glo")); 107 } 108 109 $this->addColumn("", "", "1"); 110 111 $this->setEnableHeader(true); 112 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj)); 113 $this->setRowTemplate("tpl.term_tbl_row.html", "Modules/Glossary"); 114 $this->setEnableTitle(true); 115 116 $this->addMultiCommand("copyTerms", $this->lng->txt("copy")); 117 $this->addMultiCommand("referenceTerms", $this->lng->txt("glo_reference")); 118 $this->addMultiCommand("confirmTermDeletion", $this->lng->txt("delete")); 119 //$this->addMultiCommand("addDefinition", $this->lng->txt("cont_add_definition")); 120 121 $this->setShowRowsSelector(true); 122 123 $this->initFilter(); 124 $this->setData($this->glossary->getTermList( 125 $this->filter["term"], 126 "", 127 $this->filter["definition"], 128 $this->tax_node, 129 true, 130 true, 131 null, 132 false, 133 true 134 )); 135 } 136 137 /** 138 * Show glossary column 139 * 140 * @param 141 * @return 142 */ 143 public function showGlossaryColumn() 144 { 145 include_once("./Modules/Glossary/classes/class.ilGlossaryTermReferences.php"); 146 return (in_array( 147 $this->glossary->getVirtualMode(), 148 array("level", "subtree") 149 ) || ilGlossaryTermReferences::hasReferences($this->glossary->getId())); 150 } 151 152 153 /** 154 * Get selectable columns 155 * 156 * @param 157 * @return 158 */ 159 public function getSelectableColumns() 160 { 161 return $this->selectable_cols; 162 } 163 164 /** 165 * Should this field be sorted numeric? 166 * 167 * @return boolean numeric ordering; default is false 168 */ 169 public function numericOrdering($a_field) 170 { 171 if (substr($a_field, 0, 3) == "md_") { 172 $md_id = (int) substr($a_field, 3); 173 if ($this->adv_fields[$md_id]["type"] == ilAdvancedMDFieldDefinition::TYPE_DATE) { 174 return true; 175 } 176 } 177 return false; 178 } 179 180 /** 181 * Init filter 182 */ 183 public function initFilter() 184 { 185 // term 186 include_once("./Services/Form/classes/class.ilTextInputGUI.php"); 187 $ti = new ilTextInputGUI($this->lng->txt("cont_term"), "term"); 188 $ti->setMaxLength(64); 189 $ti->setSize(20); 190 $ti->setSubmitFormOnEnter(true); 191 $this->addFilterItem($ti); 192 $ti->readFromSession(); 193 $this->filter["term"] = $ti->getValue(); 194 195 // definition 196 if ($this->glossary->supportsLongTextQuery()) { 197 include_once("./Services/Form/classes/class.ilTextInputGUI.php"); 198 $ti = new ilTextInputGUI($this->lng->txt("cont_definition"), "defintion"); 199 $ti->setMaxLength(64); 200 $ti->setSize(20); 201 $ti->setSubmitFormOnEnter(true); 202 $this->addFilterItem($ti); 203 $ti->readFromSession(); 204 $this->filter["definition"] = $ti->getValue(); 205 } 206 } 207 208 /** 209 * Fill table row 210 */ 211 protected function fillRow($term) 212 { 213 include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php"); 214 215 $defs = ilGlossaryDefinition::getDefinitionList($term["id"]); 216 $this->ctrl->setParameterByClass("ilobjglossarygui", "term_id", $term["id"]); 217 $this->ctrl->setParameterByClass("ilglossarytermgui", "term_id", $term["id"]); 218 $this->ctrl->setParameterByClass("ilglossarydefpagegui", "term_id", $term["id"]); 219 220 // actions drop down 221 //if ($this->glossary->getId() == $term["glo_id"]) 222 223 if ($this->term_perm->checkPermission("write", $term["id"]) || 224 $this->term_perm->checkPermission("edit_content", $term["id"])) { 225 include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php"); 226 include_once("./Modules/Glossary/classes/class.ilGlossaryTermReferences.php"); 227 if (ilGlossaryTerm::_lookGlossaryID($term["id"]) == $this->glossary->getId() || 228 ilGlossaryTermReferences::isReferenced($this->glossary->getId(), $term["id"])) { 229 $list = new ilAdvancedSelectionListGUI(); 230 $list->addItem($this->lng->txt("cont_edit_term"), "", $this->ctrl->getLinkTargetByClass("ilglossarytermgui", "editTerm")); 231 if (count($defs) > 1) { 232 $list->addItem($this->lng->txt("cont_edit_definitions"), "", $this->ctrl->getLinkTargetByClass("ilglossarytermgui", "listDefinitions")); 233 } elseif (count($defs) == 1) { 234 $this->ctrl->setParameterByClass("ilglossarydefpagegui", "def", $defs[0]["id"]); 235 $list->addItem($this->lng->txt("cont_edit_definition"), "", $this->ctrl->getLinkTargetByClass(array("ilglossarytermgui", 236 "iltermdefinitioneditorgui", 237 "ilglossarydefpagegui"), "edit")); 238 } 239 $list->addItem($this->lng->txt("cont_add_definition"), "", $this->ctrl->getLinkTargetByClass("ilobjglossarygui", "addDefinition")); 240 $this->ctrl->setParameterByClass("ilglossarydefpagegui", "def", ""); 241 242 $list->setId("act_term_" . $term["id"]); 243 $list->setListTitle($this->lng->txt("actions")); 244 $this->tpl->setVariable("ACTIONS", $list->getHTML()); 245 } 246 } 247 248 249 for ($j = 0; $j < count($defs); $j++) { 250 $def = $defs[$j]; 251 252 253 // text 254 $this->tpl->setCurrentBlock("definition"); 255 $short_str = $def["short_text"]; 256 257 if ($def["short_text_dirty"]) { 258 // #18022 259 $def_obj = new ilGlossaryDefinition($def["id"]); 260 $def_obj->updateShortText(); 261 $short_str = $def_obj->getShortText(); 262 } 263 264 // replace tex 265 // if a tex end tag is missing a tex end tag 266 $ltexs = strrpos($short_str, "[tex]"); 267 $ltexe = strrpos($short_str, "[/tex]"); 268 if ($ltexs > $ltexe) { 269 $page = new ilGlossaryDefPage($def["id"]); 270 $page->buildDom(); 271 $short_str = $page->getFirstParagraphText(); 272 $short_str = strip_tags($short_str, "<br>"); 273 $ltexe = strpos($short_str, "[/tex]", $ltexs); 274 $short_str = ilUtil::shortenText($short_str, $ltexe + 6, true); 275 } 276 277 include_once './Services/MathJax/classes/class.ilMathJax.php'; 278 $short_str = ilMathJax::getInstance()->insertLatexImages($short_str); 279 280 $short_str = ilPCParagraph::xml2output($short_str); 281 $this->tpl->setVariable("DEF_SHORT", $short_str); 282 $this->tpl->parseCurrentBlock(); 283 284 $this->tpl->setCurrentBlock("definition_row"); 285 $this->tpl->parseCurrentBlock(); 286 } 287 288 $this->tpl->setCurrentBlock("check_col"); 289 $this->tpl->setVariable("CHECKBOX_ID", $term["id"]); 290 $this->tpl->parseCurrentBlock(); 291 292 $this->ctrl->setParameter($this->parent_obj, "term_id", $term["id"]); 293 294 295 // usage 296 if (in_array("usage", $this->getSelectedColumns())) { 297 $nr_usage = ilGlossaryTerm::getNumberOfUsages($term["id"]); 298 if ($nr_usage > 0 && $this->glossary->getId() == $term["glo_id"]) { 299 $this->tpl->setCurrentBlock("link_usage"); 300 $this->ctrl->setParameterByClass("ilglossarytermgui", "term_id", $term["id"]); 301 $this->tpl->setVariable("LUSAGE", ilGlossaryTerm::getNumberOfUsages($term["id"])); 302 $this->tpl->setVariable( 303 "LINK_USAGE", 304 $this->ctrl->getLinkTargetByClass("ilglossarytermgui", "listUsages") 305 ); 306 $this->ctrl->setParameterByClass("ilglossarytermgui", "term_id", ""); 307 $this->tpl->parseCurrentBlock(); 308 } else { 309 $this->tpl->setCurrentBlock("usage"); 310 $this->tpl->setVariable("USAGE", ilGlossaryTerm::getNumberOfUsages($term["id"])); 311 $this->tpl->parseCurrentBlock(); 312 } 313 $this->tpl->setCurrentBlock("td_usage"); 314 $this->tpl->parseCurrentBlock(); 315 } 316 317 // glossary title 318 if ($this->showGlossaryColumn()) { 319 $this->tpl->setCurrentBlock("glossary"); 320 $this->tpl->setVariable("GLO_TITLE", ilObject::_lookupTitle($term["glo_id"])); 321 $this->tpl->parseCurrentBlock(); 322 } 323 324 // output language 325 if (in_array("language", $this->getSelectedColumns())) { 326 $this->tpl->setCurrentBlock("td_lang"); 327 $this->tpl->setVariable("TEXT_LANGUAGE", $this->lng->txt("meta_l_" . $term["language"])); 328 $this->tpl->parseCurrentBlock(); 329 } 330 331 332 foreach ($this->adv_cols_order as $c) { 333 if ($c["id"] == 0) { 334 $this->tpl->setCurrentBlock("td"); 335 $this->tpl->setVariable("TD_VAL", $term["term"]); 336 $this->tpl->parseCurrentBlock(); 337 } else { 338 if (in_array("md_" . $c["id"], $this->selected_cols)) { 339 $id = (int) $c["id"]; 340 341 $val = " "; 342 if (isset($term["md_" . $id . "_presentation"])) { 343 $pb = $term["md_" . $id . "_presentation"]->getHTML(); 344 if ($pb) { 345 $val = $pb; 346 } 347 } 348 349 $this->tpl->setCurrentBlock("td"); 350 $this->tpl->setVariable("TD_VAL", $val); 351 $this->tpl->parseCurrentBlock(); 352 } 353 } 354 } 355 } 356} 357