/** * Returns sql where statement based on active user filters * @param string $extra sql * @param boolean $include_clustertree true if we want to include the clustertree filter, otherwise false * @return string */ function get_sql_filter($extra = '', $exceptions = array(), $allow_interactive_filters = false, $allow_configured_filters = true, $secondary_filtering_key = '', $include_clustertree = true) { global $SESSION; if (isset($this->secondary_filterings[$secondary_filtering_key])) { //if this is not the primary filtering, use a secondary one return $this->secondary_filterings[$secondary_filtering_key]->get_sql_filter($extra, $exceptions, $allow_interactive_filters, $allow_configured_filters); } //interactive filters, if applicable if ($allow_interactive_filters) { $result = parent::get_sql_filter($extra, $exceptions); } else { $result = ''; } //if configured filters are not enabled for this report, just use interactive filtering, //if applicable if (!$allow_configured_filters) { return $result; } $per_filter_data = array(); $sqls = array(); //obtain the pool of attributes to pull preferences from $per_filter_data = $this->get_preferences(); //grab the SQL filters foreach ($this->_fields as $shortname => $field) { //added condition: allow for disabling of the clustertree filter type if (!$field instanceof generalized_filter_clustertree || $include_clustertree) { if (isset($per_filter_data[$shortname])) { $formatted_data = $field->check_data((object) $per_filter_data[$shortname]); if ($formatted_data != false) { $newsql = $field->get_sql_filter($formatted_data); if ($newsql !== null) { $sqls[] = $newsql; } } } } } //combine SQL conditions if (!empty($sqls)) { $sql_piece = implode(' AND ', $sqls); if ($result === '') { $result = $sql_piece; } else { $result .= ' AND ' . $sql_piece; } } return $result; }
/** * Returns sql where statement based on active user filters * @param string $extra sql * @param boolean $include_clustertree true if we want to include the clustertree filter, otherwise false * @return string */ function get_sql_filter($extra = '', $exceptions = array(), $allow_interactive_filters = false, $allow_configured_filters = true, $secondary_filtering_key = '', $include_clustertree = true) { if (isset($this->secondary_filterings[$secondary_filtering_key])) { //error_log("/local/elisreports/instances/UCC::clustertree_optional_filtering::get_sql_filter() isset(this->secondary_filterings['{$secondary_filtering_key}'])"); //if this is not the primary filtering, use a secondary one return $this->secondary_filterings[$secondary_filtering_key]->get_sql_filter($extra, $exceptions, $allow_interactive_filters, $allow_configured_filters); } $params = array(); //error_log("/local/elisreports/instances/UCC::clustertree_optional_filtering::get_sql_filter() - allow_interactive_filters = {$allow_interactive_filters}"); //interactive filters, if applicable if ($allow_interactive_filters) { list($result, $params) = parent::get_sql_filter($extra, $exceptions); } else { $result = ''; } //if configured filters are not enabled for this report, just use interactive filtering, //if applicable if (!$allow_configured_filters) { //error_log("/local/elisreports/instances/UCC::clustertree_optional_filtering::get_sql_filter() - !allow_configured_filters => returning: array({$result}, params);"); return array($result, $params); } $sqls = array(); //obtain the pool of attributes to pull preferences from $per_filter_data = $this->get_preferences(); //print_object($per_filter_data); //grab the SQL filters foreach ($this->_fields as $shortname => $field) { //added condition: allow for disabling of the clustertree filter type if (!$field instanceof generalized_filter_clustertree || $include_clustertree) { //error_log("/local/elisreports/instances/UCC::clustertree_optional_filtering::get_sql_filter() -> {$shortname}"); if (isset($per_filter_data[$shortname])) { $formatted_data = $field->check_data((object) $per_filter_data[$shortname]); if ($formatted_data != false) { $newsql = $field->get_sql_filter($formatted_data); if (!empty($newsql) && !empty($newsql[0])) { $sqls[] = $newsql[0]; if (!empty($newsql[1]) && is_array($newsql[1])) { $params = array_merge($params, $newsql[1]); } } } else { //error_log("/local/elisreports/instances/UCC::clustertree_optional_filtering::get_sql_filter() - formatted_data == FALSE"); } } else { //error_log("/local/elisreports/instances/UCC::clustertree_optional_filtering::get_sql_filter() NOT isset(per_filter_data[{$shortname}])"); } } } //combine SQL conditions if (!empty($sqls)) { $sql_piece = implode(' AND ', $sqls); if ($result == '') { $result = $sql_piece; } else { $result .= ' AND ' . $sql_piece; } } return array($result, $params); }