/** * This function returns the HtmlElements to display for 1:n relations * * @todo this only works with single valued identifiers * @param array $assocMapping Mapping information for this relation * @param string $entityClass FQCN of the foreign entity * @param int $entityId ID of the local entity * @return array Set of \Cx\Core\Html\Model\Entity\HtmlElement instances */ protected function getIdentifyingDisplayValue($assocMapping, $entityClass, $entityId) { global $_CORELANG; $localEntityMetadata = \Env::get('em')->getClassMetadata($this->entityClass); $localEntityIdentifierField = $localEntityMetadata->getSingleIdentifierFieldName(); $localEntityRepo = \Env::get('em')->getRepository($this->entityClass); $localEntity = $localEntityRepo->find($entityId); if (!$localEntity) { throw new \Exception('Entity not found'); } $foreignEntityGetter = 'get' . preg_replace('/_([a-z])/', '\\1', ucfirst($assocMapping["fieldName"])); $foreignEntities = $localEntity->{$foreignEntityGetter}(); $htmlElements = array(); foreach ($foreignEntities as $index => $foreignEntity) { // entity base implements __toString() $displayValue = (string) $foreignEntity; $foreignEntityMetadata = \Env::get('em')->getClassMetadata(get_class($foreignEntity)); $foreignEntityIdentifierField = $foreignEntityMetadata->getSingleIdentifierFieldName(); $entityValueSerialized = 'vg_increment_number=' . $this->formId; $fieldsToParse = $foreignEntityMetadata->fieldNames; foreach ($fieldsToParse as $dbColName => $fieldName) { $entityValueSerialized .= '&' . $fieldName . '=' . $this->getDataElementValueAsString($foreignEntityMetadata->getFieldValue($foreignEntity, $fieldName)); } // add relations foreach ($foreignEntityMetadata->associationMappings as $foreignAssocMapping) { if (!$foreignAssocMapping['isOwningSide']) { continue; } $joinColumns = reset($foreignAssocMapping['joinColumns']); // if the association is a backreference to our main entity we skip it if ($foreignAssocMapping['targetEntity'] == $this->entityClass && $joinColumns['referencedColumnName'] == $localEntityIdentifierField) { continue; } $foreignForeignEntity = $foreignEntityMetadata->getFieldValue($foreignEntity, $foreignAssocMapping['fieldName']); if (!$foreignForeignEntity) { continue; } $foreignEntityIdentifierGetter = 'get' . preg_replace('/_([a-z])/', '\\1', ucfirst($foreignEntityIdentifierField)); $entityValueSerialized .= '&' . $foreignAssocMapping['fieldName'] . '=' . $foreignForeignEntity->{$foreignEntityIdentifierGetter}(); } $sorroundingDiv = new \Cx\Core\Html\Model\Entity\HtmlElement('div'); $sorroundingDiv->setAttribute('class', 'oneToManyEntryRow'); $displaySpan = new \Cx\Core\Html\Model\Entity\HtmlElement('span'); $displaySpan->addChild(new \Cx\Core\Html\Model\Entity\TextElement($displayValue)); $displaySpan->allowDirectClose(false); $hiddenInput = new \Cx\Core\Html\Model\Entity\DataElement('input'); $hiddenInput->setAttributes(array('type' => 'hidden', 'name' => $this->createCssClassNameFromEntity($entityClass) . '[]', 'value' => $entityValueSerialized)); $editLink = new \Cx\Core\Html\Model\Entity\HtmlElement('a'); $editLink->setAttributes(array('class' => 'edit', 'title' => $_CORELANG['TXT_EDIT'])); $editLink->allowDirectClose(false); $deleteLink = new \Cx\Core\Html\Model\Entity\HtmlElement('a'); $deleteLink->setAttributes(array('onclick' => 'deleteAssociationMappingEntry(this)', 'class' => 'remove existing', 'title' => $_CORELANG['TXT_DELETE'])); $deleteLink->allowDirectClose(false); $sorroundingDiv->addChild($displaySpan); $sorroundingDiv->addChild($hiddenInput); $sorroundingDiv->addChild($editLink); $sorroundingDiv->addChild($deleteLink); $htmlElements[] = $sorroundingDiv; } return $htmlElements; }
/** * Returs a string representing the complete paging HTML code for the * current page * @author Reto Kohli <*****@*****.**> (Rewritten statically) * @access public * @global array $_CONFIG Configuration * @global array $_CORELANG Core language * @param string $uri_parameter Optional additional URI parameters, * *MUST* start with an URI encoded * ampersand (&). By reference * @param string $paging_text The text to be put in front of the * paging * @param integer $numof_rows The number of rows available * @param integer $results_per_page The optional maximum number of * rows to be shown on a single page. * Defaults to the corePagingLimit * setting. * @param boolean $showeverytime If true, the paging is shown even if * $numof_rows is less than * $results_per_page * @param integer $position The optional starting position * offset. Defaults to null * @param string $parameter_name The optional name for the URI * parameter. Will be determined * automatically if empty. * @return string HTML code for the paging */ static function get(&$uri_parameter, $paging_text, $numof_rows, $results_per_page = 0, $showeverytime = false, $position = null, $parameter_name = null) { global $_CONFIG, $_CORELANG; $headIncludes = array(); if (empty($results_per_page)) { $results_per_page = intval($_CONFIG['corePagingLimit']); } if ($numof_rows <= $results_per_page && !$showeverytime) { return ''; } $parameter_name = self::getParametername($parameter_name); if (!isset($position)) { $position = self::getPosition($parameter_name); } // Fix illegal values: // The position must be in the range [0 .. numof_rows - 1]. // If it's outside this range, reset it if ($position < 0 || $position >= $numof_rows) { $position = 0; } // Total number of pages: [1 .. n] $numof_pages = ceil($numof_rows / $results_per_page); // Current page number: [1 .. numof_pages] $page_number = 1 + intval($position / $results_per_page); $corr_value = $results_per_page; if ($numof_rows % $results_per_page) { $corr_value = $numof_rows % $results_per_page; } // remove all parameters otherwise the url object has parameters like &act=add $requestUrl = clone \Env::get('Resolver')->getUrl(); $currentParams = $requestUrl->getParamArray(); $requestUrl->removeAllParams(); if (isset($currentParams['section'])) { $requestUrl->setParam('section', $currentParams['section']); } $requestUrl->setParams($uri_parameter); $firstUrl = clone $requestUrl; $firstUrl->setParam($parameter_name, 0); $lastUrl = clone $requestUrl; $lastUrl->setParam($parameter_name, $numof_rows - $corr_value); // Set up the base navigation entries $array_paging = array('first' => '<a class="pagingFirst" href="' . Cx\Core\Routing\Url::encode_amp($firstUrl) . '" rel="nofollow">', 'last' => '<a class="pagingLast" href="' . Cx\Core\Routing\Url::encode_amp($lastUrl) . '" rel="nofollow">', 'total' => $numof_rows, 'lower' => $numof_rows ? $position + 1 : 0, 'upper' => $numof_rows); if ($position + $results_per_page < $numof_rows) { $array_paging['upper'] = $position + $results_per_page; } // Note: previous/next link are currently unused. if ($position != 0) { $previousUrl = clone $requestUrl; $previousUrl->setParam($parameter_name, $position - $results_per_page); $array_paging['previous_link'] = '<a href="' . Cx\Core\Routing\Url::encode_amp($previousUrl) . '">'; $link = new \Cx\Core\Html\Model\Entity\HtmlElement('link'); $link->setAttribute('href', $previousUrl->toString()); $link->setAttribute('rel', 'prev'); $headIncludes[] = $link; } if ($numof_rows - $position > $results_per_page) { $int_new_position = $position + $results_per_page; $nextUrl = clone $requestUrl; $nextUrl->setParam($parameter_name, $int_new_position); $array_paging['next_link'] = '<a href="' . Cx\Core\Routing\Url::encode_amp($nextUrl) . '">'; $link = new \Cx\Core\Html\Model\Entity\HtmlElement('link'); $link->setAttribute('href', $nextUrl->toString()); $link->setAttribute('rel', 'next'); $headIncludes[] = $link; } // TODO: This is a temporary solution for setting HEAD_INCLUDES. // The proper and correct way will by handled by the // upcoming implementation of the response object. if ($headIncludes) { \Cx\Core\Core\Controller\Cx::instanciate()->getTemplate()->setVariable('HEAD_INCLUDES', join("\n", $headIncludes)); } // Add single pages, indexed by page numbers [1 .. numof_pages] for ($i = 1; $i <= $numof_pages; ++$i) { if ($i == $page_number) { $array_paging[$i] = '<b class="pagingPage' . $i . '">' . $i . '</b>'; } else { $pageUrl = clone $requestUrl; $pageUrl->setParam($parameter_name, ($i - 1) * $results_per_page); $array_paging[$i] = '<a class="pagingPage' . $i . '" href="' . Cx\Core\Routing\Url::encode_amp($pageUrl) . '">' . $i . '</a>'; } } $paging = $paging_text . ' <span class="pagingLower">' . $array_paging['lower'] . '</span> ' . $_CORELANG['TXT_TO'] . ' <span class="pagingUpper">' . $array_paging['upper'] . '</span> ' . $_CORELANG['TXT_FROM'] . ' <span class="pagingTotal">' . $array_paging['total'] . '</span>'; if ($numof_pages) { $paging .= ' [ ' . $array_paging['first'] . '<<</a> ' . '<span class="pagingPages">'; } if ($page_number > 3) { $paging .= $array_paging[$page_number - 3] . ' '; } if ($page_number > 2) { $paging .= $array_paging[$page_number - 2] . ' '; } if ($page_number > 1) { $paging .= $array_paging[$page_number - 1] . ' '; } if ($numof_pages) { $paging .= $array_paging[$page_number] . ' '; } if ($page_number < $numof_pages - 0) { $paging .= $array_paging[$page_number + 1] . ' '; } if ($page_number < $numof_pages - 1) { $paging .= $array_paging[$page_number + 2] . ' '; } if ($page_number < $numof_pages - 2) { $paging .= $array_paging[$page_number + 3] . ' '; } if ($numof_pages) { $paging .= '</span> ' . $array_paging['last'] . '>></a> ]'; } return $paging; }
public function getDataElement($name, $type, $length, $value, $options) { global $_ARRAYLANG; if (isset($options['formfield']) && is_callable($options['formfield'])) { $formFieldGenerator = $options['formfield']; $formField = $formFieldGenerator($name, $type, $length, $value, $options); if (is_a($formField, 'Cx\\Core\\Html\\Model\\Entity\\HtmlElement')) { return $formField; } else { $value = $formField; } } if (isset($options['showDetail']) && $options['showDetail'] === false) { return ''; } switch ($type) { case 'bool': case 'boolean': // yes/no checkboxes $fieldset = new \Cx\Core\Html\Model\Entity\HtmlElement('div'); $inputYes = new \Cx\Core\Html\Model\Entity\DataElement($name, 'yes'); $inputYes->setAttribute('type', 'radio'); $inputYes->setAttribute('value', '1'); $inputYes->setAttribute('id', 'form-' . $this->formId . '-' . $name . '_yes'); if (isset($options['attributes'])) { $inputYes->setAttributes($options['attributes']); } $fieldset->addChild($inputYes); $labelYes = new \Cx\Core\Html\Model\Entity\HtmlElement('label'); $labelYes->setAttribute('for', 'form-' . $this->formId . '-' . $name . '_yes'); $labelYes->addChild(new \Cx\Core\Html\Model\Entity\TextElement($_ARRAYLANG['TXT_YES'])); $fieldset->addChild($labelYes); $inputNo = new \Cx\Core\Html\Model\Entity\DataElement($name, 'no'); $inputNo->setAttribute('id', 'form-' . $this->formId . '-' . $name . '_no'); $inputNo->setAttribute('type', 'radio'); $inputNo->setAttribute('value', '0'); if (isset($options['attributes'])) { $inputNo->setAttributes($options['attributes']); } $fieldset->addChild($inputNo); $labelNo = new \Cx\Core\Html\Model\Entity\HtmlElement('label'); $labelNo->setAttribute('for', 'form-' . $this->formId . '-' . $name . '_no'); $labelNo->addChild(new \Cx\Core\Html\Model\Entity\TextElement($_ARRAYLANG['TXT_NO'])); $fieldset->addChild($labelNo); if ($value) { $inputYes->setAttribute('checked'); } else { $inputNo->setAttribute('checked'); } return $fieldset; break; case 'int': case 'integer': // input field with type number $inputNumber = new \Cx\Core\Html\Model\Entity\DataElement($name, $value, \Cx\Core\Html\Model\Entity\DataElement::TYPE_INPUT, new \Cx\Core\Validate\Model\Entity\RegexValidator('/-?[0-9]*/')); if (isset($options['attributes'])) { $inputNumber->setAttributes($options['attributes']); } $inputNumber->setAttribute('type', 'number'); return $inputNumber; break; case 'Cx\\Model\\Base\\EntityBase': $entityClass = get_class($value); $entities = \Env::get('em')->getRepository($entityClass)->findAll(); $foreignMetaData = \Env::get('em')->getClassMetadata($entityClass); $primaryKeyName = $foreignMetaData->getSingleIdentifierFieldName(); $selected = $foreignMetaData->getFieldValue($value, $primaryKeyName); $arrEntities = array(); $closeMetaData = \Env::get('em')->getClassMetadata($this->entityClass); $assocMapping = $closeMetaData->getAssociationMapping($name); if (!isset($assocMapping['joinColumns'][0]['nullable']) || $assocMapping['joinColumns'][0]['nullable']) { $arrEntities['NULL'] = $_ARRAYLANG['TXT_CORE_NONE']; } foreach ($entities as $entity) { $arrEntities[\Env::get('em')->getClassMetadata($entityClass)->getFieldValue($entity, $primaryKeyName)] = $entity; } $select = new \Cx\Core\Html\Model\Entity\DataElement($name, \Html::getOptions($arrEntities, $selected), \Cx\Core\Html\Model\Entity\DataElement::TYPE_SELECT); if (isset($options['attributes'])) { $select->setAttributes($options['attributes']); } return $select; break; case 'Country': // this is for customizing only: $data = \Cx\Core\Country\Controller\Country::getNameById($value); if (empty($data)) { $value = 204; } $options = \Cx\Core\Country\Controller\Country::getMenuoptions($value); $select = new \Cx\Core\Html\Model\Entity\DataElement($name, $options, \Cx\Core\Html\Model\Entity\DataElement::TYPE_SELECT); if (isset($options['attributes'])) { $select->setAttributes($options['attributes']); } return $select; break; case 'DateTime': case 'datetime': case 'date': // input field with type text and class datepicker if ($value instanceof \DateTime) { $value = $value->format(ASCMS_DATE_FORMAT); } if (is_null($value)) { $value = ''; } $input = new \Cx\Core\Html\Model\Entity\DataElement($name, $value); $input->setAttribute('type', 'text'); $input->setAttribute('class', 'datepicker'); if (isset($options['readonly']) && $options['readonly']) { $input->setAttribute('disabled'); } if (isset($options['attributes'])) { $input->setAttributes($options['attributes']); } \DateTimeTools::addDatepickerJs(); \JS::registerCode(' cx.jQuery(function() { cx.jQuery(".datepicker").datetimepicker(); }); '); return $input; break; case 'multiselect': case 'select': $values = array(); if (isset($options['validValues'])) { if (is_array($options['validValues'])) { $values = $options['validValues']; } else { $values = explode(',', $options['validValues']); $values = array_combine($values, $values); } } if ($type == 'multiselect') { $value = explode(',', $value); $value = array_combine($value, $value); } $selectOptions = \Html::getOptions($values, $value); $select = new \Cx\Core\Html\Model\Entity\DataElement($name, $selectOptions, \Cx\Core\Html\Model\Entity\DataElement::TYPE_SELECT); if ($type == 'multiselect') { $select->setAttribute('multiple'); } if (isset($options['attributes'])) { $select->setAttributes($options['attributes']); } return $select; break; case 'slider': // this code should not be here // create sorrounding div $element = new \Cx\Core\Html\Model\Entity\HtmlElement('div'); // create div for slider $slider = new \Cx\Core\Html\Model\Entity\HtmlElement('div'); $slider->setAttribute('class', 'slider'); $element->addChild($slider); // create hidden input for slider value $input = new \Cx\Core\Html\Model\Entity\DataElement($name, $value + 0, \Cx\Core\Html\Model\Entity\DataElement::TYPE_INPUT); $input->setAttribute('type', 'hidden'); if (isset($options['attributes'])) { $input->setAttributes($options['attributes']); } $element->addChild($input); // add javascript to update input value $min = 0; $max = 10; if (isset($options['validValues'])) { $values = explode(',', $options['validValues']); $min = $values[0]; if (isset($values[1])) { $max = $values[1]; } } if (!isset($value)) { $value = 0; } $script = new \Cx\Core\Html\Model\Entity\HtmlElement('script'); $script->addChild(new \Cx\Core\Html\Model\Entity\TextElement(' cx.jQuery("#form-' . $this->formId . '-' . $name . ' .slider").slider({ value: ' . ($value + 0) . ', min: ' . ($min + 0) . ', max: ' . ($max + 0) . ', slide: function( event, ui ) { cx.jQuery("input[name=' . $name . ']").val(ui.value); cx.jQuery("input[name=' . $name . ']").change(); } }); ')); $element->addChild($script); return $element; break; case 'checkboxes': $dataElementGroupType = \Cx\Core\Html\Model\Entity\DataElementGroup::TYPE_CHECKBOX; case 'radio': $values = array(); if (isset($options['validValues'])) { $values = explode(',', $options['validValues']); $values = array_combine($values, $values); } if (!isset($dataElementGroupType)) { $dataElementGroupType = \Cx\Core\Html\Model\Entity\DataElementGroup::TYPE_RADIO; } $radio = new \Cx\Core\Html\Model\Entity\DataElementGroup($name, $values, $value, $dataElementGroupType); if (isset($options['attributes'])) { $radio->setAttributes($options['attributes']); } return $radio; break; case 'text': // textarea $textarea = new \Cx\Core\Html\Model\Entity\HtmlElement('textarea'); $textarea->setAttribute('name', $name); if (isset($options['readonly']) && $options['readonly']) { $textarea->setAttribute('disabled'); } $textarea->addChild(new \Cx\Core\Html\Model\Entity\TextElement($value)); if (isset($options['attributes'])) { $textarea->setAttributes($options['attributes']); } return $textarea; break; case 'phone': // input field with type phone $input = new \Cx\Core\Html\Model\Entity\DataElement($name, $value); $input->setAttribute('type', 'phone'); if (isset($options['readonly']) && $options['readonly']) { $input->setAttribute('disabled'); } if (isset($options['attributes'])) { $input->setAttributes($options['attributes']); } return $input; break; case 'mail': // input field with type mail $emailValidator = new \Cx\Core\Validate\Model\Entity\EmailValidator(); $input = new \Cx\Core\Html\Model\Entity\DataElement($name, $value, 'input', $emailValidator); $input->setAttribute('onkeyup', $emailValidator->getJavaScriptCode()); $input->setAttribute('type', 'mail'); if (isset($options['attributes'])) { $input->setAttributes($options['attributes']); } if (isset($options['readonly']) && $options['readonly']) { $input->setAttribute('disabled'); } return $input; break; case 'uploader': \JS::registerCode(' function javascript_callback_function(data) { if(data.type=="file") { cx.jQuery("#' . $name . '").val(data.data[0].datainfo.filepath); } } '); $mediaBrowser = new \Cx\Core_Modules\MediaBrowser\Model\Entity\MediaBrowser(); $mediaBrowser->setOptions(array('type' => 'button')); $mediaBrowser->setCallback('javascript_callback_function'); $mediaBrowser->setOptions(array('data-cx-mb-views' => 'filebrowser,uploader', 'id' => 'page_target_browse', 'cxMbStartview' => 'MediaBrowserList')); $input = new \Cx\Core\Html\Model\Entity\DataElement($name, $value); $input->setAttribute('type', 'text'); $input->setAttribute('id', $name); $div = new \Cx\Core\Html\Model\Entity\HtmlElement('div'); $div->addChild($input); $div->addChild(new \Cx\Core\Html\Model\Entity\TextElement($mb = $mediaBrowser->getXHtml($_ARRAYLANG['TXT_CORE_CM_BROWSE']))); return $div; break; case 'image': \JS::registerCode(' function javascript_callback_function(data) { if ( data.data[0].datainfo.extension=="Jpg" || data.data[0].datainfo.extension=="Gif" || data.data[0].datainfo.extension=="Png" ) { cx.jQuery("#' . $name . '").attr(\'value\', data.data[0].datainfo.filepath); cx.jQuery("#' . $name . '").prevAll(\'.deletePreviewImage\').first().css(\'display\', \'inline-block\'); cx.jQuery("#' . $name . '").prevAll(\'.previewImage\').first().attr(\'src\', data.data[0].datainfo.filepath); } } jQuery(document).ready(function(){ jQuery(\'.deletePreviewImage\').click(function(){ cx.jQuery("#' . $name . '").attr(\'value\', \'\'); cx.jQuery(this).prev(\'img\').attr(\'src\', \'/images/Downloads/no_picture.gif\'); cx.jQuery(this).css(\'display\', \'none\'); cx.jQuery(this).nextAll(\'input\').first().attr(\'value\', \'\'); }); }); '); $mediaBrowser = new \Cx\Core_Modules\MediaBrowser\Model\Entity\MediaBrowser(); $mediaBrowser->setOptions(array('type' => 'button')); $mediaBrowser->setCallback('javascript_callback_function'); $defaultOptions = array('data-cx-mb-views' => 'filebrowser,uploader', 'id' => 'page_target_browse', 'cxMbStartview' => 'MediaBrowserList'); $mediaBrowser->setOptions(is_array($options['options']) ? array_merge($defaultOptions, $options['options']) : $defaultOptions); // create hidden input to save image $input = new \Cx\Core\Html\Model\Entity\DataElement($name, $value); $input->setAttribute('type', 'hidden'); $input->setAttribute('id', $name); $div = new \Cx\Core\Html\Model\Entity\HtmlElement('div'); if (isset($value) && in_array(pathinfo($value, PATHINFO_EXTENSION), array('gif', 'jpg', 'png')) || $name == 'imagePath') { // this image is meant to be a preview of the selected image $previewImage = new \Cx\Core\Html\Model\Entity\HtmlElement('img'); $previewImage->setAttribute('class', 'previewImage'); $previewImage->setAttribute('src', $value != '' ? $value : '/images/Downloads/no_picture.gif'); // this image is uesd as delete function for the selected image over javascript $deleteImage = new \Cx\Core\Html\Model\Entity\HtmlElement('img'); $deleteImage->setAttribute('class', 'deletePreviewImage'); $deleteImage->setAttribute('src', '/core/Core/View/Media/icons/delete.gif'); $div->addChild($previewImage); $div->addChild($deleteImage); $div->addChild(new \Cx\Core\Html\Model\Entity\HtmlElement('br')); } $div->addChild($input); $div->addChild(new \Cx\Core\Html\Model\Entity\TextElement($mediaBrowser->getXHtml($_ARRAYLANG['TXT_CORE_CM_BROWSE']))); return $div; break; case 'sourcecode': //set mode $mode = 'html'; if (isset($options['options']['mode'])) { switch ($options['options']['mode']) { case 'js': $mode = 'javascript'; break; case 'yml': case 'yaml': $mode = 'yaml'; break; } } //define textarea $textarea = new \Cx\Core\Html\Model\Entity\HtmlElement('textarea'); $textarea->setAttribute('name', $name); $textarea->setAttribute('id', $name); $textarea->setAttribute('style', 'display:none;'); $textarea->addChild(new \Cx\Core\Html\Model\Entity\TextElement($value)); //define pre $pre = new \Cx\Core\Html\Model\Entity\HtmlElement('pre'); $pre->setAttribute('id', 'editor-' . $name); $pre->addChild(new \Cx\Core\Html\Model\Entity\TextElement(contrexx_raw2xhtml($value))); //set readonly if necessary $readonly = ''; if (isset($options['readonly']) && $options['readonly']) { $readonly = 'editor.setReadOnly(true);'; $textarea->setAttribute('disabled'); } //create div and add all stuff $div = new \Cx\Core\Html\Model\Entity\HtmlElement('div'); $div->addChild($textarea); $div->addChild($pre); //register js $jsCode = <<<CODE var editor; \$J(function(){ if (\$J("#editor-{$name}").length) { editor = ace.edit("editor-{$name}"); editor.getSession().setMode("ace/mode/{$mode}"); editor.setShowPrintMargin(false); editor.focus(); editor.gotoLine(1); {$readonly} } \$J('form').submit(function(){ \$J('#{$name}').val(editor.getSession().getValue()); }); }); CODE; \JS::activate('ace'); \JS::registerCode($jsCode); return $div; break; case 'string': case 'hidden': default: // convert NULL to empty string if (is_null($value)) { $value = ''; } // input field with type text $input = new \Cx\Core\Html\Model\Entity\DataElement($name, $value); if (isset($options['validValues'])) { $input->setValidator(new \Cx\Core\Validate\Model\Entity\RegexValidator('/^' . $options['validValues'] . '$/')); } if ($type == 'hidden') { $input->setAttribute('type', 'hidden'); } else { $input->setAttribute('type', 'text'); $input->setClass('form-control'); } if (isset($options['readonly']) && $options['readonly']) { $input->setAttribute('disabled'); } if (isset($options['attributes'])) { $input->setAttributes($options['attributes']); } return $input; break; } }
/** * This method defines the option to generate the backend view (list and form) * * @global array $_ARRAYLANG Language data * @param string $entityClassName contains the FQCN from entity * @return array array containing the options */ protected function getViewGeneratorOptions($entityClassName) { global $_ARRAYLANG; $classNameParts = explode('\\', $entityClassName); $classIdentifier = end($classNameParts); $placeholderPrefix = 'TXT_' . strtoupper($this->getType() . '_' . $this->getName() . '_ACT_' . $classIdentifier); return array('header' => $_ARRAYLANG[$placeholderPrefix], 'entityName' => $_ARRAYLANG[$placeholderPrefix . '_ENTITY'], 'order' => array('overview' => array('active', 'title')), 'functions' => array('add' => true, 'edit' => true, 'delete' => true, 'sorting' => true, 'paging' => true, 'filtering' => false), 'fields' => array('id' => array('showOverview' => false), 'title' => array('header' => $_ARRAYLANG[$placeholderPrefix . '_TITLE'], 'table' => array('parse' => function ($data, $rows, $options) { $editUrl = \Cx\Core\Html\Controller\ViewGenerator::getVgEditUrl($options['functions']['vg_increment_number'], $rows['id']); $link = new \Cx\Core\Html\Model\Entity\HtmlElement('a'); $link->setAttribute('href', $editUrl); $link->setAttribute('title', $data); $value = new \Cx\Core\Html\Model\Entity\TextElement($data); $link->addChild($value); return $link; })), 'active' => array('header' => $_ARRAYLANG[$placeholderPrefix . '_STATE'], 'formtext' => $_ARRAYLANG[$placeholderPrefix . '_ACTIVE'], 'sorting' => false, 'table' => array('parse' => function ($data, $rows) { if ($data) { return \Html::getLed('green'); } return \Html::getLed('red'); })), 'htmlContent' => array('header' => $_ARRAYLANG[$placeholderPrefix . '_HTML_CONTENT'] . ' <span class="tooltip-trigger icon-info">' . '</span><span class="tooltip-message">' . $_ARRAYLANG[$placeholderPrefix . '_HTML_CONTENT_TOOLTIP'] . '</span>', 'showOverview' => false, 'formfield' => function ($name, $type, $length, $value, $options) { $editor = new \Cx\Core\Wysiwyg\Wysiwyg($name, $value, 'fullpage'); $span = new \Cx\Core\Html\Model\Entity\HtmlElement('span'); $span->addChild(new \Cx\Core\Html\Model\Entity\TextElement($editor)); return $span; }))); }