public function update()
 {
     // Load the $substatus for editing
     if (isset($_REQUEST['substatus_id']) && $_REQUEST['substatus_id']) {
         try {
             $substatus = new Substatus($_REQUEST['substatus_id']);
         } catch (\Exception $e) {
             $_SESSION['errorMessages'][] = $e;
             header('Location: ' . BASE_URL . '/substatus');
             exit;
         }
     } else {
         $substatus = new Substatus();
     }
     if (isset($_POST['name'])) {
         $substatus->handleUpdate($_POST);
         try {
             $substatus->save();
             header('Location: ' . BASE_URL . '/substatus');
             exit;
         } catch (\Exception $e) {
             $_SESSION['errorMessages'][] = $e;
         }
     }
     $this->template->blocks[] = new Block('substatus/updateForm.inc', array('substatus' => $substatus));
 }
示例#2
0
 /**
  * Update the status and substatus
  *
  * The new status will delete the current substatus if
  * the current substatus is not valid for the new status
  *
  * @param string $string
  * @param int $substatus_id
  */
 public function setStatus($status, $substatus_id = null)
 {
     $oldStatus = $this->getStatus();
     $oldSubStatusId = $this->getSubstatus_id();
     parent::set('status', $status);
     if ($substatus_id) {
         try {
             $substatus = new Substatus($substatus_id);
             if ($substatus->getStatus() == $this->getStatus()) {
                 $this->setSubstatus($substatus);
             }
         } catch (\Exception $e) {
             // Invalid substatus will just ignored
         }
     } else {
         // See if there's a default substatus to set
         $zend_db = Database::getConnection();
         $result = $zend_db->query('select * from substatus where status=? and isDefault=1')->execute([$this->getStatus()]);
         if (count($result)) {
             $this->setSubstatus(new Substatus($result->fetch()));
         }
     }
     if ($this->getSubstatus_id()) {
         if ($this->getSubstatus()->getStatus() != $this->getStatus()) {
             $this->setSubstatus_id(null);
         }
     }
     // See if we need to update the closedDate
     $newStatus = $this->getStatus();
     if ($newStatus == 'closed') {
         if ($newStatus != $oldStatus || $this->getSubstatus_id() != $oldSubStatusId) {
             $this->setClosedDate(date(DATE_FORMAT));
         }
     }
 }