Skip to content
Snippets Groups Projects
Select Git revision
  • 2af1d21bc220f507f0ed7568a47acd6df083d5e5
  • master default
  • disable-new-requests
  • fix-bulletin-view-missing-notes-error
  • add-missing-queue-managers
  • projects-task-53
  • projects-task-51
  • projects-task-43
  • projects-task-24
  • projects-task-31
  • projects-task-32
  • projects-task-8
  • project-setup-docs
  • projects-task-28
  • projects-task-27
  • projects-task-9
  • projects-task-7
  • mass-update-course-codes-in-sections
  • wdn-four
  • learning-outcomes
  • additional-bulletin-pages
  • svn-redesign
  • svn-popups
  • svn-trunk
  • svn-performance
  • svn-tim
26 results

ApprovalchainmanagerController.php

Blame
  • ApprovalchainmanagerController.php 10.26 KiB
    <?php
    
    class ApprovalChainManagerController extends Nmc_Controller_Action
    {
    
        public function init()
        {
            $this->_registerPlugin(new Application_Controller_Action_Plugin_Authorize());
        }
    
        public function indexAction()
        {
            return $this->listAction();
        }
    
        public function listAction()
        {
            $approvalChains = ApprovalChains::getInstance()->fetchAll();
    
            $out = new Application_View();
            $out->page = 'approval_chain_manager';
            $out->approvalChains = $approvalChains;
            $out->clearSidebarModules();
            echo $out->render('unlModernWrapper.xhtml');
        }
    
        public function editChainAction()
        {
            $in = $this->getRequest();
            $chainId = Zend_Filter_Int::filter($in->getParam(0));
            if($chainId == 'new') {
                $chain = ApprovalChains::getInstance()->fetchNew();
            } else {
                $chain = ApprovalChains::getInstance()->findOne($chainId);
            }
    
            $approvalChains = ApprovalChains::getInstance()->fetchAll();
    
            $approvalActions = ApprovalActions::getInstance()->getAvailableActions();
            $approvalActionList = array('-1' => '--Select Action--');
            foreach ($approvalActions as $approvalAction) {
                $approvalActionList[$approvalAction->getRowReturnType()] = $approvalAction->getActionName();
            }
    
            $user = Nmc_User::getInstance()->getUser();
            $approvalBodies = ApprovalBodies::getInstance()->fetchApprovalBodiesUserCanAdminister($user);
    
            $out = new Application_View();
            $out->page = 'approval_chain_manager';
            $out->chain = $chain;
            $out->approvalChains = $approvalChains;
            $out->approvalActions = $approvalActionList;
            $out->approvalChain = $chain;
            $out->approvalBodies = $approvalBodies;
            $out->clearSidebarModules();
            echo $out->render('unlModernWrapper.xhtml');
        }
    
        public function editChainPostAction()
        {
            $in = $this->getRequest();
            $postData = $in->getPost();
            $chainId = $postData['chainId'];
            $ownerId = Zend_Filter_Int::filter($postData['ownerBody']);
    
            $chainId = Zend_Filter_Int::filter($chainId);
            if ($chainId > 0) {
                $chain = ApprovalChains::getInstance()->findOne($chainId);
            } else {
                $chain = ApprovalChains::getInstance()->fetchNew();
            }
    
            $ownerBody = ApprovalBodies::getInstance()->findOne($ownerId);
    
            $chain->name = $postData['name'];
            $chain->ownerBody = $ownerBody;
            $chain->description = '';
            $chain->save();
    
            $chainId = $chain->getPrimaryKey();
    
            $view = new Application_View();
            $view->refresh = '/ApprovalChainManager/EditChain/' . $chainId;
            $view->clearSidebarModules();
    
            $out = $this->getResponse();
            $out->setBody($view->render('unlModernWrapper.xhtml'));
        }
    
        public function addLinkPostAction()
        {
            $in = $this->getRequest();
            $postData = $in->getPost();
    
            $chainId = Zend_Filter_Int::filter($postData['chainId']);
            if ($chainId > 0) {
                $chain = ApprovalChains::getInstance()->findOne($chainId);
            } else {
                throw new Exception('Attempted to edit invalid chain.');
            }
    
            $currentActionId = Zend_Filter_Int::filter($postData['currentAction']);
            if ($currentActionId > 0) {
                $currentAction = ApprovalActionsAbstract::getInstance()->findOne($currentActionId);
            } else {
                $currentAction = null;
            }
    
            $nextActionId = Zend_Filter_Int::filter($postData['nextAction']);
            if ($nextActionId) {
                $nextAction = ApprovalActionsAbstract::getInstance()->findOne($nextActionId);
            } else {
                $nextAction = null;
            }
    
            $newLink = ApprovalLinks::getInstance()->fetchNew();
            $newLink->name = '';
            $newLink->description = '';
            $newLink->chain = $chain->getPrimaryKey();
            $newLink->currentAction = $currentAction;
            if ($postData['currentState'] != '_null') {
                $newLink->currentState = $postData['currentState'];
            }
            $newLink->nextAction = $nextAction;
            $newLink->save();
    
            $out = new Application_View();
            $out->refresh = '/ApprovalChainManager/EditChain/' . $chain->getPrimaryKey();
            $out->clearSidebarModules();
            $this->getResponse()->setBody($out->render('unlModernWrapper.xhtml'));
        }
    
        public function editLinksPostAction()
        {
            $in = $this->getRequest();
            $postData = $in->getPost();
    
            $chainId = Zend_Filter_Int::filter($postData['chainId']);
            if ($chainId > 0) {
                $chain = ApprovalChains::getInstance()->findOne($chainId);
            } else {
                throw new Exception('Attempted to edit invalid chain.');
            }
    
            foreach ($postData['edit'] as $currentChainId => $currentLinkData) {
    
                $currentActionId = Zend_Filter_Int::filter($currentLinkData['currentAction']);
                if ($currentActionId > 0) {
                    $currentAction = ApprovalActionsAbstract::getInstance()->findOne($currentActionId);
                } else {
                    $currentAction = null;
                }
    
                $nextActionId = Zend_Filter_Int::filter($currentLinkData['nextAction']);
                if ($nextActionId > 0) {
                    $nextAction = ApprovalActionsAbstract::getInstance()->findOne($nextActionId);
                } else {
                    $nextAction = null;
                }
    
    
                $currentLink = ApprovalLinks::getInstance()->findOne($currentChainId);
    
                if($currentLinkData['delete']) {
                    $currentLink->delete();
                    break;
                }
    
                $currentLink->chain = $chain->getPrimaryKey();
                $currentLink->currentAction = $currentAction;
                if ($currentLinkData['currentState'] != '_null') {
                    $currentLink->currentState = $currentLinkData['currentState'];
                }
                $currentLink->nextAction = $nextAction;
                $currentLink->save();
            }
    
            $out = new Application_View();
            $out->refresh = '/ApprovalChainManager/EditChain/' . $chain->getPrimaryKey();
            $out->clearSidebarModules();
            $this->getResponse()->setBody($out->render('unlModernWrapper.xhtml'));
        }
    
        public function addActionPostAction()
        {
            $in = $this->getRequest();
            $actionRowClass = $in->getPost('type');
            $actionTableClass = 'ApprovalActions'
                        . substr($actionRowClass, strlen('ApprovalAction'));
            $actionTable = call_user_func(array($actionTableClass, 'getInstance'));
    
            $newAction = $actionTable->fetchNew($in->getPost());
            $newAction->name = $in->getPost('name');
            $newAction->approvalChain = $in->getPost('chainId');
            $newAction->save();
    
            $out = new Application_View();
            $out->refresh = '/ApprovalChainManager/EditChain/' . $in->getPost('chainId');
            $out->clearSidebarModules();
            echo $out->render('unlModernWrapper.xhtml');
        }
    
        public function editActionPostAction()
        {
            $in = $this->getRequest();
    
            foreach($in->getPost('edit') as $actionId => $actionData) {
                $action = ApprovalActionsAbstract::getInstance()->findOne($actionId);
                if($actionData['delete'] == '1') {
                    $action->delete();
                    continue;
                }
    
                $action->name = $actionData['name'];
                $action->updateFromForm($actionData);
                $action->participants = ApprovalBodyRoles::getInstance()->find($actionData['participatingRoles']);
                $action->save();
            }
    
            $out = new Application_View();
            $out->refresh = '/ApprovalChainManager/EditChain/' . $in->getPost('chainId');
            $out->clearSidebarModules();
            echo $out->render('unlModernWrapper.xhtml');
        }
    
        public function getActionDetailXMLAction()
        {
            $in = $this->getRequest();
            $actionId = Zend_Filter_Int::filter($in->getParam(0));
            $actionRow = ApprovalActionsAbstract::getInstance()->findOne($actionId);
            $actionTable = $actionRow->getTable();
            $results = $actionTable->getResultStatusStrings();
    
            $out = new DOMDocument();
            $element = $out->createElement('action');
            $element->setAttribute('id', $actionRow->getPrimaryKey());
            $element->setAttribute('name', $actionRow->name);
            $element->setAttribute('className', get_class($actionRow));
            foreach ($results as $result) {
                $resultElement = $out->createElement('result');
                $resultElement->setAttribute('name', $result);
                $element->appendChild($resultElement);
            }
            $out->appendChild($element);
            $this->getResponse()->setHeader('Content-type', 'application/xml');
            $this->getResponse()->setBody($out->saveXML());
        }
    
        public function getActionListAction()
        {
            $approvalActions = ApprovalActions::getInstance()->getAvailableActions();
    
            $out = new DOMDocument();
            foreach ($approvalActions as $approvalAction) {
                $element = $out->createElement('action');
                $element->setAttribute('name', $approvalAction->getActionName());
                $element->setAttribute('className', get_class($approvalAction));
                foreach($approvalAction->getResultStatusStrings() as $actionResult)
                {
                    $resultElement = $out->createElement('result');
                    $resultElement->setAttribute('name', $actionResult);
                    $element->appendChild($resultElement);
                }
                $out->appendChild($element);
            }
            $this->getResponse()->setHeader('Content-type', 'application/xml');
            $this->getResponse()->setBody($out->saveXML());
        }
    
        public function getActionEditXhtmlAction()
        {
            $in = $this->getRequest();
            $actionName = $in->getParam(0);
            $className = 'ApprovalActions' . substr($actionName, strlen('ApprovalAction'));
            $action = call_user_method('getInstance', $className);
            $template = $action->getEditTemplate();
    
            $out = new Nmc_View();
            $xhtml = $out->render($template);
            $dom = new DOMDocument();
            $dom->loadHTML($xhtml);
            $dom->childNodes->item(1)->data .= 'xmlns="http://www.w3.org/1999/xhtml"';
            header('Content-type: application/xhtml+xml');
            echo $dom->saveXML();
        }
    }