You are here

quiz_views_handler_argument_user_uid_nullable.inc in Quiz 6.3

File

includes/views/handlers/quiz_views_handler_argument_user_uid_nullable.inc
View source
<?php

/*
 * @file
 * Handles argument user id nullable.
 */
class quiz_views_handler_argument_user_uid_nullable extends views_handler_argument_user_uid {
  function option_definition() {
    $options = parent::option_definition();
    $options['allow_null'] = array(
      'default' => FALSE,
    );
    return $options;
  }
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    unset($form['break_phrase']);
    $form['allow_null'] = array(
      '#type' => 'checkbox',
      '#title' => t('Used for Quiz Status'),
      '#description' => t('When this agument is used, this box must be checked if the Quiz Status field is to work properly.'),
      '#default_value' => $this->options['allow_null'],
    );
  }
  function query() {
    $this
      ->ensure_my_table();
    $operator = empty($this->options['not']) ? '=' : '!=';
    $where = "{$this->table_alias}.{$this->real_field} {$operator} %d";
    if ($this->options['allow_null']) {
      $group = $this->query
        ->set_where_group('AND', 'qnr_user');
      $where .= " OR {$this->table_alias}.{$this->real_field} IS NULL";
    }
    else {
      $group = 0;
    }

    // By adding the IS NULL, joins can properly inform us about quiz state
    $this->query
      ->add_where($group, $where, $this->argument);
  }

}