ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCustomUserFieldsHelper.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
12{
13 private static $instance = null;
14
15
19 private $lng = null;
20
24 private $plugin_admin = null;
25
29 private $logger = null;
30
31 public function __construct()
32 {
33 global $DIC;
34
35 $this->lng = $DIC->language();
36 $this->logger = $DIC->logger()->usr();
37 $this->plugin_admin = $DIC['ilPluginAdmin'];
38 }
39
44 public static function getInstance()
45 {
46 if (self::$instance) {
47 return self::$instance;
48 }
49 return self::$instance = new self();
50 }
51
56 public function getUDFTypes()
57 {
58 $types = array(
59 UDF_TYPE_TEXT => $this->lng->txt('udf_type_text'),
60 UDF_TYPE_SELECT => $this->lng->txt('udf_type_select'),
61 UDF_TYPE_WYSIWYG => $this->lng->txt('udf_type_wysiwyg')
62 );
63 include_once './Services/User/classes/class.ilUDFDefinitionPlugin.php';
64 foreach ($this->getActivePlugins() as $plugin) {
65 $types[$plugin->getDefinitionType()] = $plugin->getDefinitionTypeName();
66 }
67 return $types;
68 }
69
74 public function getPluginForType($a_type)
75 {
76 foreach ($this->getActivePlugins() as $plugin) {
77 if ($plugin->getDefinitionType() == $a_type) {
78 return $plugin;
79 }
80 }
81 return null;
82 }
83
89 public function getActivePlugins()
90 {
91 $plugins = array();
92
93 include_once './Services/User/classes/class.ilUDFDefinitionPlugin.php';
94 foreach (
95 $this->plugin_admin->getActivePluginsForSlot(
99 )
100 as $plugin) {
101 $plug = $this->plugin_admin->getPluginObject(
105 $plugin
106 );
107 if ($plug instanceof ilUDFDefinitionPlugin) {
108 $plugins[] = $plug;
109 }
110 }
111 return $plugins;
112 }
113
119 public function getFormPropertyForDefinition($definition, $a_changeable = true, $a_default_value = null)
120 {
121 $fprop = null;
122
123 switch ($definition['field_type']) {
124 case UDF_TYPE_TEXT:
125 $fprop = new ilTextInputGUI(
126 $definition['field_name'],
127 'udf_' . $definition['field_id']
128 );
129 $fprop->setValue($a_default_value);
130 $fprop->setSize(40);
131 $fprop->setMaxLength(255);
132 $fprop->setRequired($definition['required'] ? true : false);
133 if (!$a_changeable && (!$definition['required'] || $a_default_value)) {
134 $fprop->setDisabled(true);
135 }
136 break;
137
138 case UDF_TYPE_WYSIWYG:
139 $fprop = new ilTextAreaInputGUI(
140 $definition['field_name'],
141 'udf_' . $definition['field_id']
142 );
143 $fprop->setValue($a_default_value);
144 $fprop->setUseRte(true);
145 $fprop->setRequired($definition['required'] ? true : false);
146 if (!$a_changeable && (!$definition['required'] || $a_default_value)) {
147 $fprop->setDisabled(true);
148 }
149 break;
150
151 case UDF_TYPE_SELECT:
152 $fprop = new ilSelectInputGUI(
153 $definition['field_name'],
154 'udf_' . $definition['field_id']
155 );
156
157 include_once './Services/User/classes/class.ilUserDefinedFields.php';
158 $user_defined_fields = ilUserDefinedFields::_getInstance();
159
160 $fprop->setOptions($user_defined_fields->fieldValuesToSelectArray($definition['field_values']));
161 $fprop->setValue($a_default_value);
162 $fprop->setRequired($definition['required'] ? true : false);
163 if (!$a_changeable && (!$definition['required'] || $a_default_value)) {
164 $fprop->setDisabled(true);
165 }
166 break;
167
168 default:
169 // should be a plugin
170 foreach ($this->getActivePlugins() as $plugin) {
171 if ($plugin->getDefinitionType() == $definition['field_type']) {
172 $fprop = $plugin->getFormPropertyForDefinition($definition, $a_changeable, $a_default_value);
173 break;
174 }
175 }
176 break;
177 }
178
179 return $fprop;
180 }
181}
An exception for terminatinating execution or to throw for unit testing.
const UDF_TYPE_SELECT
const UDF_TYPE_WYSIWYG
const UDF_TYPE_TEXT
getActivePlugins()
Get plugins for fields.
getPluginForType($a_type)
Get plugin for udf type.
getFormPropertyForDefinition($definition, $a_changeable=true, $a_default_value=null)
Get form property for definition.
This class represents a selection list property in a property form.
This class represents a text area property in a property form.
This class represents a text property in a property form.
UDF type deefinition plugin.
static _getInstance()
Get instance.
global $DIC
Definition: goto.php:24