/** * Retorna o valor antigo do registro antes de realizar a atualização * * @return Cms_Model_Status_Mapper */ public function getValueOld() { if (!$this->_dataOld instanceof Cms_Model_Status_Mapper) { $this->_dataOld = new Cms_Model_Status_Mapper(); $this->_dataOld->setId($this->getId()); $this->_dataOld->retrive(); } return $this->_dataOld; }
protected function _beforeSave() { parent::_beforeSave(); if ($this->_action == 'insert') { /*if (!$this->getIdStatus(true)->toPhp()) { $this->setIdStatus(1); }*/ if (!$this->getChaveMacro(true)->toPhp()) { $this->setChaveMacro('{dh_ini_pub}_{titulo}'); } if (!$this->getIdUsuarioInc(true)->toPhp()) { $idUsuario = Zend_Auth::getInstance()->getStorage()->read()->getId(); $this->setIdUsuarioInc($idUsuario); } if (!$this->getDhIniPub(true)->toPhp()) { $this->setDhIniPub('SYSDATE'); } if (!$this->getPublico(true)->toPhp()) { $this->setPublico('S'); } if (!$this->getTitulo(true)->toPhp()) { $titulo = html_entity_decode(substr(strip_tags(str_replace("\n", " ", $this->getCorpo(true)->get())), 0, 40)) . "..."; $this->setTitulo($titulo); } if (!$this->getIdFilial(true)->toPhp()) { $idFilial = $_SESSION['logon']['filial']['id']; $this->setIdFilial($idFilial); } $now = ZendT_Type_Date::nowDateTime(); $_categoria = new Cms_Model_Categoria_Mapper(); $_categoria->setId($this->getIdCategoria(true)->toPhp())->retrieve(); $chaveCategoria = $_categoria->getChave(true)->toPhp(); if (strpos($chaveCategoria, 'fale-com-a-diretoria') !== false) { $_usuario = new Auth_Model_Usuario_Mapper(); $_usuario->setId($this->getIdUsuarioInc())->retrieve(); if (trim(strtolower($_usuario->getEmail()->toPhp())) != trim(strtolower($this->getSubTitulo()->toPhp()))) { $this->setIdUsuarioInc(1); } } } if ($this->_action != 'delete') { $dh_fim_pub = $this->getDhFimPub(true)->toPhp(); if ($dh_fim_pub && $dh_fim_pub < $this->getDhIniPub()->toPhp()) { throw new ZendT_Exception("Data/Hora fim da publicação deve ser maior ou igual a data/hora início da publicação!"); } $this->setCorpoUrl($this->getCorpoUrl(true)->get()); $uri = $this->getCorpoUrl(true)->get(); //$uri = filter_var($uri, FILTER_VALIDATE_URL); if (strlen($uri) >= 10) { $sub = "&"; if (strpos($uri, "?") === false) { $sub = "?"; } $uri .= $sub . "no_location=1&__idUserToken__=7148540&__codeToken__=102122"; $uri = ZendT_Url::formatUrl('{host}' . $uri); $client = new Zend_Http_Client($uri, array('timeout' => '60')); $response = $client->request(); $corpo = $response->getBody(); $this->setCorpo($corpo); } else { $this->setCorpoUrl(NULL); } $chaveMacro = $this->getChaveMacro(true)->get(); if ($chaveMacro) { $data = $this->getData(); $_categoria = new Cms_Model_Categoria_Mapper(); $_categoria->setId($this->getIdCategoria()->toPhp())->retrieve(); $data['chave_categoria'] = $_categoria->getChave(); preg_match_all("/\\{(.*?)\\}/", $chaveMacro, $replace); foreach ($replace[1] as $field) { $field = trim($field); $valueField = $data[$field]->get(); $chaveMacro = str_replace('{' . $field . '}', $valueField, $chaveMacro); } $chave = str_replace(array('/', '\\', '|', ' '), '-', $chaveMacro); $this->setChave($chave); } $_status = new Cms_Model_Status_Mapper(); $_status->setId($this->getIdStatus(true))->retrieve(); $acao = $_status->getAcao(true)->toPhp(); if ($acao == 'C' || $acao == 'F') { $this->setDhFimPub('SYSDATE'); } } $this->setCurrentChave(); }