Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
23f6546
Added Log file, modified .gitignore.
ericpharr Aug 18, 2017
d57a929
Case added to pagecontroller file to automatically display home page …
rex725 Aug 18, 2017
8a48e8a
Merge confilcts resolved.
rex725 Aug 18, 2017
7f1268f
ok
h9warren Aug 18, 2017
6fb0f78
Merge branch 'master' of github.com:microchemglobulecore/adlister.dev
h9warren Aug 18, 2017
e04dc4e
Routes added to switchcase to display our different pages.
rex725 Aug 18, 2017
bbd29de
Merge branch 'master' of github.com:microchemglobulecore/adlister.dev
h9warren Aug 18, 2017
920b21f
Added ads migration and seeder files and Ad model.
ericpharr Aug 18, 2017
89a9963
Sign up function added to the helper_functions and pagecontroller cas…
rex725 Aug 18, 2017
f1a72ad
Updated seeder.
ericpharr Aug 18, 2017
9a00dc2
Added index showing all adds.
ericpharr Aug 18, 2017
fa8f255
added a Main.css for tweaking bootstrap.
h9warren Aug 18, 2017
6ae0ce5
User log in completed.
rex725 Aug 18, 2017
cdde274
adding navbar and footer.
h9warren Aug 18, 2017
266d080
added a bootstrap CDN link and a main.css link to the header.
h9warren Aug 18, 2017
ed46999
added an account details page
h9warren Aug 18, 2017
62700f4
Merge pull request #1 from microchemglobulecore/ads-display
rex725 Aug 18, 2017
7b05e5d
Merge branch 'master' into user-sign-in
ericpharr Aug 18, 2017
67efe3f
Merge pull request #2 from microchemglobulecore/user-sign-in
ericpharr Aug 18, 2017
bfeed8a
Merge pull request #3 from microchemglobulecore/account_plus_css
ericpharr Aug 18, 2017
f7d2147
Moved code for logging in from inside page to page controller.
rex725 Aug 20, 2017
f721f55
Merge pull request #4 from microchemglobulecore/user-sign-in
ericpharr Aug 20, 2017
29a6f4a
Links added to the navbar to link between the different pages.
rex725 Aug 20, 2017
3f34bc7
Dynamic navbar for logged in users and logout function added.
rex725 Aug 21, 2017
ffc87a2
Merge pull request #6 from microchemglobulecore/dynamic-navbar
ericpharr Aug 21, 2017
1d21bdc
Updated account page. Update user info works. Added logic in helper f…
h9warren Aug 21, 2017
e4246e1
Merge pull request #7 from microchemglobulecore/account_plus_css
ericpharr Aug 21, 2017
3a81ced
Added checks to look for unique usernames and emails as well as redir…
rex725 Aug 21, 2017
1e7495a
Merge branch 'master' into sign-up-unique-verification
h9warren Aug 21, 2017
6fa922a
Merge pull request #8 from microchemglobulecore/sign-up-unique-verifi…
h9warren Aug 21, 2017
2237cc2
Added Ad creation form.
ericpharr Aug 21, 2017
bd194c4
When an add on the index page is clicked it will take the user to the…
rex725 Aug 21, 2017
1d7ceb5
Added functions to create and display ads with images. CSS image styling
ericpharr Aug 21, 2017
9df427c
Merge pull request #9 from microchemglobulecore/show-page
ericpharr Aug 21, 2017
2f69d66
Merge branch 'master' into ads-display
ericpharr Aug 21, 2017
68034b2
Merge pull request #10 from microchemglobulecore/ads-display
ericpharr Aug 21, 2017
9bc8fd0
Added function order to Model to return the top three most viewed ite…
rex725 Aug 21, 2017
6a7626c
Removed update username functionality. Added search to navbar partial.
h9warren Aug 22, 2017
545a0ef
Merge branch 'master' into account_plus_css
ericpharr Aug 22, 2017
3f3521c
Merge pull request #12 from microchemglobulecore/account_plus_css
ericpharr Aug 22, 2017
1327172
Merge branch 'master' into home_page_featured_display
ericpharr Aug 22, 2017
c36f0a5
Merge pull request #11 from microchemglobulecore/home_page_featured_d…
ericpharr Aug 22, 2017
5032820
Added pictures to individual ad page.
ericpharr Aug 22, 2017
0d811a6
Merge pull request #13 from microchemglobulecore/ads-display
ericpharr Aug 22, 2017
718bfdf
Added the logic to pull in the featured list on the home page which w…
rex725 Aug 22, 2017
f74075d
Delete var dumps from login.
ericpharr Aug 22, 2017
a9b228b
Changed user variable on lines 86 and 89 from user to userInfo to ref…
rex725 Aug 22, 2017
800d7c8
Merge pull request #14 from microchemglobulecore/ads-display
ericpharr Aug 22, 2017
859331a
Merge pull request #15 from microchemglobulecore/logout_page_feature_…
ericpharr Aug 22, 2017
771dbb4
Merge pull request #16 from microchemglobulecore/sign_up_page_fix
ericpharr Aug 22, 2017
e19f693
Navbar fixes.
rex725 Aug 22, 2017
e7a38c7
Merge pull request #18 from microchemglobulecore/navbar
rex725 Aug 22, 2017
6df2ab5
Refactored getAds() query to retrieve seller username and email.
ericpharr Aug 22, 2017
56f345d
Created findAds function to select ad by id and return seller info.
ericpharr Aug 22, 2017
0f78524
Created updateClicks() to updated clicks on individual ads.
ericpharr Aug 22, 2017
6fa634c
Updated order() function to return Ad object instead of assoc array.
ericpharr Aug 22, 2017
fe25427
Added call to updateClicks() to pageController for clicked ads.
ericpharr Aug 22, 2017
02aadde
Redid the navbar to allow collapsing.
rex725 Aug 22, 2017
5175d45
Merge pull request #19 from microchemglobulecore/ads-display
ericpharr Aug 22, 2017
4b917fa
Merge pull request #20 from microchemglobulecore/navbar
ericpharr Aug 22, 2017
c4eabc4
Various view modifications.
ericpharr Aug 22, 2017
45e735e
updated:
h9warren Aug 22, 2017
8df37fd
Homepage fixes changed treating of from an array to an object.
rex725 Aug 22, 2017
eda20ab
Merge branch 'account_plus_css' into master
rex725 Aug 22, 2017
1f3d5bb
Merge pull request #21 from microchemglobulecore/master
rex725 Aug 22, 2017
ef9a08e
Merge branch 'master' into homepage_fix
h9warren Aug 22, 2017
7c46e46
Merge pull request #22 from microchemglobulecore/homepage_fix
h9warren Aug 22, 2017
395c6b7
Merge branch 'master' into ads-display
ericpharr Aug 22, 2017
a596f80
Merge pull request #23 from microchemglobulecore/ads-display
rex725 Aug 22, 2017
4c0e7fb
Styling changes to accomodate later styling.
rex725 Aug 22, 2017
ca48ac2
Merge branch 'master' of github.com:microchemglobulecore/adlister.dev…
rex725 Aug 22, 2017
0ae29cf
created a homepage bg image and logo.
h9warren Aug 22, 2017
e32ab25
Merge branch 'account_plus_css' of github.com:microchemglobulecore/ad…
h9warren Aug 22, 2017
ba8a4f4
New seeder with images.
rex725 Aug 22, 2017
8be1239
Merge pull request #24 from microchemglobulecore/account_plus_css
rex725 Aug 22, 2017
a866632
Merge pull request #25 from microchemglobulecore/stylings
rex725 Aug 22, 2017
0ab2f8a
Added editAd() helper function.
ericpharr Aug 23, 2017
f0d7f26
Added findAdsByUser() to Ad class and implemented in account page.
ericpharr Aug 23, 2017
60a217a
Created forms for editing ads.
ericpharr Aug 23, 2017
5372379
Added close X on show page.
ericpharr Aug 23, 2017
2453a8f
Merge branch 'master' into new_seeder
ericpharr Aug 23, 2017
9e82ffc
Merge pull request #26 from microchemglobulecore/new_seeder
ericpharr Aug 23, 2017
f69448d
Merge pull request #27 from microchemglobulecore/ads-display
ericpharr Aug 23, 2017
13dbb70
-Added styling css to main.css. Made nav into branded color with cust…
h9warren Aug 23, 2017
2b8511b
Merge branch 'account_plus_css' into master
ericpharr Aug 23, 2017
776d6b0
Merge pull request #28 from microchemglobulecore/master
ericpharr Aug 23, 2017
96efe71
Restored updatePass() function.
ericpharr Aug 23, 2017
cb8beeb
Merge pull request #29 from microchemglobulecore/ads-display
ericpharr Aug 23, 2017
d13c29b
Increased specificity by adding the div id #search before styled clas…
h9warren Aug 23, 2017
7ce6211
Merge branch 'master' of github.com:microchemglobulecore/adlister.dev…
h9warren Aug 23, 2017
0c05e38
updated navbar for dropdown and alternate logged in nav.
h9warren Aug 23, 2017
f17fd3a
Merge branch 'account_plus_css' of github.com:microchemglobulecore/ad…
h9warren Aug 23, 2017
4fa90c1
Merge pull request #30 from microchemglobulecore/account_plus_css
ericpharr Aug 23, 2017
f72ceae
added margin-bottom: to the body tag in main.css to stop content from…
h9warren Aug 23, 2017
29e40ac
Merge pull request #31 from microchemglobulecore/account_plus_css
ericpharr Aug 23, 2017
5fc654f
assigned a link to the 'sell your old stuff' button on homepage.
h9warren Aug 23, 2017
013791a
Styling edits.
ericpharr Aug 23, 2017
019c8dc
Merge pull request #32 from microchemglobulecore/account_plus_css
rex725 Aug 23, 2017
0db3a44
Merge pull request #33 from microchemglobulecore/ads-display
rex725 Aug 23, 2017
792f942
Applied max height for images that makes them more uniform.
rex725 Aug 23, 2017
9ce552f
Merge pull request #34 from microchemglobulecore/image_styling
h9warren Aug 23, 2017
75392ff
CSS fix for image height on the accounts page.
rex725 Aug 23, 2017
df09cf2
updated css to crop images on #ad_img
h9warren Aug 23, 2017
3f454a8
Merge pull request #35 from microchemglobulecore/image_styling
ericpharr Aug 23, 2017
766d3f5
Merge pull request #36 from microchemglobulecore/account_plus_css
rex725 Aug 23, 2017
c1b4238
latest changes
h9warren Oct 12, 2017
71329bc
fixing css that got deleted. merging with master.
h9warren Oct 12, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.env.php
.env.*.php
env.*.php
/.idea
4 changes: 3 additions & 1 deletion bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// require models
require_once __DIR__ . '/models/User.php';
require_once __DIR__ . '/models/Ad.php';


