示例#1
0
 function transactionSave()
 {
     $conn = Doctrine_Manager::connection();
     $session = SessionWrapper::getInstance();
     # begin transaction to save
     try {
         $conn->beginTransaction();
         # initial save
         $this->save();
         # commit changes
         $conn->commit();
         # update default userid on the companyid
         if ($this->isSelfRegistered() && !isEmptyString($this->getCompanyID()) && isEmptyString($this->getCompany()->getDefaultUserID())) {
             $this->getCompany()->setDefaultUserID($this->getID());
             $this->setCreatedBy($this->getID());
             $this->save();
             // $this->getCompany()->save();
         }
         # send signup notification to email for public registration
         if ($this->isSelfRegistered() && $this->isCompanyAdmin()) {
             $this->sendSignupNotification();
         }
         # invite via email
         if ($this->getIsInvited() == 1) {
             $this->inviteViaEmail();
         }
         # check if shift has been defined
         if (!isEmptyString($this->getShift())) {
             $shift_data = array("userid" => $this->getID(), "sessionid" => $this->getShift(), "startdate" => date('Y-m-d', strtotime($this->getDateCreated())), "status" => 1, "dateadded" => DEFAULT_DATETIME, "addedbyid" => $session->getVar('userid'));
             $shift = new ShiftSchedule();
             $shift->processPost($shift_data);
             $shift->save();
             /* debugMessage($shift->toArray());
             			debugMessage('errors are '.$shift->getErrorStackAsString()); */
         }
         # add log to audit trail
         $view = new Zend_View();
         $controller = $this->getController();
         $url = $view->serverUrl($view->baseUrl('profile/view/id/' . encode($this->getID())));
         $profiletype = 'User Profile ';
         $usecase = '1.3';
         $module = '1';
         $type = USER_CREATE;
         $browser = new Browser();
         $audit_values = $session->getVar('browseraudit');
         $audit_values['module'] = $module;
         $audit_values['usecase'] = $usecase;
         $audit_values['transactiontype'] = $type;
         $audit_values['status'] = "Y";
         $audit_values['userid'] = $session->getVar('userid');
         $audit_values['transactiondetails'] = $profiletype . " <a href='" . $url . "' class='blockanchor'>" . $this->getName() . "</a> created";
         $audit_values['url'] = $url;
         // debugMessage($audit_values);
         $this->notify(new sfEvent($this, $type, $audit_values));
     } catch (Exception $e) {
         $conn->rollback();
         // debugMessage('Error is '.$e->getMessage());
         throw new Exception($e->getMessage());
         return false;
     }
     return true;
 }
 function schedulecreateAction()
 {
     $session = SessionWrapper::getInstance();
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(TRUE);
     // parent::createAction();
     $formvalues = $this->_getAllParams();
     // debugMessage($formvalues); exit();
     $formvalues['id'] = $id = decode($formvalues['id']);
     $status = $formvalues['status'];
     $old_shift = $formvalues['shift_old'];
     $isactive = false;
     $shift = new ShiftSchedule();
     if (!isArrayKeyAnEmptyString('id', $formvalues)) {
         $shift->populate($id);
         $isactive = $shift->isActive();
     } else {
         $formvalues['addedbyid'] = $session->getVar('userid');
         $formvalues['dateadded'] = DEFAULT_DATETIME;
     }
     $shift->processPost($formvalues);
     if ($shift->hasError()) {
         debugMessage('errors are ' . $shift->getErrorStackAsString());
         exit;
         $session->setVar(ERROR_MESSAGE, $shift->getErrorStackAsString());
         $this->_helper->redirector->gotoUrl(decode($this->_getParam(URL_FAILURE)));
         exit;
     }
     // exit;
     try {
         $updateshift = false;
         if ($status == 1) {
             if ($old_shift != $shift->getSessionID()) {
                 $shift->getUser()->setShift($shift->getSessionID());
                 $updateshift = true;
             }
         } else {
             if (!isEmptyString($old_shift) && $isactive) {
                 $shift->getUser()->setShift(NULL);
                 $updateshift = true;
             }
         }
         // debugMessage($shift->toArray()); exit;
         $shift->save();
         # update any previous shifts that could still be active when setting a new active session
         if ($status == 1) {
             $updateableshifts = $shift->getCurrentActiveShiftsForUser($shift->getUserID());
             // debugMessage($updateableshifts->toArray());
             if ($updateableshifts->count() > 0) {
                 foreach ($updateableshifts as $ashift) {
                     $ashift->setStatus(0);
                     $ashift->save();
                 }
             }
         }
         $session->setVar(SUCCESS_MESSAGE, $this->_getParam('successmessage'));
         $this->_helper->redirector->gotoUrl(decode($this->_getParam(URL_SUCCESS)));
     } catch (Exception $e) {
         $session->setVar(ERROR_MESSAGE, $e->getMessage());
         //debugMessage('save error '.$e->getMessage());
         $this->_helper->redirector->gotoUrl(decode($this->_getParam(URL_FAILURE)));
     }
 }