Skip to content

Commit

Permalink
MVC architecture for client
Browse files Browse the repository at this point in the history
  • Loading branch information
jvoros committed Apr 30, 2015
1 parent 709cd0d commit e869071
Show file tree
Hide file tree
Showing 36 changed files with 1,194 additions and 443 deletions.
1 change: 1 addition & 0 deletions TODO.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[] checkout time check, if checkout-checkin > conf.duration only log conf.duration
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"google/apiclient": "1.0.*@beta"
},
"autoload": {
"psr-4": { "JV\\" : "lib/src/" },
"classmap": ["vendor/redbean/"]
}
}
Binary file modified dbase.sqlite
Binary file not shown.
10 changes: 10 additions & 0 deletions htaccess.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
RewriteEngine On

# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
RewriteBase /public_html/attend

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
59 changes: 39 additions & 20 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
R::freeze(true);

// app wide utility functions and constants
// also defined in app.js
define('BASE_URL', 'http://localhost/Sites/DHREM/Attend');
//define('BASE_URL', 'http://www.denverem.org/attend');


/*********************************
Expand Down Expand Up @@ -45,40 +45,59 @@
$twig->addGlobal('session', $_SESSION);
$twig->addExtension(new \Twig_Extension_Debug());

// Google PHP Library
$client = new Google_Client();
$client->setApplicationName('Attend');
$client->setClientId('459801839286-j103ceme00kacpbrk19nihn7r3l2icme.apps.googleusercontent.com');
$client->setClientSecret('C95vXMePXkVXKgtuQr8lWCqk');
$client->setRedirectUri(BASE_URL . '/login');
$client->setScopes(array(
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile',
));
$app->client = $client;
// Model services
$app->userService = new \JV\UserService();
$app->confService = new \JV\ConfService();
$app->checkinService = new \JV\CheckinService($app->userService, $app->confService);
$app->reportService = new \JV\ReportService($app->userService, $app->confService, $app->checkinService);

// Auth handling
$googleClientParams = array(
'client_id' => '459801839286-j103ceme00kacpbrk19nihn7r3l2icme.apps.googleusercontent.com',
'client_secret' => 'C95vXMePXkVXKgtuQr8lWCqk',
'redirect_uri' => BASE_URL . '/login',
);

/*********************************
UTILITY FUNCTIONS
*********************************/
$app->auth = new \JV\Auth($app, $app->userService, $googleClientParams);

require 'lib/utilityFunctions.php';

/*********************************
ROUTES
*********************************/

// Routes act as views, managing data from Model services
// include all route files
$routeFiles = (array) glob('lib/routes/*.php');
foreach($routeFiles as $routeFile) {
require_once $routeFile;
}

// TEST ROUTES

$app->get('/getsession', function() use ($app) {
header("Content-Type: application/json");
echo json_encode($_SESSION);
$app->get('/test', function() use($app) {
$confs = $app->confService->getConferencesByDateRange('2015-04-01', '2016-01-01');
foreach ($confs as $conf) {
$start = date('Y-m-d', strtotime($conf->start));
echo "<p><b>". $conf->name ."</b> on ". $start ."</p>";
}

$checkins = $app->checkinService->getCheckinsForUserByDateRange(1, '2015-01-01', '2016-01-01');
echo "<b>Checkins</b>";
foreach($checkins as $checkin) {
$in = date('Y-m-d', strtotime($checkin->in_time));
echo "<p>User_id: ". $checkin->user_id .". In: ". $in ."</p>";
}

$report = $app->reportService->userAttendanceByDate(1, '2015-01-01', '2016-01-01');
echo "<b>Report</b><br>";
echo "Required hours: ".$report['required_hours']."<br>";
echo "Checkins: <br><pre>";
echo print_r($report['checkins'], true);
echo "</pre>";
echo "Electives: <br><pre>";
echo print_r($report['user_electives'], true);
echo "</pre>";
});

/*********************************
RUN
*********************************/
Expand Down
19 changes: 19 additions & 0 deletions lib/controllers/admin/home.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?
function getTodaysConferences($checkins = NULL) {
$conference_beans = R::find('conference', ' start LIKE ? ORDER BY start ASC ', array(date("Y-m-d").'%'));
$conferences = array();
foreach ($conference_beans as $bean) {
// only include if current time is earlier than one hour after finish time
if (strtotime($bean->finish) - time() > -3600) { $conferences[] = getConferenceAsArray($bean, $checkins); }
}

return $conferences;
}

// UPCOMING CONFERENCES X3
$future_conferences = R::find('conference', ' start >= ? ORDER BY start ASC ', array(date("Y-m-d")));

$data = array(
'future_conferences' => $future_conferences,
'upcoming_conferences' => array_slice($future_conferences, 0, 3),
);
41 changes: 41 additions & 0 deletions lib/controllers/admin/location-new.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?
$postVars = $app->request->post();
$formErrors = array();

if ($postVars["name"] == '') {
$formErrors[] = "Name is required.";
}

if ($postVars['address'] == '') {
$formErrors[] = "Address is required.";
}

$nameTest = R::findOne('location', ' name = ? ', array($postVars["name"]));
if (isset($nameTest)) {
$formErrors[] = "That name is already in use.";
}

$addressTest = R::findOne('location', ' address = ? ', array($postVars["address"]));
if (isset($addressTest)){
$formErrors[] = "That address is already in use.";
}

if (empty($formErrors)) {
$location = R::dispense('location');
$location->name = $postVars["name"];
$location->address = $postVars["address"];
$location->lat = $postVars["lat"];
$location->lng = $postVars["lng"];
$location->radius = $postVars["radius"];
$location->favorite = $postVars["favorite"];
$loc_id = R::store($location);
}

if (isset($loc_id)) {
$app->flash('message', 'Added location: '.$location->name);
$app->redirect(BASE_URL . '/admin/locations');
} else {
$app->flash('formErrors', $formErrors);
$app->render('admin/location.html');
}

33 changes: 33 additions & 0 deletions lib/controllers/admin/location-update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?
$postVars = $app->request->post();

$location = R::load('location', $id);
if ($location->id == 0) {
echo ajaxRespond('error', 'Location not found');
$app->stop();
}

if ($postVars["name"] == '') {
echo ajaxRespond('error', 'Location name is required');
$app->stop();
}

if ($postVars['address'] == '') {
echo ajaxRespond('error', 'Location address is required');
$app->stop();
}

$location->name = $postVars["name"];
$location->address = $postVars["address"];
$location->lat = $postVars["lat"];
$location->lng = $postVars["lng"];
$location->radius = $postVars["radius"];
$location->favorite = $postVars["favorite"];
$loc_id = R::store($location);

if (isset($loc_id)) {
echo ajaxRespond('success', 'Location updated');
} else {
echo ajaxRespond('error', 'Unable to save updates');
}

73 changes: 0 additions & 73 deletions lib/controllers/conference-control.php

This file was deleted.

60 changes: 0 additions & 60 deletions lib/controllers/home.php

This file was deleted.

Loading

0 comments on commit e869071

Please sign in to comment.