diff --git a/application/controllers/ApprovalchainmanagerController.php b/application/controllers/ApprovalchainmanagerController.php index dcb342c24332c08aace74d7b83731ec2e459d914..257b6b059862af7435e4ab05b6e8af584e7968cb 100644 --- a/application/controllers/ApprovalchainmanagerController.php +++ b/application/controllers/ApprovalchainmanagerController.php @@ -215,6 +215,19 @@ class ApprovalChainManagerController extends Nmc_Controller_Action $action->updateFromForm($actionData); $action->participants = ApprovalBodyRoles::getInstance()->find($actionData['participatingRoles']); $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(); diff --git a/application/controllers/HomeController.php b/application/controllers/HomeController.php index e3cc3ed33f2bbe7b47457fd4aa065337613e7fa7..44875d3f8e03ef049b2f7b164bc47cec7bb373f6 100644 --- a/application/controllers/HomeController.php +++ b/application/controllers/HomeController.php @@ -11,39 +11,11 @@ class HomeController extends Nmc_Controller_Action public function indexAction() { $user = Nmc_User::getInstance()->getUser(); - $requests = Requests::getInstance()->getRequestsForUser($user, Requests::COMPLETED_REQUESTS_BOTH); - - $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) { + $rm = Nmc_Db_RowManager::getInstance(); - $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(); foreach($roles as $role) { @@ -92,6 +64,46 @@ class HomeController extends Nmc_Controller_Action } 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->user = $user; $out->roles = $rolesData; diff --git a/application/models/rows/ApprovalAction.php b/application/models/rows/ApprovalAction.php index bbfb45b4cffe578ffa0dbacf0ce1f559c447f498..1c69e166ad8abfd666e6f89d945f554abdc8ae73 100644 --- a/application/models/rows/ApprovalAction.php +++ b/application/models/rows/ApprovalAction.php @@ -20,7 +20,8 @@ class ApprovalAction extends Nmc_Db_Table_Row ); $participantRelation->setLinkingTable( ApprovalActionParticipants::getInstance(), - 'approvalBodyRole' + 'approvalBodyRole', + 'participantLinks' ); $this->_registerRelation($participantRelation); } @@ -30,4 +31,17 @@ class ApprovalAction extends Nmc_Db_Table_Row { 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 diff --git a/application/models/rows/ApprovalBodyRole.php b/application/models/rows/ApprovalBodyRole.php index e309344b5cc712c7d24aad2472f81f5e7d6f389a..ced402d15a47a8b233b83d318ca7113323a5f23d 100644 --- a/application/models/rows/ApprovalBodyRole.php +++ b/application/models/rows/ApprovalBodyRole.php @@ -30,6 +30,16 @@ class ApprovalBodyRole extends Nmc_Db_Table_Row } 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 diff --git a/application/models/rows/ApprovalChain.php b/application/models/rows/ApprovalChain.php index 17927d0468598436c881667a5787274530ba7413..06cf5f40646cdfb313e79a53cc4569005bea2a57 100644 --- a/application/models/rows/ApprovalChain.php +++ b/application/models/rows/ApprovalChain.php @@ -52,20 +52,25 @@ class ApprovalChain extends Nmc_Db_Table_Row } foreach ($currentAction->participants as $participant) { - try { + $queueItem = ApprovalBodyRoleQueues::getInstance()->fetchByRequestActionAndRole( + $request, $currentAction, $participant + ); + if (!$queueItem) { $queueItem = ApprovalBodyRoleQueues::getInstance()->fetchNew(); $queueItem->request = $request; $queueItem->approvalBodyRole = $participant; $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); diff --git a/application/models/tables/ApprovalActionParticipants.php b/application/models/tables/ApprovalActionParticipants.php index 6f21220cd168f569dcaf3ce7a8311ea18d4021f8..883c8543fdfabbc7c082195028762914daab1070 100644 --- a/application/models/tables/ApprovalActionParticipants.php +++ b/application/models/tables/ApprovalActionParticipants.php @@ -24,5 +24,12 @@ class ApprovalActionParticipants extends Nmc_Db_Table } return self::$_instance; } + + public function fetchNew() + { + $row = parent::fetchNew(); + $row->canEdit = 'no'; + return $row; + } } diff --git a/application/models/tables/ApprovalBodyRoleQueues.php b/application/models/tables/ApprovalBodyRoleQueues.php index 47a1dcf057589f932a11696dd071b756bc28637c..e6f24da7a7a9ef94a5df2b08bb07ab79c6919df8 100755 --- a/application/models/tables/ApprovalBodyRoleQueues.php +++ b/application/models/tables/ApprovalBodyRoleQueues.php @@ -63,6 +63,17 @@ class ApprovalBodyRoleQueues extends Nmc_Db_Table 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) { $db = $this->getAdapter(); @@ -71,10 +82,7 @@ class ApprovalBodyRoleQueues extends Nmc_Db_Table $requestTablePrimary = $requestTable->getPrimaryKeyName(); $select = new Zend_Db_Select($db); - $select->from($this->getTableName(), array()); - $select->join($requestTableName, - $this->getTableName() . '.request = ' . $requestTableName . '.' . $requestTablePrimary, - $requestTablePrimary); + $select->from($this->getTableName(), 'request'); $select->where($db->quoteInto('approvalBodyRole = ?', $role->getPrimaryKey())); $select->where($db->quoteInto('visible = ?', 'yes')); $rows = $db->fetchCol($select); diff --git a/application/views/approval_chain_manager.xhtml b/application/views/approval_chain_manager.xhtml index 26fc70cbdb0315dbc2f7bff90c6242d9a979312c..0898f509ab4a6c235bd56ecb0b7da2d47e75606a 100644 --- a/application/views/approval_chain_manager.xhtml +++ b/application/views/approval_chain_manager.xhtml @@ -150,6 +150,7 @@ <form action="/ApprovalChainManager/AddActionPost" method="post"> <?php echo $this->formHidden('chainId', $this->approvalChain->getPrimaryKey()); ?> <div class="edit_approval_chain"> + <div> <label> Name:<br /> <?php echo $this->formText('name'); ?> @@ -160,7 +161,10 @@ array('class' => 'action_type_select'), $this->approvalActions); ?> </label> + </div> <?php if ($this->approvalChain->getPrimaryKey()) { ?> + <div class="clear"></div> + <div> <label class="participating_roles"> Participating Roles:<br/> <?php echo $this->formSelect('participatingRoles', null, @@ -169,6 +173,15 @@ 'name', ApprovalBodyRoles::getInstance()->getPrimaryKeyName() )); ?> </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 } ?> <div class="edit_approval_chain_specifics clear"></div> </div> @@ -179,33 +192,49 @@ <?php echo $this->formHidden('chainId', $this->approvalChain->getPrimaryKey()); ?> <?php foreach ($this->approvalChain->approvalActions as $approvalAction) { ?> <div class="edit_approval_chain"> - <label> - Name: <br/> - <?php echo $this->formText('edit[' . $approvalAction->getPrimaryKey() . '][name]', - $approvalAction->name); ?> - </label> - <label> - Type: <br /> - <?php echo $this->formSelect('edit[' . $approvalAction->getPrimaryKey() . '][type]', - $approvalAction->className, - array('class' => 'action_type_select'), - $this->approvalActions); ?> - </label> - <label class="participating_roles"> - Participating Roles:<br/> - <?php echo $this->formSelect('edit[' . $approvalAction->getPrimaryKey() . '][participatingRoles]', - $approvalAction->participants->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> + <label> + Name: <br/> + <?php echo $this->formText('edit[' . $approvalAction->getPrimaryKey() . '][name]', + $approvalAction->name); ?> + </label> + <label> + Type: <br /> + <?php echo $this->formSelect('edit[' . $approvalAction->getPrimaryKey() . '][type]', + $approvalAction->className, + array('class' => 'action_type_select'), + $this->approvalActions); ?> + </label> + </div> + <div class="clear"></div> + <div> + <label class="participating_roles"> + Participating Roles:<br/> + <?php echo $this->formSelect('edit[' . $approvalAction->getPrimaryKey() . '][participatingRoles]', + $approvalAction->participants->columnToArray( + ApprovalBodyRoles::getInstance()->getPrimaryKeyName() + ), + array('multiple' => 'multiple'), + $this->approvalChain->ownerBody->roles->columnToArray( + 'name', ApprovalBodyRoles::getInstance()->getPrimaryKeyName() + )); ?> + </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"> <?php include $approvalAction->getTable()->getEditTemplate(); ?> </div> diff --git a/application/views/home.xhtml b/application/views/home.xhtml index 4d0f730f29be94d8ed9e6f2306562334ac3bf2a6..7b333e975c888c6867d548f237b0b8fc2fe79923 100755 --- a/application/views/home.xhtml +++ b/application/views/home.xhtml @@ -209,11 +209,13 @@ href="/Request/View/<?php echo $request->getPrimaryKey(); ?>"> View </a> + <?php if($role['role']->canEditRequest($request)) { ?> / <a class="requestLink<?php echo $linkClass; ?>" href="/Request/Load/<?php echo $request->getPrimaryKey(); ?>"> Edit </a> + <?php } ?> </td> <td> <?php diff --git a/document_root/css/approval_chain_manager.css b/document_root/css/approval_chain_manager.css index 170c2e7ba7cbc9cc57da47996bec9dacd88c63e6..1555c80f0feb21a34c2bd99dac145255baa4304f 100644 --- a/document_root/css/approval_chain_manager.css +++ b/document_root/css/approval_chain_manager.css @@ -1,5 +1,9 @@ @import "manager.css"; +div#manage_links select { + max-width: 200px; +} + div.edit_approval_chain { border: 1px solid #ccc; padding: 5px;