1<?php 2/* 3 +-----------------------------------------------------------------------------+ 4 | ILIAS open source | 5 +-----------------------------------------------------------------------------+ 6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne | 7 | | 8 | This program is free software; you can redistribute it and/or | 9 | modify it under the terms of the GNU General Public License | 10 | as published by the Free Software Foundation; either version 2 | 11 | of the License, or (at your option) any later version. | 12 | | 13 | This program is distributed in the hope that it will be useful, | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 16 | GNU General Public License for more details. | 17 | | 18 | You should have received a copy of the GNU General Public License | 19 | along with this program; if not, write to the Free Software | 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 21 +-----------------------------------------------------------------------------+ 22*/ 23 24 25include_once './Services/Search/classes/class.ilSearchSettings.php'; 26 27/** 28* Base class for all sub item list gui's 29* 30* @author Stefan Meyer <meyer@leifos.com> 31* @version $Id$ 32* 33* 34* @ingroup ServicesObject 35*/ 36abstract class ilSubItemListGUI 37{ 38 /** 39 * @var ilCtrl 40 */ 41 protected $ctrl; 42 43 /** 44 * @var ilLanguage 45 */ 46 protected $lng; 47 48 protected static $MAX_SUBITEMS = 5; 49 50 protected $cmdClass = null; 51 52 protected $tpl; 53 private $highlighter = null; 54 55 private static $details = array(); 56 57 private $subitem_ids = array(); 58 private $item_list_gui; 59 private $ref_id; 60 private $obj_id; 61 private $type; 62 63 /** 64 * Constructor 65 * @param 66 * @return 67 */ 68 public function __construct($a_cmd_class) 69 { 70 global $DIC; 71 72 $this->ctrl = $DIC->ctrl(); 73 $this->lng = $DIC->language(); 74 75 $this->cmdClass = $a_cmd_class; 76 self::$MAX_SUBITEMS = ilSearchSettings::getInstance()->getMaxSubitems(); 77 } 78 79 /** 80 * set show details. 81 * Show all subitem links for a specific object 82 * As long as static::setShowDetails is not possible this method is final 83 * 84 * @return 85 * @param int $a_obj_id object id 86 * @static 87 */ 88 final public static function setShowDetails($a_obj_id) 89 { 90 $_SESSION['lucene_search']['details'][$a_obj_id] = true; 91 } 92 93 /** 94 * reset details 95 * As long as static::resetDetails is not possible this method is final 96 * 97 * @return 98 * @static 99 */ 100 final public static function resetDetails() 101 { 102 $_SESSION['lucene_search']['details'] = array(); 103 } 104 105 /** 106 * enabled show details 107 * As long as static::enableDetails is not possible this method is final 108 * 109 * @param int $a_obj_id object id 110 * @return bool 111 * @static 112 */ 113 final public static function enabledDetails($a_obj_id) 114 { 115 return isset($_SESSION['lucene_search']['details'][$a_obj_id]) and $_SESSION['lucene_search']['details'][$a_obj_id]; 116 } 117 118 /** 119 * get cmd class 120 * @return 121 */ 122 public function getCmdClass() 123 { 124 return $this->cmdClass; 125 } 126 127 128 /** 129 * set highlighter 130 * @param 131 * @return 132 */ 133 public function setHighlighter($a_highlighter) 134 { 135 $this->highlighter = $a_highlighter; 136 } 137 138 /** 139 * get highlighter 140 * @param 141 * @return 142 */ 143 public function getHighlighter() 144 { 145 return $this->highlighter; 146 } 147 148 /** 149 * get ref id 150 * @return 151 */ 152 public function getRefId() 153 { 154 return $this->ref_id; 155 } 156 157 /** 158 * get obj id 159 * @return 160 */ 161 public function getObjId() 162 { 163 return $this->obj_id; 164 } 165 166 /** 167 * get type 168 * @return 169 */ 170 public function getType() 171 { 172 return $this->type; 173 } 174 175 /** 176 * get sub item ids 177 * @param bool $a_limited 178 * @return 179 */ 180 public function getSubItemIds($a_limited = false) 181 { 182 if ($a_limited and !self::enabledDetails($this->getObjId())) { 183 return array_slice($this->subitem_ids, 0, self::$MAX_SUBITEMS); 184 } 185 186 return $this->subitem_ids; 187 } 188 189 /** 190 * get item list gui 191 * @return 192 */ 193 public function getItemListGUI() 194 { 195 return $this->item_list_gui; 196 } 197 198 /** 199 * init 200 * @param 201 * @return 202 */ 203 public function init($item_list_gui, $a_ref_id, $a_subitem_ids) 204 { 205 $this->tpl = new ilTemplate('tpl.subitem_list.html', true, true, 'Services/Object'); 206 $this->item_list_gui = $item_list_gui; 207 $this->ref_id = $a_ref_id; 208 $this->obj_id = ilObject::_lookupObjId($this->getRefId()); 209 $this->type = ilObject::_lookupType($this->getObjId()); 210 211 $this->subitem_ids = $a_subitem_ids; 212 } 213 214 /** 215 * show details link 216 * @return 217 */ 218 protected function showDetailsLink() 219 { 220 $ilCtrl = $this->ctrl; 221 $lng = $this->lng; 222 223 if (count($this->getSubItemIds()) <= self::$MAX_SUBITEMS) { 224 return; 225 } 226 if (self::enabledDetails($this->getObjId())) { 227 return; 228 } 229 230 $additional = count($this->getSubItemIds()) - self::$MAX_SUBITEMS; 231 232 $ilCtrl->setParameterByClass(get_class($this->getCmdClass()), 'details', (int) $this->getObjId()); 233 $link = $ilCtrl->getLinkTargetByClass(get_class($this->getCmdClass()), ''); 234 $ilCtrl->clearParametersByClass(get_class($this->getCmdClass())); 235 236 $this->tpl->setCurrentBlock('choose_details'); 237 $this->tpl->setVariable('LUC_DETAILS_LINK', $link); 238 $this->tpl->setVariable('LUC_NUM_HITS', sprintf($lng->txt('lucene_more_hits_link'), $additional)); 239 $this->tpl->parseCurrentBlock(); 240 } 241 242 // begin-patch mime_filter 243 protected function parseRelevance($sub_item) 244 { 245 if (!ilSearchSettings::getInstance()->isSubRelevanceVisible() || 246 !ilSearchSettings::getInstance()->enabledLucene()) { 247 return ''; 248 } 249 250 $relevance = $this->getHighlighter()->getRelevance($this->getObjId(), $sub_item); 251 252 //$this->tpl->addBlockFile('SUB_REL','sub_rel','tpl.lucene_sub_relevance.html','Services/Search'); 253 254 include_once "Services/UIComponent/ProgressBar/classes/class.ilProgressBar.php"; 255 $pbar = ilProgressBar::getInstance(); 256 $pbar->setCurrent($relevance); 257 258 $this->tpl->setVariable('REL_PBAR', $pbar->render()); 259 } 260 // end-patch mime_filter 261 262 abstract public function getHTML(); 263} 264