diff --git a/meta/AccessTable.php b/meta/AccessTable.php index f7144145..346128c5 100644 --- a/meta/AccessTable.php +++ b/meta/AccessTable.php @@ -506,7 +506,12 @@ protected function buildGetDataSQL($idColumn = 'pid') foreach ($this->schema->getColumns(false) as $col) { $col->getType()->select( - $QB, 'DATA', $mtable, 'out' . $col->getColref(), false, $sep + $QB, + 'DATA', + $mtable, + 'out' . $col->getColref(), + false, + $sep ); } diff --git a/meta/Search.php b/meta/Search.php index 9cbb9f8a..ce89263d 100755 --- a/meta/Search.php +++ b/meta/Search.php @@ -115,7 +115,7 @@ public function addSchema($table, $alias = '', $joinon = array()) ); } if ($joinon[1] != '=') { - throw new StructException('Only equality comparison is supported for JOIN conditions'); + throw new StructException('Only equality comparison is supported for JOIN conditions'); } $this->joins[$schema->getTable()] = $this->getJoinColumns($schema, $joinon[0], $joinon[2]); } @@ -125,13 +125,14 @@ public function addSchema($table, $alias = '', $joinon = array()) * Returns the columns being matched against for a JOIN ... ON * expression. The result will be ordered such that the first * column is the one from a previously-joined schema. - * + * * @param Schema $schema The schema being JOINed to the query * @param string $left The LHS of the JOIN ON comparison * @param string $right the RHS of the JOIN ON comparison * @return array The first element is the LHS column object and second is the RHS */ - protected function getJoinColumns($schema, $left, $right) { + protected function getJoinColumns($schema, $left, $right) + { $lcol = $this->findColumn($left); if ($lcol === false) { throw new StructException('Unrecognoside field ' . $left); @@ -143,7 +144,7 @@ protected function getJoinColumns($schema, $left, $right) { $table = $schema->getTable(); $left_is_old_table = $lcol->getTable() != $table; if ($left_is_old_table == ($rcol->getTable() != $table)) { - throw new StructException("Exactly one side of ON condition $left = $right must be a column of $table" ); + throw new StructException("Exactly one side of ON condition $left = $right must be a column of $table"); } if ($left_is_old_table) { return array($lcol, $rcol); diff --git a/meta/SearchCloud.php b/meta/SearchCloud.php index 0feb9f3c..85e85c25 100644 --- a/meta/SearchCloud.php +++ b/meta/SearchCloud.php @@ -56,10 +56,8 @@ public function getSQL() $QB->filters()->where('AND', 'tag IS NOT \'\''); $col = $this->columns[0]; - $col->getType()->select( - $QB, 'data_' . $datatable, 'multi_' . $col->getTable(), 'tag', true - ); - + $col->getType()->select($QB, 'data_' . $datatable, 'multi_' . $col->getTable(), 'tag', true); + $QB->addSelectStatement('COUNT(tag)', 'count'); $QB->addSelectColumn('schema_assignments', 'assigned', 'ASSIGNED'); if ($col->isMulti()) { diff --git a/meta/SearchSQLBuilder.php b/meta/SearchSQLBuilder.php index ef4339f6..876ea780 100644 --- a/meta/SearchSQLBuilder.php +++ b/meta/SearchSQLBuilder.php @@ -48,8 +48,12 @@ public function addSchemas($schemas, $joins) $lefttable = 'data_' . $lcol->getTable(); $righttable = 'data_' . $rcol->getTable(); $on = $lcol->getType()->joinCondition( - $this->qb, $lefttable, $lcol->getColName(), $righttable, - $rcol->getColName(), $rcol->getType() + $this->qb, + $lefttable, + $lcol->getColName(), + $righttable, + $rcol->getColName(), + $rcol->getType() ); $this->qb->addLeftJoin($lefttable, $righttable, $righttable, $on); } @@ -100,8 +104,12 @@ public function addColumns($columns) $n = 0; foreach ($columns as $col) { $col->getType()->select( - $this->qb, 'data_' . $col->getTable(), 'multi_' . $col->getTable(), - 'C' . $n++, true, $sep + $this->qb, + 'data_' . $col->getTable(), + 'multi_' . $col->getTable(), + 'C' . $n++, + true, + $sep ); } } diff --git a/types/AbstractBaseType.php b/types/AbstractBaseType.php index 5e501002..692b73de 100644 --- a/types/AbstractBaseType.php +++ b/types/AbstractBaseType.php @@ -371,7 +371,8 @@ public function renderTagCloudLink($value, \Doku_Renderer $R, $mode, $page, $fil * @param bool $test_rid Whether to require RIDs to be equal in the JOIN condition * @return string Alias for the multi-table */ - public function joinMulti(QueryBuilder $QB, $datatable, $multitable, $colref, $test_rid = true) { + public function joinMulti(QueryBuilder $QB, $datatable, $multitable, $colref, $test_rid = true) + { $MN = $QB->generateTableAlias('M'); $condition = "$datatable.pid = $MN.pid "; if ($test_rid) $condition .= "AND $datatable.rid = $MN.rid "; @@ -384,7 +385,7 @@ public function joinMulti(QueryBuilder $QB, $datatable, $multitable, $colref, $t ); return $MN; } - + /** * This function is used to modify an aggregation query to add a filter * for the given column matching the given value. A type should add at @@ -432,14 +433,14 @@ public function filter(QueryBuilderWhere $add, $tablealias, $colname, $comp, $va * need to add additional logic to the conditional expression or make * additional JOINs. * - * @param QueryBuilderWhere &$add The WHERE or ON clause which will contain the conditional expression this comparator will be used in + * @param QueryBuilderWhere &$add The WHERE or ON clause to contain the conditional this comparator will be used in * @param string $tablealias The table the values are stored in * @param string $colname The column name on the above table - * @param string &$op the logical operator this filter shoudl use + * @param string &$op the logical operator this filter should use * @return string|array The SQL expression to be used on one side of the comparison operator */ - protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, - $colname, &$op) { + protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, $colname, &$op) + { return "$tablealias.$colname"; } @@ -452,7 +453,8 @@ protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, * @param string $value The value a column is being compared to * @return string A SQL expression processing the value in some way. */ - protected function getSqlConstantValue($value) { + protected function getSqlConstantValue($value) + { return $value; } @@ -477,8 +479,11 @@ public function joinCondition($QB, $left_table, $left_colname, $right_table, $ri $add = new QueryBuilderWhere($QB); $op = 'AND'; $lhs = $this->getSqlCompareValue($add, $left_table, $left_colname, $op); - $rhs = $this->getSqlConstantValue($right_coltype->getSqlCompareValue($add, $right_table, $right_colname, $op)); - // FIXME: Need to handle possibility of getSqlCompareValue returning multiple values (i.e., due to joining on page name) + $rhs = $this->getSqlConstantValue( + $right_coltype->getSqlCompareValue($add, $right_table, $right_colname, $op) + ); + // FIXME: Need to handle possibility of getSqlCompareValue returning multiple + // values (i.e., due to joining on page name) // FIXME: Need to consider how/whether to handle multi-valued columns $AN = $add->getQB()->generateTableAlias('A'); $subquery = "(SELECT assigned @@ -506,10 +511,11 @@ public function joinCondition($QB, $left_table, $left_colname, $right_table, $ri * @param string $colname Name of the column being JOINed ON * @return string One side of the equality comparion being used for the JOIN */ - protected function joinArgument(QueryBuilderWhere $add, $table, $colname) { + protected function joinArgument(QueryBuilderWhere $add, $table, $colname) + { return "$table.$colname"; } - + /** * Add the proper selection for this type to the current Query. Handles the * possibility of multi-valued columns. @@ -519,7 +525,7 @@ protected function joinArgument(QueryBuilderWhere $add, $table, $colname) { * @param string $multitable The name of the table the values are stored in if the column is multi-valued * @param string $alias The added selection *has* to use this column alias * @param bool $test_rid Whether to require RIDs to be equal if JOINing multi-table - * @param string|null $concat_sep Seperator to concatenate mutli-values together. If null, don't perform concatentation. + * @param string|null $concat_sep Seperator to concatenate mutli-values together. Don't concatenate if null. */ public function select(QueryBuilder $QB, $singletable, $multitable, $alias, $test_rid = true, $concat_sep = null) { diff --git a/types/AutoSummary.php b/types/AutoSummary.php index 72185399..c5d1557a 100644 --- a/types/AutoSummary.php +++ b/types/AutoSummary.php @@ -41,18 +41,18 @@ public function sort(QueryBuilder $QB, $tablealias, $colname, $order) /** * When using `%lastsummary%`, we need to compare against the `title` table. * - * @param QueryBuilderWhere &$add The WHERE or ON clause which will contain the conditional expression this comparator will be used in + * @param QueryBuilderWhere &$add The WHERE or ON clause to contain the conditional this comparator will be used in * @param string $tablealias The table the values are stored in * @param string $colname The column name on the above table - * @param string &$op the logical operator this filter shoudl use + * @param string &$op the logical operator this filter should use * @return string The SQL expression to be used on one side of the comparison operator */ - protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, - $colname, &$op) { + protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, $colname, &$op) + { $QB = $add->getQB(); $rightalias = $QB->generateTableAlias(); $QB->addLeftJoin($tablealias, 'titles', $rightalias, "$tablealias.pid = $rightalias.pid"); return "$rightalias.lastsummary"; - } + } } diff --git a/types/DateTime.php b/types/DateTime.php index 9c26fab7..37b63ca8 100644 --- a/types/DateTime.php +++ b/types/DateTime.php @@ -118,17 +118,18 @@ public function selectCol(QueryBuilder $QB, $tablealias, $colname, $alias) /** - * Handle case of a revision column, where you need to convert from a Unix + * Handle case of a revision column, where you need to convert from a Unix * timestamp. * - * @param QueryBuilderWhere &$add The WHERE or ON clause which will contain the conditional expression this comparator will be used in + * @param QueryBuilderWhere &$add The WHERE or ON clause to contain the conditional this comparator will be used in * @param string $tablealias The table the values are stored in * @param string $colname The column name on the above table * @return string The SQL expression to be used on one side of the comparison operator - * @param string &$op the logical operator this filter shoudl use + * @param string &$op the logical operator this filter should use + * @return string|array The SQL expression to be used on one side of the comparison operator */ - protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, - $colname, &$op) { + protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, $colname, &$op) + { $col = "$tablealias.$colname"; $QB = $add->getQB(); @@ -141,7 +142,7 @@ protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, return $col; } - + /** * When sorting `%lastupdated%`, then sort the data from the `titles` table instead the `data_` table. * diff --git a/types/Decimal.php b/types/Decimal.php index 56b92108..61f5ce6c 100644 --- a/types/Decimal.php +++ b/types/Decimal.php @@ -155,10 +155,10 @@ public function sort(QueryBuilder $QB, $tablealias, $colname, $order) /** * Decimals need to be casted to proper type for comparison * - * @param QueryBuilderWhere &$add The WHERE or ON clause which will contain the conditional expression this comparator will be used in + * @param QueryBuilderWhere &$add The WHERE or ON clause to contain the conditional this comparator will be used in * @param string $tablealias The table the values are stored in * @param string $colname The column name on the above table - * @param string &$op the logical operator this filter shoudl use + * @param string &$op the logical operator this filter should use * @return string The SQL expression to be used on one side of the comparison operator */ protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, $colname, &$op) @@ -174,7 +174,8 @@ protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, $col * @param string $value The value a column is being compared to * @return string SQL expression casting $value to a decimal */ - protected function getSqlConstantValue($value) { + protected function getSqlConstantValue($value) + { return "CAST($value AS DECIMAL)"; } diff --git a/types/Lookup.php b/types/Lookup.php index 236d8fce..a57a38f7 100644 --- a/types/Lookup.php +++ b/types/Lookup.php @@ -256,14 +256,14 @@ public function selectCol(QueryBuilder $QB, $tablealias, $colname, $alias) /** * Compare against lookup table * - * @param QueryBuilderWhere &$add The WHERE or ON clause which will contain the conditional expression this comparator will be used in + * @param QueryBuilderWhere &$add The WHERE or ON clause to contain the conditional this comparator will be used in * @param string $tablealias The table the values are stored in * @param string $colname The column name on the above table - * @param string &$op the logical operator this filter shoudl use + * @param string &$op the logical operator this filter should use * @return string|array The SQL expression to be used on one side of the comparison operator */ - protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, - $colname, &$op) { + protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, $colname, &$op) + { $schema = 'data_' . $this->config['schema']; $column = $this->getLookupColumn(); if (!$column) { @@ -290,7 +290,8 @@ protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, * @param string $value The value a column is being compared to * @return string A SQL expression processing the value in some way. */ - protected function getSqlConstantValue($value) { + protected function getSqlConstantValue($value) + { $schema = 'data_' . $this->config['schema']; $column = $this->getLookupColumn(); if (!$column) { diff --git a/types/Page.php b/types/Page.php index 8b049d29..0c2b5bde 100644 --- a/types/Page.php +++ b/types/Page.php @@ -187,14 +187,13 @@ public function displayValue($value) /** * When using titles, we need to compare against the title table, too. * - * @param QueryBuilderWhere &$add The WHERE or ON clause which will contain the conditional expression this comparator will be used in + * @param QueryBuilderWhere &$add The WHERE or ON clause to contain the conditional this comparator will be used in * @param string $tablealias The table the values are stored in * @param string $colname The column name on the above table - * @param string &$op the logical operator this filter shoudl use + * @param string &$op the logical operator this filter should use * @return array The SQL expression to be used on one side of the comparison operator */ - protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, - $colname, &$op) + protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, $colname, &$op) { if (!$this->config['usetitles']) { return parent::getSqlCompareValue($add, $tablealias, $colname, $op); @@ -272,6 +271,6 @@ protected function mergeConfig($current, &$config) // if (!$this->config['usetitles']) { // return parent::joinArgument($add, $table, $colname); // } - // // FIXME: How to handle multiple values + // // FIXME: How to handle multiple values // } } diff --git a/types/Tag.php b/types/Tag.php index bd66b51b..4caecd13 100644 --- a/types/Tag.php +++ b/types/Tag.php @@ -115,14 +115,14 @@ protected function buildSQLFromContext(Column $context) /** * Normalize tags before comparing * - * @param QueryBuilderWhere &$add The WHERE or ON clause which will contain the conditional expression this comparator will be used in + * @param QueryBuilderWhere &$add The WHERE or ON clause to contain the conditional this comparator will be used in * @param string $tablealias The table the values are stored in * @param string $colname The column name on the above table - * @param string &$op the logical operator this filter shoudl use + * @param string &$op the logical operator this filter should use * @return string The SQL expression to be used on one side of the comparison operator */ - protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, - $colname, &$op) { + protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, $colname, &$op) + { return "LOWER(REPLACE($tablealias.$colname, ' ', ''))"; } @@ -132,7 +132,8 @@ protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, * @param string $value The value a column is being compared to * @return string A SQL expression processing the value in some way. */ - protected function getSqlConstantValue($value) { + protected function getSqlConstantValue($value) + { return "LOWER(REPLACE($value, ' ', ''))"; } } diff --git a/types/TraitFilterPrefix.php b/types/TraitFilterPrefix.php index 05ec6b86..fb32a71e 100644 --- a/types/TraitFilterPrefix.php +++ b/types/TraitFilterPrefix.php @@ -17,14 +17,14 @@ trait TraitFilterPrefix /** * Comparisons are done against the full string (including prefix/postfix) * - * @param QueryBuilderWhere &$add The WHERE or ON clause which will contain the conditional expression this comparator will be used in + * @param QueryBuilderWhere &$add The WHERE or ON clause to contain the conditional this comparator will be used in * @param string $tablealias The table the values are stored in * @param string $colname The column name on the above table - * @param string &$op the logical operator this filter shoudl use + * @param string &$op the logical operator this filter should use * @return string|array The SQL expression to be used on one side of the comparison operator */ - protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, - $colname, &$op) { + protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, $colname, &$op) + { $column = parent::getSqlCompareValue($add, $tablealias, $colname, $op); $add = $add->where($op); // open a subgroup diff --git a/types/User.php b/types/User.php index d4e2edf0..ccc22919 100644 --- a/types/User.php +++ b/types/User.php @@ -139,14 +139,14 @@ public function sort(QueryBuilder $QB, $tablealias, $colname, $order) } /** - * @param QueryBuilderWhere &$add The WHERE or ON clause which will contain the conditional expression this comparator will be used in + * @param QueryBuilderWhere &$add The WHERE or ON clause to contain the conditional this comparator will be used in * @param string $tablealias The table the values are stored in * @param string $colname The column name on the above table - * @param string &$op the logical operator this filter shoudl use + * @param string &$op the logical operator this filter should use * @return string The SQL expression to be used on one side of the comparison operator */ - protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, - $colname, &$op) { + protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, $colname, &$op) + { if (is_a($this->context, 'dokuwiki\plugin\struct\meta\UserColumn')) { $QB = $add->getQB(); $rightalias = $QB->generateTableAlias(); @@ -156,5 +156,4 @@ protected function getSqlCompareValue(QueryBuilderWhere &$add, $tablealias, return parent::getSqlCompareValue($add, $tablealias, $colname, $comp, $value, $op); } - }