/** * Do the output rendering. * * As this is a generic view which can be called by * many different actions we need the actionConfId in * $viewData in order to read its special configuration, * including redirection options etc. * * @param string $template * @param ArrayObject $viewData * @param tx_rnbase_configurations $configurations * @param tx_rnbase_util_FormatUtil $formatter * @return mixed Ready rendered output or HTTP redirect */ public function createOutput($template, &$viewData, &$configurations, &$formatter) { //View-Daten abholen $items = $viewData->offsetGet(self::VIEWDATA_ITEMS); $filter = $viewData->offsetGet(self::VIEWDATA_FILTER); $markerData = $viewData->offsetGet(self::VIEWDATA_MARKER); $confId = $this->getController()->getConfId(); $markerArray = $formatter->getItemMarkerArrayWrapped($markerData, $confId . 'markers.'); $subpartArray = array(); $itemPath = $this->getItemPath($configurations, $confId); if ($filter && $filter->hideResult()) { $subpartArray['###' . strtoupper($itemPath) . 'S###'] = ''; $items = array(); $template = $filter->getMarker()->parseTemplate($template, $formatter, $confId . $itemPath . '.filter.', strtoupper($itemPath)); } else { $markerClass = $this->getMarkerClass($configurations, $confId); //Liste generieren $listBuilder = tx_rnbase::makeInstance('tx_rnbase_util_ListBuilder'); $template = $listBuilder->render($items, $viewData, $template, $markerClass, $confId . $itemPath . '.', strtoupper($itemPath), $formatter); } $template = tx_rnbase_util_Templates::substituteMarkerArrayCached($template, $markerArray, $subpartArray); //, $wrappedSubpartArray); return $template; }
/** * Links vorbereiten * * @param Tx_Rnbase_Domain_Model_DataInterface $item * @param string $marker * @param array $markerArray * @param array $wrappedSubpartArray * @param string $confId * @param tx_rnbase_util_FormatUtil $formatter */ protected function prepareLinks($item, $marker, &$markerArray, &$subpartArray, &$wrappedSubpartArray, $confId, $formatter, $template) { $configurations = $formatter->getConfigurations(); $pluginData = $configurations->getCObj()->data; $configurations->getCObj()->data = $item->getProperty(); $linkIds = $configurations->getKeyNames($confId . 'links.'); for ($i = 0, $cnt = count($linkIds); $i < $cnt; $i++) { $linkId = $linkIds[$i]; // Check if link is defined in template if (!self::checkLinkExistence($linkId, $marker, $template)) { continue; } $linkConfId = $confId . 'links.' . $linkId; // Die Parameter erzeugen $params = array(); $paramMap = (array) $configurations->get($linkConfId . '._cfg.params.'); foreach ($paramMap as $paramName => $colName) { if (is_scalar($colName) && array_key_exists($colName, $item->getProperty())) { $params[$paramName] = $item->getProperty($colName); } elseif (is_array($colName)) { $paramName = substr($paramName, 0, strlen($paramName) - 1); $params[$paramName] = $this->createParam($paramName, $colName, $item); } } // check for charbrowser config and add the parameter if ($configurations->getBool($linkConfId . '._cfg.charbrowser')) { $cbId = $configurations->get($linkConfId . '._cfg.charbrowser.cbid'); $cbId = empty($cbId) ? 'charpointer' : $cbId; $cbColname = $configurations->get($linkConfId . '._cfg.charbrowser.colname'); $cbColname = empty($cbColname) ? 'uid' : $cbColname; $params[$cbId] = strtoupper(substr((string) $item->getProperty($cbColname), 0, 1)); } // @TODO: that only works on Tx_Rnbase_Domain_Model_DomainInterface! if ($configurations->getBool($linkConfId . '.skipPersistedCheck') || $item->isPersisted()) { $this->initLink($markerArray, $subpartArray, $wrappedSubpartArray, $formatter, $confId, $linkId, $marker, $params, $template); } else { $linkMarker = $marker . '_' . strtoupper($linkId) . 'LINK'; $remove = intval($configurations->get($linkConfId . '.removeIfDisabled')); $this->disableLink($markerArray, $subpartArray, $wrappedSubpartArray, $linkMarker, $remove > 0); } } $configurations->getCObj()->data = $pluginData; }
/** * Call services for single markers * * @param string $template * @param array $markerArray * @param array $params * @param tx_rnbase_util_FormatUtil $formatter */ protected static function callModuleMarkers($template, &$markerArray, &$params, $formatter) { preg_match_all('!\\<\\!--[a-zA-Z0-9 ]*###([A-Z0-9_\\-|]*)\\###[a-zA-Z0-9 ]*-->!is', $template, $match); $allMarkers = array_unique($match[1]); preg_match_all('!\\###([A-Z0-9_\\-|]*)\\###!is', $template, $match); $allSingleMarkers = array_unique($match[1]); $allSingleMarkers = array_diff($allSingleMarkers, $allMarkers); $suffixesToTry = self::getSuffixesToTry($formatter->getConfigurations()); foreach ($allSingleMarkers as $marker) { if (preg_match('/MARKERMODULE__([A-Z0-9_\\-])*/', $marker)) { $module = tx_rnbase::makeInstanceService('markermodule', substr($marker, 14)); if (is_object($module)) { $subTemplate = tx_rnbase_util_Templates::getSubpart($template, '###' . $marker . '###'); $value = $module->getMarkerValue($params, $formatter); if ($value !== FALSE) { $markerArray['###' . $marker . '###'] = $value; } } } elseif (preg_match('/LABEL_.*/', $marker)) { $markerArray['###' . $marker . '###'] = ''; // remove marker per default foreach ($suffixesToTry as $suffix) { $completeKey = $marker . $suffix; // Hier kommt immer ein leerer String zurück, weil T3 keinen Alternativ-String unterstützt $translation = $formatter->getConfigurations()->getLL(strtolower($completeKey)); if ($translation !== '') { $markerArray['###' . $marker . '###'] = $translation; break; } } } } }
/** * Icon für den Typ hinzufügen * * @param string $template * @param tx_mklib_model_Dam $item * @param tx_rnbase_util_FormatUtil $formatter * @param string $confId * @param string $marker * @return string */ private function addIcon($template, &$item, &$formatter, $confId, $marker) { if (!$this->containsMarker($template, $marker . '_ICON')) { return $template; } $item->record['icon'] = ''; return $template; //@TODO: implement if needet /* ###TS icon = IMAGE icon { ### welches feld soll für das mapping genutzt werden? (file_mime_type, file_mime_subtype, file_type ) field = file_type fileext = gif ## wenn kein mapping zutrifft default = unknown ### mapping der Felder ### wenn im field docx und in fileext gif steht wird doc.gif ausgegeben ### ACHTUNG: in der kommaseparierten liste dürfen keine leerzeichen sein! ### doc, docx wäre falsch und würde nicht funktionieren. mapping { doc = doc,docx jpg = jpg,jpeg dwg = dwg dxf = dxf pdf = pdf tiff = tiff xls = xls zip = zip video = } } icon.file { import = EXT:mkdownloads/res/fileicons/ import.field = icon } */ $configuration = $formatter->getConfigurations(); $field = $configuration->get($confId . 'icon.field'); $field = $field ? $field : 'fiel_type'; $mapping = $configuration->get($confId . 'icon.mapping'); $type = $item->record[$field]; $default = $configuration->get($confId . 'icon.default'); $default = $default ? $default : $type; $fileExt = $configuration->get($confId . 'icon.fileext'); $fileExt = $fileExt ? $fileExt : 'gif'; $icon = $default . '.' . $fileExt; if (is_array($mapping)) { foreach ($mapping as $key => $value) { if (t3lib_div::inList($value, $type)) { $icon = $key . '.' . $fileExt; break; } } } $item->record['icon'] = $icon; }
/** * @param string $template HTML template * @param array $markerArray * @param array $subpartArray * @param array $wrappedSubpartArray * @param tx_rnbase_util_FormatUtil $formatter * @param string $confId * @param string $marker * * @return void */ private function insertMarkersForSorting($template, &$markerArray, &$subpartArray, &$wrappedSubpartArray, &$formatter, $confId) { $confId = $this->getConfId() . $this->sortConfId; $configurations = $formatter->getConfigurations(); $sortFields = $this->getAllowedSortFields(); if (!empty($sortFields)) { tx_rnbase::load('tx_rnbase_util_BaseMarker'); $token = md5(microtime()); $markOrders = array(); foreach ($sortFields as $field) { $isField = $field == $this->getSortBy(); // sortOrder ausgeben $markOrders[$field . '_order'] = $isField ? $this->getSortOrder() : ''; $fieldMarker = $this->markerPrefix . '_' . strtoupper($field) . '_LINK'; $makeLink = tx_rnbase_util_BaseMarker::containsMarker($template, $fieldMarker); $makeUrl = tx_rnbase_util_BaseMarker::containsMarker($template, $fieldMarker . 'URL'); // link generieren if ($makeLink || $makeUrl) { // sortierungslinks ausgeben $params = array('sortBy' => $field, 'sortOrder' => $isField && $this->getSortOrder() == 'asc' ? 'desc' : 'asc'); $link = $configurations->createLink(); $link->label($token); $link->initByTS($configurations, $confId . $this->sortLinkConfId, $params); if ($makeLink) { $wrappedSubpartArray['###' . $fieldMarker . '###'] = explode($token, $link->makeTag()); } if ($makeUrl) { $markerArray['###' . $fieldMarker . 'URL###'] = $link->makeUrl(false); } } } // die sortOrders parsen $markOrders = $formatter->getItemMarkerArrayWrapped($markOrders, $confId, 0, $this->markerPrefix . '_', array_keys($markOrders)); $markerArray = array_merge($markerArray, $markOrders); } }
/** * Render an array of data entries with an html template. The html template should look like this: * ###DATAS### * ###DATA### * ###DATA_UID### * ###DATA### * ###DATAEMPTYLIST### * Shown if list is empty * ###DATAEMPTYLIST### * ###DATAS### * We have some conventions here: * The given parameter $marker should be named 'DATA' for this example. The the list subpart * is experted to be named '###'.$marker.'S###'. Please notice the trailing S! * If you want to render a pagebrowser add it to the $viewData with key 'pagebrowser'. * A filter will be detected and rendered too. It should be available in $viewData with key 'filter'. * * @param array|Traversable $dataArr entries * @param string $template * @param string $markerClassname item-marker class * @param string $confId ts-Config for data entries like team. * @param string $marker name of marker like TEAM * @param tx_rnbase_util_FormatUtil $formatter * @param array $markerParams array of settings for itemmarker * @return string */ function render(&$dataArr, $viewData, $template, $markerClassname, $confId, $marker, $formatter, $markerParams = NULL) { $viewData = is_object($viewData) ? $viewData : new ArrayObject(); $debugKey = $formatter->getConfigurations()->get($confId . '_debuglb'); $debug = $debugKey && ($debugKey === '1' || $_GET['debug'] && array_key_exists($debugKey, array_flip(tx_rnbase_util_Strings::trimExplode(',', $_GET['debug']))) || $_POST['debug'] && array_key_exists($debugKey, array_flip(tx_rnbase_util_Strings::trimExplode(',', $_POST['debug'])))); if ($debug) { $time = microtime(TRUE); $mem = memory_get_usage(); $wrapTime = tx_rnbase_util_FormatUtil::$time; $wrapMem = tx_rnbase_util_FormatUtil::$mem; } $outerMarker = $this->getOuterMarker($marker, $template); $htmlParser = tx_rnbase_util_Typo3Classes::getHtmlParserClass(); while ($templateList = $htmlParser::getSubpart($template, '###' . $outerMarker . 'S###')) { if ((is_array($dataArr) || $dataArr instanceof Traversable) && count($dataArr)) { /* @var $listMarker tx_rnbase_util_ListMarker */ $listMarker = tx_rnbase::makeInstance('tx_rnbase_util_ListMarker', $this->info->getListMarkerInfo()); $templateEntry = $htmlParser::getSubpart($templateList, '###' . $marker . '###'); $offset = 0; $pageBrowser = $viewData->offsetGet('pagebrowser'); if ($pageBrowser) { $state = $pageBrowser->getState(); $offset = $state['offset']; } $markerArray = $subpartArray = array(); $listMarker->addVisitors($this->visitors); $out = $listMarker->render($dataArr, $templateEntry, $markerClassname, $confId, $marker, $formatter, $markerParams, $offset); $subpartArray['###' . $marker . '###'] = $out; $subpartArray['###' . $marker . 'EMPTYLIST###'] = ''; // Das Menu für den PageBrowser einsetzen if ($pageBrowser) { $subpartArray['###PAGEBROWSER###'] = tx_rnbase_util_BaseMarker::fillPageBrowser($htmlParser::getSubpart($template, '###PAGEBROWSER###'), $pageBrowser, $formatter, $confId . 'pagebrowser.'); $listSize = $pageBrowser->getListSize(); } else { $listSize = count($dataArr); } $markerArray['###' . $marker . 'COUNT###'] = $formatter->wrap($listSize, $confId . 'count.'); // charbrowser $pagerData = $viewData->offsetGet('pagerData'); $charPointer = $viewData->offsetGet('charpointer'); $subpartArray['###CHARBROWSER###'] = tx_rnbase_util_BaseMarker::fillCharBrowser(tx_rnbase_util_Templates::getSubpart($template, '###CHARBROWSER###'), $markerArray, $pagerData, $charPointer, $formatter->getConfigurations(), $confId . 'charbrowser.'); $out = tx_rnbase_util_BaseMarker::substituteMarkerArrayCached($templateList, $markerArray, $subpartArray); } else { // Support für EMPTYLIST-Block if (tx_rnbase_util_BaseMarker::containsMarker($template, $marker . 'EMPTYLIST')) { $out = $htmlParser::getSubpart($template, '###' . $marker . 'EMPTYLIST###'); } else { $out = $this->info->getEmptyListMessage($confId, $viewData, $formatter->getConfigurations()); } } $template = tx_rnbase_util_Templates::substituteSubpart($template, '###' . $outerMarker . 'S###', $out, 0); } $markerArray = array(); $subpartArray = array(); // Muss ein Formular mit angezeigt werden // Zuerst auf einen Filter prüfen $filter = $viewData->offsetGet('filter'); if ($filter) { $template = $filter->getMarker()->parseTemplate($template, $formatter, $confId . 'filter.', $marker); } // Jetzt noch die alte Variante $markerArray['###SEARCHFORM###'] = ''; $seachform = $viewData->offsetGet('searchform'); if ($seachform) { $markerArray['###SEARCHFORM###'] = $seachform; } $out = tx_rnbase_util_BaseMarker::substituteMarkerArrayCached($template, $markerArray, $subpartArray); if ($debug) { tx_rnbase::load('class.tx_rnbase_util_Misc.php'); $wrapTime = tx_rnbase_util_FormatUtil::$time - $wrapTime; $wrapMem = tx_rnbase_util_FormatUtil::$mem - $wrapMem; tx_rnbase_util_Debug::debug(array('Rows' => count($dataArr), 'Execustion time' => microtime(TRUE) - $time, 'WrapTime' => $wrapTime, 'WrapMem' => $wrapMem, 'Memory start' => $mem, 'Memory consumed' => memory_get_usage() - $mem), 'ListBuilder Statistics for: ' . $confId . ' Key: ' . $debugKey); } return $out; }
/** * Füllt ein MarkerArray mit den Datens einer DAM-Mediadatei * @param tx_dam_media $media : Die DAM-Datei * @param string $confId : Configuration to wrap data * @param string $mediaMarker : The marker to store the image or media. Additional data will be stored to $mediaMarker.'_'... */ function getItemMarkerArray4DAM(&$media, $confId, $mediaMarker) { $conf = $this->configurations->get($confId); // Alle Metadaten auslesen und wrappen $meta = array(); while (list($colname, $value) = each($media->meta)) { $meta[$colname] = $this->stdWrap($value, $conf[$colname . '.']); } $markerArray = tx_rnbase_util_FormatUtil::getItemMarkerArray($meta, array('l18n_diffsource'), $mediaMarker . '_', tx_rnbase_util_FormatUtil::getDAMColumns()); // Jetzt die eigentliche Datei einbinden $filePath = $media->getMeta('file_path') . $media->getMeta('file_name'); if ($media->meta['media_type'] == TXDAM_mtype_image) { $markerArray['###' . $mediaMarker . '_IMGTAG###'] = $this->getDAMImage($filePath, $confId); } return $markerArray; }