Start implementation of new SQL scheme

This commit is contained in:
Léo Serre 2018-08-21 20:15:53 +02:00
parent 2e2c17c13b
commit 4fdae170d6
1 changed files with 30 additions and 41 deletions

View File

@ -12,12 +12,18 @@ require_once($config['third_folder']."Md/MarkdownExtra.inc.php");
class WikiPage class WikiPage
{ {
public $id = 0; private $id = 0;
public $title = NULL; private $permalink = 0;
public $url = NULL; private $version = 0;
public $locale = NULL; private $locale = NULL;
public $lastedit = NULL; private $creation_date = NULL;
public $archive = NULL; private $update_date = NULL;
private $author = NULL;
private $is_public = NULL;
private $is_archive = NULL;
private $is_commentable = NULL;
private $type = "wiki";
public $name = NULL;
public $content = NULL; public $content = NULL;
/***** /*****
@ -29,11 +35,11 @@ class WikiPage
$con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass']) $con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
or die ("Could not connect to server\n"); or die ("Could not connect to server\n");
$query = "SELECT id FROM wiki WHERE url=$1"; $query = "SELECT * FROM contents WHERE permalink=$1";
if($withArchive==0) { if($withArchive==0) {
$query .= " AND archive=FALSE"; $query .= " AND is_archive=FALSE AND is_public=FALSE";
} }
$query .= " ORDER BY lastedit DESC LIMIT 1 OFFSET $2"; $query .= " ORDER BY update_date DESC LIMIT 1 OFFSET $2";
pg_prepare($con, "prepare1", $query) pg_prepare($con, "prepare1", $query)
or die ("Cannot prepare statement\n"); or die ("Cannot prepare statement\n");
@ -43,13 +49,11 @@ class WikiPage
pg_close($con); pg_close($con);
if(pg_num_rows($result) == 1) { if(pg_num_rows($result) == 1) {
$wiki = pg_fetch_assoc($result); $row = pg_fetch_assoc($result);
$this->id = $wiki['id']; $this->populate($row);
$this->url = $url;
return 1; return 1;
} }
else { else {
$this->url = $url;
return 0; return 0;
} }
} }
@ -57,34 +61,19 @@ class WikiPage
/***** /*****
** Populate the object using its ID ** Populate the object using its ID
*****/ *****/
public function populate() { private function populate($row) {
global $config; $this->permalink = $row['permalink'];
$this->version = $row['version'];
if($this->id != 0) { $this->locale = $row['locale'];
$con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass']) $this->creation_date = $row['creation_date'];
or die ("Could not connect to server\n"); $this->update_date = $row['update_date'];
$this->author = $row['author'];
$query = "SELECT * FROM wiki WHERE id=$1"; $this->is_public = $row['is_public'];
$this->is_archive = $row['is_archive'];
pg_prepare($con, "prepare1", $query) $this->is_commentable = $row['is_commentable'];
or die ("Cannot prepare statement\n"); $this->type = $row['type'];
$result = pg_execute($con, "prepare1", array($this->id)) $this->name = $row['name'];
or die ("Cannot execute statement\n"); $this->content = $row['content'];
pg_close($con);
$wiki = pg_fetch_assoc($result);
$this->title = $wiki['title'];
$this->url = $wiki['url'];
$this->locale = $wiki['locale'];
$this->lastedit = $wiki['lastedit'];
$this->archive = $wiki['archive'];
$this->content = $wiki['content'];
}
else {
die("Cannot populate a wiki page without ID");
}
} }
/***** /*****