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

Change vote recording to keep track of votes on a per queue period basis in...

Change vote recording to keep track of votes on a per queue period basis in additon to per request and user.  This will allow for much more accurate voting reports.
parent d83cffc8
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,9 @@ class Requests_ApprovalActionQueueModel extends Requests_ApprovalActionModel
$select = new Zend_Db_Select($db);
$select->from(array('a' => 'creqApprovalActions'));
$select->join(array('q' => 'creqApprovalActionsQueue'), 'a.approvalActionId = q.approvalActionId');
$select->join(array('p' => 'creqApprovalActionsQueuePeriods'),
'a.approvalActionId = p.approvalAction AND p.endTime IS NULL',
array('startTime', 'currentPeriod' => 'approvalActionsQueuePeriodId'));
if (Unl_Util::isArray($id)) {
$select->where('a.approvalActionId IN(?)', $id);
} else {
......@@ -304,21 +307,12 @@ class Requests_ApprovalActionQueueModel extends Requests_ApprovalActionModel
public function userMadeDecisions($requests, $requestDecisions)
{
$user = Auth_UserModel::findCurrentUser();
$votes = Requests_ApproverVoteModel::findUsersVotesForRequests($user, $requests, $this);
$requestHistories = Requests_ApprovalHistoryModel::findByRequest($requests);
$votes = Requests_ApproverVoteModel::findUsersVotesForRequests($user, $requests, $this->getCurrentPeriodId());
foreach ($requests as $request) {
$histories = $requestHistories[$request->getId()];
$histories->orderBy('getUnixtime', SORT_DESC);
$lastEndTime = new Zend_Date(0);
foreach ($histories as $history) {
if ($history->getApprovalAction() == $this->getId()) {
$lastEndTime = $history->getTime();
break;
}
}
if ($votes[$request->getId()] && $votes[$request->getId()]->getApprovalAction() == $this->getId()) {
$vote = $votes[$request->getId()];
if (!$this->getCanChangeVote() && $lastEndTime->isEarlier($vote->getTime())) {
if ($votes[$request->getId()]) {
if ($this->getCanChangeVote()) {
$vote = $votes[$request->getId()];
} else {
continue;
}
} else {
......@@ -383,5 +377,15 @@ class Requests_ApprovalActionQueueModel extends Requests_ApprovalActionModel
$this->setDates($dates);
}
public function getCurrentPeriodStartTime()
{
return new Zend_Date($this->_data['startTime']);
}
public function getCurrentPeriodId()
{
return $this->_data['currentPeriod'];
}
}
......@@ -10,6 +10,9 @@ class Requests_ApprovalActionVoteModel extends Requests_ApprovalActionQueueModel
$select->from(array('a' => 'creqApprovalActions'));
$select->join(array('q' => 'creqApprovalActionsQueue'), 'a.approvalActionId = q.approvalActionId');
$select->join(array('v' => 'creqApprovalActionsVote'), 'a.approvalActionId = v.approvalActionId');
$select->join(array('p' => 'creqApprovalActionsQueuePeriods'),
'a.approvalActionId = p.approvalAction AND p.endTime IS NULL',
array('startTime', 'currentPeriod' => 'approvalActionsQueuePeriodId'));
if (Unl_Util::isArray($id)) {
$select->where('a.approvalActionId IN(?)', $id);
} else {
......
......@@ -79,7 +79,7 @@ class Requests_ApproverVoteModel extends Unl_Model
return $requestVotes;
}
static public function findUsersVotesForRequests(Auth_UserModel $user, $requests, $approvalAction = null)
static public function findUsersVotesForRequests(Auth_UserModel $user, $requests, $queuePeriodId = null)
{
$db = Zend_Registry::get('db');
......@@ -94,10 +94,14 @@ class Requests_ApproverVoteModel extends Unl_Model
$select->where('a.request = ?', $requests->getId());
}
$select->where('user = ?', $user->getId());
if ($approvalAction instanceof Requests_ApprovalActionModel) {
$select->where('approvalAction = ?', $approvalAction->getId());
}
$select->order('time');
if ($queuePeriodId) {
$select->join(array('p' => 'creqApprovalActionsQueuePeriods'),
'a.approvalAction = p.approvalAction AND a.time >= p.startTime AND (a.time <= p.endTime OR p.endTime IS NULL)',
array());
$select->where('p.approvalActionsQueuePeriodId = ?', $queuePeriodId);
}
$records = $db->query($select)->fetchAll();
$requestVoteIds = array();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment