1<?php 2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */ 3 4/** 5 * Class ilDclBaseFieldRepresentation 6 * 7 * @author Michael Herren <mh@studer-raimann.ch> 8 * @version 1.0.0 9 */ 10abstract class ilDclBaseFieldRepresentation 11{ 12 protected $field; 13 /** 14 * @var ilLanguage 15 */ 16 protected $lng; 17 /** 18 * @var ilCtrl $ctrl ; 19 */ 20 protected $ctrl; 21 22 23 public function __construct(ilDclBaseFieldModel $field) 24 { 25 global $DIC; 26 $lng = $DIC['lng']; 27 $ilCtrl = $DIC['ilCtrl']; 28 $this->field = $field; 29 $this->lng = $lng; 30 $this->ctrl = $ilCtrl; 31 } 32 33 34 /** 35 * Add filter input to TableGUI 36 * 37 * @param ilTable2GUI $table 38 * 39 * @return null 40 */ 41 public function addFilterInputFieldToTable(ilTable2GUI $table) 42 { 43 return null; 44 } 45 46 47 /** 48 * Set basic settings for filter-input-gui 49 * 50 * @param ilFormPropertyGUI $input 51 */ 52 protected function setupFilterInputField(ilFormPropertyGUI $input) 53 { 54 if ($input != null) { 55 $input->setTitle($this->getField()->getTitle()); 56 } 57 } 58 59 60 /** 61 * Checks if a filter affects a record 62 * 63 * @param ilDclBaseRecordModel $record 64 * @param $filter 65 * 66 * @return bool 67 */ 68 public function passThroughFilter(ilDclBaseRecordModel $record, $filter) 69 { 70 $value = $record->getRecordFieldValue($this->getField()->getId()); 71 $pass = true; 72 73 if (($this->getField()->getId() == "owner" || $this->getField()->getId() == "last_edit_by") && $filter) { 74 $pass = false; 75 $user = new ilObjUser($value); 76 if (strpos($user->getFullname(), $filter) !== false) { 77 $pass = true; 78 } 79 } 80 81 return $pass; 82 } 83 84 85 /** 86 * 87 * @param $value 88 * @param bool $link 89 * 90 * @return mixed 91 */ 92 public function parseSortingValue($value, $link = true) 93 { 94 return $value; 95 } 96 97 98 /** 99 * Returns field-input 100 * 101 * @param ilPropertyFormGUI $form 102 * @param int $record_id 103 * 104 * @return null 105 */ 106 public function getInputField(ilPropertyFormGUI $form, $record_id = 0) 107 { 108 return null; 109 } 110 111 112 /** 113 * Sets basic settings on field-input 114 * 115 * @param ilFormPropertyGUI $input 116 * @param ilDclBaseFieldModel $field 117 */ 118 protected function setupInputField(ilFormPropertyGUI $input, ilDclBaseFieldModel $field) 119 { 120 $input->setRequired($field->getRequired()); 121 $input->setInfo($field->getDescription() . ($input->getInfo() ? '<br>' . $input->getInfo() : '')); 122 } 123 124 125 /** 126 * @param $input 127 * 128 * @return null 129 */ 130 protected function getFilterInputFieldValue(/*ilPropertyFormGUI*/ 131 $input 132 ) { 133 $value = $input->getValue(); 134 if (is_array($value)) { 135 if ($value['from'] || $value['to']) { 136 return $value; 137 } 138 } else { 139 if ($value != '') { 140 return $value; 141 } 142 } 143 144 return null; 145 } 146 147 148 /** 149 * Adds the options for the field-types to the field-creation form 150 * 151 * @param $form 152 * @param ilObjDataCollection $dcl 153 * @param string $mode 154 */ 155 public function addFieldCreationForm($form, ilObjDataCollection $dcl, $mode = "create") 156 { 157 $opt = $this->buildFieldCreationInput($dcl, $mode); 158 159 if ($mode != 'create' && $this->getField()->getDatatypeId() == ilDclDatatype::INPUTFORMAT_PLUGIN) { 160 $new_plugin_title = $opt->getTitle(); 161 $plugin_name = ilDclFieldFactory::getPluginNameFromFieldModel($this->getField()); 162 if ($plugin_name !== "DclBase") { 163 $new_plugin_title .= ': ' . $plugin_name; 164 } 165 $opt->setTitle($new_plugin_title); 166 } 167 168 $form->addOption($opt); 169 } 170 171 172 /** 173 * Build the creation-input-field 174 * 175 * @param ilObjDataCollection $dcl 176 * @param string $mode 177 * 178 * @return ilPropertyFormGUI 179 */ 180 protected function buildFieldCreationInput(ilObjDataCollection $dcl, $mode = 'create') 181 { 182 $opt = new ilRadioOption($this->lng->txt('dcl_' . $this->getField()->getDatatype()->getTitle()), $this->getField()->getDatatypeId()); 183 $opt->setInfo($this->lng->txt('dcl_' . $this->getField()->getDatatype()->getTitle() . '_desc')); 184 185 return $opt; 186 } 187 188 189 /** 190 * Return post-var for property-fields 191 * 192 * @param $property 193 * 194 * @return string 195 */ 196 public function getPropertyInputFieldId($property) 197 { 198 return "prop_" . $property; 199 } 200 201 202 /** 203 * Return BaseFieldModel 204 * 205 * @return ilDclBaseFieldModel 206 */ 207 public function getField() 208 { 209 return $this->field; 210 } 211} 212