From 15c77d2e256617dffcc584d3d3b97db98a9e635d Mon Sep 17 00:00:00 2001 From: Tim Steiner <tsteiner2@unl.edu> Date: Thu, 11 Jan 2007 22:59:16 +0000 Subject: [PATCH] Made the request submittal process actually place the new request into the default chain for its type. --- .../controllers/NewrequestController.php | 2 +- application/controllers/TestController.php | 17 +++---- .../controllers/UseradminController.php | 2 +- application/models/rows/CourseGeneration.php | 4 +- application/models/rows/Request.php | 51 +++++++++++++++++-- application/models/rows/RequestStack.php | 20 ++++++++ application/models/rows/RequestType.php | 11 ++++ application/models/tables/ApprovalBodies.php | 9 ++++ application/models/tables/RequestStacks.php | 24 ++++++++- application/models/tables/RequestStates.php | 29 +++++++++++ application/models/tables/RequestTypes.php | 28 ++++++++-- application/views/my_home.xhtml | 4 +- document_root/index.php | 3 ++ 13 files changed, 178 insertions(+), 26 deletions(-) create mode 100644 application/models/rows/RequestStack.php create mode 100644 application/models/rows/RequestType.php create mode 100644 application/models/tables/RequestStates.php diff --git a/application/controllers/NewrequestController.php b/application/controllers/NewrequestController.php index b019a82b..ce076054 100644 --- a/application/controllers/NewrequestController.php +++ b/application/controllers/NewrequestController.php @@ -76,7 +76,7 @@ class NewRequestController extends Nmc_Controller_Action $courseLetter = Zend_Filter::getAlpha($in[3]); $request = Requests::getInstance()->fetchNew(); - $request->owner = Nmc_User::getInstance()->getUser()->getId(); + $request->owner = Nmc_User::getInstance()->getUser(); $request->type = RequestTypes::getInstance()->stringToType($type); $course = Nmc_Registry_Session::getInstance()->course; diff --git a/application/controllers/TestController.php b/application/controllers/TestController.php index cf35d852..0701d103 100644 --- a/application/controllers/TestController.php +++ b/application/controllers/TestController.php @@ -2,23 +2,20 @@ class TestController extends Nmc_Controller_Action { - public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array()) + + public function init() { - parent::__construct($request, $response, $invokeArgs); //$this->_registerPlugin(new Nmc_Controller_Action_Plugin_Authorize()); //$this->_registerPlugin(new Nmc_Controller_Action_Plugin_Test()); } public function indexAction() { - return; - - $files = Files::getInstance()->fetchAll(); - foreach($files as $file) { - $fileHash = hash('whirlpool', $file->data); - $file->hash = $fileHash; - $file->save(); - } + $out = $this->getResponse(); + $view = new Nmc_View(); + $out->setBody($view->render('index.xhtml')); + //$out->renderExceptions(true); + throw new Exception("this is bad!"); } } diff --git a/application/controllers/UseradminController.php b/application/controllers/UseradminController.php index a258ecfb..2fbf70be 100644 --- a/application/controllers/UseradminController.php +++ b/application/controllers/UseradminController.php @@ -19,7 +19,7 @@ class UserAdminController extends Nmc_Controller_Action $in = $this->getRequest(); $userId = Zend_Filter::getInt($in->getParam(0)); - if($in['Submit'] == 'Submit') { + if($in->getPost('Submit') == 'Submit') { return $this->editUserActionPost(); } diff --git a/application/models/rows/CourseGeneration.php b/application/models/rows/CourseGeneration.php index 04107f34..c97ac7ab 100644 --- a/application/models/rows/CourseGeneration.php +++ b/application/models/rows/CourseGeneration.php @@ -10,10 +10,8 @@ class CourseGeneration extends Asset { protected $_homeCrosslisting; - public function __construct($config = array()) + public function _init() { - parent::__construct($config); - $this->_registerRelation( new Nmc_Db_Table_Relation_HasOne(CourseDetails::getInstance(), $this, 'generation')); $this->_registerRelation( diff --git a/application/models/rows/Request.php b/application/models/rows/Request.php index 831ab20d..4a8c5852 100644 --- a/application/models/rows/Request.php +++ b/application/models/rows/Request.php @@ -3,11 +3,33 @@ class Request extends Nmc_Db_Table_Row { - public function __construct($config = array()) { - parent::__construct($config); - $this->_registerRelation( - new Nmc_Db_Table_Relation_HasMany(RequestFiles::getInstance(), - $this, 'request', 'files')); + public function _init() { + $requestRelation = new Nmc_Db_Table_Relation_HasMany(RequestFiles::getInstance(), $this, 'request', 'files'); + $this->_registerRelation($requestRelation); + + $ownerRelation = new Nmc_Db_Table_Relation_HasOne(Users::getInstance(), $this, 'owner'); + $ownerRelation->setForeignKeyInLocalTable(true); + $ownerRelation->setAttributeName('owner'); + $ownerRelation->setOverrideLocal(true); + $this->_registerRelation($ownerRelation); + + $stackRelation = new Nmc_Db_Table_Relation_HasOne(RequestStacks::getInstance(), $this, 'stack_pointer'); + $stackRelation->setForeignKeyInLocalTable(true); + $stackRelation->setAttributeName('stackPointer'); + $stackRelation->setOverrideLocal(true); + $this->_registerRelation($stackRelation); + + $stateRelation = new Nmc_Db_Table_Relation_HasOne(RequestStates::getInstance(), $this, 'state'); + $stateRelation->setForeignKeyInLocalTable(true); + $stateRelation->setAttributeName('state'); + $stateRelation->setOverrideLocal(true); + $this->_registerRelation($stateRelation); + + $typeRelation = new Nmc_Db_Table_Relation_HasOne(RequestTypes::getInstance(), $this, 'type'); + $typeRelation->setForeignKeyInLocalTable(true); + $typeRelation->setAttributeName('type'); + $typeRelation->setOverrideLocal(true); + $this->_registerRelation($typeRelation); } /** @@ -80,6 +102,25 @@ class Request extends Nmc_Db_Table_Row $newFile->type = $type; $this->files[$key] = $newFile; } + + protected function _preSave() + { + // should only need to worry about this when dealing with a new request + if($this->getPrimaryKey() != '') { + return parent::_save(); + } + + // create the stack for this request and start its journy along the approval chain + $approvalBody = ApprovalBodies::getInstance()->fetchRootApprovalBody(); + + $stack = RequestStacks::getInstance()->fetchNew(); + $stack->chain = $this->type->approvalChain; + $stack->body = $approvalBody; + $stack->save(); + + $this->stackPointer = $stack; + $this->state = null; + } } ?> \ No newline at end of file diff --git a/application/models/rows/RequestStack.php b/application/models/rows/RequestStack.php new file mode 100644 index 00000000..bd6b08e2 --- /dev/null +++ b/application/models/rows/RequestStack.php @@ -0,0 +1,20 @@ +<?php + +class RequestStack extends Nmc_Db_Table_Row +{ + public function _init() + { + $bodyRelation = new Nmc_Db_Table_Relation_HasOne(ApprovalBodies::getInstance(), $this, 'body'); + $bodyRelation->setForeignKeyInLocalTable(true); + $bodyRelation->setOverrideLocal(true); + $bodyRelation->setAttributeName('body'); + $this->_registerRelation($bodyRelation); + + + $chainRelation = new Nmc_Db_Table_Relation_HasOne(ApprovalChains::getInstance(), $this, 'chain'); + $chainRelation->setForeignKeyInLocalTable(true); + $chainRelation->setOverrideLocal(true); + $chainRelation->setAttributeName('chain'); + $this->_registerRelation($chainRelation); + } +} \ No newline at end of file diff --git a/application/models/rows/RequestType.php b/application/models/rows/RequestType.php new file mode 100644 index 00000000..fceb0d37 --- /dev/null +++ b/application/models/rows/RequestType.php @@ -0,0 +1,11 @@ +<?php + +class RequestType extends Nmc_Db_Table_Row +{ + protected function _init() + { + $chainRelation = new Nmc_Db_Table_Relation_HasOne(ApprovalChains::getInstance(), $this, 'approval_chain', 'approvalChain', true); + $chainRelation->setOverrideLocal(true); + $this->_registerRelation($chainRelation); + } +} \ No newline at end of file diff --git a/application/models/tables/ApprovalBodies.php b/application/models/tables/ApprovalBodies.php index 40410d5a..10628de2 100644 --- a/application/models/tables/ApprovalBodies.php +++ b/application/models/tables/ApprovalBodies.php @@ -31,6 +31,15 @@ class ApprovalBodies extends Nmc_Db_Table } + /** + * Returns the root approval body object (ie: superadmin). + * + * @return ApprovalBody + */ + public function fetchRootApprovalBody() + { + return $this->find(1); + } } ?> \ No newline at end of file diff --git a/application/models/tables/RequestStacks.php b/application/models/tables/RequestStacks.php index 1b583107..c2579373 100644 --- a/application/models/tables/RequestStacks.php +++ b/application/models/tables/RequestStacks.php @@ -2,9 +2,31 @@ /** * + * @rowClass RequestStack * @primary request_stack_id * */ -class RequestStacks extends Nmc_Db_Table {} +class RequestStacks extends Nmc_Db_Table +{ + /** + * The one true instance + * + * @var RequestStacks + */ + static protected $_instance; + + /** + * Return the one true instance + * + * @return RequestStacks + */ + static public function getInstance($config = array()) + { + if (!self::$_instance) { + self::$_instance = new RequestStacks($config); + } + return self::$_instance; + } +} ?> \ No newline at end of file diff --git a/application/models/tables/RequestStates.php b/application/models/tables/RequestStates.php new file mode 100644 index 00000000..d8808bef --- /dev/null +++ b/application/models/tables/RequestStates.php @@ -0,0 +1,29 @@ +<?php + +/** + * @primary request_state_id + * + */ +class RequestStates extends Nmc_Db_Table +{ + /** + * The one true instance + * + * @var RequestStates + */ + static protected $_instance; + + /** + * Return the one true instance + * + * @return RequestStates + */ + static public function getInstance($config = array()) + { + if (!self::$_instance) { + self::$_instance = new RequestStates($config); + } + return self::$_instance; + } + +} \ No newline at end of file diff --git a/application/models/tables/RequestTypes.php b/application/models/tables/RequestTypes.php index 60c081a2..34a1cf0e 100644 --- a/application/models/tables/RequestTypes.php +++ b/application/models/tables/RequestTypes.php @@ -3,6 +3,7 @@ /** * * @primary request_type_id + * @rowClass RequestType * */ class RequestTypes extends Nmc_Db_Table @@ -15,7 +16,7 @@ class RequestTypes extends Nmc_Db_Table parent::__construct($config); $contents = $this->fetchAll(); foreach($contents as $row) { - $this->_map[$row->name] = $row->getPrimaryKey(); + $this->_map[$row->name] = $row; } } @@ -34,9 +35,30 @@ class RequestTypes extends Nmc_Db_Table return self::$_instance; } - public function stringToType($string) + /** + * Returns an instance of the request type specified + * + * @param string $type + * @return RequestType + */ + public function stringToType($type) { - return $this->_map[$string]; + return $this->_map[$type]; + } + + /** + * Returns an object for the supplied request type + * + * @param string|int $type + * @return RequestType + */ + public function fetchRequestType($type) + { + if(!Zend_Filter::isInt($type)) { + $type = $this->stringToType($string); + } + + return $this->find($type); } } diff --git a/application/views/my_home.xhtml b/application/views/my_home.xhtml index 3a44513e..75b66de9 100644 --- a/application/views/my_home.xhtml +++ b/application/views/my_home.xhtml @@ -45,7 +45,7 @@ . $request->getCourseGeneration()->courseNumber . $request->getCourseGeneration()->courseLetter; ?></td> <td>NONC</td> - <td><?php echo $request->type; ?></td> + <td><?php echo $request->type->name; ?></td> <td><select><option>Submission</option></select></td> <td> <a href="/NewRequest/Load/<?php echo $request->getPrimaryKey(); ?>"> @@ -91,7 +91,7 @@ . $request->getCourseGeneration()->courseNumber . $request->getCourseGeneration()->courseLetter; ?></td> <td>NONC</td> - <td><?php echo $request->type; ?></td> + <td><?php echo $request->type->name; ?></td> <td><select><option>Submission</option></select></td> <td> <a href="/NewRequest/Load/<?php echo $request->getPrimaryKey(); ?>"> diff --git a/document_root/index.php b/document_root/index.php index e28237ae..2bc3d6bd 100644 --- a/document_root/index.php +++ b/document_root/index.php @@ -29,6 +29,9 @@ $controller = Zend_Controller_Front::getInstance(); $controller->setRouter($router); $controller->setControllerDirectory(APPLICATION_PATH . '/controllers'); //$controller->registerPlugin(new Nmc_Controller_Plugin_Http()); +$controller->throwExceptions(true); $controller->dispatch(); + + ?> -- GitLab