/** * 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)); } } }