ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 283 of file ilCharSelectorConfig.php.

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

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 301 of file ilCharSelectorConfig.php.

References $ilSetting, and $ilUser.

Referenced by ilCharSelectorGUI\_getCurrentGUI().

302  {
303  global $ilSetting, $ilUser;
304 
305  // check configuration from administration settings
306  $admin_config = new self(self::CONTEXT_ADMIN, true);
307  $admin_config->setAvailability($ilSetting->get('char_selector_availability'));
308  $admin_config->setDefinition($ilSetting->get('char_selector_definition'));
309  if ($admin_config->getAvailability() == self::INACTIVE) {
310  // a globally inactive selector can't be overwritten by users or tests
311  return $admin_config;
312  }
313 
314  // a test configuration is relevant for test runs
315  if (isset($a_test_obj)) {
316  $test_config = new self(self::CONTEXT_TEST, false);
317  $test_config->setAvailability($a_test_obj->getCharSelectorAvailability());
318  $test_config->setDefinition($a_test_obj->getCharSelectorDefinition());
319  if ($test_config->getAvailability() != self::INHERIT) {
320  // a specific test configuration has precedence over user configuration
321  return $test_config;
322  }
323  }
324 
325  // check configuration from user settings
326  $user_config = new self(self::CONTEXT_USER, true);
327  $user_config->setAvailability($ilUser->getPref('char_selector_availability'));
328  $user_config->setDefinition($ilUser->getPref('char_selector_definition'));
329  if ($user_config->getAvailability() != self::INHERIT) {
330  // take user specific config
331  return $user_config;
332  } else {
333  // take admin config as default
334  return $admin_config;
335  }
336  }
$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 519 of file ilCharSelectorConfig.php.

References array.

Referenced by setDefinition().

520  {
521  $a_item = trim($a_item);
522  $matches = array();
523  if (preg_match('/^\[(.+)\]$/', $a_item, $matches)) {
524  $block_name = $matches[1];
525  if ($block_name == 'all'
526  or in_array($block_name, array_keys(self::$unicode_blocks))) {
527  return $block_name;
528  }
529  }
530  return '';
531  }
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 397 of file ilCharSelectorConfig.php.

References $added_blocks.

398  {
399  return $this->added_blocks;
400  }

◆ getAvailability()

ilCharSelectorConfig::getAvailability ( )

get the availability of the selector

Returns
int availability

Definition at line 373 of file ilCharSelectorConfig.php.

References $availability.

374  {
375  return $this->availability;
376  }

◆ getBlockOptions()

ilCharSelectorConfig::getBlockOptions ( )

get the options for a block selection

Returns
array options

Definition at line 479 of file ilCharSelectorConfig.php.

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

480  {
481  global $lng;
482 
483  $options = array(
484  '' => $lng->txt('please_select'),
485  'all' => $lng->txt('char_selector_unicode_all')
486  );
487  foreach (array_keys(self::$unicode_blocks) as $block_name) {
488  $options[$block_name] = $this->getBlockTitle($block_name);
489  }
490  return $options;
491  }
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...
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
+ 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 501 of file ilCharSelectorConfig.php.

References $lng.

Referenced by getBlockOptions(), and getCharPages().

502  {
503  global $lng;
504 
505  $langvar = 'char_selector_unicode_' . $a_block_name;
506  if ($lng->txt($langvar) != '-' . $langvar . '-') {
507  return $lng->txt($langvar);
508  } else {
509  return self::$unicode_blocks[$a_block_name][0];
510  }
511  }
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 539 of file ilCharSelectorConfig.php.

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

540  {
541  global $lng;
542 
543  $pages = array();
544 
545  // add custom block
546  //
547  $page = array($lng->txt('char_selector_custom_items'));
548  foreach ($this->custom_items as $item) {
549  if (strpos($item, '-') > 0) {
550  // handle range
551  $subitems = explode('-', $item);
552  $start = $this->getItemCodepoint($subitems[0]);
553  $end = $this->getItemCodepoint($subitems[1]);
554  array_push($page, array($start, $end));
555  } else {
556  // handle normal item
557  array_push($page, $this->getItemParsed($item));
558  }
559  }
560  if (count($page) > 1) {
561  array_push($pages, $page);
562  }
563 
564  // add unicode blocks
565  //
566  $blocks = in_array('all', $this->added_blocks) ?
567  array_keys(self::$unicode_blocks) :
568  $this->added_blocks;
569 
570  foreach ($blocks as $block_name) {
571  $start = hexdec(self::$unicode_blocks[$block_name][1]);
572  $end = hexdec(self::$unicode_blocks[$block_name][2]);
573  $page = array($this->getBlockTitle($block_name), array($start, $end));
574  array_push($pages, $page);
575  }
576 
577  return $pages;
578  }
$end
Definition: saml1-acs.php:18
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 344 of file ilCharSelectorConfig.php.

