You are here

function regcode_get_codes in Registration codes 5.3

Return the database query result for the given options to list codes

Parameters

$options: An array of options for retrieving registration codes: filter_field - registration code field to filter the results by (see regcode_get_fields) filter_operand - The filter operand: contains / equals / not / greater / smaller (see regcode_get_filter_operands) filter_data - The data to filter on, string or number start - db result sequence number of first code to retrieve, see regcode_get_fields limit - number of codes to retrieve order - registration code field to order the results by (see regcode_get_fields) sort - sort order to order the results by: ASC / DESC pager - the pager identifier if a paging mechanism should be used

Return value

An array list of code data arrays

1 call to regcode_get_codes()
regcode_admin_list in ./regcode_admin.inc.php
Return the code list page content with(in) the according filter form

File

./regcode_api.inc.php, line 100
regcode_api.inc.php contains general low-level functions for the registration-code module, for tasks like

Code

function regcode_get_codes($options = array()) {
  $o = array_merge(array(
    'filter_operand' => 'equals',
    'start' => 0,
    'limit' => 100,
    'order' => 'code',
    'sort' => 'asc',
    'pager' => NULL,
  ), $options);
  $fields = regcode_get_fields(TRUE);
  if (isset($o['filter_field']) && isset($o['filter_data'])) {
    if ($fields[$o['filter_field']]) {
      $filter = $o['filter_field'];
    }
    $operand = regcode_get_filter_operands('sql', $o['filter_operand']);
    $sql_where = "WHERE     {$filter} {$operand} ";
  }
  $order = isset($fields[$o['order']]) ? $o['order'] : 'code';
  $sort = drupal_strtoupper($o['sort']) == 'DESC' ? 'DESC' : 'ASC';
  foreach (array_keys($fields) as $f) {
    $sql_fields[] = $f . ' as ' . str_replace('.', '___', $f);
  }
  $sql = "SELECT " . implode(', ', $sql_fields) . "\n          FROM      {regcode} c\n          LEFT JOIN {users} u ON (u.uid = c.uid)\n          LEFT JOIN {role}  r ON (r.rid = c.rid)\n          {$sql_where}\n          ORDER BY  {$order} {$sort}\n          ";
  $args = array(
    $o['filter_data'],
  );
  if (isset($o['pager'])) {
    $result = pager_query($sql, $o['limit'], $o['pager'], NULL, $args);
  }
  else {
    $result = db_query_range($sql, $args, $o['start'], $o['limit']);
  }
  while ($row = db_fetch_object($result)) {
    foreach ((array) $row as $key => $data) {
      $row_temp[str_replace('___', '.', $key)] = $data;
    }
    $rows[] = $row_temp;
  }
  return $rows;
}