Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/kernel/kbase.php
Show First 20 Lines • Show All 260 Lines • ▼ Show 20 Line(s) | |||||
* Event, that was used to create this object | * Event, that was used to create this object | ||||
* | * | ||||
* @var kEvent | * @var kEvent | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected $parentEvent = null; | protected $parentEvent = null; | ||||
/** | /** | ||||
* Formatters cache. | |||||
* | |||||
* @var kFormatter[] | |||||
*/ | |||||
static private $_formattersCache = array(); | |||||
/** | |||||
* Sets new parent event to the object | * Sets new parent event to the object | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access public | * @access public | ||||
*/ | */ | ||||
public function setParentEvent($event) | public function setParentEvent($event) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 601 Lines • ▼ Show 20 Line(s) | |||||
*/ | */ | ||||
public function GetField($name, $format = null) | public function GetField($name, $format = null) | ||||
{ | { | ||||
$formatter_class = $this->GetFieldOption($name, 'formatter'); | $formatter_class = $this->GetFieldOption($name, 'formatter'); | ||||
if ( $formatter_class ) { | if ( $formatter_class ) { | ||||
$value = ($formatter_class == 'kMultiLanguage') && !preg_match('/^l[0-9]+_/', $name) ? '' : $this->GetDBField($name); | $value = ($formatter_class == 'kMultiLanguage') && !preg_match('/^l[0-9]+_/', $name) ? '' : $this->GetDBField($name); | ||||
/** @var kFormatter $formatter */ | return $this->getFormatter($formatter_class)->Format($value, $name, $this, $format); | ||||
$formatter = $this->Application->recallObject($formatter_class); | |||||
return $formatter->Format($value, $name, $this, $format); | |||||
} | } | ||||
return $this->GetDBField($name); | return $this->GetDBField($name); | ||||
} | } | ||||
/** | /** | ||||
* Returns unformatted field value | * Returns unformatted field value | ||||
* | * | ||||
Show All 30 Lines | |||||
public function UpdateFormattersSubFields($fields = null) | public function UpdateFormattersSubFields($fields = null) | ||||
{ | { | ||||
if ( !is_array($fields) ) { | if ( !is_array($fields) ) { | ||||
$fields = array_keys($this->Fields); | $fields = array_keys($this->Fields); | ||||
} | } | ||||
foreach ($fields as $field) { | foreach ($fields as $field) { | ||||
if ( isset($this->Fields[$field]['formatter']) ) { | if ( isset($this->Fields[$field]['formatter']) ) { | ||||
/** @var kFormatter $formatter */ | $this | ||||
$formatter = $this->Application->recallObject($this->Fields[$field]['formatter']); | ->getFormatter($this->Fields[$field]['formatter']) | ||||
->UpdateSubFields($field, $this->GetDBField($field), $this->Fields[$field], $this); | |||||
$formatter->UpdateSubFields($field, $this->GetDBField($field), $this->Fields[$field], $this); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Use formatters, specified in field declarations to perform additional field initialization in unit config | * Use formatters, specified in field declarations to perform additional field initialization in unit config | ||||
* | * | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function prepareConfigOptions() | protected function prepareConfigOptions() | ||||
{ | { | ||||
$field_names = array_keys($this->Fields); | $field_names = array_keys($this->Fields); | ||||
foreach ($field_names as $field_name) { | foreach ($field_names as $field_name) { | ||||
if ( !array_key_exists('formatter', $this->Fields[$field_name]) ) { | if ( !array_key_exists('formatter', $this->Fields[$field_name]) ) { | ||||
continue; | continue; | ||||
} | } | ||||
/** @var kFormatter $formatter */ | $this | ||||
$formatter = $this->Application->recallObject( $this->Fields[$field_name]['formatter'] ); | ->getFormatter($this->Fields[$field_name]['formatter']) | ||||
->PrepareOptions($field_name, $this->Fields[$field_name], $this); | |||||
} | |||||
} | |||||
$formatter->PrepareOptions($field_name, $this->Fields[$field_name], $this); | /** | ||||
* Returns formatter. | |||||
* | |||||
* @param string $name Name. | |||||
* | |||||
* @return kFormatter | |||||
*/ | |||||
protected function getFormatter($name) | |||||
{ | |||||
if ( !isset(self::$_formattersCache[$name]) ) { | |||||
self::$_formattersCache[$name] = $this->Application->recallObject($name); | |||||
} | } | ||||
return self::$_formattersCache[$name]; | |||||
} | } | ||||
/** | /** | ||||
* Escapes fields only, not expressions | * Escapes fields only, not expressions | ||||
* | * | ||||
* @param string $field_expr | * @param string $field_expr | ||||
* @return string | * @return string | ||||
* @access protected | * @access protected | ||||
▲ Show 20 Lines • Show All 220 Lines • Show Last 20 Lines |