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

Add the ability to make decisions on course requests while viewing their...

Add the ability to make decisions on course requests while viewing their details.  Also allowed for a cleaner way to check if a user has an edit link when viewing a course's request details.
parent 280eec34
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,6 @@ class Courses_ViewController extends App_Controller_Action
$initialRequest = true;
}
$preview = true;
$canEdit = false;
} else {
$request = Requests_RequestModel::find($requestId);
$course = Courses_CourseModel::findLatestOfRequest($request);
......@@ -46,12 +45,31 @@ class Courses_ViewController extends App_Controller_Action
$nextRequestId = $requestOrder[$listPosition + 1];
}
}
$canEdit = in_array($request->getId(), $myRequestSession->editableRequests);
}
$comments = Requests_CommentsModel::findByRequest($request);
$user = Auth_UserModel::findCurrentUser();
$action = null;
$canEdit = false;
if ($request->getId()) {
$possibleAction = Requests_ApprovalActionModel::findByRequest($request);
if ($possibleAction instanceof Requests_ApprovalActionSubmitterApprovalModel && $request->getOwner() == $user->getId()) {
$action = $possibleAction;
}
$userRoles = Requests_ApprovalRoleModel::findByUser($user);
$allowedRoles = array_intersect(array(1) + $possibleAction->getParticipatingRoleIds(), $userRoles->getId());
if (count($allowedRoles) > 0) {
$action = $possibleAction;
}
$editAllowedRoles = array_intersect(array(1) + $possibleAction->getEditingRoleIds(), $userRoles->getId());
if (count($editAllowedRoles) > 0) {
$canEdit = true;
}
}
$this->view->request = $request;
$this->view->course = $course;
$this->view->parentCourse = $parentCourse;
......@@ -66,6 +84,7 @@ class Courses_ViewController extends App_Controller_Action
$this->view->canEdit = $canEdit;
$this->view->lastList = $list;
$this->view->lastRoleId = $roleId;
$this->view->action = $action;
$session = new Zend_Session_Namespace(__CLASS__);
if ($session->tabName) {
......
......@@ -154,12 +154,20 @@ $this->layout()->breadcrumbs = array($breadcrumb . ': ' . $this->course->getCour
<a id="nextRequestLink" href="<?php echo $this->url(array('id' => $this->nextRequestId)); ?>">Next--&gt;</a>
<?php } ?>
<?php } ?>
<?php if($this->canEdit) { ?>
<div id="editLink">
<a href="<?php echo $this->baseUrl(); ?>/requests/edit/load/id/<?php echo $this->request->getId(); ?>/role/<?php echo $this->lastRoleId; ?>/list/<?php echo $this->lastList; ?>">-Edit-</a>
</div>
<?php } ?>
<?php if ($this->action) { ?>
<form id="decisionForm" action="<?php echo $this->baseUrl(); ?>/requests/index/decide.post">
<?php echo $this->formHidden('returnUrl', '/courses/view/index/id/' . $this->request->getId()); ?>
<?php echo $this->formSelect('decisions[' . $this->request->getId() . ']', null, null, array('_null' => '--Decision--') + $this->action->getResultStatusStrings($this->user)); ?>
<?php echo $this->formSubmit('submit', 'Submit Decision'); ?>
</form>
<?php } ?>
<div class="clear"></div>
</div>
......@@ -213,7 +213,6 @@ class Requests_IndexController extends App_Controller_Action
// save the order of requests to the session so we can have next/previous links on other pages.
$session = new Zend_Session_Namespace('My Requests');
$session->requestOrder = array();
$session->editableRequests = array();
foreach ($roleData as $role) {
$roleId = $role['role']->getId();
$session->requestOrder[$roleId] = array();
......@@ -223,9 +222,6 @@ class Requests_IndexController extends App_Controller_Action
foreach ($requestList as $request) {
$requestId = $request['request']->getId();
$session->requestOrder[$roleId]['normal'][] = $requestId;
if ($request['request']->isEditable()) {
$session->editableRequests[] = $requestId;
}
}
}
}
......@@ -276,7 +272,11 @@ class Requests_IndexController extends App_Controller_Action
Requests_ApprovalChainModel::consider($requests);
$this->_redirect('/requests');
if (array_key_exists('returnUrl', $in)) {
$this->_redirect($in['returnUrl']);
} else {
$this->_redirect('/requests');
}
}
public function hideRequestPostAction()
......
......@@ -72,4 +72,9 @@ div#comments table.comments tr.evenRow {
}
div#comments table.comments tr.oddRow {
background-color:#CCCCCC;
}
#decisionForm {
margin: 1em;
text-align: center;
}
\ No newline at end of file
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