Skip to content

Commit

Permalink
Merge pull request #22 from HarryAndrewMorgan/DashboardFeatures
Browse files Browse the repository at this point in the history
Dashboard features
  • Loading branch information
hamogor authored Feb 5, 2018
2 parents 3fd8c66 + f7d1fb1 commit f37bd29
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 65 deletions.
8 changes: 6 additions & 2 deletions advert.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php
require_once ('models/connectdb.php');
require_once ('models/Database.php');
require_once ('models/User.php');
$user = new User($connection);
require_once ('models/Advert.php');
session_start();
$_dbHandle = Database::getInstance()->getdbConnection();
$user = new User($_dbHandle);
$advert = new Advert($_dbHandle);
$view = new stdClass();
$view->pageTitle = 'Advert';
require_once('views/advert.phtml');
6 changes: 2 additions & 4 deletions createadvert.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
$price = trim($_POST['price']);
$description = trim($_POST['description']);
$type = trim($_POST['type']);
//$picture = $_FILES['file']['name'];
//$data = file_get_contents($_FILES["file"]["tmp_name"]);
$imgtype = $_FILES["file"]["type"];
$picture = $_FILES['file']['name'];
$userID = $_SESSION['UserID'];
try {
if ($advert->createAdvert($name, $price, $description, $type, $userID)) {
if ($advert->createAdvert($name, $price, $description, $type, $userID, $picture)) {
$advert->redirect('youradverts.php');
}
} catch (PDOException $exception) {
Expand Down
4 changes: 1 addition & 3 deletions dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
}
$username = $_SESSION['Username'];
$email = $_SESSION['Email'];
$sqlQuery = $_dbHandle->prepare("SELECT * FROM Users WHERE Username=".$username);
$sqlQuery->execute(array(":user"=>$username));
$userRow=$sqlQuery->fetch(PDO::FETCH_ASSOC);
$user->fetchAUser($username);

if(isset($_POST['logout']))
{
Expand Down
Binary file added img/forceofwill.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 9 additions & 7 deletions models/Advert.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ function __construct($_dbhandle)
$this->db = $_dbhandle;
}

public function createAdvert($name, $price, $description, $type, $userID)
public function createAdvert($name, $price, $description, $type, $userID, $picture)
{
{
try {
$sqlQuery = $this->db->prepare("INSERT INTO Adverts(AdvertName,AdvertPrice,AdvertDescription, AdvertType, UserID) VALUES(:aname, :price, :description, :type, :userID)");
$sqlQuery = $this->db->prepare("INSERT INTO Adverts(AdvertName,AdvertPrice,AdvertDescription, AdvertType, UserID, PhotoName) VALUES(:aname, :price, :description, :type, :userID, :picture)");
$sqlQuery->bindparam(":aname", $name);
$sqlQuery->bindparam(":price", $price);
$sqlQuery->bindparam(":description", $description);
$sqlQuery->bindparam(":type", $type);
$sqlQuery->bindparam(":userID", $userID);
$sqlQuery->bindparam(":picture", $picture);
$sqlQuery->execute();


Expand Down Expand Up @@ -76,14 +77,15 @@ public function returnAdverts()
{
$sqlQuery = $this->db->prepare("SELECT * FROM Adverts");
$sqlQuery->execute();
$results = $sqlQuery->fetchAll(PDO::FETCH_ASSOC);
$results = $sqlQuery->fetchAll(PDO::FETCH_OBJ);
return $results;
}
public function getPhotoName()
public function getAdvertForUser($userID)
{
$sqlQuery = $this->db->prepare("SELECT * FROM Adverts");
$sqlQuery = $this->db->prepare("SELECT * FROM Adverts WHERE UserID=:userID");
$sqlQuery->bindparam(":userID", $userID);
$sqlQuery->execute();
$results = $sqlQuery->fetch(PDO::FETCH_ASSOC);
echo $results['PhotoName'];
$results = $sqlQuery->fetchAll(PDO::FETCH_OBJ);
return $results;
}
}
2 changes: 1 addition & 1 deletion models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class User extends PDO

function __construct($_dbhandle)
{
$this->db = $_dbhandle;
$this->_dbHandle = $_dbhandle;
}

public function register($username, $email, $pass, $address, $phone)
Expand Down
12 changes: 0 additions & 12 deletions models/connectdb.php

This file was deleted.

2 changes: 1 addition & 1 deletion register.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
else {
try {
//prepare statement to find matching username and emails
$sqlQuery = $connection->prepare("SELECT Username, Email FROM Users WHERE Username=:username OR Email=:email");
$sqlQuery = $_dbHandle->prepare("SELECT Username, Email FROM Users WHERE Username=:username OR Email=:email");
//execute statement and enter values into an array for easy access
$sqlQuery->execute(array(':username' => $username, ':email' => $email));
//fetches the associated rows
Expand Down
1 change: 0 additions & 1 deletion views/advert.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<h1 class="my-4">Advert Name</h1>
<div class="list-group">
<a href="#" class="list-group-item active">Description</a>
<a href="#" class="list-group-item">Seller Details</a>
<a href="#" class="list-group-item">Save Advert</a>
</div>
</div>
Expand Down
29 changes: 14 additions & 15 deletions views/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,23 @@

<?php


foreach($view->adverts as $advert)
{
echo "<div class=\"col-lg-4 col-md-6 mb-4\">
<div class=\"card h-100\">
<a href=\"advert.php\"><img class=\"card-img-top\" src=\"img\yidris.jpg\" alt=\"\"></a>
<div class=\"card-body\">
<h4 class=\"card-title\">
<a href=\"advert.php\">Item One</a>
</h4>
<h5></h5>
<p class=\"card-text\">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Amet numquam aspernatur!</p>
</div>
<div class=\"card-footer\">
<small class=\"text-muted\">&#9733; &#9733; &#9733; &#9733; &#9734;</small>
</div>
</div>
</div>";
<div class=\"card h-100\">
<a href=\"advert.php\"><img class=\"card-img-top\" src=\"img/$advert->PhotoName\" alt=\"\"></a>
<div class=\"card-body\">
<h4 class=\"card-title\">
<a href=\"advert.php\">$advert->AdvertName</a>
</h4>
<h5>£ $advert->AdvertPrice</h5>
<p class=\"card-text\">$advert->AdvertDescription</p>
</div>
<div class=\"card-footer\">
<small class=\"text-muted\">&#9733; &#9733; &#9733; &#9733; &#9734;</small>
</div>
</div>
</div>";
}
?>

Expand Down
32 changes: 15 additions & 17 deletions views/youradverts.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@

<?php


foreach($view->adverts as $advert)
{
echo "<div class=\"col-lg-4 col-md-6 mb-4\">
<div class=\"card h-100\">
<a href=\"advert.php\"><img class=\"card-img-top\" src=\"http://placehold.it/700x400\" alt=\"\"></a>
<div class=\"card-body\">
<h4 class=\"card-title\">
<a href=\"advert.php\">Item One</a>
</h4>
<h5>$24.99</h5>
<p class=\"card-text\">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Amet numquam aspernatur!</p>
</div>
<div class=\"card-footer\">
<small class=\"text-muted\">&#9733; &#9733; &#9733; &#9733; &#9734;</small>
</div>
</div>
</div>";
echo "<div class=\"col-lg-4 col-md-6 mb-4\">
<div class=\"card h-100\">
<a href=\"advert.php\"><img class=\"card-img-top\" src=\"img/$advert->PhotoName\" alt=\"\"></a>
<div class=\"card-body\">
<h4 class=\"card-title\">
<a href=\"advert.php\">$advert->AdvertName</a>
</h4>
<h5>£ $advert->AdvertPrice</h5>
<p class=\"card-text\">$advert->AdvertDescription</p>
</div>
<div class=\"card-footer\">
<small class=\"text-muted\">&#9733; &#9733; &#9733; &#9733; &#9734;</small>
</div>
</div>
</div>";
}
?>
</div>
Expand All @@ -42,7 +41,6 @@
</body>
</html>


<!-- Bootstrap core JavaScript -->
<script src="../vendor/jquery/jquery.min.js"></script>
<script src="../vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
Expand Down
3 changes: 1 addition & 2 deletions youradverts.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
$_dbHandle = Database::getInstance()->getdbConnection();
$advert = new Advert($_dbHandle);
$view->numberOfRows = $advert->countAdverts();
$view->adverts = $advert->returnAdverts();
$view->pageTitle = 'Your Adverts';
$view->adverts = $advert->getAdvertForUser($_SESSION['UserID']);
require_once('Views/youradverts.phtml');

0 comments on commit f37bd29

Please sign in to comment.