123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- use Redis\Logger\Reader;
- /**
- * @file
- * Administrative controllers for the Redis Logger module.
- */
- function redis_logger_form_overview($form, $form_state) {
- $redis = Redis_Client::getClient();
- $reader = new Reader($redis);
- $severity_levels = $reader->getSettings()->getSeverityLevels();
- $base_form = $form;
- $form['redis_logger_filter_form'] = _redis_logger_filter_form($base_form, $reader);
- $form['redis_logger_clear_log_form'] = _redis_logger_clear_log_form($base_form);
- $header = array(
- t('Type'),
- t('Level'),
- t('Message template'),
- t('Occurrences'),
- );
- $templates = $reader->getTemplates();
- dsm($templates);
- $regex = $reader->getSettings()->getSplittingRegex();
- $rows = array();
- foreach ($templates as $template) {
- preg_match($regex, $template, $matches);
- list(, $channel, $severity, $template) = $matches;
- $occurrences = l(t('Occurrences'), 'admin/reports/redis/logger/' . $template);
- $rows[] = array(
- $channel,
- $severity_levels[$severity],
- $template,
- $occurrences,
- );
- }
- $form['redis_logger_table'] = array(
- '#theme' => 'table',
- '#header' => $header,
- '#rows' => $rows,
- '#attributes' => array('id' => 'admin-dblog'),
- '#empty' => t('No log messages available.'),
- );
- $build['dblog_pager'] = array('#theme' => 'pager');
- return $form;
- }
- /**
- * TODO implement. Beware of XSS.
- *
- * @param string $template
- *
- * @return string
- */
- function redis_logger_page_event($template) {
- return check_plain($template);
- }
- /**
- * Form constructor for the form that clears out the log.
- *
- * TODO implement.
- *
- * @see dblog_clear_log_submit()
- * @ingroup forms
- */
- function _redis_logger_clear_log_form($form) {
- $form['redis_logger_clear'] = array(
- '#type' => 'fieldset',
- '#title' => t('Clear log messages'),
- '#description' => t('NOT IMPLEMENTED YET. This will permanently remove the log messages from the Redis store.'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- );
- $form['redis_logger_clear']['clear'] = array(
- '#type' => 'submit',
- '#value' => t('Clear log messages'),
- '#submit' => array('redis_logger_clear_log_submit'),
- );
- return $form;
- }
- /**
- * Helper for the Redis logger filter form builder.
- *
- * @param \Redis\Logger\Reader $reader
- *
- * @return array
- */
- function _redis_logger_filters(Reader $reader) {
- $filters = array();
- $filters['type'] = array(
- 'title' => t('Type'),
- 'options' => $reader->getChannels(),
- );
- $filters['severity'] = array(
- 'title' => t('Severity'),
- 'options' => $reader->getSettings()->getSeverityLevels(),
- );
- return $filters;
- }
- /**
- * Build the filter form. Shares session status with DBLog.
- *
- * @param array $form
- * @param \Redis\Logger\Reader $reader
- *
- * @return mixed
- */
- function _redis_logger_filter_form($form, Reader $reader) {
- $filters = _redis_logger_filters($reader);
- $form['filters'] = array(
- '#type' => 'fieldset',
- '#title' => t('Filter log messages'),
- '#collapsible' => TRUE,
- '#collapsed' => empty($_SESSION['dblog_overview_filter']),
- );
- foreach ($filters as $key => $filter) {
- $form['filters']['status'][$key] = array(
- '#title' => $filter['title'],
- '#type' => 'select',
- '#multiple' => TRUE,
- '#size' => 8,
- '#options' => $filter['options'],
- );
- if (!empty($_SESSION['dblog_overview_filter'][$key])) {
- $form['filters']['status'][$key]['#default_value'] = $_SESSION['dblog_overview_filter'][$key];
- }
- }
- $form['filters']['actions'] = array(
- '#type' => 'actions',
- '#attributes' => array('class' => array('container-inline')),
- );
- $form['filters']['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Filter'),
- );
- if (!empty($_SESSION['dblog_overview_filter'])) {
- $form['filters']['actions']['reset'] = array(
- '#type' => 'submit',
- '#value' => t('Reset')
- );
- }
- return $form;
- }
|