ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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->setDisabled(!$a_changeable);
130  $fprop->setValue($a_default_value);
131  $fprop->setSize(40);
132  $fprop->setMaxLength(255);
133  $fprop->setRequired($definition['required'] ? true : false);
134  break;
135 
136  case UDF_TYPE_WYSIWYG:
137  $fprop = new ilTextAreaInputGUI(
138  $definition['field_name'],
139  'udf_' . $definition['field_id']
140  );
141  $fprop->setDisabled(!$a_changeable);
142  $fprop->setValue($a_default_value);
143  $fprop->setUseRte(true);
144  $fprop->setRequired($definition['required'] ? true : false);
145  break;
146 
147  case UDF_TYPE_SELECT:
148  $fprop = new ilSelectInputGUI(
149  $definition['field_name'],
150  'udf_' . $definition['field_id']
151  );
152  $fprop->setDisabled(!$a_changeable);
153 
154  include_once './Services/User/classes/class.ilUserDefinedFields.php';
155  $user_defined_fields = ilUserDefinedFields::_getInstance();
156 
157  $fprop->setOptions($user_defined_fields->fieldValuesToSelectArray($definition['field_values']));
158  $fprop->setValue($a_default_value);
159  $fprop->setRequired($definition['required'] ? true : false);
160  break;
161 
162  default:
163  // should be a plugin
164  foreach ($this->getActivePlugins() as $plugin) {
165  if ($plugin->getDefinitionType() == $definition['field_type']) {
166  $fprop = $plugin->getFormPropertyForDefinition($definition, $a_changeable, $a_default_value);
167  break;
168  }
169  }
170  break;
171  }
172 
173  return $fprop;
174  }
175 }
const UDF_TYPE_SELECT
static _getInstance()
Get instance.
This class represents a selection list property in a property form.
global $DIC
Definition: saml.php:7
getFormPropertyForDefinition($definition, $a_changeable=true, $a_default_value=null)
Get form property for definition.
getPluginForType($a_type)
Get plugin for udf type.
$a_type
Definition: workflow.php:92
UDF type deefinition plugin.
getActivePlugins()
Get plugins for fields.
const UDF_TYPE_TEXT
This class represents a text property in a property form.
const UDF_TYPE_WYSIWYG
This class represents a text area property in a property form.