Add method to count number of blogs in website
This commit is contained in:
parent
9c683fb951
commit
d6966dd429
@ -274,7 +274,7 @@ WEBSITE_PAGEURL=URL of page
|
|||||||
WEBSITE_TITLE=Title
|
WEBSITE_TITLE=Title
|
||||||
WEBSITE_DESCRIPTION=Description
|
WEBSITE_DESCRIPTION=Description
|
||||||
WEBSITE_IMAGE=Image
|
WEBSITE_IMAGE=Image
|
||||||
WEBSITE_IMAGEDesc=Relative path of the image media. You can keep this empty as this is rarely used (it can be used by dynamic content to show a thumbnail in a list of blog posts). Use __WEBSITEKEY__ in the path if path depends on website name.
|
WEBSITE_IMAGEDesc=Relative path of the image media. You can keep this empty as this is rarely used (it can be used by dynamic content to show a thumbnail in a list of blog posts). Use __WEBSITE_KEY__ in the path if path depends on website name.
|
||||||
WEBSITE_KEYWORDS=Keywords
|
WEBSITE_KEYWORDS=Keywords
|
||||||
LinesToImport=Lines to import
|
LinesToImport=Lines to import
|
||||||
|
|
||||||
|
|||||||
@ -369,6 +369,59 @@ class WebsitePage extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Count objects in the database.
|
||||||
|
*
|
||||||
|
* @param string $websiteid Web site
|
||||||
|
* @param array $filter Filter array
|
||||||
|
* @param string $filtermode Filter mode (AND or OR)
|
||||||
|
* @return int int <0 if KO, array of pages if OK
|
||||||
|
*/
|
||||||
|
public function countAll($websiteid, array $filter = array(), $filtermode = 'AND')
|
||||||
|
{
|
||||||
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
|
||||||
|
$result = 0;
|
||||||
|
|
||||||
|
$sql = 'SELECT COUNT(t.rowid) as nb';
|
||||||
|
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
|
||||||
|
$sql .= ' WHERE t.fk_website = '.$websiteid;
|
||||||
|
// Manage filter
|
||||||
|
$sqlwhere = array();
|
||||||
|
if (count($filter) > 0) {
|
||||||
|
foreach ($filter as $key => $value) {
|
||||||
|
if ($key == 't.rowid' || $key == 't.fk_website') {
|
||||||
|
$sqlwhere[] = $key.'='.$value;
|
||||||
|
} elseif ($key == 'lang' || $key == 't.lang') {
|
||||||
|
$sqlwhere[] = $key." = '".$this->db->escape(substr($value, 0, 2))."'";
|
||||||
|
} else {
|
||||||
|
$sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count($sqlwhere) > 0) {
|
||||||
|
$sql .= ' AND ('.implode(' '.$filtermode.' ', $sqlwhere).')';
|
||||||
|
}
|
||||||
|
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if ($resql) {
|
||||||
|
$obj = $this->db->fetch_object($resql);
|
||||||
|
if ($obj) {
|
||||||
|
$result = $obj->nb;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->free($resql);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
} else {
|
||||||
|
$this->error = 'Error '.$this->db->lasterror();
|
||||||
|
$this->errors[] = $this->error;
|
||||||
|
dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update object into database
|
* Update object into database
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user