/** * TODO: Nested, to visualize parent-child relationships. * Get a list of all categories, selectable as input. * @param {string} $name HTML name attribute for the inputs. * @param {int} $inputType Input type: INPUT_CHECKBOX, INPUT_RADIO. * @param {array} $preselect Pre-select certain category IDs. (Optional.) * @param {array} $omit IDs to omit. (Optional.) * @return {string} HTML list with inputs. */ public static function categories($name, $inputType, $preselect = array(), $omit = array()) { $filter = array('WHERE' => 'ca_status = "' . ae_CategoryModel::STATUS_AVAILABLE . '"'); $caList = new ae_CategoryList($filter); $templateInput = "\t\t"; $templateLabel = "\t\t" . '<label for="ca-%s">%s</label>' . PHP_EOL; if ($inputType == self::INPUT_CHECKBOX) { $templateInput .= '<input type="checkbox" name="%s[]" value="%s" id="ca-%s" />' . PHP_EOL; } else { if ($inputType == self::INPUT_RADIO) { $templateInput .= '<input type="radio" name="%s" value="%s" id="ca-%s" />' . PHP_EOL; } } $out = '<ol class="choose-categories">' . PHP_EOL; // Only for "radio": default "none" option if ($inputType == self::INPUT_RADIO) { $out .= "\t" . '<li>' . PHP_EOL; $out .= sprintf($templateInput, $name, 0, 0); if (count($preselect) == 0 || $preselect[0] < 1) { $out = str_replace(' />', ' checked />', $out); } $out .= sprintf($templateLabel, 0, '<em>none</em>'); $out .= "\t" . '</li>' . PHP_EOL; } // All categories while ($ca = $caList->next()) { if (in_array($ca->getId(), $omit)) { continue; } $out .= "\t" . '<li>' . PHP_EOL; $input = sprintf($templateInput, $name, $ca->getId(), $ca->getId()); if (in_array($ca->getId(), $preselect)) { $input = str_replace(' />', ' checked />', $input); } $out .= $input; $out .= sprintf($templateLabel, $ca->getId(), htmlspecialchars($ca->getTitle())); $out .= '</li>' . PHP_EOL; } $out .= '</ol>' . PHP_EOL; return $out; }
<?php $memoryPeak = sprintf('%.4f', memory_get_peak_usage() / 1024 / 1024); $memoryFinal = sprintf('%.4f', memory_get_usage() / 1024 / 1024); $scriptTime = ae_Timer::stop('total'); $filter = array('ORDER BY' => 'ca_title ASC'); $caList = new ae_CategoryList($filter, array(), FALSE); ?> <footer class="main-footer"> <div> <h6>Kategorien</h6> <ul class="categories"> <?php while ($ca = $caList->next()) { ?> <li><a href="<?php echo $ca->getLink(); ?> "><?php echo $ca->getTitle(); ?> </a></li> <?php } ?> </ul> </div> <div> <h6>Seiten</h6>