Skip to content
Snippets Groups Projects
Commit 0604a6a3 authored by Tim Steiner's avatar Tim Steiner
Browse files

Voting ApprovalAction

parent 7837de69
Branches
No related tags found
No related merge requests found
......@@ -69,31 +69,33 @@ class ApprovalActionQueue extends ApprovalAction
*/
public function updateFromForm($formData)
{
foreach ($formData['schedule'] as $scheduleId => $scheduleData) {
if($scheduleId < 0) {
$schedule = ApprovalActionsQueueDates::getInstance()->fetchNew();
$schedule->approvalAction = $this;
} else {
$schedule = ApprovalActionsQueueDates::getInstance()->findOne($scheduleId);
if ($scheduleData['delete'] == 1) {
$schedule->delete();
CronJobs::unscheduleJob($date, 'ApprovalActionsQueue', 'advanceQueues');
continue;
if (is_array($formData['schedule'])) {
foreach ($formData['schedule'] as $scheduleId => $scheduleData) {
if($scheduleId < 0) {
$schedule = ApprovalActionsQueueDates::getInstance()->fetchNew();
$schedule->approvalAction = $this;
} else {
$schedule = ApprovalActionsQueueDates::getInstance()->findOne($scheduleId);
if ($scheduleData['delete'] == 1) {
$schedule->delete();
CronJobs::unscheduleJob($date, 'ApprovalActionsQueue', 'advanceQueues');
continue;
}
}
$date = new Zend_Date();
$date->setYear($scheduleData['year']);
$date->setMonth($scheduleData['month']);
$date->setDay($scheduleData['day']);
$date->setHour(0);
$date->setMinute(0);
$date->setSecond(0);
$schedule->date = $date;
$schedule->save();
try {
CronJobs::scheduleJob($date, 'ApprovalActionsQueue', 'advanceQueues');
} catch(Zend_Db_Exception $e) {
// TODO: we should only ignore duplicate record exceptions
}
}
$date = new Zend_Date();
$date->setYear($scheduleData['year']);
$date->setMonth($scheduleData['month']);
$date->setDay($scheduleData['day']);
$date->setHour(0);
$date->setMinute(0);
$date->setSecond(0);
$schedule->date = $date;
$schedule->save();
try {
CronJobs::scheduleJob($date, 'ApprovalActionsQueue', 'advanceQueues');
} catch(Zend_Db_Exception $e) {
// TODO: we should only ignore duplicate record exceptions
}
}
}
......
......@@ -7,8 +7,7 @@ require_once 'ApprovalActionRow/Interface.php';
* @tableClass ApprovalActionsVote
*
*/
class ApprovalActionVote extends ApprovalAction
implements Application_ApprovalActionRow_Interface
class ApprovalActionVote extends ApprovalActionQueue
{
public function _init()
{
......@@ -23,37 +22,15 @@ class ApprovalActionVote extends ApprovalAction
);
$this->_registerRelation($votingBodyRelation);
$datesRelation = new Nmc_Db_Table_Relation_HasMany(
ApprovalActionsVoteDates::getInstance(),
$this,
'approvalAction',
'dates'
);
$datesRelation->setSaveChildRows(false);
$this->_registerRelation($datesRelation);
/*
$votesRelation = new Nmc_Db_Table_Relation_HasMany(
ApprovalActionsVoteVotes::getInstance(),
ApproverVotes::getInstance(),
$this,
'approvalAction',
'votes'
);
$this->_registerRelation($votesRelation);*/
}
/**
* Reutrns an array of strings, corresponding to the possible
* results of performing this action. If a customized action can only
* result a subset of the possible results, return that subset.
*
* @return array
*/
public function getResultStatusStrings()
{
return array('Approve' => 'Approve',
'Deny' => 'Deny',
'Table' => 'Table');
$votesRelation->setSaveChildRows(false);
$this->_registerRelation($votesRelation);
}
/**
......@@ -65,7 +42,7 @@ class ApprovalActionVote extends ApprovalAction
*/
public function consider(Request $request, ApprovalChain $parentChain)
{
//
//parent::consider($request, $parentChain);
}
/**
......@@ -79,28 +56,7 @@ class ApprovalActionVote extends ApprovalAction
$this->votingRole = ApprovalBodyRoles::getInstance()->findOne($votingRoleId);
$this->quorum = Zend_Filter_Int::filter($formData['quorum']);
foreach ($formData['schedule'] as $scheduleId => $scheduleData) {
if($scheduleId < 0) {
$schedule = ApprovalActionsVoteDates::getInstance()->fetchNew();
$schedule->approvalAction = $this;
} else {
$schedule = ApprovalActionsVoteDates::getInstance()->findOne($scheduleId);
if ($scheduleData['delete'] == 1) {
$schedule->delete();
continue;
}
}
$date = new Zend_Date();
$date->setYear($scheduleData['year']);
$date->setMonth($scheduleData['month']);
$date->setDay($scheduleData['day']);
$date->setHour(0);
$date->setMinute(0);
$date->setSecond(0);
$schedule->date = $date;
$schedule->type = $scheduleData['type'];
$schedule->save();
}
parent::updateFromForm($formData);
}
/**
......@@ -113,26 +69,57 @@ class ApprovalActionVote extends ApprovalAction
*/
public function userMadeDecision(Request $request, User $user, $decision)
{
$vote = ApprovalActionsVoteVotes::getInstance()->fetchByRequestUserAndAction($request, $user, $this);
if ($vote) {
$vote->vote = $decision;
} else {
$vote = ApprovalActionsVoteVotes::getInstance()->fetchNew();
$vote->vote = $decision;
$vote->request = $request;
$vote->user = $user;
$vote->approvalAction = $this;
}
$vote->save();
parent::userMadeDecision($request, $user, $decision);
}
public function getUserDecision(Request $request, User $user)
public function advanceQueue()
{
$vote = ApprovalActionsVoteVotes::getInstance()->fetchByRequestUserAndAction($request, $user, $this);
if ($vote) {
return $vote->vote;
} else {
return null;
$requests = Requests::getInstance()->fetchAllWithCurrentAction($this);
foreach ($requests as $request) {
$queuedRequestStatus = ApprovalActionsQueueRequests::getInstance()->getStatusForRequestInQueue($request, $this);
if ($queuedRequestStatus == ApprovalActionsQueueRequests::STATUS_ACTIVE) {
// check to see if quorum is met, tally votes, etc
$voteTally = array();
foreach ($this->votes as $vote) {
if (!array_key_exists($vote->vote, $voteTally)) {
$voteTally[$vote->vote] = 0;
}
$voteTally[$vote->vote]++;
}
$maxVotes = max($voteTally);
$winningVotes = array_keys($voteTally, $maxVotes);
if (count($winningVotes) > 1) {
// tie
$winningVote = 'Table';
} else if (count($voteTally) < $this->quorum) {
// quorum not met
$winningVote = 'Table';
} else {
$winningVote = $winningVotes[0];
}
// update request to reflect result of voting
$request->state = $winningVote;
// if the request is tabled, roll it back to STATUS_HOLDING so that when the
// queue advances, this request will go right back to being active.
if ($request->state == 'Table') {
ApprovalActionsQueueRequests::getInstance()->setStatusForRequestInQueue(
$request, $this, ApprovalActionsQueueRequests::STATUS_HOLDING
);
}
}
}
parent::advanceQueue();
}
}
\ No newline at end of file
......@@ -72,7 +72,8 @@ class ApprovalActionsVote extends Nmc_Db_Table
$new = parent::fetchNew();
$new->className = 'ApprovalActionVote';
$new->closed = 'No';
$new->quorum = 0;
//$new->closed = 'No';
return $new;
}
}
\ No newline at end of file
......@@ -4,12 +4,8 @@ $currentSave = $current;
$current['id'] = '';
$current['value'] = null;
$current['approvalRoles'] = $this->chain->ownerBody->roles->columnToArray('name', 'approvalBodyRoleId');
$current['selectedRoleId'] = null;
if ($approvalAction) {
if ($approvalAction->votingRole) {
$current['selectedRoleId'] = $approvalAction->votingRole->getPrimaryKey();
}
$current['keyPrefix'] = 'edit[' . $approvalAction->getPrimaryKey() . '][';
$current['keySuffix'] = ']';
$current['quorum'] = $approvalAction->quorum;
......@@ -23,46 +19,33 @@ if ($approvalAction) {
}
?>
<div>
<label>
Voting Role: <br />
<?php echo $this->formSelect($current['keyPrefix'] . 'votingRole' . $current['keySuffix'],
$current['selectedRoleId'], null,
array('-1' => '--Select a Role--') + $current['approvalRoles']);
?>
</label>
<label>
Quorum: <br />
<?php echo $this->formText($current['keyPrefix'] . 'quorum' . $current['keySuffix'],
$current['quorum']);
?>
</label>
<label for="<?php echo $current['keyPrefix'] . 'quorum' . $current['keySuffix']; ?>">Quorum:</label>
<?php echo $this->formText($current['keyPrefix'] . 'quorum' . $current['keySuffix'],
$current['quorum']);
?>
</div>
<div class="clear"></div>
<div>
<table>
<tr>
<th>Mode</th>
<th>Year</th>
<th>Month</th>
<th>Day</th>
</tr>
<?php foreach ($current['dates'] as $scheduledVote) { ?>
<?php foreach ($current['dates'] as $scheduledAdvance) { ?>
<tr>
<td><?php echo $this->formSelect($current['keyPrefix'] . 'schedule' . $current['keySuffix'] . '[' . $scheduledVote->getPrimaryKey() . '][type]',
$scheduledVote->type, null,
array('View' => 'View', 'Vote' => 'Vote')); ?></td>
<td><?php echo $this->formSelectYear($current['keyPrefix'] . 'schedule' . $current['keySuffix'] . '[' . $scheduledVote->getPrimaryKey() . '][year]',
$scheduledVote->date->get(Zend_Date::YEAR)); ?></td>
<td><?php echo $this->formSelectMonth($current['keyPrefix'] . 'schedule' . $current['keySuffix'] . '[' . $scheduledVote->getPrimaryKey() . '][month]',
$scheduledVote->date->get(Zend_Date::MONTH)); ?></td>
<td><?php echo $this->formSelectDay($current['keyPrefix'] . 'schedule' . $current['keySuffix'] . '[' . $scheduledVote->getPrimaryKey() . '][day]',
$scheduledVote->date->get(Zend_Date::DAY)); ?></td>
<td><?php echo $this->formCheckbox($current['keyPrefix'] . 'schedule' . $current['keySuffix'] . '[' . $scheduledVote->getPrimaryKey() . '][delete]'); ?></td>
<td><?php echo $this->formSelectYear($current['keyPrefix'] . 'schedule' . $current['keySuffix'] . '[' . $scheduledAdvance->getPrimaryKey() . '][year]',
$scheduledAdvance->date->get(Zend_Date::YEAR)); ?></td>
<td><?php echo $this->formSelectMonth($current['keyPrefix'] . 'schedule' . $current['keySuffix'] . '[' . $scheduledAdvance->getPrimaryKey() . '][month]',
$scheduledAdvance->date->get(Zend_Date::MONTH)); ?></td>
<td><?php echo $this->formSelectDay($current['keyPrefix'] . 'schedule' . $current['keySuffix'] . '[' . $scheduledAdvance->getPrimaryKey() . '][day]',
$scheduledAdvance->date->get(Zend_Date::DAY)); ?></td>
<td><?php echo $this->formCheckbox($current['keyPrefix'] . 'schedule' . $current['keySuffix'] . '[' . $scheduledAdvance->getPrimaryKey() . '][delete]'); ?></td>
</tr>
<?php } ?>
<tr class="hidden_new_record">
<td> <?php echo $this->formSelect($current['keyPrefix'] . 'schedule' . $current['keySuffix'] . '[__key__][type]', null, array('disabled' => 'disabled'),
array('View' => 'View', 'Vote' => 'Vote')); ?> </td>
<td> <?php echo $this->formSelectYear($current['keyPrefix'] . 'schedule' . $current['keySuffix'] . '[__key__][year]', null, array('disabled' => 'disabled')); ?> </td>
<td> <?php echo $this->formSelectMonth($current['keyPrefix'] . 'schedule' . $current['keySuffix'] . '[__key__][month]', null, array('disabled' => 'disabled')); ?> </td>
<td> <?php echo $this->formSelectDay($current['keyPrefix'] . 'schedule' . $current['keySuffix'] . '[__key__][day]', null, array('disabled' => 'disabled')); ?> </td>
......@@ -70,11 +53,8 @@ if ($approvalAction) {
</tr>
<tr>
<td colspan="4">
<a href="#" class="add_record_button">Add Scheduled Vote</a>
<a href="#" class="add_record_button">Add Scheduled Advance</a>
</td>
</tr>
</table>
</div>
<?php
$current = $currentSave;
</div>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment