Skip to content

Commit

Permalink
add ability to copy suites from previous quarter to admin page, use a…
Browse files Browse the repository at this point in the history
…bsence table to calculate multiplier and visibility as a slivkan
  • Loading branch information
benthemonkey committed Jun 26, 2015
1 parent 835d882 commit 83f0eab
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 2 deletions.
41 changes: 39 additions & 2 deletions ajax/PointsCenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,16 @@ public function getDirectory()

public function getSlivkans()
{
$absentSlivkans = self::fetchAllQuery('SELECT nu_email FROM absences WHERE qtr=:qtr', PDO::FETCH_COLUMN);

$slivkans = self::fetchAllQuery(
"SELECT CONCAT(first_name, ' ', last_name) AS full_name,
slivkans.nu_email,gender,wildcard,committee,photo,suite,year
FROM slivkans
LEFT JOIN committees ON slivkans.nu_email=committees.nu_email AND committees.qtr=:qtr
LEFT JOIN suites ON slivkans.nu_email=suites.nu_email AND suites.qtr=:qtr
WHERE qtr_joined <= :qtr AND (qtr_final IS NULL OR qtr_final >= :qtr)
AND slivkans.nu_email NOT IN('" . implode("','", $absentSlivkans) . "')
ORDER BY first_name,last_name"
);

Expand Down Expand Up @@ -741,7 +744,7 @@ public function getMultipliers()
{
$slivkans = self::fetchAllQuery(
"SELECT CONCAT(first_name,' ',last_name) AS full_name,
slivkans.nu_email,gender,qtr_joined,qtrs_away,qtr_final,year,suite
slivkans.nu_email,gender,qtr_joined,qtr_final,year,suite
FROM slivkans
LEFT JOIN suites ON slivkans.nu_email=suites.nu_email AND suites.qtr=:qtr
WHERE qtr_final IS NULL OR qtr_final>=:qtr
Expand All @@ -750,6 +753,8 @@ public function getMultipliers()

$noShows = self::fetchAllQuery("SELECT nu_email, COUNT(nu_email) AS count FROM noshows", PDO::FETCH_KEY_PAIR);

$absences = self::fetchAllQuery("SELECT nu_email, COUNT(nu_email) AS count from absences GROUP BY nu_email", PDO::FETCH_KEY_PAIR);

$count = count($slivkans);
$is_housing = self::$config['is_housing'] == 'true';

Expand All @@ -763,7 +768,12 @@ public function getMultipliers()
$y_acc = ($y_this - $y_join) / 100;
$q_acc = $q_this - $q_join;

$q_total = $q_acc + 3 * $y_acc - $slivkans[$s]['qtrs_away'];
$q_total = $q_acc + 3 * $y_acc;

// Subtract from multiplier all quarters spent away
if (array_key_exists($slivkans[$s]['nu_email'], $absences)) {
$q_total -= $absences[$slivkans];
}

// give multiplier for current qtr if it isnt housing
if (!$is_housing) {
Expand Down Expand Up @@ -1065,6 +1075,33 @@ public function updateSuite($slivkans, $suite)
return true;
}

public function copySuites()
{
// figure out previous quarter
$y = round(self::$qtr, -2);
$q = self::$qtr - $y;
if ($q == 1) {
$qtrPrevious = ($y - 100) + 3;
} else {
$qtrPrevious = $y + ($q - 1);
}

try {
$statement = self::$dbConn->prepare(
"INSERT INTO suites (nu_email,suite,qtr)
SELECT s.nu_email,s.suite,:qtr FROM suites AS s WHERE s.qtr=:qtrPrevious"
);
$statement->bindValue(':qtr', self::$qtr);
$statement->bindValue(':qtrPrevious', $qtrPrevious);
$statement->execute();
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
die();
}

return true;
}

public function submitCommitteePoint($nu_email, $event_name, $points, $contributions, $comments)
{
if (($points == '0' || $points == '0.0') && $contributions == '' && $comments == '') {
Expand Down
8 changes: 8 additions & 0 deletions ajax/copySuites.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
header('Content-type: text/html; charset=utf-8');
require_once "./PointsCenter.php";
$points_center = new \Slivka\PointsCenter();

$response = $points_center->copySuites();

echo json_encode($response);
14 changes: 14 additions & 0 deletions js/pointsCenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,20 @@ define(['jquery', 'moment', 'hogan'], function($, moment, Hogan){
$.getJSON(root + '/ajax/getCommitteeOrSuite.php', { suite: $('#edit-suite').val() }, admin.addSlivkans);
});

$('[data-copy-suites]').on('click', function(){
if(window.confirm('Are you sure? This can only be done once per quarter.')){
$.getJSON(root + '/ajax/copySuites.php', function(response){
if(response == '1'){
window.alert('Success!');
}else{
window.alert(response);
}
});
}

return false;
});

$('#editCommitteeOrSuite form').on('submit', function(){
var i, name, pts, formData,
entries = $('.slivkan-entry', '#slivkan-entry-tab'),
Expand Down
9 changes: 9 additions & 0 deletions spc-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
$date = \DateTime::createFromFormat('Y-m-d', $qtr_info['end_date']);
$end_date = $date->format('m/d/Y');

$q = $qtr_info['qtr'] - round($qtr_info['qtr'], -2);

function getSlivkanName($slivkans, $nu_email)
{
foreach ($slivkans as $s) {
Expand Down Expand Up @@ -312,6 +314,13 @@ function getSlivkanName($slivkans, $nu_email)
<a href="#editCommitteeOrSuite" class="btn btn-default btn-block" data-toggle="modal" data-edit-suite>Edit</a>
</div>
</div>
<?php if ($q != 3) { ?>
<div class="row">
<div class="col-xs-12" style="margin-top: 10px;">
<a href="#copySuites" class="btn btn-info btn-block" data-copy-suites>Copy Suites from Last Quarter</a>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
Expand Down

0 comments on commit 83f0eab

Please sign in to comment.