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

Vote approval action implemented.

parent 2350eb96
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,18 @@ class Requests_ApprovalActionVoteModel extends Requests_ApprovalActionQueueModel ...@@ -24,6 +24,18 @@ class Requests_ApprovalActionVoteModel extends Requests_ApprovalActionQueueModel
$objects[$objectId] = $object; $objects[$objectId] = $object;
} }
$select = new Zend_Db_Select($db);
$select->from(array('v' => 'creqApproverVotes'));
if (Unl_Util::isArray($id)) {
$select->where('v.approvalAction IN(?)', $id);
} else {
$select->where('v.approvalAction = ?', $id);
}
$records = $select->query()->fetchAll();
foreach ($records as $record) {
$objects[$record['approvalAction']]->_data['votes'][$record['request']][$record['approverVoteId']] = $record;
}
if (Unl_Util::isArray($objects)) { if (Unl_Util::isArray($objects)) {
return $objects; return $objects;
} else { } else {
...@@ -37,13 +49,58 @@ class Requests_ApprovalActionVoteModel extends Requests_ApprovalActionQueueModel ...@@ -37,13 +49,58 @@ class Requests_ApprovalActionVoteModel extends Requests_ApprovalActionQueueModel
return new Unl_Model_Collection('Requests_RequestModel'); return new Unl_Model_Collection('Requests_RequestModel');
} }
public function userMadeDecisions($requests, $requestDecisions) public function finalize($requests)
{ {
// Don't do anything here, this is an automated action. // TODO: Tally votes and update the state of each request.
foreach ($requests as $request) {
$votes = $this->_data['votes'][$request->getId()];
if (!Unl_Util::isArray($votes) || count($votes) == 0) {
$request->setState(null);
continue;
} }
public function finalize($requests) $voteCount = count($votes);
if ($voteCount < $this->getQuorum()) {
$request->setState(null);
continue;
}
$voteTally = array();
foreach ($votes as $vote) {
$voteTally[$vote['vote']]++;
}
if ($voteTally['Table']) {
$request->setState('Table');
continue;
}
// TODO: Handle Ties
$mostVotes = 0;
$winner = '';
foreach ($voteTally as $name => $count) {
if ($count > $mostVotes) {
$winner = $name;
$mostVotes = $count;
}
}
if ($this->_data['requiredVotes'] == 'plurality') {
$request->setState($winner);
} else if ($this->_data['requiredVotes'] == 'majority' && ($mostVotes / $voteCount) >= 0.5) {
$request->setState($winner);
} else if ($this->_data['requiredVotes'] == 'unanimity' && ($mostVotes / $voteCount) == 1.0) {
$request->setState($winner);
} else {
$request->setState(null);
}
}
Requests_RequestModel::save($requests);
}
public function getQuorum()
{ {
// TODO: Tally votes and update the state of each request. return $this->_data['quorum'];
} }
} }
...@@ -46,6 +46,7 @@ class Requests_ApproverVoteModel extends Unl_Model ...@@ -46,6 +46,7 @@ class Requests_ApproverVoteModel extends Unl_Model
$select->where('a.request = ?', $requests->getId()); $select->where('a.request = ?', $requests->getId());
} }
$select->where('user = ?', $user->getId()); $select->where('user = ?', $user->getId());
$select->order('time');
$records = $db->query($select)->fetchAll(); $records = $db->query($select)->fetchAll();
$requestVoteIds = array(); $requestVoteIds = array();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment