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

Allow selective editing based on an Approval Body's Approval Actions

parent 7105b044
No related branches found
No related tags found
No related merge requests found
...@@ -215,6 +215,19 @@ class ApprovalChainManagerController extends Nmc_Controller_Action ...@@ -215,6 +215,19 @@ class ApprovalChainManagerController extends Nmc_Controller_Action
$action->updateFromForm($actionData); $action->updateFromForm($actionData);
$action->participants = ApprovalBodyRoles::getInstance()->find($actionData['participatingRoles']); $action->participants = ApprovalBodyRoles::getInstance()->find($actionData['participatingRoles']);
$action->save(); $action->save();
foreach ($action->participantLinks as $participantLink) {
if (is_array($actionData['editingRoles']) &&
in_array($participantLink->approvalBodyRole, $actionData['editingRoles'])) {
$participantLink->canEdit = 'yes';
} else {
$participantLink->canEdit = 'no';
}
if (is_array($actionData['participatingRoles']) &&
in_array($participantLink->approvalBodyRole, $actionData['participatingRoles'])) {
$participantLink->save();
}
}
} }
$out = new Application_View(); $out = new Application_View();
......
...@@ -11,39 +11,11 @@ class HomeController extends Nmc_Controller_Action ...@@ -11,39 +11,11 @@ class HomeController extends Nmc_Controller_Action
public function indexAction() public function indexAction()
{ {
$user = Nmc_User::getInstance()->getUser(); $user = Nmc_User::getInstance()->getUser();
$requests = Requests::getInstance()->getRequestsForUser($user, Requests::COMPLETED_REQUESTS_BOTH); $rm = Nmc_Db_RowManager::getInstance();
$roles = ApprovalBodyRoles::getInstance()->fetchRolesForUser($user);
$myRequests = array();
$myRequests['subject'] = array();
$myRequests['courseNumber'] = array();
$myRequests['courseLetter'] = array();
$myRequests['counter'] = array();
$myRequests['request'] = array();
$i = 0;
foreach($requests as $index => $request) {
$course = $request->getCourseGeneration(); /************/
$originalCourse = $course->getParentGeneration(true);
if (!$originalCourse) {
$originalCourse = $course;
}
$myRequests['subject'][] = $originalCourse->subject;
$myRequests['courseNumber'][] = $originalCourse->courseNumber;
$myRequests['courseLetter'][] = $originalCourse->courseLetter;
$myRequests['counter'][] = $i++;
$myRequests['request'][] = $request;
}
array_multisort($myRequests['subject'],
$myRequests['courseNumber'],
$myRequests['courseLetter'],
$myRequests['counter'],
$myRequests['request']);
$roles = ApprovalBodyRoles::getInstance()->fetchRolesForUser($user);
$rolesData = array(); $rolesData = array();
foreach($roles as $role) { foreach($roles as $role) {
...@@ -92,6 +64,46 @@ class HomeController extends Nmc_Controller_Action ...@@ -92,6 +64,46 @@ class HomeController extends Nmc_Controller_Action
} }
Nmc_Registry_Session::getInstance('requests')->order = $requestOrder; Nmc_Registry_Session::getInstance('requests')->order = $requestOrder;
/***********/
$requests = Requests::getInstance()->getRequestsForUser($user, Requests::COMPLETED_REQUESTS_BOTH);
$myRequests = array();
$myRequests['subject'] = array();
$myRequests['courseNumber'] = array();
$myRequests['courseLetter'] = array();
$myRequests['counter'] = array();
$myRequests['request'] = array();
$i = 0;
foreach($requests as $index => $request) {
$course = $request->getCourseGeneration();
$originalCourse = $course->getParentGeneration(true);
if (!$originalCourse) {
$originalCourse = $course;
}
$myRequests['subject'][] = $originalCourse->subject;
$myRequests['courseNumber'][] = $originalCourse->courseNumber;
$myRequests['courseLetter'][] = $originalCourse->courseLetter;
$myRequests['counter'][] = $i++;
$myRequests['request'][] = $request;
}
array_multisort($myRequests['subject'],
$myRequests['courseNumber'],
$myRequests['courseLetter'],
$myRequests['counter'],
$myRequests['request']);
/*************/
/***************/
$out = new Application_View(); $out = new Application_View();
$out->user = $user; $out->user = $user;
$out->roles = $rolesData; $out->roles = $rolesData;
......
...@@ -20,7 +20,8 @@ class ApprovalAction extends Nmc_Db_Table_Row ...@@ -20,7 +20,8 @@ class ApprovalAction extends Nmc_Db_Table_Row
); );
$participantRelation->setLinkingTable( $participantRelation->setLinkingTable(
ApprovalActionParticipants::getInstance(), ApprovalActionParticipants::getInstance(),
'approvalBodyRole' 'approvalBodyRole',
'participantLinks'
); );
$this->_registerRelation($participantRelation); $this->_registerRelation($participantRelation);
} }
...@@ -30,4 +31,17 @@ class ApprovalAction extends Nmc_Db_Table_Row ...@@ -30,4 +31,17 @@ class ApprovalAction extends Nmc_Db_Table_Row
{ {
return ApprovalActions::getInstance()->getPrimaryKeyName(); return ApprovalActions::getInstance()->getPrimaryKeyName();
} }
public function getEditingParticipants()
{
$editingParticipantIds = array(-1);
foreach ($this->participantLinks as $participantLink) {
if ($participantLink->canEdit == 'yes') {
$editingParticipantIds[] = $participantLink->approvalBodyRole;
}
}
$editingParticipants = ApprovalBodyRoles::getInstance()->findAll($editingParticipantIds);
return $editingParticipants;
}
} }
\ No newline at end of file
...@@ -30,6 +30,16 @@ class ApprovalBodyRole extends Nmc_Db_Table_Row ...@@ -30,6 +30,16 @@ class ApprovalBodyRole extends Nmc_Db_Table_Row
} }
return ApprovalBodyRoleQueues::getInstance()->fetchRequestsByRole($this); return ApprovalBodyRoleQueues::getInstance()->fetchRequestsByRole($this);
} }
public function canEditRequest(Request $request)
{
$action = $request->getCurrentAction();
$row = ApprovalBodyRoleQueues::getInstance()->fetchByRequestActionAndRole($request, $action, $this);
if ($row && $row->canEdit == 'yes') {
return true;
}
return false;
}
} }
?> ?>
\ No newline at end of file
...@@ -52,20 +52,25 @@ class ApprovalChain extends Nmc_Db_Table_Row ...@@ -52,20 +52,25 @@ class ApprovalChain extends Nmc_Db_Table_Row
} }
foreach ($currentAction->participants as $participant) { foreach ($currentAction->participants as $participant) {
try { $queueItem = ApprovalBodyRoleQueues::getInstance()->fetchByRequestActionAndRole(
$request, $currentAction, $participant
);
if (!$queueItem) {
$queueItem = ApprovalBodyRoleQueues::getInstance()->fetchNew(); $queueItem = ApprovalBodyRoleQueues::getInstance()->fetchNew();
$queueItem->request = $request; $queueItem->request = $request;
$queueItem->approvalBodyRole = $participant; $queueItem->approvalBodyRole = $participant;
$queueItem->approvalAction = $currentAction; $queueItem->approvalAction = $currentAction;
$queueItem->visible = 'yes';
$queueItem->save();
} catch (Zend_Db_Statement_Exception $e) {
if(strstr($e->getMessage(), 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry') !== FASE) {
continue;
}
throw $e;
} }
$queueItem->visible = 'yes';
$queueItem->save();
}
foreach ($currentAction->getEditingParticipants() as $participant) {
$queueItem = ApprovalBodyRoleQueues::getInstance()->fetchByRequestActionAndRole(
$request, $currentAction, $participant
);
$queueItem->canEdit = 'yes';
$queueItem->save();
} }
$currentAction->consider($request, $this); $currentAction->consider($request, $this);
......
...@@ -24,5 +24,12 @@ class ApprovalActionParticipants extends Nmc_Db_Table ...@@ -24,5 +24,12 @@ class ApprovalActionParticipants extends Nmc_Db_Table
} }
return self::$_instance; return self::$_instance;
} }
public function fetchNew()
{
$row = parent::fetchNew();
$row->canEdit = 'no';
return $row;
}
} }
...@@ -63,6 +63,17 @@ class ApprovalBodyRoleQueues extends Nmc_Db_Table ...@@ -63,6 +63,17 @@ class ApprovalBodyRoleQueues extends Nmc_Db_Table
return $this->fetchAll($where, $order, $count, $offset); return $this->fetchAll($where, $order, $count, $offset);
} }
public function fetchByRequestActionAndRole(Request $request, ApprovalAction $action, ApprovalBodyRole $role)
{
$db = $this->getAdapter();
$where = array();
$where[] = $db->quoteInto('request = ?', $request->getPrimaryKey());
$where[] = $db->quoteInto('approvalAction = ?', $action->getPrimaryKey());
$where[] = $db->quoteInto('approvalBodyRole = ?', $role->getPrimaryKey());
$where = implode(' AND ', $where);
return $this->fetchRow($where);
}
public function fetchRequestsByRole(ApprovalBodyRole $role) { public function fetchRequestsByRole(ApprovalBodyRole $role) {
$db = $this->getAdapter(); $db = $this->getAdapter();
...@@ -71,10 +82,7 @@ class ApprovalBodyRoleQueues extends Nmc_Db_Table ...@@ -71,10 +82,7 @@ class ApprovalBodyRoleQueues extends Nmc_Db_Table
$requestTablePrimary = $requestTable->getPrimaryKeyName(); $requestTablePrimary = $requestTable->getPrimaryKeyName();
$select = new Zend_Db_Select($db); $select = new Zend_Db_Select($db);
$select->from($this->getTableName(), array()); $select->from($this->getTableName(), 'request');
$select->join($requestTableName,
$this->getTableName() . '.request = ' . $requestTableName . '.' . $requestTablePrimary,
$requestTablePrimary);
$select->where($db->quoteInto('approvalBodyRole = ?', $role->getPrimaryKey())); $select->where($db->quoteInto('approvalBodyRole = ?', $role->getPrimaryKey()));
$select->where($db->quoteInto('visible = ?', 'yes')); $select->where($db->quoteInto('visible = ?', 'yes'));
$rows = $db->fetchCol($select); $rows = $db->fetchCol($select);
......
...@@ -150,6 +150,7 @@ ...@@ -150,6 +150,7 @@
<form action="/ApprovalChainManager/AddActionPost" method="post"> <form action="/ApprovalChainManager/AddActionPost" method="post">
<?php echo $this->formHidden('chainId', $this->approvalChain->getPrimaryKey()); ?> <?php echo $this->formHidden('chainId', $this->approvalChain->getPrimaryKey()); ?>
<div class="edit_approval_chain"> <div class="edit_approval_chain">
<div>
<label> <label>
Name:<br /> Name:<br />
<?php echo $this->formText('name'); ?> <?php echo $this->formText('name'); ?>
...@@ -160,7 +161,10 @@ ...@@ -160,7 +161,10 @@
array('class' => 'action_type_select'), array('class' => 'action_type_select'),
$this->approvalActions); ?> $this->approvalActions); ?>
</label> </label>
</div>
<?php if ($this->approvalChain->getPrimaryKey()) { ?> <?php if ($this->approvalChain->getPrimaryKey()) { ?>
<div class="clear"></div>
<div>
<label class="participating_roles"> <label class="participating_roles">
Participating Roles:<br/> Participating Roles:<br/>
<?php echo $this->formSelect('participatingRoles', null, <?php echo $this->formSelect('participatingRoles', null,
...@@ -169,6 +173,15 @@ ...@@ -169,6 +173,15 @@
'name', ApprovalBodyRoles::getInstance()->getPrimaryKeyName() 'name', ApprovalBodyRoles::getInstance()->getPrimaryKeyName()
)); ?> )); ?>
</label> </label>
<label class="editing_roles">
Editing Roles:<br/>
<?php echo $this->formSelect('editingRoles', null,
array('multiple' => 'multiple'),
$this->approvalChain->ownerBody->roles->columnToArray(
'name', ApprovalBodyRoles::getInstance()->getPrimaryKeyName()
)); ?>
</label>
</div>
<?php } ?> <?php } ?>
<div class="edit_approval_chain_specifics clear"></div> <div class="edit_approval_chain_specifics clear"></div>
</div> </div>
...@@ -179,33 +192,49 @@ ...@@ -179,33 +192,49 @@
<?php echo $this->formHidden('chainId', $this->approvalChain->getPrimaryKey()); ?> <?php echo $this->formHidden('chainId', $this->approvalChain->getPrimaryKey()); ?>
<?php foreach ($this->approvalChain->approvalActions as $approvalAction) { ?> <?php foreach ($this->approvalChain->approvalActions as $approvalAction) { ?>
<div class="edit_approval_chain"> <div class="edit_approval_chain">
<label> <div>
Name: <br/> <label>
<?php echo $this->formText('edit[' . $approvalAction->getPrimaryKey() . '][name]', Name: <br/>
$approvalAction->name); ?> <?php echo $this->formText('edit[' . $approvalAction->getPrimaryKey() . '][name]',
</label> $approvalAction->name); ?>
<label> </label>
Type: <br /> <label>
<?php echo $this->formSelect('edit[' . $approvalAction->getPrimaryKey() . '][type]', Type: <br />
$approvalAction->className, <?php echo $this->formSelect('edit[' . $approvalAction->getPrimaryKey() . '][type]',
array('class' => 'action_type_select'), $approvalAction->className,
$this->approvalActions); ?> array('class' => 'action_type_select'),
</label> $this->approvalActions); ?>
<label class="participating_roles"> </label>
Participating Roles:<br/> </div>
<?php echo $this->formSelect('edit[' . $approvalAction->getPrimaryKey() . '][participatingRoles]', <div class="clear"></div>
$approvalAction->participants->columnToArray( <div>
ApprovalBodyRoles::getInstance()->getPrimaryKeyName() <label class="participating_roles">
), Participating Roles:<br/>
array('multiple' => 'multiple'), <?php echo $this->formSelect('edit[' . $approvalAction->getPrimaryKey() . '][participatingRoles]',
$this->approvalChain->ownerBody->roles->columnToArray( $approvalAction->participants->columnToArray(
'name', ApprovalBodyRoles::getInstance()->getPrimaryKeyName() ApprovalBodyRoles::getInstance()->getPrimaryKeyName()
)); ?> ),
</label> array('multiple' => 'multiple'),
<label> $this->approvalChain->ownerBody->roles->columnToArray(
Delete: <br /> 'name', ApprovalBodyRoles::getInstance()->getPrimaryKeyName()
<?php echo $this->formCheckbox('edit[' . $approvalAction->getPrimaryKey() . '][delete]'); ?> )); ?>
</label> </label>
<label class="editing_roles">
Editing Roles:<br/>
<?php echo $this->formSelect('edit[' . $approvalAction->getPrimaryKey() . '][editingRoles]',
$approvalAction->getEditingParticipants()->columnToArray(
ApprovalBodyRoles::getInstance()->getPrimaryKeyName()
),
array('multiple' => 'multiple'),
$this->approvalChain->ownerBody->roles->columnToArray(
'name', ApprovalBodyRoles::getInstance()->getPrimaryKeyName()
)); ?>
</label>
<label>
Delete: <br />
<?php echo $this->formCheckbox('edit[' . $approvalAction->getPrimaryKey() . '][delete]'); ?>
</label>
</div>
<div class="edit_approval_chain_specifics clear"> <div class="edit_approval_chain_specifics clear">
<?php include $approvalAction->getTable()->getEditTemplate(); ?> <?php include $approvalAction->getTable()->getEditTemplate(); ?>
</div> </div>
......
...@@ -209,11 +209,13 @@ ...@@ -209,11 +209,13 @@
href="/Request/View/<?php echo $request->getPrimaryKey(); ?>"> href="/Request/View/<?php echo $request->getPrimaryKey(); ?>">
View View
</a> </a>
<?php if($role['role']->canEditRequest($request)) { ?>
/ /
<a class="requestLink<?php echo $linkClass; ?>" <a class="requestLink<?php echo $linkClass; ?>"
href="/Request/Load/<?php echo $request->getPrimaryKey(); ?>"> href="/Request/Load/<?php echo $request->getPrimaryKey(); ?>">
Edit Edit
</a> </a>
<?php } ?>
</td> </td>
<td> <td>
<?php <?php
......
@import "manager.css"; @import "manager.css";
div#manage_links select {
max-width: 200px;
}
div.edit_approval_chain { div.edit_approval_chain {
border: 1px solid #ccc; border: 1px solid #ccc;
padding: 5px; padding: 5px;
......
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