mirror of
https://github.com/processwire/processwire.git
synced 2025-08-21 14:02:59 +02:00
Update FieldtypeComments::find() method to support inclusion of page.parent_id or page.templates_id in comment search
This commit is contained in:
@@ -478,7 +478,7 @@ class FieldtypeComments extends FieldtypeMulti {
|
|||||||
CREATE TABLE `{$table}_votes` (
|
CREATE TABLE `{$table}_votes` (
|
||||||
`comment_id` int unsigned NOT NULL,
|
`comment_id` int unsigned NOT NULL,
|
||||||
`vote` tinyint NOT NULL,
|
`vote` tinyint NOT NULL,
|
||||||
`created` TIMESTAMP NOT NULL,
|
`created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
`ip` VARCHAR(15) NOT NULL default '',
|
`ip` VARCHAR(15) NOT NULL default '',
|
||||||
`user_id` int unsigned NOT NULL default 0,
|
`user_id` int unsigned NOT NULL default 0,
|
||||||
PRIMARY KEY (`comment_id`, `ip`, `vote`),
|
PRIMARY KEY (`comment_id`, `ip`, `vote`),
|
||||||
@@ -1032,7 +1032,7 @@ class FieldtypeComments extends FieldtypeMulti {
|
|||||||
* ~~~~
|
* ~~~~
|
||||||
*
|
*
|
||||||
* @param string|null $selectorString Selector string with query
|
* @param string|null $selectorString Selector string with query
|
||||||
* @param Field|string Optional Field object. If omitted, then it will be determined automatically.
|
* @param CommentField|string Optional Field object. If omitted, then it will be determined automatically.
|
||||||
* @param array $options
|
* @param array $options
|
||||||
* - `count` (bool): Return a total count rather than a CommentArray? (default=false)
|
* - `count` (bool): Return a total count rather than a CommentArray? (default=false)
|
||||||
* @return CommentArray|int
|
* @return CommentArray|int
|
||||||
@@ -1048,11 +1048,9 @@ class FieldtypeComments extends FieldtypeMulti {
|
|||||||
);
|
);
|
||||||
$options = array_merge($defaults, $options);
|
$options = array_merge($defaults, $options);
|
||||||
if($field !== null) {
|
if($field !== null) {
|
||||||
if($selectorString instanceof Field || Selectors::stringHasSelector($field)) {
|
if($selectorString instanceof Field || (is_string($field) && Selectors::stringHasSelector($field))) {
|
||||||
// arguments are reversed
|
// arguments are reversed
|
||||||
$s = $selectorString;
|
list($selectorString, $field) = array($field, $selectorString);
|
||||||
$selectorString = $field;
|
|
||||||
$field = $s;
|
|
||||||
}
|
}
|
||||||
if(is_string($field)) $field = $this->wire('fields')->get($field);
|
if(is_string($field)) $field = $this->wire('fields')->get($field);
|
||||||
}
|
}
|
||||||
@@ -1099,8 +1097,8 @@ class FieldtypeComments extends FieldtypeMulti {
|
|||||||
|
|
||||||
$table = $database->escapeTable($field->getTable());
|
$table = $database->escapeTable($field->getTable());
|
||||||
|
|
||||||
$selectQuery->select("$table.*")->from($table)->where('id>0');
|
$selectQuery->select("$table.*")->from($table)->where("$table.id>0");
|
||||||
$countQuery->select('COUNT(*)')->from($table)->where('id>0');
|
$countQuery->select('COUNT(*)')->from($table)->where("$table.id>0");
|
||||||
|
|
||||||
/** @var Selectors $selectors */
|
/** @var Selectors $selectors */
|
||||||
$selectors = $selectorString instanceof Selectors ? $selectorString : $this->wire(new Selectors($selectorString));
|
$selectors = $selectorString instanceof Selectors ? $selectorString : $this->wire(new Selectors($selectorString));
|
||||||
@@ -1207,10 +1205,19 @@ class FieldtypeComments extends FieldtypeMulti {
|
|||||||
} else {
|
} else {
|
||||||
$colName = 'data';
|
$colName = 'data';
|
||||||
}
|
}
|
||||||
/** @var Field $field */
|
|
||||||
$field = $this->wire('fields')->get($fieldName);
|
if($fieldName === 'parent_id' || $fieldName === 'templates_id') {
|
||||||
if(!$field) continue;
|
$ids = array();
|
||||||
$fieldTable = $field->getTable();
|
foreach($values as $id) $ids[] = (int) $id;
|
||||||
|
$ids = implode(',', $ids);
|
||||||
|
$joinTable = "pages_$fieldName";
|
||||||
|
$joins[] = "pages AS $joinTable ON $joinTable.$fieldName IN($ids) AND $table.pages_id=$joinTable.id";
|
||||||
|
|
||||||
|
} else {
|
||||||
|
/** @var Field $f */
|
||||||
|
$f = $this->wire('fields')->get($fieldName);
|
||||||
|
if(!$f) continue;
|
||||||
|
$fieldTable = $f->getTable();
|
||||||
if(!$database->isOperator($operator)) $operator = '=';
|
if(!$database->isOperator($operator)) $operator = '=';
|
||||||
if(count($values) > 1) {
|
if(count($values) > 1) {
|
||||||
$ors = array();
|
$ors = array();
|
||||||
@@ -1229,6 +1236,7 @@ class FieldtypeComments extends FieldtypeMulti {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if no status was specified and we’re on the front-end, match only approved comments
|
// if no status was specified and we’re on the front-end, match only approved comments
|
||||||
if($status === null && $this->wire('page')->template != 'admin') {
|
if($status === null && $this->wire('page')->template != 'admin') {
|
||||||
|
Reference in New Issue
Block a user