// require helper classes
Expand All @@ -10,4 +11,5 @@


// require front controller
require_once __DIR__ . '/controllers/PageController.php';
require_once __DIR__ . '/controllers/PageController.php';

108 changes: 105 additions & 3 deletions controllers/PageController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

require_once __DIR__ . '/../utils/helper_functions.php';
require_once __DIR__ . '/../utils/functions.php';
require_once __DIR__ . '/../models/User.php';

function pageController()
{
Expand All @@ -10,18 +12,118 @@ function pageController()

// get the part of the request after the domain name
$request = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);

// var_dump($request);
// switch that will run functions and setup variables dependent on what route was accessed
$data['homeStatus'] = '';
$data['indexStatus'] = '';
$data['accountStatus'] = '';
$data['loginStatus'] = '';
$data['signupStatus'] = '';
$data['adsStatus'] = '';
switch ($request) {
// TODO: put routes here
case ('/'):
$mainView = '../views/home.php';
$ads = Ad::order('clicks');
$data['ads'] = $ads;
$navbarStatus = 'active';
$data['homeStatus'] = $navbarStatus;
break;
case ('/create'):
if(Auth::check()) {
$mainView = '../views/ads/create.php';
} else if (!Auth::check()) {
$mainView = '../views/users/login.php';
}
$navbarStatus = 'active';
$data['adsStatus'] = $navbarStatus;
break;
case ('/edit_ads'):
if(Auth::check()) {
$mainView = '../views/ads/edit.php';
} else if (!Auth::check()) {
$mainView = '../views/users/login.php';
}
$ad = Ad::findAd($_GET['ad']);
if ($ad->username !== $_SESSION['IS_LOGGED_IN']){
header('Location:/index');
die;
}
$data['ad'] = $ad;
editAd();
$navbarStatus = 'active';
$data['adsStatus'] = $navbarStatus;
break;
case ('/index'):
$mainView = '../views/ads/index.php';
$ads = Ad::all();
$data['ads'] = $ads;
$navbarStatus = 'active';
$data['indexStatus'] = $navbarStatus;
break;
case ('/show'):
$mainView = '../views/ads/show.php';
$ad = Ad::findAd($_GET['ad']);
$data['ad'] = $ad;
$ad->updateClicks();
break;
case ('/account'):
if(Auth::check()) {
$mainView = '../views/users/account.php';
} else if (!Auth::check()) {
$mainView = '../views/users/login.php';
}
$ads = Ad::findAdsByUser();
$navbarStatus = 'active';
$data['accountStatus'] = $navbarStatus;
break;
case ('/edit_users'):
if(Auth::check()) {
$mainView = '../views/users/edit.php';
} else if (!Auth::check()) {
$mainView = '../views/users/login.php';
}
break;
case ('/login'):
$mainView = '../views/users/login.php';
logIn();
$navbarStatus = 'active';
$data['loginStatus'] = $navbarStatus;
break;
case ('/signup'):
$mainView = '../views/users/signup.php';
signUp();
$navbarStatus = 'active';
$data['signupStatus'] = $navbarStatus;
break;
case ('/update'):
if(Auth::check()) {
$mainView = '../views/users/update.php';
} else if (!Auth::check()) {
$mainView = '../views/users/login.php';
}
updateUser();
break;
case ('/password'):
$mainView = '../views/users/password.php';
updatePass();
break;
case ('/logout'):
$mainView = '../views/home.php';
Auth::logout();
$ads = Ad::order('clicks');
$data['ads'] = $ads;
break;
default: // displays 404 if route not specified above
$mainView = '../views/404.php';
break;
}

