You are here

function dynamic_banner_admin_page in Dynamic Banner 7

Same name and namespace in other branches
  1. 6 includes/callbacks.inc \dynamic_banner_admin_page()
  2. 7.2 dynamic_banner.module \dynamic_banner_admin_page()
  3. 8.x dynamic_banner.module \dynamic_banner_admin_page()

Return a listing of all defined URL aliases. When filter key passed, perform a standard search on the given key, and return the list of matching URL aliases.

1 string reference to 'dynamic_banner_admin_page'
dynamic_banner_menu in ./dynamic_banner.module
Implements hook_menu(). it is key to note here access arguments is referring to permissions

File

includes/callbacks.inc, line 15
Dynamic Banner Admin Pages and various other functions to make them work Most of the code in this file was derived from path module

Code

function dynamic_banner_admin_page() {
  $output = [];

  // default
  // grab the filter if the user set one
  $filter = dynamic_banner_build_filter_query();

  // Add a search above overview table
  $output['dynamic_banner_admin_search_form'] = drupal_get_form('dynamic_banner_admin_search_form');

  // Add the filter form above the overview table. // fix bug first //

  //$output['dynamic_banner_admin_filter_form'] = drupal_get_form('dynamic_banner_admin_filter_form');

  // construct the headers of the table
  $header = array(
    array(
      'data' => t('Url'),
      'field' => 'd.path',
      'sort' => 'asc',
    ),
    array(
      'data' => t('ImgUrl'),
    ),
    array(
      'data' => t('Text'),
      'field' => 'd.text',
    ),
    array(
      'data' => t('Link'),
      'field' => 'd.link',
    ),
    array(
      'data' => t('Mode'),
      'field' => 'd.mode',
    ),
    array(
      'data' => t('Operations'),
      'colspan' => '2',
    ),
  );

  // contruct the db call for the list
  // load all data fields and attach pager and sorter function in
  $query = db_select('dynamic_banner', 'd')
    ->extend('PagerDefault')
    ->extend('TableSort');

  // alias the table name to d
  $query
    ->fields('d')
    ->limit(20)
    ->orderByHeader($header);

  // find if the filter has returned a where clause and add it in before executing
  if (!empty($filter['where'])) {
    $query
      ->where($filter['where'], $filter['args']);

    // not working yet
  }

  // search according to search parameters. Filter during query
  if ($_GET['searchUrl'] != '') {
    $query
      ->condition('d.path', '%' . $_GET['searchUrl'] . '%', 'LIKE');
  }
  if ($_GET['searchText'] != '') {
    $query
      ->condition('d.text', '%' . $_GET['searchText'] . '%', 'LIKE');
  }
  if ($_GET['searchLink'] != '') {
    $query
      ->condition('d.link', '%' . $_GET['searchLink'] . '%', 'LIKE');
  }
  $result = $query
    ->execute();

  // start constructing the individual rows (with XSS protection)
  $rows = array();
  foreach ($result as $data) {
    $image = dynamic_banner_image_handler($data->imgurl, $data->imgfid);

    // Since image string is defined after query, we search after the query
    if ($_GET['searchImgUrl'] == '' || strpos($image, $_GET['searchImgUrl']) !== false) {
      $rows[] = array(
        'data' => array(
          $data->path,
          $image,
          filter_xss($data->text),
          filter_xss($data->link),
          $data->mode,
          l(t('edit'), "admin/structure/banners/edit/" . $data->dbid),
          l(t('delete'), "admin/structure/banners/delete/" . $data->dbid),
        ),
      );
    }
  }

  // construct the call for the theme function to run on this
  $output['dynamic_banner_table'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => t('No Banners Found.'),
  );

  // adds the pager buttons to the bottom of the table
  $output['dynamic_banner_pager'] = array(
    '#theme' => 'pager',
  );

  // let drupal handle print and echo
  return $output;
}