ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
ilCharSelectorConfig Class Reference
+ Collaboration diagram for ilCharSelectorConfig:

Public Member Functions

 __construct ($a_context=self::CONTEXT_NONE)
 Constructor. More...
 
 getContext ()
 get the context of the configuration (the context is set at initialisation and can't be changed) More...
 
 setAvailability ($a_availability)
 set the availability of the selector More...
 
 getAvailability ()
 get the availability of the selector More...
 
 setAddedBlocks ($a_blocks=array())
 set the added unicode blocks More...
 
 getAddedBlocks ()
 set the added unicode blocks More...
 
 setCustomItems ($a_items='')
 set the custom items More...
 
 getCustomItems ()
 set the custom items More...
 
 setDefinition ($a_definition='')
 
 getDefinition ()
 Set the definition of the available characters. More...
 
 getBlockOptions ()
 get the options for a block selection More...
 
 getBlockTitle ($a_block_name)
 Get the title of a unicode block for display or selection A translation is used if it exists. More...
 
 getCharPages ()
 Get the character pages. More...
 

Static Public Member Functions

static _getCurrentConfig (ilObjTest $a_test_obj=null)
 Get the configuration that should be used for the current selector. More...
 

Data Fields

const INACTIVE = 0
 Availabilities INACTIVE/INHERIT corresponds to an unconfigured selector (no database entries) More...
 
const INHERIT = 0
 
const ENABLED = 1
 
const DISABLED = 2
 
const CONTEXT_NONE = ''
 Configuration contexts. More...
 
const CONTEXT_ADMIN = 'admin'
 
const CONTEXT_USER = 'user'
 
const CONTEXT_TEST = 'test'
 

Static Public Attributes

static $unicode_blocks
 

Private Member Functions

 extractUnicodeBlock ($a_item='')
 Extract the unicode block name from a definition item. More...
 
 getItemCodepoint ($a_item)
 get the unicode index of an item More...
 
 getItemParsed ($a_item)
 replace unicode notations with their utf8 chars in a string More...
 
 getItemParsedCallback ($matches)
 callback for replacement of unicode notations More...
 

Private Attributes

 $context = self::CONTEXT_NONE
 
 $availability = self::INHERIT
 
 $added_blocks = array()
 
 $custom_items = array()
 

Detailed Description

Definition at line 4 of file ilCharSelectorConfig.php.

Constructor & Destructor Documentation

◆ __construct()

ilCharSelectorConfig::__construct (   $a_context = self::CONTEXT_NONE)

Constructor.

Parameters
stringcontext identifier
boolread the settings for the given context

Definition at line 284 of file ilCharSelectorConfig.php.

285  {
286  switch($a_context)
287  {
288  case self::CONTEXT_ADMIN:
289  case self::CONTEXT_TEST:
290  case self::CONTEXT_USER:
291  $this->context = $a_context;
292  break;
293  default:
294  $this->context = self::CONTEXT_NONE;
295  }
296  }

Member Function Documentation

◆ _getCurrentConfig()

static ilCharSelectorConfig::_getCurrentConfig ( ilObjTest  $a_test_obj = null)
static

Get the configuration that should be used for the current selector.

Parameters
object(optional) current running test
Returns
ilCharSelectorConfig

Definition at line 303 of file ilCharSelectorConfig.php.

References $ilSetting, and $ilUser.

Referenced by ilCharSelectorGUI\_getCurrentGUI().

304  {
305  global $ilSetting, $ilUser;
306 
307  // check configuration from administration settings
308  $admin_config = new self(self::CONTEXT_ADMIN, true);
309  $admin_config->setAvailability($ilSetting->get('char_selector_availability'));
310  $admin_config->setDefinition($ilSetting->get('char_selector_definition'));
311  if ($admin_config->getAvailability() == self::INACTIVE)
312  {
313  // a globally inactive selector can't be overwritten by users or tests
314  return $admin_config;
315  }
316 
317  // a test configuration is relevant for test runs
318  if (isset($a_test_obj))
319  {
320  $test_config = new self(self::CONTEXT_TEST, false);
321  $test_config->setAvailability($a_test_obj->getCharSelectorAvailability());
322  $test_config->setDefinition($a_test_obj->getCharSelectorDefinition());
323  if ($test_config->getAvailability() != self::INHERIT)
324  {
325  // a specific test configuration has precedence over user configuration
326  return $test_config;
327  }
328  }
329 
330  // check configuration from user settings
331  $user_config = new self(self::CONTEXT_USER, true);
332  $user_config->setAvailability($ilUser->getPref('char_selector_availability'));
333  $user_config->setDefinition($ilUser->getPref('char_selector_definition'));
334  if ($user_config->getAvailability() != self::INHERIT)
335  {
336  // take user specific config
337  return $user_config;
338  }
339  else
340  {
341  // take admin config as default
342  return $admin_config;
343  }
344  }
$ilUser
Definition: imgupload.php:18
global $ilSetting
Definition: privfeed.php:17
+ Here is the caller graph for this function:

◆ extractUnicodeBlock()

ilCharSelectorConfig::extractUnicodeBlock (   $a_item = '')
private

Extract the unicode block name from a definition item.

Parameters
stringdefinition item
Returns
string unicode block name

Definition at line 540 of file ilCharSelectorConfig.php.

References array.

Referenced by setDefinition().

541  {
542  $a_item = trim($a_item);
543  $matches = array();
544  if (preg_match('/^\[(.+)\]$/', $a_item, $matches))
545  {
546  $block_name = $matches[1];
547  if ($block_name == 'all'
548  or in_array($block_name, array_keys(self::$unicode_blocks)))
549  {
550  return $block_name;
551  }
552  }
553  return '';
554  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ getAddedBlocks()

ilCharSelectorConfig::getAddedBlocks ( )

set the added unicode blocks

Returns
array list of block names

Definition at line 408 of file ilCharSelectorConfig.php.

References $added_blocks.

409  {
410  return $this->added_blocks;
411  }

◆ getAvailability()

ilCharSelectorConfig::getAvailability ( )

get the availability of the selector

Returns
int availability

Definition at line 382 of file ilCharSelectorConfig.php.

References $availability.

383  {
384  return $this->availability;
385  }

◆ getBlockOptions()

ilCharSelectorConfig::getBlockOptions ( )

get the options for a block selection

Returns
array options

Definition at line 496 of file ilCharSelectorConfig.php.

References $lng, $options, array, and getBlockTitle().

497  {
498  global $lng;
499 
500  $options = array(
501  '' => $lng->txt('please_select'),
502  'all' => $lng->txt('char_selector_unicode_all')
503  );
504  foreach (array_keys(self::$unicode_blocks) as $block_name)
505  {
506  $options[$block_name] = $this->getBlockTitle($block_name);
507  }
508  return $options;
509  }
if(!is_array($argv)) $options
Create styles array
The data for the language used.
global $lng
Definition: privfeed.php:17
getBlockTitle($a_block_name)
Get the title of a unicode block for display or selection A translation is used if it exists...
+ Here is the call graph for this function:

◆ getBlockTitle()

ilCharSelectorConfig::getBlockTitle (   $a_block_name)

Get the title of a unicode block for display or selection A translation is used if it exists.

Parameters
stringblock name
Returns
string title

Definition at line 519 of file ilCharSelectorConfig.php.

References $lng.

Referenced by getBlockOptions(), and getCharPages().

520  {
521  global $lng;
522 
523  $langvar = 'char_selector_unicode_'. $a_block_name;
524  if ($lng->txt($langvar) != '-'.$langvar.'-' )
525  {
526  return $lng->txt($langvar);
527  }
528  else
529  {
530  return self::$unicode_blocks[$a_block_name][0];
531  }
532  }
global $lng
Definition: privfeed.php:17
+ Here is the caller graph for this function:

◆ getCharPages()

ilCharSelectorConfig::getCharPages ( )

Get the character pages.

Returns
array [["page1", "A", "BC", [123,456], ...], ["page2], "X", ...], ...]

Definition at line 562 of file ilCharSelectorConfig.php.

References $added_blocks, $lng, $start, array, getBlockTitle(), getItemCodepoint(), and getItemParsed().

563  {
564  global $lng;
565 
566  $pages = array();
567 
568  // add custom block
569  //
570  $page = array($lng->txt('char_selector_custom_items'));
571  foreach ($this->custom_items as $item)
572  {
573  if (strpos($item, '-') > 0)
574  {
575  // handle range
576  $subitems = explode('-', $item);
577  $start = $this->getItemCodepoint($subitems[0]);
578  $end = $this->getItemCodepoint($subitems[1]);
579  array_push($page, array($start, $end));
580  }
581  else
582  {
583  // handle normal item
584  array_push($page, $this->getItemParsed($item));
585  }
586  }
587  if (count($page) > 1)
588  {
589  array_push($pages, $page);
590  }
591 
592  // add unicode blocks
593  //
594  $blocks = in_array('all', $this->added_blocks) ?
595  array_keys(self::$unicode_blocks) :
596  $this->added_blocks;
597 
598  foreach ($blocks as $block_name)
599  {
600  $start = hexdec(self::$unicode_blocks[$block_name][1]);
601  $end = hexdec(self::$unicode_blocks[$block_name][2]);
602  $page = array($this->getBlockTitle($block_name), array($start, $end));
603  array_push($pages, $page);
604  }
605 
606  return $pages;
607  }
getItemCodepoint($a_item)
get the unicode index of an item
Create styles array
The data for the language used.
global $lng
Definition: privfeed.php:17
getItemParsed($a_item)
replace unicode notations with their utf8 chars in a string
getBlockTitle($a_block_name)
Get the title of a unicode block for display or selection A translation is used if it exists...
+ Here is the call graph for this function:

◆ getContext()

ilCharSelectorConfig::getContext ( )

get the context of the configuration (the context is set at initialisation and can't be changed)

Returns
string context identifier

Definition at line 352 of file ilCharSelectorConfig.php.

References $context.

353  {
354  return $this->context;
355  }

◆ getCustomItems()

ilCharSelectorConfig::getCustomItems ( )

set the custom items

Returns
array list of strings
See also
self::setDefinition() for item syntax

Definition at line 428 of file ilCharSelectorConfig.php.

429  {
430  return implode(' ', $this->custom_items);
431  }

◆ getDefinition()

ilCharSelectorConfig::getDefinition ( )

Set the definition of the available characters.

Returns
string
See also
self::setDefinition()

Definition at line 481 of file ilCharSelectorConfig.php.

482  {
483  $definition = implode(' ', $this->custom_items);
484  foreach($this->added_blocks as $block_name)
485  {
486  $definition = $definition . ' [' . $block_name . ']';
487  }
488  return trim($definition);
489  }

◆ getItemCodepoint()

ilCharSelectorConfig::getItemCodepoint (   $a_item)
private

get the unicode index of an item

Parameters
string$a_item

Definition at line 614 of file ilCharSelectorConfig.php.

References utf8ToCodepoint().

Referenced by getCharPages().

615  {
616  if (preg_match('/^[uU]\+[0-9a-fA-F]+$/', $a_item))
617  {
618  return (int) hexdec(substr($a_item, 2));
619  }
620  else
621  {
622  //take the codepoint of the first character
623  require_once "include/Unicode/UtfNormalUtil.php";
624  return (int) utf8ToCodepoint($a_item);
625  }
626  }
utf8ToCodepoint( $char)
Determine the Unicode codepoint of a single-character UTF-8 sequence.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getItemParsed()

ilCharSelectorConfig::getItemParsed (   $a_item)
private

replace unicode notations with their utf8 chars in a string

Parameters
string$a_item
Returns
string parsed string

Definition at line 633 of file ilCharSelectorConfig.php.

References array.

Referenced by getCharPages().

634  {
635  return preg_replace_callback(
636  '/[uU]\+[0-9a-fA-F]+/',
637  array($this,'getItemParsedCallback'),
638  $a_item
639  );
640  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ getItemParsedCallback()

ilCharSelectorConfig::getItemParsedCallback (   $matches)
private

callback for replacement of unicode notations

Parameters
arraypreg matches
Returns
string replacement string

Definition at line 647 of file ilCharSelectorConfig.php.

References codepointToUtf8().

648  {
649  require_once "include/Unicode/UtfNormalUtil.php";
650  return codepointToUtf8(hexdec(substr($matches[0], 2)));
651  }
codepointToUtf8( $codepoint)
Return UTF-8 sequence for a given Unicode code point.
+ Here is the call graph for this function:

◆ setAddedBlocks()

ilCharSelectorConfig::setAddedBlocks (   $a_blocks = array())

set the added unicode blocks

Parameters
arraylist of block names

Definition at line 391 of file ilCharSelectorConfig.php.

References array.

392  {
393  $this->added_blocks = array();
394  foreach ($a_blocks as $block_name)
395  {
396  if ($block_name == "all" or
397  in_array($block_name, array_keys(self::$unicode_blocks)))
398  {
399  array_push($this->added_blocks, $block_name);
400  }
401  }
402  }
Create styles array
The data for the language used.

◆ setAvailability()

ilCharSelectorConfig::setAvailability (   $a_availability)

set the availability of the selector

Parameters
intavailability

Definition at line 362 of file ilCharSelectorConfig.php.

363  {
364  switch((int) $a_availability)
365  {
366  case self::INACTIVE:
367  case self::INHERIT:
368  case self::ENABLED:
369  case self::DISABLED:
370  $this->availability = (int) $a_availability;
371  break;
372  default:
373  $this->availability = self::INHERIT;
374  }
375  }

◆ setCustomItems()

ilCharSelectorConfig::setCustomItems (   $a_items = '')

set the custom items

Parameters
arraylist of strings
See also
self::setDefinition() for item syntax

Definition at line 418 of file ilCharSelectorConfig.php.

419  {
420  $this->custom_items = explode(' ', $a_items);
421  }

◆ setDefinition()

ilCharSelectorConfig::setDefinition (   $a_definition = '')

Definition at line 449 of file ilCharSelectorConfig.php.

References array, and extractUnicodeBlock().

450  {
451  // first reset all previous settings
452  $this->added_blocks = array();
453  $this->custom_items = array();
454 
455  // set the default definition to all unicode blocks
456  if (trim($a_definition) == '')
457  {
458  $a_definition = "[all]";
459  }
460 
461  // analyze definition items
462  $items = explode(' ', $a_definition);
463  foreach ($items as $item)
464  {
465  if (strlen($block_name = $this->extractUnicodeBlock($item)))
466  {
467  array_push($this->added_blocks, $block_name);
468  }
469  else if ($item != '')
470  {
471  array_push($this->custom_items, trim($item));
472  }
473  }
474  }
extractUnicodeBlock($a_item='')
Extract the unicode block name from a definition item.
Create styles array
The data for the language used.
+ Here is the call graph for this function:

Field Documentation

◆ $added_blocks

ilCharSelectorConfig::$added_blocks = array()
private

Definition at line 271 of file ilCharSelectorConfig.php.

Referenced by getAddedBlocks(), and getCharPages().

◆ $availability

ilCharSelectorConfig::$availability = self::INHERIT
private

Definition at line 266 of file ilCharSelectorConfig.php.

Referenced by getAvailability().

◆ $context

ilCharSelectorConfig::$context = self::CONTEXT_NONE
private

Definition at line 261 of file ilCharSelectorConfig.php.

Referenced by getContext().

◆ $custom_items

ilCharSelectorConfig::$custom_items = array()
private

Definition at line 276 of file ilCharSelectorConfig.php.

◆ $unicode_blocks

ilCharSelectorConfig::$unicode_blocks
static

Definition at line 27 of file ilCharSelectorConfig.php.

◆ CONTEXT_ADMIN

◆ CONTEXT_NONE

const ilCharSelectorConfig::CONTEXT_NONE = ''

Configuration contexts.

Definition at line 18 of file ilCharSelectorConfig.php.

◆ CONTEXT_TEST

◆ CONTEXT_USER

◆ DISABLED

const ilCharSelectorConfig::DISABLED = 2

Definition at line 13 of file ilCharSelectorConfig.php.

Referenced by ilCharSelectorGUI\addFormProperties().

◆ ENABLED

◆ INACTIVE

const ilCharSelectorConfig::INACTIVE = 0

Availabilities INACTIVE/INHERIT corresponds to an unconfigured selector (no database entries)

Definition at line 10 of file ilCharSelectorConfig.php.

Referenced by ilCharSelectorGUI\addFormProperties().

◆ INHERIT

const ilCharSelectorConfig::INHERIT = 0

Definition at line 11 of file ilCharSelectorConfig.php.

Referenced by ilCharSelectorGUI\addFormProperties().


The documentation for this class was generated from the following file: