GetContentEncoding() != null)
AddStr($headerString, 'charset=' . $page->GetContentEncoding(), ';');
header($headerString);
}
protected function Captions() {
return $this->captions;
}
/**
* @return Captions
*/
public function GetCaptions() {
return $this->captions;
}
private function CreateSmatryObject() {
$result = new Smarty();
$result->template_dir = 'components/templates';
return $result;
}
public function __construct($captions) {
$this->captions = $captions;
}
#region Rendering
public function DisplayTemplate($TemplateName, $InputObjects, $InputValues) {
$smarty = $this->CreateSmatryObject();
foreach($InputObjects as $ObjectName => &$Object)
$smarty->assign_by_ref($ObjectName, $Object);
$smarty->assign_by_ref('Renderer', $this);
$smarty->assign_by_ref('Captions', $this->captions);
$smarty->assign('RenderScripts', $this->renderScripts);
$smarty->assign('RenderText', $this->renderText);
if (isset($this->additionalParams))
{
foreach($this->additionalParams as $ValueName => $Value)
{
$smarty->assign($ValueName, $Value);
}
}
foreach($InputValues as $ValueName => $Value)
$smarty->assign($ValueName, $Value);
$this->result = $smarty->fetch($TemplateName);
}
public function Render($Object, $renderScripts = true, $renderText = true, $additionalParams = null) {
$oldRenderScripts = $this->renderScripts;
$oldRenderText = $this->renderText;
$oldAdditionalParams = $this->additionalParams;
$this->renderScripts = $renderScripts;
$this->renderText = $renderText;
$this->additionalParams = array();
if (isset($additionalParams))
$this->additionalParams = $additionalParams;
if (defined('SHOW_VARIABLES') && ($Object instanceof IVariableContainer)) {
$this->additionalParams['Variables'] = $this->RenderVariableContainer($Object);
}
$Object->Accept($this);
$this->renderScripts = $oldRenderScripts;
$this->renderText = $oldRenderText;
$this->additionalParams = $oldAdditionalParams;
return $this->result;
}
public function RenderDef($object, $default = '', $additionalParams = null) {
if (isset($object))
return $this->Render($object, true, true, $additionalParams);
else
return $default;
}
#endregion
#region Editors
private function RenderEditor(CustomEditor $editor, $nameInTemplate, $templateFile, $additionalParams = array()) {
$validatorsInfo = array();
$validatorsInfo['InputAttributes'] = $editor->GetValidationAttributes();
$validatorsInfo['InputAttributes'] .= StringUtils::Format(
' data-legacy-field-name="%s" data-pgui-legacy-validate="true"',
$editor->GetFieldName()
);
$this->DisplayTemplate(
Path::Combine('editors', $templateFile),
array($nameInTemplate => $editor),
array_merge(
array(
'Validators' => $validatorsInfo,
($nameInTemplate == 'Editor' ? 'EditControl' : 'Editor') => $editor->GetViewData()
),
$additionalParams
));
}
public function RenderTimeEdit(TimeEdit $editor)
{
$this->RenderEditor($editor, 'Editor', 'time_edit.tpl');
}
public function RenderMaskedEdit(MaskedEdit $editor)
{
$this->RenderEditor($editor, 'Editor', 'masked_edit.tpl');
}
public function RenderMultiLevelComboBoxEditor(MultiLevelComboBoxEditor $editor)
{
$params = array();
$editors = array();
foreach($editor->GetLevels() as $level)
{
$editorInfo = array();
$editorInfo['Name'] = $level->GetName();
$editorInfo['DataURL'] = $level->GetDataUrl();
$editorInfo['ParentEditor'] = $level->GetParentEditor();
$editorInfo['DisplayValue'] = $level->GetDisplayValue();
$editorInfo['Value'] = $level->GetValue();
$editorInfo['Caption'] = $level->GetCaption();
$editors[] = $editorInfo;
}
$params['Editors'] = $editors;
$this->RenderEditor($editor, 'MultilevelEditor', 'multilevel_selection.tpl', $params);
}
public final function RenderAutocompleteComboBox(AutocomleteComboBox $comboBox)
{
$this->RenderEditor($comboBox, 'ComboBox', 'autocomplete_combo_box.tpl');
}
public final function RenderCheckBox(CheckBox $checkBox)
{
$this->RenderEditor($checkBox, 'CheckBox', 'check_box.tpl');
}
public final function RenderCheckBoxGroup(CheckBoxGroup $checkBoxGroup)
{
$this->RenderEditor($checkBoxGroup, 'CheckBoxGroup', 'check_box_group.tpl');
}
public final function RenderComboBox(ComboBox $comboBox)
{
$this->RenderEditor($comboBox, 'ComboBox', 'combo_box.tpl');
}
public final function RenderDateTimeEdit(DateTimeEdit $dateTimeEdit)
{
$this->RenderEditor($dateTimeEdit, 'DateTimeEdit', 'datetime_edit.tpl');
}
public final function RenderHtmlWysiwygEditor(HtmlWysiwygEditor $editor)
{
$this->RenderEditor($editor, 'Editor', 'html_wysiwyg_editor.tpl');
}
protected function ForceHideImageUploaderImage()
{
return false;
}
public final function RenderImageUploader(ImageUploader $imageUploader)
{
$this->RenderEditor($imageUploader, 'Uploader', 'image_uploader.tpl',
array('HideImage' => $this->ForceHideImageUploaderImage()));
}
public final function RenderRadioEdit(RadioEdit $radioEdit)
{
$this->RenderEditor($radioEdit, 'RadioEdit', 'radio_edit.tpl');
}
public final function RenderSpinEdit(SpinEdit $spinEdit)
{
$this->RenderEditor($spinEdit, 'SpinEdit', 'spin_edit.tpl');
}
public final function RenderTextEdit(TextEdit $textEdit)
{
$this->RenderEditor($textEdit, 'TextEdit', 'text_edit.tpl');
}
public final function RenderTextAreaEdit(TextAreaEdit $textArea)
{
$this->RenderEditor($textArea, 'TextArea', 'textarea.tpl');
}
#endregion
#region HTML Components
public function RenderComponent($Component) {
$this->result = '';
}
public function RenderTextBox($textBox) {
$this->result = $textBox->GetCaption();
}
public function RenderImage($Image) {
$this->DisplayTemplate('image.tpl',
array('Image' => $Image),
array());
}
public function RenderCustomHtmlControl($control) {
$this->result = $control->GetHtml();
}
/**
* @param Hyperlink $hyperLink
*/
public function RenderHyperLink($hyperLink) {
$this->result = sprintf('%s%s', $hyperLink->GetLink(), $hyperLink->GetInnerText(), $hyperLink->GetAfterLinkText());
}
public function RenderHintedTextBox($textBox) {
$this->DisplayTemplate('hinted_text_box.tpl',
array('TextBox' => $textBox),
array());
}
#endregion
#region Variables
public function GetPageVariables(Page $page) {
if (defined('SHOW_VARIABLES'))
{
$this->RenderVariableContainer(
$page->GetColumnVariableContainer()
);
$variables = $this->result;
}
else
{
$variables = '';
}
return $variables;
}
public function RenderVariableContainer(IVariableContainer $variableContainer) {
$values = array();
$variableContainer->FillVariablesValues($values);
$this->DisplayTemplate('variables_container.tpl',
array(),
array('Variables' => $values)
);
}
#endregion
#region Columns
private function GetNullValuePresentation($column) {
if ($this->ShowHtmlNullValue())
return StringUtils::Format('%s', $this->GetCaptions()->GetMessageString('NullAsString')) ;
else
return '';
}
/**
* @param CustomViewColumn $column
* @return void
*/
public final function RenderCustomViewColumn(CustomViewColumn $column) {
$this->result = $column->GetValue();
}
protected function GetFriendlyColumnName(CustomViewColumn $column) {
return $column->GetGrid()->GetDataset()->IsLookupField($column->GetName()) ?
$column->GetGrid()->GetDataset()->IsLookupFieldNameByDisplayFieldName($column->GetName()) :
$column->GetName();
}
/**
* @param CustomViewColumn $column
* @param array $rowValues
* @return string
*/
protected function GetCustomRenderedViewColumn(CustomViewColumn $column, $rowValues) {
return null;
}
/**
* @param \CustomViewColumn $column
* @param array $rowValues
* @return string
*/
public final function RenderViewColumn(CustomViewColumn $column, $rowValues)
{
$customValue = $this->GetCustomRenderedViewColumn($column, $rowValues);
if (isset($customValue))
return $column->GetGrid()->GetPage()->RenderText($customValue);
else
return $this->Render($column);
}
public final function RenderCustomDatasetFieldViewColumn(CustomDatasetFieldViewColumn $column)
{
$value = $column->GetValue();
if (!isset($value))
$this->result = $this->GetNullValuePresentation($column);
else
$this->result = $value;
}
/**
* @param TextViewColumn $column
*/
public function RenderTextViewColumn($column)
{
$value = $column->GetValue();
$dataset = $column->GetDataset();
$column->BeforeColumnRender->Fire(array(&$value, &$dataset));
if (!isset($value))
{
$this->result = $this->GetNullValuePresentation($column);
}
else
{
if ($column->GetEscapeHTMLSpecialChars())
$value = htmlspecialchars($value);
$columnMaxLength = $column->GetMaxLength();
if ($this->HttpHandlersAvailable() &&
$this->ChildPagesAvailable() &&
isset($columnMaxLength) &&
isset($value) &&
strlen($value) > $columnMaxLength)
{
$originalValue = $value;
if ($this->HtmlMarkupAvailable() && $column->GetReplaceLFByBR())
$originalValue = str_replace("\n", "
", $originalValue);
$value = StringUtils::SubString($value, 0, $columnMaxLength, $column->GetGrid()->GetPage()->GetContentEncoding());
$value .=
'... GetMoreLink() . '\'; return false;">' . $this->captions->GetMessageString('more') .
'';
$value .=
'
", $value);
$this->result = $value;
}
}
public function RenderCheckBoxViewColumn($column)
{
$value = $column->GetInnerField()->GetData();
if (!isset($value))
$this->result = $this->Render($column->GetInnerField());
else if (empty($value))
{
if ($this->HtmlMarkupAvailable())
$this->result = $column->GetFalseValue();
else
$this->result = 'false';
}
else
{
if ($this->HtmlMarkupAvailable())
$this->result = $column->GetTrueValue();
else
$this->result = 'true';
}
}
public function RenderDivTagViewColumnDecorator($column)
{
if ($this->HtmlMarkupAvailable())
{
$styles = '';
$styleBuilder = new StyleBuilder();
if (isset($column->Bold))
$styleBuilder->Add('font-weight', ($column->Bold ? 'bold' : 'normal'));
if (isset($column->Italic))
$styleBuilder->Add('font-style', ($column->Italic ? 'italic' : 'normal'));
$this->result = '