mirror of
https://github.com/processwire/processwire.git
synced 2025-08-21 14:02:59 +02:00
Update FieldtypeComments, FieldtypeOptions and FieldtypePage to take advantage of new PageFinder and Database class improvements
This commit is contained in:
@@ -1265,13 +1265,16 @@ class FieldtypeComments extends FieldtypeMulti {
|
||||
}
|
||||
|
||||
// COUNT
|
||||
$query = $database->prepare($countQuery->getQuery());
|
||||
$sql = $countQuery->getQuery();
|
||||
$query = $database->prepare($sql);
|
||||
foreach($binds as $key => $value) {
|
||||
$query->bindValue(":$key", $value);
|
||||
}
|
||||
$countQuery->copyBindValuesTo($query); // populate from $countQuery to $query
|
||||
$query->execute();
|
||||
list($total) = $query->fetch(\PDO::FETCH_NUM);
|
||||
$total = (int) $total;
|
||||
$query->closeCursor();
|
||||
if($options['count']) return $total;
|
||||
|
||||
// SELECT
|
||||
@@ -1290,6 +1293,7 @@ class FieldtypeComments extends FieldtypeMulti {
|
||||
foreach($binds as $key => $value) {
|
||||
$query->bindValue(":$key", $value);
|
||||
}
|
||||
$selectQuery->copyBindValuesTo($query); // populate from $selectQuery to $query
|
||||
$query->execute();
|
||||
$commentPages = array();
|
||||
|
||||
|
@@ -345,9 +345,13 @@ class FieldtypeOptions extends FieldtypeMulti implements Module {
|
||||
$database = $this->wire('database');
|
||||
$t = $database->escapeTable($query->field->getTable());
|
||||
$s = $database->escapeCol($subfield);
|
||||
$v = $database->escapeStr($value);
|
||||
$query->where("(SELECT COUNT(*) FROM $t WHERE $t.pages_id=pages.id AND $t.$s='$v')=0");
|
||||
$query->parentQuery->where("($table.data IS NULL OR $table.$s!='$v')");
|
||||
|
||||
$bindKey = $query->bindValueGetKey($value);
|
||||
$query->where("(SELECT COUNT(*) FROM $t WHERE $t.pages_id=pages.id AND $t.$s=$bindKey)=0");
|
||||
|
||||
$bindKey = $query->parentQuery->bindValueGetKey($value);
|
||||
$query->parentQuery->where("($table.data IS NULL OR $table.$s!=$bindKey)");
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
@@ -27,6 +27,14 @@ class SelectableOptionManager extends Wire {
|
||||
*/
|
||||
protected $useLanguages = false;
|
||||
|
||||
/**
|
||||
* Cache of loaded options
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
*/
|
||||
protected $optionsCache = array();
|
||||
|
||||
/**
|
||||
* Options removed that have not yet been deleted
|
||||
*
|
||||
@@ -92,7 +100,13 @@ class SelectableOptionManager extends Wire {
|
||||
*
|
||||
*/
|
||||
public function getOptions(Field $field, array $filters = array()) {
|
||||
|
||||
|
||||
$hasFilters = count($filters) > 0;
|
||||
|
||||
if(isset($this->optionsCache[$field->id]) && !$hasFilters) {
|
||||
return $this->optionsCache[$field->id];
|
||||
}
|
||||
|
||||
$defaults = array(
|
||||
'id' => array(),
|
||||
'title' => array(),
|
||||
@@ -175,6 +189,8 @@ class SelectableOptionManager extends Wire {
|
||||
}
|
||||
|
||||
$options->resetTrackChanges();
|
||||
|
||||
if(!$hasFilters) $this->optionsCache[$field->id] = $options;
|
||||
|
||||
return $options;
|
||||
}
|
||||
@@ -543,6 +559,8 @@ class SelectableOptionManager extends Wire {
|
||||
*
|
||||
*/
|
||||
public function updateOptions(Field $field, $options) {
|
||||
|
||||
unset($this->optionsCache[$field->id]);
|
||||
|
||||
$database = $this->wire('database');
|
||||
$sql = "UPDATE " . self::optionsTable . " SET sort=:sort, title=:title, `value`=:value ";
|
||||
@@ -596,6 +614,7 @@ class SelectableOptionManager extends Wire {
|
||||
*
|
||||
*/
|
||||
public function deleteOptions(Field $field, $options) {
|
||||
unset($this->optionsCache[$field->id]);
|
||||
$ids = array();
|
||||
foreach($options as $option) {
|
||||
if(!$option instanceof SelectableOption) continue;
|
||||
@@ -616,6 +635,7 @@ class SelectableOptionManager extends Wire {
|
||||
*/
|
||||
public function deleteOptionsByID(Field $field, array $ids) {
|
||||
|
||||
unset($this->optionsCache[$field->id]);
|
||||
$database = $this->wire('database');
|
||||
$table = $database->escapeTable($field->getTable());
|
||||
$cleanIDs = array();
|
||||
@@ -664,6 +684,8 @@ class SelectableOptionManager extends Wire {
|
||||
// options that have pre-assigned IDs
|
||||
$optionsByID = array();
|
||||
|
||||
unset($this->optionsCache[$field->id]);
|
||||
|
||||
// determine if any added options already have IDs
|
||||
foreach($options as $option) {
|
||||
if(!$option instanceof SelectableOption || !strlen($option->title)) continue;
|
||||
|
@@ -43,7 +43,7 @@ class FieldtypePage extends FieldtypeMulti implements Module, ConfigurableModule
|
||||
'created',
|
||||
'modified',
|
||||
'published',
|
||||
);
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
@@ -758,7 +758,7 @@ class FieldtypePage extends FieldtypeMulti implements Module, ConfigurableModule
|
||||
'path',
|
||||
'url',
|
||||
'sort',
|
||||
);
|
||||
);
|
||||
|
||||
$database = $this->wire('database');
|
||||
|
||||
@@ -813,20 +813,29 @@ class FieldtypePage extends FieldtypeMulti implements Module, ConfigurableModule
|
||||
}
|
||||
}
|
||||
|
||||
$value = $database->escapeStr($value);
|
||||
$subfield = $database->escapeCol($subfield);
|
||||
|
||||
if($operator == '!=') {
|
||||
$t = $database->escapeTable($query->field->getTable());
|
||||
$where =
|
||||
"SELECT COUNT(*) FROM $t " .
|
||||
"WHERE $t.pages_id=pages.id " .
|
||||
"AND " . ($idstr ? "$t.$subfield IN($value)" : "$t.$subfield='$value'");
|
||||
$where = "SELECT COUNT(*) FROM $t WHERE $t.pages_id=pages.id ";
|
||||
if($idstr) {
|
||||
$value = explode(',', $value);
|
||||
$value = array_map('intval', $value);
|
||||
$value = implode(',', $value);
|
||||
$where .= "AND $t.$subfield IN($value)";
|
||||
} else {
|
||||
$bindKey = $query->bindValueGetKey($value);
|
||||
$where .= "AND $t.$subfield=$bindKey";
|
||||
}
|
||||
$query->where("($where)=0");
|
||||
} else if($operator == '=' && $idstr) {
|
||||
$value = explode(',', $value);
|
||||
$value = array_map('intval', $value);
|
||||
$value = implode(',', $value);
|
||||
$query->where("($table.{$subfield} IN($value))");
|
||||
} else {
|
||||
$query->where("($table.{$subfield}{$operator}'$value')");
|
||||
$bindKey = $query->bindValueGetKey($value);
|
||||
$query->where("($table.{$subfield}{$operator}$bindKey)");
|
||||
}
|
||||
|
||||
} else if($this->getMatchQueryNative($query, $table, $subfield, $operator, $value)) {
|
||||
@@ -894,9 +903,8 @@ class FieldtypePage extends FieldtypeMulti implements Module, ConfigurableModule
|
||||
$table = $database->escapeTable($table);
|
||||
$table2 = "_fieldtypepage" . (++$n);
|
||||
$subfield = $database->escapeCol($subfield);
|
||||
|
||||
$value = $database->escapeStr($value);
|
||||
$query->join("pages AS $table2 ON $table2.$subfield$operator'$value'");
|
||||
$bindKey = $query->bindValueGetKey($value);
|
||||
$query->join("pages AS $table2 ON $table2.$subfield$operator$bindKey");
|
||||
$query->where("($table.data=$table2.id)");
|
||||
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user