$data['mainView'] = $mainView;

$data['errorMessage'] = signup();
$data['user'] = Auth::user();
return $data;
}

extract(pageController());
// var_dump($_SESSION);
extract(pageController());
20 changes: 20 additions & 0 deletions database/migrations/ads_migration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

$_ENV = include __DIR__ . '/../../.env.php';
require_once __DIR__ . '/../db_connect.php';

$dbc->exec('DROP TABLE IF EXISTS ads');

$query = 'CREATE TABLE ads (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(240) NOT NULL,
description TEXT,
seller_id INT UNSIGNED,
clicks INT UNSIGNED DEFAULT "0",
image VARCHAR(240),
PRIMARY KEY (id)
)';

$dbc->exec($query);

?>
44 changes: 44 additions & 0 deletions database/seeds/ads_seeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php


require_once __DIR__ . '/../../models/Ad.php';


$ad = new Ad;
$ad->name = "Finn's old shoes";
$ad->description = "Just some old shoes";
$ad->seller_id = 1;
$ad->image = 'img/uploads/old_shoes.jpg';
$ad->save();

$ad = new Ad;
$ad->name = "Jakes's old shirt";
$ad->description = "Just an old shirt";
$ad->seller_id = 2;
$ad->image = 'img/uploads/jakes_Old_shirt.jpg';
$ad->save();

