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

Initial skeleton for a queue manager.

parent ec78cd63
No related branches found
No related tags found
No related merge requests found
<?php
class Requests_QueueManagerController extends App_Controller_Action
{
public function preDispatch()
{
$user = Auth_UserModel::findCurrentUser();
$roles = Auth_GroupModel::findByUser($user);
if (!in_array(1, $roles->getId())) {
throw new Exception('You must be logged in to view this page.');
}
}
public function indexAction()
{
$queues = Requests_ApprovalActionQueueModel::findAll();
$this->view->queues = $queues;
}
public function viewAction()
{
$in = $this->_getAllParams();
$queue = Requests_ApprovalActionModel::find($in['id']);
$requests = Requests_RequestModel::findWithCurrentApprovalAction($queue);
$this->view->queue = $queue;
$this->view->requests = $requests;
}
public function editPostAction()
{
$in = $this->_getAllParams();
}
}
......@@ -46,6 +46,23 @@ class Requests_ApprovalActionQueueModel extends Requests_ApprovalActionModel
}
}
static public function findAll()
{
$db = Zend_Registry::get('db');
$select = new Zend_Db_Select($db);
$select->from('creqApprovalActionsQueue', array('approvalActionId'));
$data = $select->query()->fetchAll();
$approvalActionIds = array(-1);
foreach ($data as $row) {
$approvalActionIds[] = $row['approvalActionId'];
}
return self::find($approvalActionIds);
}
static public function fetchNew()
{
$data = array(
......
......@@ -302,6 +302,63 @@ class Requests_RequestModel extends Unl_Model
return self::find($requestIds);
}
static public function findWithCurrentApprovalAction($approvalActions)
{
$singleId = FALSE;
if (!Unl_Util::isArray($approvalActions)) {
if (!$approvalActions) {
return array();
}
if (!($approvalActions instanceof Requests_ApprovalActionModel)) {
throw new Zend_Exception('Invalid Argument');
}
$singleId = $approvalActions->getId();
$collection = new Unl_Model_Collection('Requests_ApprovalActionModel');
$collection[] = $approvalActions;
$approvalActions = $collection;
} else {
if (count($approvalActions) == 0) {
return array();
}
}
$db = Zend_Registry::get('db');
$select = new Zend_Db_Select($db);
$select->from(array('r' => 'creqRequests'), array('requestId'));
$select->join(array('s' => 'creqRequestStacks'), 'r.stackPointer = s.requestStackId', array('action'));
$select->where('s.action IN(?)', $approvalActions->getId());
$data = $select->query()->fetchAll();
$requestIds = array();
$actionRequestIds = array();
foreach ($data as $row) {
$requestIds[] = $row['requestId'];
$actionRequestIds[$row['action']][] = $row['requestId'];
}
$requests = self::find($requestIds);
$actionRequests = array();
foreach ($approvalActions as $approvalAction) {
$approvalActionId = $approvalAction->getId();
$actionRequests[$approvalActionId] = new Unl_Model_Collection('Requests_RequestModel');
if (!array_key_exists($approvalActionId, $actionRequestIds)) {
continue;
}
foreach ($actionRequestIds[$approvalActionId] as $requestId) {
$actionRequests[$approvalActionId][$requestId] = $requests[$requestId];
}
}
if ($singleId) {
return $actionRequests[$singleId];
} else {
return $actionRequests;
}
}
static protected function _loadTypeMap()
{
......
<?php $this->layout()->breadcrumbs = array('Queue Manager'); ?>
<ul>
<?php $this->queues->orderBy('getName'); ?>
<?php foreach ($this->queues as $queue) { ?>
<li>
<a href="<?php echo $this->baseUrl(); ?>/requests/queue-manager/view/id/<?php echo $queue->getId(); ?>"><?php echo $queue->getName();?></a>
</li>
<?php } ?>
</ul>
<?php $this->layout()->breadcrumbs = array('Queue Manager: ' . $this->queue->getName()); ?>
<h3>Requests:</h3>
<ul>
<?php foreach ($this->requests as $request) { ?>
<li><a href="<?php echo $this->baseUrl(); ?>/requests/view/index/id/<?php echo $request->getId(); ?>"><?php echo $request->getId(); ?></a></li>
<?php } ?>
</ul>
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