*/ class twIf_Widget_Listbox extends twIf_Object_Access { public static function generateListbox ($Items, $Definition = array (), $Link = null, $GroupBy = null) { // Check if there are any items for output if (!is_array ($Items) || (count ($Items) == 0)) return; // Peak the first item foreach ($Items as $First) break; // Check if there is a special definition for image-output if (isset ($Definition ['_Image'])) { $ImageDefintion = parent::parseFieldDef ('_Image', $Definition ['_Image'], $First, 0, true); unset ($Definition ['_Image']); } else $ImageDefintion = null; // Start the output $buf = "
\n" . "
\n"; // Prepare the groups if ($GroupBy === null) $Groups = array ($Items); else { $Groups = array (); $gDef = null; foreach ($Items as $Item) { // Parse pointer to group if ($gDef === null) $gDef = self::parseFieldDef ('Group', array ('Read' => $GroupBy), $Item, 0, true); // Get the group from object $Group = self::getFieldValue ($Item, $gDef, true); if (is_object ($Group)) { if (is_callable (array ($Group, 'getName'))) $Group = $Group->getName (); elseif (is_callable (array ($Group, 'toString'))) $Group = $Group->toString (); elseif (is_callable (array ($Group, '__toString'))) $Group = $Group->__toString (); else $Group = strval ($Group); } // Append item to group if (!isset ($Groups [$Group])) $Groups [$Group] = array (); $Groups [$Group][] = $Item; } } // Output every item foreach ($Groups as $Caption=>$Items) { // Output caption of group if ($onGroup = ((count ($Groups) > 1) || !is_numeric ($Caption))) $buf .= '
' . twIf_i18n::getText ($Caption) . "
\n"; // Output all items on group foreach ($Items as $Item) { $buf .= "
\n" . ($Link !== null ? '\n" : ''); // Output image if there is such definition if ($haveImage = ($ImageDefintion !== null)) { $tagOrURL = parent::getFieldValue ($Item, $ImageDefintion, true); // Check wheter to append image-tag if (substr ($tagOrURL, 0, 4) != ''; } $buf .= '
' . $tagOrURL . "
\n" . "
\n"; } // Output everything else $Suffix = ''; foreach ($Definition as $Key=>$Def) { if (!isset ($Def ['_parsed'])) $Definition [$Key]['_parsed'] = $Def ['_parsed'] = parent::parseFieldDef ($Key, $Def, $Item, 0, true); $Prefix = ($haveImage ? ' ' : '') . ' '; $Value = parent::formatOutput (parent::getFieldValue ($Item, $Def ['_parsed'], true), $Def ['_parsed']['Type'], $Def ['_parsed']['Default'], $Prefix, $Suffix); $buf .= $Value . "\n"; } $buf .= ($haveImage ? '
' : '') . ($Link !== null ? "
\n" : '') . "
\n"; } if ($onGroup) $buf .= "
\n"; } // Finish the output $buf .= "
\n" . "
\n" . '
'; return $buf; } } ?>