From 61fddadc3f0130d420209137c09f8c695ae0f4da Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 20 Nov 2018 18:29:29 +0100 Subject: [PATCH] Complete the fetchAll of modulebuilder + websitepage --- .../template/class/myobject.class.php | 71 +++++++++++++++++++ htdocs/website/class/websitepage.class.php | 11 ++- htdocs/website/index.php | 3 + 3 files changed, 82 insertions(+), 3 deletions(-) diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index 571c8614b17..14989e4d4b6 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -314,6 +314,77 @@ class MyObject extends CommonObject return count($this->lines)?1:0; }*/ + /** + * Load list of objects in memory from the database. + * + * @param string $sortorder Sort Order + * @param string $sortfield Sort field + * @param int $limit limit + * @param int $offset Offset + * @param array $filter Filter array + * @param string $filtermode Filter mode (AND or OR) + * @return array|int int <0 if KO, array of pages if OK + */ + public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND') + { + global $conf; + + dol_syslog(__METHOD__, LOG_DEBUG); + + $records=array(); + + $sql = 'SELECT'; + $sql .= ' t.rowid'; + // TODO Gett all fields + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t'; + $sql .= ' WHERE t.entity = '.$conf->entity; + // Manage filter + $sqlwhere = array(); + if (count($filter) > 0) { + foreach ($filter as $key => $value) { + if ($key=='t.rowid') { + $sqlwhere[] = $key . '='. $value; + } else { + $sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; + } + } + } + if (count($sqlwhere) > 0) { + $sql .= ' AND (' . implode(' '.$filtermode.' ', $sqlwhere).')'; + } + + if (!empty($sortfield)) { + $sql .= $this->db->order($sortfield, $sortorder); + } + if (!empty($limit)) { + $sql .= ' ' . $this->db->plimit($limit, $offset); + } + + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + + while ($obj = $this->db->fetch_object($resql)) + { + $record = new self($this->db); + + $record->id = $obj->rowid; + // TODO Get other fields + + //var_dump($record->id); + $records[$record->id] = $record; + } + $this->db->free($resql); + + return $records; + } else { + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + + return -1; + } + } + /** * Update object into database * diff --git a/htdocs/website/class/websitepage.class.php b/htdocs/website/class/websitepage.class.php index 4210e5981de..e84acc03527 100644 --- a/htdocs/website/class/websitepage.class.php +++ b/htdocs/website/class/websitepage.class.php @@ -169,6 +169,7 @@ class WebsitePage extends CommonObject $sql .= " t.aliasalt,"; $sql .= " t.title,"; $sql .= " t.description,"; + $sql .= " t.image,"; $sql .= " t.keywords,"; $sql .= " t.htmlheader,"; $sql .= " t.content,"; @@ -215,6 +216,7 @@ class WebsitePage extends CommonObject $this->title = $obj->title; $this->description = $obj->description; + $this->image = $obj->image; $this->keywords = $obj->keywords; $this->htmlheader = $obj->htmlheader; $this->content = $obj->content; @@ -243,7 +245,7 @@ class WebsitePage extends CommonObject } /** - * Load object in memory from the database + * Load list of objects in memory from the database. * * @param string $websiteid Web site * @param string $sortorder Sort Order @@ -254,7 +256,7 @@ class WebsitePage extends CommonObject * @param string $filtermode Filter mode (AND or OR) * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($websiteid, $sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND') + public function fetchAll($websiteid, $sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND') { dol_syslog(__METHOD__, LOG_DEBUG); @@ -268,6 +270,7 @@ class WebsitePage extends CommonObject $sql .= " t.aliasalt,"; $sql .= " t.title,"; $sql .= " t.description,"; + $sql .= " t.image,"; $sql .= " t.keywords,"; $sql .= " t.htmlheader,"; $sql .= " t.content,"; @@ -300,7 +303,7 @@ class WebsitePage extends CommonObject $sql .= $this->db->order($sortfield, $sortorder); } if (!empty($limit)) { - $sql .= ' ' . $this->db->plimit($limit, $offset); + $sql .= ' ' . $this->db->plimit($limit, $offset); } $resql = $this->db->query($sql); @@ -318,6 +321,7 @@ class WebsitePage extends CommonObject $record->aliasalt = preg_replace('/,+$/', '', preg_replace('/^,+/', '', $obj->aliasalt)); $record->title = $obj->title; $record->description = $obj->description; + $record->image = $obj->image; $record->keywords = $obj->keywords; $record->htmlheader = $obj->htmlheader; $record->content = $obj->content; @@ -570,6 +574,7 @@ class WebsitePage extends CommonObject $this->aliasalt = 'specimenalt'; $this->title = 'My Page'; $this->description = 'This is my page'; + $this->image = ''; $this->keywords = 'keyword1, keyword2'; $this->htmlheader = ''; $this->content = 'This is a html content'; diff --git a/htdocs/website/index.php b/htdocs/website/index.php index 1951fe379fa..2082b9b70b6 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -626,6 +626,7 @@ if ($action == 'addcontainer') $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME','alpha'); $objectpage->aliasalt = GETPOST('WEBSITE_ALIASALT','alpha'); $objectpage->description = GETPOST('WEBSITE_DESCRIPTION','alpha'); + $objectpage->image = GETPOST('WEBSITE_IMAGE','alpha'); $objectpage->keywords = GETPOST('WEBSITE_KEYWORDS','alpha'); $objectpage->lang = GETPOST('WEBSITE_LANG','aZ09'); $objectpage->htmlheader = GETPOST('htmlheader','none'); @@ -1127,6 +1128,7 @@ if ($action == 'updatemeta') $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME', 'alpha'); $objectpage->aliasalt = GETPOST('WEBSITE_ALIASALT', 'alpha'); $objectpage->description = GETPOST('WEBSITE_DESCRIPTION', 'alpha'); + $objectpage->image = GETPOST('WEBSITE_IMAGE', 'alpha'); $objectpage->keywords = GETPOST('WEBSITE_KEYWORDS', 'alpha'); $objectpage->lang = GETPOST('WEBSITE_LANG', 'aZ09'); $objectpage->htmlheader = trim(GETPOST('htmlheader', 'none')); @@ -2451,6 +2453,7 @@ if ($action == 'editmeta' || $action == 'createcontainer') $pagealiasalt=$objectpage->aliasalt; $pagetitle=$objectpage->title; $pagedescription=$objectpage->description; + $pageimage=$objectpage->image; $pagekeywords=$objectpage->keywords; $pagelang=$objectpage->lang; $pagehtmlheader=$objectpage->htmlheader;