/** * Retorna o valor antigo do registro antes de realizar a atualização * * @return Ca_Model_Pessoa_Mapper */ public function getValueOld() { if (!$this->_dataOld instanceof Ca_Model_Pessoa_Mapper) { $this->_dataOld = new Ca_Model_Pessoa_Mapper(); $this->_dataOld->setId($this->getId()); $this->_dataOld->retrive(); } return $this->_dataOld; }
protected function _afterSave() { parent::_afterSave(); $oldHierarquia = $this->getHierarquia(true)->toPhp(); $idResp = $this->getIdPessoaResp(true)->toPhp(); if ($idResp) { $_mapper = new Ca_Model_Pessoa_Mapper(); $_mapper->setId($idResp)->retrieve(); $hirarquia = $_mapper->getHierarquia(true)->toPhp() . '.' . $this->getId()->toPhp(); } else { $hirarquia = $this->getId()->toPhp(); } $hierarquiaComp = substr($hirarquia, 0, strlen($oldHierarquia)); if ($hierarquiaComp && $oldHierarquia == $hierarquiaComp && $hierarquiaComp != $this->getId()->toPhp()) { //throw new ZendT_Exception_Alert(_i18n('Não é possível associar a empresa responvável para este registro, devido a infringir a hierarquia!')); } if ($oldHierarquia != $hirarquia) { $data = array(); $data['hierarquia'] = $hirarquia; $this->getModel()->getAdapter()->update($this->getModel()->getName(), $data, 'id = ' . $this->getId()->toPhp()); } $this->setHierarquia($hirarquia); if ($this->_action == 'update' && $oldHierarquia && $oldHierarquia != $hirarquia) { $_where = new ZendT_Db_Where(); $_where->addFilter($this->getModel()->getName() . '.hierarquia', $oldHierarquia, '?%'); $_where->addFilter($this->getModel()->getName() . '.id', $this->getId(), '!='); $_mapper = new Ca_DataView_Pessoa_MapperView(); $_mapper->findAll($_where, '*'); while ($_mapper->fetch()) { $_mapper->update(); } } }