Queries had been simplified
This commit is contained in:
parent
832ac65248
commit
d74067b461
|
@ -887,13 +887,10 @@ class Profile
|
||||||
*/
|
*/
|
||||||
public static function searchProfiles($start = 0, $count = 100, $search = null)
|
public static function searchProfiles($start = 0, $count = 100, $search = null)
|
||||||
{
|
{
|
||||||
$publish = (DI::config()->get('system', 'publish_all') ? '' : "AND `publish` = 1");
|
|
||||||
$total = 0;
|
|
||||||
|
|
||||||
if (!empty($search)) {
|
if (!empty($search)) {
|
||||||
|
$publish = (DI::config()->get('system', 'publish_all') ? '' : "AND `publish` ");
|
||||||
$searchTerm = '%' . $search . '%';
|
$searchTerm = '%' . $search . '%';
|
||||||
$cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` FROM `owner-view`
|
$condition = ["NOT `blocked` AND NOT `account_removed`
|
||||||
WHERE NOT `blocked` AND NOT `account_removed`
|
|
||||||
$publish
|
$publish
|
||||||
AND ((`name` LIKE ?) OR
|
AND ((`name` LIKE ?) OR
|
||||||
(`nickname` LIKE ?) OR
|
(`nickname` LIKE ?) OR
|
||||||
|
@ -903,62 +900,24 @@ class Profile
|
||||||
(`country-name` LIKE ?) OR
|
(`country-name` LIKE ?) OR
|
||||||
(`pub_keywords` LIKE ?) OR
|
(`pub_keywords` LIKE ?) OR
|
||||||
(`prv_keywords` LIKE ?))",
|
(`prv_keywords` LIKE ?))",
|
||||||
$searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm);
|
$searchTerm, $searchTerm, $searchTerm, $searchTerm,
|
||||||
|
$searchTerm, $searchTerm, $searchTerm, $searchTerm];
|
||||||
} else {
|
} else {
|
||||||
$cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total`
|
$condition = ['blocked' => false, 'account_removed' => false];
|
||||||
FROM `owner-view` WHERE NOT `blocked` AND NOT `account_removed` $publish");
|
if (!DI::config()->get('system', 'publish_all')) {
|
||||||
}
|
$condition['publish'] = true;
|
||||||
|
|
||||||
if (DBA::isResult($cnt)) {
|
|
||||||
$total = $cnt['total'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$order = " ORDER BY `name` ASC ";
|
|
||||||
$profiles = [];
|
|
||||||
|
|
||||||
// If nothing found, don't try to select details
|
|
||||||
if ($total > 0) {
|
|
||||||
if (!empty($search)) {
|
|
||||||
$searchTerm = '%' . $search . '%';
|
|
||||||
|
|
||||||
$profiles = DBA::p("SELECT * FROM `owner-view`
|
|
||||||
WHERE NOT `blocked` AND NOT `account_removed`
|
|
||||||
$publish
|
|
||||||
AND ((`name` LIKE ?) OR
|
|
||||||
(`nickname` LIKE ?) OR
|
|
||||||
(`about` LIKE ?) OR
|
|
||||||
(`locality` LIKE ?) OR
|
|
||||||
(`region` LIKE ?) OR
|
|
||||||
(`country-name` LIKE ?) OR
|
|
||||||
(`pub_keywords` LIKE ?) OR
|
|
||||||
(`prv_keywords` LIKE ?))
|
|
||||||
$order LIMIT ?,?",
|
|
||||||
$searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm,
|
|
||||||
$start, $count
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$profiles = DBA::p("SELECT * FROM `owner-view`
|
|
||||||
WHERE NOT `blocked` AND NOT `account_removed`
|
|
||||||
$publish
|
|
||||||
$order
|
|
||||||
LIMIT ?, ?",
|
|
||||||
$start,
|
|
||||||
$count
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBA::isResult($profiles) && $total > 0) {
|
$total = DBA::count('owner-view', $condition);
|
||||||
return [
|
|
||||||
'total' => $total,
|
|
||||||
'entries' => DBA::toArray($profiles),
|
|
||||||
];
|
|
||||||
|
|
||||||
|
// If nothing found, don't try to select details
|
||||||
|
if ($total > 0) {
|
||||||
|
$profiles = DBA::selectToArray('owner-view', [], $condition, ['order' => ['name'], 'limit' => [$start, $count]]);
|
||||||
} else {
|
} else {
|
||||||
return [
|
$profiles = [];
|
||||||
'total' => $total,
|
|
||||||
'entries' => [],
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ['total' => $total, 'entries' => $profiles];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user