Commit be7cd310 authored by Ryan Wade's avatar Ryan Wade

SQL Library Update:

Added support for multiple tables
This enables the components to be used for both client and admin page rendering
parent 089d157b
......@@ -15,12 +15,43 @@
$this->data[$attr] = $val;
}
}
class SQL_TABLE
{
function SQL_TABLE($src)
{
$this->rows = $src;
}
public function GET_ROW($id)
{
if(($id !== null) && ($id > -1) && ($id < count($this->rows)))
return $this->rows[$id];
return new SQL_ROW(null);
}
public function GET_ROWS_BY_ATTRIBUTE($attr, $id)
{
$i=0;
foreach($this->rows as $row)
{
if(($row->GET_ATTRIBUTE($attr)==$id))
{
$Query[$i]=$row;
$i++;
}
}
if(!isset($Query))
return null;
return $Query;
}
}
class SQL
{
//private $pages = null;
private $tables = null;
function SQL()
{
include "./fakeSQL.php";
$this->tables[0] = new SQL_TABLE(getPages());
$this->tables[1] = new SQL_TABLE(getUsers());
$this->tables[2] = new SQL_TABLE(getAdmin());
}
private function getFile($location)
{
......@@ -35,26 +66,9 @@
{
return "./logo.png";
}
public function GET_PAGE($id)
{
if(($id !== null) && ($id > -1) && ($id < count($this->pages)))
return $this->pages[$id];
return new SQL_ROW(null);
}
function QUERY_PARENT_ID($id)
public function GET_TABLE($id)
{
$i=0;
foreach($this->pages as $page)
{
if(($page->GET_ATTRIBUTE(1)==$id)||(($id==0)&&($page->GET_ATTRIBUTE(0)==0)))
{
$Query[$i]=$page;
$i++;
}
}
if(!isset($Query))
return null;
return $Query;
return $this->tables[$id];
}
// ID PID Title Description Image Content
......
......@@ -2,13 +2,13 @@
//Create recursive list of links to current page and all parents until the HOME page (0) is reached
class Breadcrumb
{
private $SQL = null;
private $SQL_TABLE = null;
private $id = null;
private $title = "";
//$title is needed as special pages cannot be accessed from SQL database.
function Breadcrumb($SQL, $id, $title)
function Breadcrumb($SQL_TABLE, $id, $title)
{
$this->SQL = $SQL;
$this->SQL_TABLE = $SQL_TABLE;
$this->id = $id;
$this->title = $title;
}
......@@ -19,15 +19,15 @@
$t_title = $this->title;
$link = "<a class='breadcrumbLink' href='viewpage.php?id=".$t_id."'>".$t_title."</a>";
//Get Parent ID
$t_id = $this->SQL->GET_PAGE($t_id)->GET_ATTRIBUTE(1);
$t_id = $this->SQL_TABLE->GET_ROW($t_id)->GET_ATTRIBUTE(1);
//If parent doesn't exist, end generation
while(($t_id !== -1)&&($t_id!==null))
{
//If parent exists, add to breadcrumb
$t_title = $this->SQL->GET_PAGE($t_id)->GET_ATTRIBUTE(2);
$t_title = $this->SQL_TABLE->GET_ROW($t_id)->GET_ATTRIBUTE(2);
$link = "<a class='breadcrumbLink' href='viewpage.php?id=".$t_id."'>".$t_title."</a> > ".$link;
//Get parent id
$t_id = $this->SQL->GET_PAGE($t_id)->GET_ATTRIBUTE(1);
$t_id = $this->SQL_TABLE->GET_ROW($t_id)->GET_ATTRIBUTE(1);
}
?>
<div id="breadcrumb">
......
<?php
$this->pages =
[new SQL_ROW([0,-1,"Home" , null , null ,"This is the homepage" ]),
new SQL_ROW([1, 0,"Page1" ,"Page 1 Description" , "./title.jpg" ,"This is page 1 html content" ]),
new SQL_ROW([2, 0,"Page2" ,"Page 2 Description" , "./title.jpg" ,"This is page 2 html content</br><button>Logon</button>" ]),
new SQL_ROW([3, 0,"Page3" ,"Page 3 Description" , "./title.jpg" ,"This is page 3 html content" ]),
new SQL_ROW([4, 0,"Page4" ,"Page 4 Description" , "./title.jpg" ,"This is page 4 html content" ]),
new SQL_ROW([5, 3,"Page5" , null , null ,"This is SUB page 5 html content" ]),
new SQL_ROW([6, 3,"Page6" , null , null ,"This is SUB page 6 html content" ]),
new SQL_ROW([7, 3,"Page7" , null , null ,"This is SUB page 7 html content" ]),
new SQL_ROW([8, 6,"Page8" , null , null ,"This is SUB SUB page 8 html content" ])
];
function getPages()
{
return
[new SQL_ROW([0,-1,"Home" , null , null ,"This is the homepage" ]),
new SQL_ROW([1, 0,"Page1" ,"Page 1 Description" , "./title.jpg" ,"This is page 1 html content" ]),
new SQL_ROW([2, 0,"Page2" ,"Page 2 Description" , "./title.jpg" ,"This is page 2 html content</br><button>Logon</button>" ]),
new SQL_ROW([3, 0,"Page3" ,"Page 3 Description" , "./title.jpg" ,"This is page 3 html content" ]),
new SQL_ROW([4, 0,"Page4" ,"Page 4 Description" , "./title.jpg" ,"This is page 4 html content" ]),
new SQL_ROW([5, 3,"Page5" , null , null ,"This is SUB page 5 html content" ]),
new SQL_ROW([6, 3,"Page6" , null , null ,"This is SUB page 6 html content" ]),
new SQL_ROW([7, 3,"Page7" , null , null ,"This is SUB page 7 html content" ]),
new SQL_ROW([8, 6,"Page8" , null , null ,"This is SUB SUB page 8 html content" ])
];
}
function getUsers()
{
return null;
}
function getAdmin()
{
return null;
}
?>
\ No newline at end of file
......@@ -2,11 +2,11 @@
//Create a navigation menu
class Nav
{
private $SQL = null;
private $SQL_TABLE = null;
private $s_id = null;
function Nav($SQL, $s_id)
function Nav($SQL_TABLE, $s_id)
{
$this->SQL = $SQL;
$this->SQL_TABLE = $SQL_TABLE;
$this->s_id = $s_id;
}
......@@ -31,7 +31,7 @@
//Add to navbar
$navbar .= "<li><a class='".$linkType."' href='viewpage.php?id=".$id."'>".$title."</a>";
if($id != 0)
$navbar .= $this->createLevel($this->SQL->QUERY_PARENT_ID($id));
$navbar .= $this->createLevel($this->SQL_TABLE->GET_ROWS_BY_ATTRIBUTE(1,$id));
$navbar .= "</li>\r\n";
}
$navbar .= "</ul>\r\n";
......@@ -42,7 +42,13 @@
{
?>
<nav id="navBar">
<?php echo $this->createLevel($this->SQL->QUERY_PARENT_ID(0)); ?>
<?php
$level = $this->SQL_TABLE->GET_ROWS_BY_ATTRIBUTE(1,0);
//Add Home link if specified
if(true)
array_unshift($level, $this->SQL_TABLE->GET_ROW(0));
echo $this->createLevel($level);
?>
</nav>
<?php
}
......
{
{title=home;parent=;type=text;content=Welcome to my website!;},
{title=about;parent=;type=picture;content=[./Ryan.jpg]/r/nI am Ryan Wade.;},
{title=hobbies;parent=about;type=text;content=I enjoy programming;}
}
\ No newline at end of file
......@@ -2,10 +2,10 @@
//create sitemap
class Sitemap
{
private $SQL = null;
function Sitemap($SQL)
private $SQL_TABLE = null;
function Sitemap($SQL_TABLE)
{
$this->SQL = $SQL;
$this->SQL_TABLE = $SQL_TABLE;
}
//recursive function to build sitemap hierarchy
......@@ -25,7 +25,7 @@
//Add to sitemap
$sitemap .= "<li><a href='viewpage.php?id=".$id."'>".$title."</a>";
if($id != 0)
$sitemap .= $this->createSitemap($this->SQL->QUERY_PARENT_ID($id));
$sitemap .= $this->createSitemap($this->SQL_TABLE->GET_ROWS_BY_ATTRIBUTE(1,$id));
$sitemap .= "</li>\r\n";
}
$sitemap .= "</ul>\r\n";
......@@ -37,7 +37,11 @@
{
?>
<div id="sitemap">
<?php echo $this->createSitemap($this->SQL->QUERY_PARENT_ID(0)); ?>
<?php
$level = $this->SQL_TABLE->GET_ROWS_BY_ATTRIBUTE(1,0);
//Add Home link
array_unshift($level, $this->SQL_TABLE->GET_ROW(0));
echo $this->createSitemap($level); ?>
</div>
<?php
}
......
......@@ -33,21 +33,21 @@
$page_title = "Sitemap";
break;
default:
$page_title = $SQL->GET_PAGE($page_id)->GET_ATTRIBUTE(2);
$page_desc = $SQL->GET_PAGE($page_id)->GET_ATTRIBUTE(3);
$page_img = $SQL->GET_PAGE($page_id)->GET_ATTRIBUTE(4);
$page_src = $SQL->GET_PAGE($page_id)->GET_ATTRIBUTE(5);
$page_title = $SQL->GET_TABLE(0)->GET_ROW($page_id)->GET_ATTRIBUTE(2);
$page_desc = $SQL->GET_TABLE(0)->GET_ROW($page_id)->GET_ATTRIBUTE(3);
$page_img = $SQL->GET_TABLE(0)->GET_ROW($page_id)->GET_ATTRIBUTE(4);
$page_src = $SQL->GET_TABLE(0)->GET_ROW($page_id)->GET_ATTRIBUTE(5);
break;
}
//Initialize page component objects
$css = new CSS();
$header = new Header($site_title, $site_logo);
$nav = new NAV($SQL, $page_id);
$nav = new NAV($SQL->GET_TABLE(0), $page_id);
$title = new Title($page_id, $page_title, $page_desc, $page_img);
$breadcrumb = new Breadcrumb($SQL, $page_id, $page_title);
$breadcrumb = new Breadcrumb($SQL->GET_TABLE(0), $page_id, $page_title);
$body = new Body($page_src);
$sitemap = new Sitemap($SQL);
$sitemap = new Sitemap($SQL->GET_TABLE(0));
$footer = new footer();
//render HTML output
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment