function get_terms_query($tx, $cols = COLS_ALL_RS, $object_id = 0, $terms_only = true) { $join = $where = $orderby = ''; // this taxonomy uses a custom schema global $scoper; $tx_src = $scoper->data_sources->get($tx->source); $table = $tx_src->table; // table alias $t = $tx_src->table_alias ? $tx_src->table_alias : $table; $as = $t != $table ? "AS {$t}" : ''; if (!empty($object_id)) { $qv = ScoperCustomTaxonomyHelper::get_terms_query_vars($tx, $terms_only); if (!$terms_only) { $join = " INNER JOIN {$qv->obj->table} {$qv->obj->as} ON {$qv->obj->alias}.{$qv->obj->col_id} = {$t}.{$qv->term->col_obj_id} AND {$qv->obj->alias}.{$qv->obj->col_id} = '{$object_id}'"; } } if (COL_TAXONOMY_ID_RS == $cols) { // term_id / tt_id in separate tables is only supported for taxonomies using standard WP schema $cols = COL_ID_RS; } switch ($cols) { case COL_ID_RS: $qcols = "{$t}.{$tx_src->cols->id}"; break; case COL_COUNT_RS: $qcols = "COUNT({$t}.{$tx_src->cols->id})"; break; default: // COLS_ALL { $qcols = "{$t}.*"; $orderby = "ORDER BY {$t}.{$tx_src->cols->name}"; } if (!empty($tx->cols->require_zero)) { $where .= " AND {$tx->cols->require_zero} = '0'"; } if (!empty($tx->cols->require_nonzero)) { $where .= " AND {$tx->cols->require_nonzero} > '0'"; } return "SELECT DISTINCT {$qcols} FROM {$table} {$as} {$join} WHERE 1=1 {$where} {$orderby}"; }
function get_terms_query_vars($tx, $terms_only = false) { if (!is_object($tx)) { if (!($tx = $this->get($tx))) { return array(); } } $arr = array(); if (!empty($tx->uses_standard_schema)) { return $this->standard_query_vars($terms_only); } require_once dirname(__FILE__) . '/taxonomies-custom_rs.php'; return ScoperCustomTaxonomyHelper::get_terms_query_vars($tx, $terms_only); }