Index: views/handlers/project_issue_handler_filter_issue_status.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/views/handlers/project_issue_handler_filter_issue_status.inc,v retrieving revision 1.3 diff -u -p -r1.3 project_issue_handler_filter_issue_status.inc --- views/handlers/project_issue_handler_filter_issue_status.inc 28 Jan 2009 21:59:12 -0000 1.3 +++ views/handlers/project_issue_handler_filter_issue_status.inc 25 Feb 2009 08:14:56 -0000 @@ -4,63 +4,74 @@ /** * Filter issues based on their status. + * + * Adds a special "- Open issues -" value that is used to select all of the + * "open" issue status values as currently configured on the site. */ class project_issue_handler_filter_issue_status extends views_handler_filter_in_operator { - var $is_exposed = FALSE; - var $default_states = array(); - - function get_default_states() { - if (empty($default_states)) { - $default_states = project_issue_state(0, FALSE, FALSE, 0, TRUE); - } - return $default_states; - } + var $open_states = array(); + /** + * Return the values to use for this filter. + * + * Adds the special "- Open issues -" choice in addition to all of the + * currently configured issue statue values. + */ function get_value_options() { module_load_include('inc', 'project_issue', 'issue'); - $open_issues = array(); - if (empty($this->is_exposed) || empty($this->options['exposed']) || !empty($this->options['expose']['single'])) { - $open_issues = array('open' => t('- Open issues -')); - } - $this->value_options = $open_issues + project_issue_state(); + $this->value_options = array('Open' => t('- Open issues -')) + project_issue_state(); } - function value_form(&$form, &$form_state) { - // Set a flag so that get_value_options() knows we're building a form for - // the actual exposed filter for a view, not just configuring it. - if (!empty($form_state['exposed'])) { - $this->is_exposed = TRUE; - } - // Let our parent do most of its magic. - parent::value_form($form, $form_state); - - // If this is the form for an exposed filter with multiple values, we need - // to see if we're trying to use 'open' issues, and if so, translate into - // the real default states to avoid FAPI validation errors. - if ($this->is_exposed && empty($this->options['expose']['single'])) { - $identifier = $this->options['expose']['identifier']; - if (!empty($form_state['input'][$identifier]['open'])) { - $default_value = array_keys($this->get_default_states()); - unset($form['value']['#default_value']); - $form['value']['#default_value'] = $default_value; - $form_state['input'][$identifier] = $default_value; - } + /** + * Cache and return an array of status integers for "open" issue statuses. + */ + function get_open_states() { + if (empty($open_states)) { + $open_states = array_keys(project_issue_state(0, FALSE, FALSE, 0, TRUE)); } + return $open_states; } + /** + * Accept the input to the exposed filter and map it to the right values. + * + * This is where the special logic for the "- Open issues -" choice is + * converted back into the real status values for the underlying query. + * First, we invoke the parent method to try to handle the input. Then, we + * see if the input includes a value for this filter. If the value is an + * array we know we're a multi-select filter, and we need to more carefully + * handle the "open issues" choice (since someone might have selected that + * and a few other individual issue statuses). + */ function accept_exposed_input($input) { $rc = parent::accept_exposed_input($input); if ($rc) { if (!empty($this->options['expose']['identifier'])) { $identifier = $this->options['expose']['identifier']; if (isset($input[$identifier])) { - if ($input[$identifier] == 'open') { - $this->value = array_keys($this->get_default_states()); + if (is_array($input[$identifier])) { + $this->value = array(); + foreach ($input[$identifier] as $value) { + if ($value == 'Open') { + $this->value += $this->get_open_states(); + } + else { + $this->value[] = $value; + } + } } - // Work-around a bug in Views that doesn't handle 'All' correctly if - // the view already has a default value. - elseif ($input[$identifier] == 'All') { - $rc = FALSE; + else { + // Input is not an array (we're configured as "force single"). + switch ($input[$identifier]) { + case 'All': + // Work-around a bug in Views that doesn't handle 'All' + // correctly if the view already has a default value. + return FALSE; + + case 'Open': + $this->value = $this->get_open_states(); + break; + } } } } Index: views/project_issue.views_default.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/views/project_issue.views_default.inc,v retrieving revision 1.36 diff -u -p -r1.36 project_issue.views_default.inc --- views/project_issue.views_default.inc 22 Feb 2009 00:31:32 -0000 1.36 +++ views/project_issue.views_default.inc 25 Feb 2009 07:43:01 -0000 @@ -201,7 +201,7 @@ function project_issue_views_default_vie 'sid' => array( 'operator' => 'in', 'value' => array( - 'open' => 'open', + 'Open' => 'Open', ), 'group' => '0', 'exposed' => TRUE, @@ -580,7 +580,7 @@ function project_issue_views_default_vie 'sid' => array( 'operator' => 'in', 'value' => array( - 'open' => 'open', + 'Open' => 'Open', ), 'group' => '0', 'exposed' => TRUE, @@ -1035,7 +1035,7 @@ function project_issue_views_default_vie 'sid' => array( 'operator' => 'in', 'value' => array( - 'open' => 'open', + 'Open' => 'Open', ), 'group' => '0', 'exposed' => TRUE, @@ -1439,7 +1439,7 @@ function project_issue_views_default_vie 'sid' => array( 'operator' => 'in', 'value' => array( - 'open' => 'open', + 'Open' => 'Open', ), 'group' => '0', 'exposed' => TRUE,