From d6966dd42975653302eae333ce6a3700cd756c59 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 10 Mar 2020 15:59:48 +0100 Subject: [PATCH] Add method to count number of blogs in website --- htdocs/langs/en_US/other.lang | 2 +- htdocs/website/class/websitepage.class.php | 53 ++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang index 00259d976bc..ad08da1f4fa 100644 --- a/htdocs/langs/en_US/other.lang +++ b/htdocs/langs/en_US/other.lang @@ -274,7 +274,7 @@ WEBSITE_PAGEURL=URL of page WEBSITE_TITLE=Title WEBSITE_DESCRIPTION=Description 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 LinesToImport=Lines to import diff --git a/htdocs/website/class/websitepage.class.php b/htdocs/website/class/websitepage.class.php index 514f1033d55..ece8cff7e3a 100644 --- a/htdocs/website/class/websitepage.class.php +++ b/htdocs/website/class/websitepage.class.php @@ -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 *