$ad = new Ad;
$ad->name = "Simon's old simon game";
$ad->description = "Just a simple simon game";
$ad->seller_id = 3;
$ad->image = 'img/uploads/simon_says.jpg';
$ad->save();

$ad = new Ad;
$ad->name = "Finn's old wooden sword";
$ad->description = "Just an old wooden sword";
$ad->seller_id = 1;
$ad->image = 'img/uploads/old_wooden_sword.jpg';
$ad->save();

$ad = new Ad;
$ad->name = "Marceline's old guitar";
$ad->description = "Just an old guitar";
$ad->seller_id = 4;
$ad->image = 'img/uploads/old_guitar.jpg';
$ad->save();

?>

//just a comment
114 changes: 114 additions & 0 deletions models/Ad.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

require_once 'Model.php';

class Ad extends Model
{
protected static $table = 'ads';

protected static $ads;

public static function getAds()
{
self::dbConnect();

if (! empty($_GET)) {
$search = strip_tags($_GET['query']);

$query = "SELECT ads.*, users.email, users.username
from ". "ads " .
"join users on users.id = ads.seller_id " .
"WHERE ads.name like :search or ads.description like :search";
$stmt = self::$dbc->prepare($query);
$stmt->bindValue(":search", "%$search%");
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);

return array_map(function($result) {
$instance = new static;
$instance->attributes = $result;
return $instance;
}, $results);
} else {
$query = "SELECT ads.*, users.email, users.username
from ". "ads " .
"join users on users.id = ads.seller_id ";

$stmt = self::$dbc->query($query);

$results = $stmt->fetchAll(PDO::FETCH_ASSOC);

}
return array_map(function($result) {
$instance = new static;
$instance->attributes = $result;
return $instance;
}, $results);
}