References $context.

345  {
346  return $this->context;
347  }

◆ getCustomItems()

ilCharSelectorConfig::getCustomItems ( )

set the custom items

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

Definition at line 417 of file ilCharSelectorConfig.php.

418  {
419  return implode(' ', $this->custom_items);
420  }

◆ getDefinition()

ilCharSelectorConfig::getDefinition ( )

Set the definition of the available characters.

Returns
string
See also
self::setDefinition()

Definition at line 465 of file ilCharSelectorConfig.php.

466  {
467  $definition = implode(' ', $this->custom_items);
468  foreach ($this->added_blocks as $block_name) {
469  $definition = $definition . ' [' . $block_name . ']';
470  }
471  return trim($definition);
472  }

◆ getItemCodepoint()

ilCharSelectorConfig::getItemCodepoint (   $a_item)
private

get the unicode index of an item

Parameters
string$a_item

Definition at line 585 of file ilCharSelectorConfig.php.

References utf8ToCodepoint().

Referenced by getCharPages().

586  {
587  if (preg_match('/^[uU]\+[0-9a-fA-F]+$/', $a_item)) {
588  return (int) hexdec(substr($a_item, 2));
589  } else {
590  //take the codepoint of the first character
591  require_once "include/Unicode/UtfNormalUtil.php";
592  return (int) utf8ToCodepoint($a_item);
593  }
594  }
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 601 of file ilCharSelectorConfig.php.

References array.

Referenced by getCharPages().

602  {
603  return preg_replace_callback(
604  '/[uU]\+[0-9a-fA-F]+/',
605  array($this,'getItemParsedCallback'),
606  $a_item
607  );
608  }
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 615 of file ilCharSelectorConfig.php.

References codepointToUtf8().

616  {
617  require_once "include/Unicode/UtfNormalUtil.php";
618  return codepointToUtf8(hexdec(substr($matches[0], 2)));
619  }
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 382 of file ilCharSelectorConfig.php.

References array.

383  {
384  $this->added_blocks = array();
385  foreach ($a_blocks as $block_name) {
386  if ($block_name == "all" or
387  in_array($block_name, array_keys(self::$unicode_blocks))) {
388  array_push($this->added_blocks, $block_name);
389  }
390  }
391  }
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 354 of file ilCharSelectorConfig.php.

355  {
356  switch ((int) $a_availability) {
357  case self::INACTIVE:
358  case self::INHERIT:
359  case self::ENABLED:
360  case self::DISABLED:
361  $this->availability = (int) $a_availability;
362  break;
363  default:
364  $this->availability = self::INHERIT;
365  }
366  }

◆ setCustomItems()

ilCharSelectorConfig::setCustomItems (   $a_items = '')

set the custom items

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

Definition at line 407 of file ilCharSelectorConfig.php.

408  {
409  $this->custom_items = explode(' ', $a_items);
410  }

◆ setDefinition()

ilCharSelectorConfig::setDefinition (   $a_definition = '')

Definition at line 438 of file ilCharSelectorConfig.php.

References array, and extractUnicodeBlock().

439  {
440  // first reset all previous settings
441  $this->added_blocks = array();
442  $this->custom_items = array();
443 
444  // set the default definition to all unicode blocks
445  if (trim($a_definition) == '') {
446  $a_definition = "[all]";
447  }
448 
449  // analyze definition items
450  $items = explode(' ', $a_definition);
451  foreach ($items as $item) {
452  if (strlen($block_name = $this->extractUnicodeBlock($item))) {
453  array_push($this->added_blocks, $block_name);
454  } elseif ($item != '') {
455  array_push($this->custom_items, trim($item));
456  }
457  }
458  }
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 270 of file ilCharSelectorConfig.php.

Referenced by getAddedBlocks(), and getCharPages().

◆ $availability

ilCharSelectorConfig::$availability = self::INHERIT
private

Definition at line 265 of file ilCharSelectorConfig.php.

Referenced by getAvailability().

◆ $context

ilCharSelectorConfig::$context = self::CONTEXT_NONE
private

Definition at line 260 of file ilCharSelectorConfig.php.

Referenced by getContext().

◆ $custom_items

ilCharSelectorConfig::$custom_items = array()
private

Definition at line 275 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: