function approveAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(TRUE); $session = SessionWrapper::getInstance(); $config = Zend_Registry::get("config"); $this->_translate = Zend_Registry::get("translate"); $formvalues = $this->_getAllParams(); debugMessage($formvalues); // exit; if (!isArrayKeyAnEmptyString('id', $formvalues)) { if (isArrayKeyAnEmptyString('status', $formvalues)) { $formvalues['status'] = 3; } $timesheet = new Timesheet(); $timesheet->populate(decode($formvalues['id'])); $timesheet->setStatus($formvalues['status']); if (!isEmptyString($timesheet->getDateIn()) && !isEmptyString($timesheet->getDateOut())) { $timesheet->setHours($timesheet->getComputedHours()); } $timesheet->setDateApproved(DEFAULT_DATETIME); $timesheet->setApprovedByID($session->getVar('userid')); if (!isArrayKeyAnEmptyString('reason', $formvalues)) { $timesheet->setComments("<br/>Rejected with remarks: " . $formvalues['reason']); } // debugMessage($timesheet->toArray()); try { if ($timesheet->save()) { $session->setVar(SUCCESS_MESSAGE, "Successfully Approved"); } $timesheet->afterApprove(); } catch (Exception $e) { $session->setVar(ERROR_MESSAGE, $e->getMessage()); } } // exit; if (!isArrayKeyAnEmptyString('ids', $formvalues)) { $idsarray = array_remove_empty(explode(',', $formvalues['ids'])); // debugMessage($idsarray); if (isArrayKeyAnEmptyString('status', $formvalues)) { $formvalues['status'] = 3; } $timesheet_collection = new Doctrine_Collection(Doctrine_Core::getTable("Timesheet")); if (count($idsarray) > 0) { $hrs = 0; foreach ($idsarray as $key => $id) { $timesheet = new Timesheet(); $timesheet->populate($id); $timesheet->setStatus($formvalues['status']); $timesheet->setHours($timesheet->getComputedHours()); // debugMessage($timesheet->getComputedHours()); $timesheet->setDateApproved(DEFAULT_DATETIME); $timesheet->setApprovedByID($session->getVar('userid')); $timesheet_collection->add($timesheet); // debugMessage($timesheet->toArray()); } try { if ($timesheet_collection->save()) { $msg = "Successfully Approved"; if ($formvalues['status'] == 4) { $msg = "Successfully Rejected"; } $session->setVar(SUCCESS_MESSAGE, $msg); foreach ($timesheet_collection as $timesheet) { $timesheet->afterApprove(); } } } catch (Exception $e) { $session->setVar(ERROR_MESSAGE, $e->getMessage()); } } } $this->_helper->redirector->gotoUrl(decode($this->_getParam(URL_SUCCESS))); }