Complete the fetchAll of modulebuilder + websitepage

This commit is contained in:
Laurent Destailleur 2018-11-20 18:29:29 +01:00
parent 200de22807
commit 61fddadc3f
3 changed files with 82 additions and 3 deletions

View File

@ -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
*

View File

@ -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 = '<html><body>This is a html content</body></html>';

View File

@ -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;