Fix countAll

This commit is contained in:
Laurent Destailleur 2021-01-26 13:11:10 +01:00
parent 02098bf37b
commit a1147319d2

View File

@ -400,7 +400,7 @@ class WebsitePage extends CommonObject
$sql .= " t.fk_object"; $sql .= " t.fk_object";
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
$sql .= ' WHERE t.fk_website = '.$websiteid; $sql .= ' WHERE t.fk_website = '.$websiteid;
// Manage filter // Manage filter (same than into countAll)
$sqlwhere = array(); $sqlwhere = array();
if (count($filter) > 0) { if (count($filter) > 0) {
foreach ($filter as $key => $value) { foreach ($filter as $key => $value) {
@ -501,14 +501,27 @@ class WebsitePage extends CommonObject
$sql = 'SELECT COUNT(t.rowid) as nb'; $sql = 'SELECT COUNT(t.rowid) as nb';
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
$sql .= ' WHERE t.fk_website = '.$websiteid; $sql .= ' WHERE t.fk_website = '.$websiteid;
// Manage filter // Manage filter (same than into fetchAll)
$sqlwhere = array(); $sqlwhere = array();
if (count($filter) > 0) { if (count($filter) > 0) {
foreach ($filter as $key => $value) { foreach ($filter as $key => $value) {
if ($key == 't.rowid' || $key == 't.fk_website') { if ($key == 't.rowid' || $key == 't.fk_website' || $key == 'status') {
$sqlwhere[] = $key.'='.$value; $sqlwhere[] = $key.' = '.$value;
} elseif ($key == 'type_container') {
$sqlwhere[] = $key." = '".$this->db->escape($value)."'";
} elseif ($key == 'lang' || $key == 't.lang') { } elseif ($key == 'lang' || $key == 't.lang') {
$sqlwhere[] = $key." = '".$this->db->escape(substr($value, 0, 2))."'"; $listoflang = array();
$foundnull = 0;
foreach (explode(',', $value) as $tmpvalue) {
if ($tmpvalue == 'null') {
$foundnull++;
continue;
}
$listoflang[] = "'".$this->db->escape(substr(str_replace("'", '', $tmpvalue), 0, 2))."'";
}
$stringtouse = $key." IN (".join(',', $listoflang).")";
if ($foundnull) $stringtouse = '('.$stringtouse.' OR '.$key.' IS NULL)';
$sqlwhere[] = $stringtouse;
} else { } else {
$sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\''; $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
} }