public static function findAd($id)
{
// Get connection to the database
self::dbConnect();

//Create select statement using prepared statements
$query = "SELECT ads.*, users.email, users.username
FROM ads
JOIN users ON users.id = ads.seller_id
WHERE ads.id = :id";

$stmt = self::$dbc->prepare($query);
$stmt->bindValue(':id', $id, PDO::PARAM_INT);
$stmt->execute();

//Store the resultset in a variable named $result
$result = $stmt->fetch(PDO::FETCH_ASSOC);

$instance = null;
// if we have a result, create a new instance
if ($result) {
$instance = new static;
$instance->attributes = $result;
}

// return either the found instance or null
return $instance;
}

public static function findAdsByUser()
{
self::dbConnect();

$query = "SELECT *
FROM ads
WHERE seller_id = :id ";

$stmt = self::$dbc->prepare($query);
$stmt->bindValue(':id', Auth::id(), PDO::PARAM_INT);
$stmt->execute();

//Store the resultset in a variable named $result
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);

return array_map(function($result) {
$instance = new static;
$instance->attributes = $result;
return $instance;
}, $results);
}

public function updateClicks(){
$query = "UPDATE ads
SET clicks = :clicks
WHERE id = :id";

$stmt = self::$dbc->prepare($query);
$stmt->bindValue(':clicks', $this->clicks + 1);
$stmt->bindValue('id', $this->id);

$stmt->execute();
}
}


?>
22 changes: 19 additions & 3 deletions models/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
* is not necessary in instance methods.
*/
abstract class Model {
/** @var PDO|null the connection to the database */
/** @var PDO|null the connection to the database */
protected static $dbc;
/** @var string the name of the table */
protected static $table;

/** @var array the attributes of this instance */
protected $attributes = [];

Expand Down Expand Up @@ -207,6 +207,22 @@ public static function find($id)
// return either the found instance or null
return $instance;
}
public static function order($column_name, $limit = 3)
{
self::dbConnect();
$query = 'SELECT * FROM ' . static::$table . ' ORDER BY :column_name DESC LIMIT :limit';
$stmt = self::$dbc->prepare($query);
$stmt->bindValue(':column_name', $column_name, PDO::PARAM_STR);
$stmt->bindValue(':limit', $limit, PDO::PARAM_INT);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
return array_map(function($result) {
$instance = new static;
$instance->attributes = $result;
return $instance;
}, $results);

}


/**
Expand Down Expand Up @@ -235,4 +251,4 @@ public static function all()
}, $results);
}

}
}
Loading