Example #1
0
 protected function _afterSave()
 {
     parent::_afterSave();
     if ($this->_action == 'update') {
         $_where = new ZendT_Db_Where();
         $_where->addFilter($this->getModel()->getName() . '.hierarquia', $this->_oldHierarquia, '?%');
         $_where->addFilter($this->getModel()->getName() . '.id', $this->getId(), '!=');
         $_mapper = new Auth_DataView_Conta_MapperView();
         $_mapper->findAll($_where, '*');
         while ($_mapper->fetch()) {
             $_mapper->update();
         }
         $idPai = $this->getIdPapelPai(true)->toPhp();
         if ($this->_idPaiOld && $this->_idPaiOld != $idPai) {
             $_relation = new Auth_Model_ContaRel_Mapper();
             $_relation->setIdPapel($this->getId())->setIdPapelRel($this->_idPaiOld)->retrieve();
             if ($idPai) {
                 $_relation->setIdPapelRel($idPai)->update();
             } else {
                 $_relation->delete();
             }
         }
     } elseif ($this->_action == 'insert') {
         $_relation = new Auth_Model_ContaRel_Mapper();
         $_relation->setIdPapel($this->getId())->setIdPapelRel($this->getId())->setStatus('A')->insert();
         if ($this->getIdPapelPai(true)->toPhp()) {
             $_relation->newRow()->setIdPapel($this->getId())->setIdPapelRel($this->getIdPapelPai())->setStatus('A')->insert();
         }
     }
 }
Example #2
0
 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();
         }
     }
 }
Example #3
0
 /**
  * Retorna a lista de Profile para o Formulário
  * 
  * @param string $formName
  * @return array
  */
 public function getListProfile($formName)
 {
     $listProfile = array();
     $_profile = new Profile_DataView_ObjectView_MapperView();
     $session = Zend_Auth::getInstance()->getStorage()->read();
     $login = '';
     if ($session !== null) {
         $login = $session->getLogin();
         $_where = new ZendT_Db_Where();
         $_where->addFilter('login', $login);
         $_where->addFilter('objeto', $formName);
         $_where->addFilter('tipo', 'F');
         $_where->addFilter('publico', 'N');
         $_profile->findAll($_where, array('id', 'nome'), array('2'));
         while ($_profile->fetch()) {
             $key = $_profile->getId()->get();
             $value = $_profile->getNome()->get();
             $listProfile[$key] = $value;
         }
     }
     $_where = new ZendT_Db_Where();
     $_where->addFilter('objeto', $formName);
     $_where->addFilter('tipo', 'F');
     $_where->addFilter('publico', 'S');
     $_profile->findAll($_where, array('id', 'nome'), array('2'));
     while ($_profile->fetch()) {
         $key = $_profile->getId()->get();
         $value = $_profile->getNome()->get();
         $listProfile[$key] = $value;
     }
     return $listProfile;
 }
Example #4
0
 /**
  *
  * @param int $processId
  * @param string $value 
  * @return ZendT_Workflow_Fase_Row;
  */
 public function getFase($processId, $value)
 {
     $where = new ZendT_Db_Where();
     $where->addFilter('id_wf_processo', $processId);
     $where->addFilter('valor', $value);
     $rows = $this->getRows($where);
     $fase = new ZendT_Workflow_Fase_Row();
     $fase->setDescription($rows[0]['descricao']);
     $fase->setNotification($rows[0]['proc_notif']);
     return $fase;
 }
Example #5
0
 protected function _afterSave()
 {
     parent::_afterSave();
     if ($this->_action == 'update') {
         $_where = new ZendT_Db_Where();
         $_where->addFilter('recurso.hierarquia', $this->_oldHierarquia, '?%');
         $_where->addFilter('recurso.id', $this->getId(), '!=');
         $_mapper = new Auth_DataView_Recurso_MapperView();
         $_mapper->findAll($_where);
         while ($_mapper->fetch()) {
             $_mapper->update();
         }
     }
 }
Example #6
0
 public function processLanc()
 {
     $_lancamentos = new Financeiro_DataView_Lancamento_MapperView();
     $_where = new ZendT_Db_Where();
     $_where->addFilter('fc_lancamento.dt_lanc', ZendT_Type_Date::nowDate(), '<=');
     if (Auth_Session_User::getInstance()->getIdEmpresa()) {
         $_where->addFilter('fc_lancamento.id_empresa', Auth_Session_User::getInstance()->getIdEmpresa());
     }
     $_where->addFilter('fc_lancamento.vlr_saldo', '', '=', '', true);
     $_lancamentos->findAll($_where);
     while ($_lancamentos->fetch()) {
         $_lancamentos->update();
     }
 }
Example #7
0
 /**
  *
  * @param type $viewName 
  * @return array
  */
 public function getProfile($viewName)
 {
     $config = array();
     $row = false;
     $_profile = new Profile_DataView_User_MapperView();
     $session = Zend_Auth::getInstance()->getStorage()->read();
     $login = '';
     if ($session !== null) {
         $login = $session->getLogin();
     }
     $idProfile = Zend_Controller_Front::getInstance()->getParam('id_profile');
     if ($idProfile) {
         $_where = new ZendT_Db_Where();
         $_where->addFilter('id', $idProfile);
         $row = $_profile->retriveRow($_where);
     }
     if ($login && !$row) {
         $_where = new ZendT_Db_Where();
         $_where->addFilter('login', $login);
         $_where->addFilter('objeto', $viewName);
         $_where->addFilter('tipo', 'Grid');
         $_where->addFilter('padrao', 'S');
         $row = $_profile->retriveRow($_where);
     }
     if (!$row) {
         $login = '******';
         $_where = new ZendT_Db_Where();
         $_where->addFilter('login', $login);
         $_where->addFilter('objeto', $viewName);
         $_where->addFilter('tipo', 'Grid');
         $_where->addFilter('padrao', 'S');
         $row = $_profile->retriveRow($_where);
     }
     if (!$row) {
         $login = '******';
         $_where = new ZendT_Db_Where();
         $_where->addFilter('login', $login);
         $_where->addFilter('objeto', $viewName);
         $_where->addFilter('tipo', 'Grid');
         $_where->addFilter('padrao', 'S');
         $row = $_profile->retriveRow($_where);
     }
     if ($row) {
         $config = unserialize($row['config']->get());
         $config['grouds'] = ZendT_Sort::sortArray($config['grouds'], 'order');
     }
     return $config;
 }
Example #8
0
 public function getWhereSeekerSearch($value, $field = '')
 {
     $where = new ZendT_Db_Where('AND');
     $result = array();
     $result['column'] = '';
     $result['operation'] = '';
     $result['mapper'] = $this->getMapperName();
     if (count($this->_primary) == 1) {
         if (is_numeric($value)) {
             $result['column'] = $this->_name . "." . $this->_primary[0];
             $result['operation'] = '=';
         }
     }
     if ($result['column'] == '') {
         $result['column'] = $this->_name . "." . $this->_search;
         $result['operation'] = '=';
         $idEmpresa = Auth_Session_User::getInstance()->getIdEmpresa();
         $_veiculo = new Frota_Model_Veiculo_Mapper();
         $_veiculo->setPlaca($value)->setIdEmpresa($idEmpresa);
         if (!$_veiculo->exists()) {
             $_veiculo->setPlaca($value)->setDescricao($_veiculo->getPlaca())->setIdEmpresa($idEmpresa)->insert();
         }
     }
     if ($value) {
         $where->addFilter($result['column'], $value, $result['operation'], $result['mapper']);
     }
     return $where;
 }
Example #9
0
 public function getIdCliente()
 {
     $where = new ZendT_Db_Where();
     $where->addFilter('ca_pessoa.papel_cliente', 1);
     $_element = parent::getIdCliente();
     $_element->setWhere($where);
     return $_element;
 }
Example #10
0
 protected function _getWhere($postData)
 {
     $where = false;
     if (ZendT_Acl::getInstance()->restriction('restringe-empresa', 'auth')) {
         $where = new ZendT_Db_Where('AND');
         $where->addFilter('empresa.hierarquia', Auth_Session_User::getInstance()->getHierarquiaEmpresa(), '?%');
     }
     return $where;
 }
Example #11
0
 public function save($tableName = '', $operation = '', $key = '', $note = '')
 {
     if ($tableName && $operation && $key) {
         list($owner, $table) = explode(".", str_replace('"', '', $tableName));
         if (substr($table, 0, 4) != 'LOG_') {
             $_logTabela = new Log_Model_LogTabela_Mapper();
             $where = new ZendT_Db_Where();
             $where->addFilter('owner', $owner);
             $where->addFilter('nome', $table);
             $_logTabela->retrieve($where);
             if (!$_logTabela->getId()) {
                 $_logTabela->setOwner($owner);
                 $_logTabela->setNome($table);
                 $_logTabela->setTableName($table);
                 $_logTabela->insert();
             }
             $this->setIdLogTabela($_logTabela->getId());
             $_logObjeto = new Log_Model_LogObjeto_Mapper();
             $where = new ZendT_Db_Where();
             $where->addFilter('id_log_tabela', $_logTabela->getId());
             $_logObjeto->retrieve($where);
             if (!$_logObjeto->getId()) {
                 $_logObjeto->setNome($table);
                 $_logObjeto->setDescricao("LOG DE {$table}");
                 $_logObjeto->setStatus('A');
                 $_logObjeto->setIdLogTabela($_logTabela->getId());
                 $_logObjeto->insert();
             }
             $this->setIdLogObjeto($_logObjeto->getId());
         }
         if ($this->getIdLogTabela() && $this->getIdLogObjeto()) {
             if ($operation == 'insert') {
                 $codOperation = 'INC';
             } else {
                 if ($operation == 'update') {
                     $codOperation = 'ALT';
                 } else {
                     if ($operation == 'delete') {
                         $codOperation = 'EXC';
                     }
                 }
             }
             if ($codOperation) {
                 $this->setIdUsuario(Zend_Auth::getInstance()->getStorage()->read()->getId());
                 $this->setChave($key);
                 $this->setIdObjeto($key);
                 $this->setObservacao($note);
                 $db = $this->getModel()->getAdapter();
                 $sql = "begin\n                                        log_pkg.addlog(p_objeto     => {$db->quote($_logObjeto->getNome()->getValueToDb())},\n                                                       p_operac     => {$db->quote($codOperation)},\n                                                       p_id_objeto  => {$db->quote($this->getIdObjeto()->getValueToDb())},\n                                                       p_id_usuario => {$db->quote($this->getIdUsuario()->getValueToDb())},\n                                                       p_chave      => {$db->quote($this->getChave()->getValueToDb())},\n                                                       p_observacao => {$db->quote($this->getObservacao()->getValueToDb())},\n                                                       p_commit     => 'S',\n                                                       p_tabela     => {$db->quote($_logTabela->getNome()->getValueToDb())});\n                                    end;";
                 $stmt = $db->prepare($sql);
                 $stmt->execute();
             }
         }
     }
     return $this;
 }
Example #12
0
 public function _getWhere($postData)
 {
     if (Zend_Controller_Front::getInstance()->getRequest()->getParam('autoselectFilter')) {
         return false;
     }
     $_where = new ZendT_Db_Where('OR');
     $_where->addFilterExists("(" . $this->_restritionSql() . ")");
     $_where->addFilter("cms_categoria.publico", "S");
     return $_where;
 }
Example #13
0
 /**
  * Valida e remove os arquivos que estão com data de expiração vencida
  * 
  */
 public function validateFilesExpires()
 {
     $_where = new ZendT_Db_Where();
     $_where->addFilter('dt_expira', ZendT_Type_Date::nowDate(), '<=');
     $_arquivo = new Ged_DataView_Arquivo_Crud_MapperView();
     $_arquivo->findAll($_where);
     while ($_arquivo->fetch()) {
         $this->remove($_arquivo->getId()->toPhp());
     }
 }
Example #14
0
 /**
  * 
  * @return ZendT_Type_Number
  */
 public function save()
 {
     if ($this->getId(true)->toPhp()) {
         $where = new ZendT_Db_Where();
         $where->addFilter('image.img_docto.id', str_replace('.', '', $this->getId()->toPhp()));
         $this->update($where);
     } else {
         $this->insert();
     }
     return $this->getId();
 }
Example #15
0
 public function run()
 {
     $_job = new Tools_DataView_Job_MapperView();
     $_where = new ZendT_Db_Where();
     $_where->addFilter('job.dh_pro_exec', ZendT_Type_Date::nowDateTime(), '<=');
     $_where->addFilter('job.dh_fim_exec', ZendT_Type_Date::nowDateTime(), '>=');
     $_where->addFilter('job.status', 'A');
     $_job->findAll($_where, '*');
     while ($_job->fetch()) {
         $_now = ZendT_Type_Date::nowDateTime();
         while ($_job->getDhProExec()->toPhp() <= $_now->toPhp()) {
             if ($_job->getTpFrequencia()->toPhp() == 'H') {
                 $_job->getDhProExec()->addHour($_job->getNumFrequencia()->toPhp());
             } else {
                 if ($_job->getTpFrequencia()->toPhp() == 'D') {
                     $_job->getDhProExec()->addDay($_job->getNumFrequencia()->toPhp());
                 } else {
                     if ($_job->getTpFrequencia()->toPhp() == 'M') {
                         $_job->getDhProExec()->addMonth($_job->getNumFrequencia()->toPhp());
                     }
                 }
             }
         }
         $_job->setStatus('E');
         $_job->update();
         try {
             if ($_job->getFormaExec()->toPhp() == 'C') {
                 $_adapter = new Tools_Interface_Job_Php();
             } else {
                 $_adapter = new Tools_Interface_Job_Http();
             }
             $_adapter->jobId = $_job->getId()->toPhp();
             $_th = new ZendT_Thread();
             $_th->start($_adapter, 'run');
         } catch (Exception $ex) {
             $message = 'Mensagem: ' . $ex->getMessage() . "\n";
             $message .= 'Erro: ' . $ex->getTraceAsString() . "\n";
             Tools_Model_LogErro_Mapper::log($_job->getProcedimento()->toPhp(), $message);
         }
     }
 }
Example #16
0
 /**
  *
  * @param type $mapperName 
  * @return ZendT_Workflow_Process_Row[]
  */
 public function getProcess($mapperName)
 {
     $where = new ZendT_Db_Where();
     $where->addFilter('nome_modelo', $mapperName);
     $rows = $this->getRows($where);
     $_process = array();
     $_iProcess = 0;
     foreach ($rows as $row) {
         $_process[$_iProcess] = new ZendT_Workflow_Process_Row();
         $_process[$_iProcess]->setDescription($row['descricao']);
         $_process[$_iProcess]->setColumn($row['coluna_filtro']);
         $_process[$_iProcess]->setId($row['id']);
         $_iProcess++;
     }
     return $_process;
 }
Example #17
0
 /**
  *
  * @param type $mapper
  * @param type $id
  * @param type $filter
  * @param type $filters
  * @param type $filterOp
  * @return \ZendT_Db_Where 
  */
 private function _getWhere(&$mapper, $id, $filter, $filters, $filterOp)
 {
     $where = '';
     if ($id != '') {
         $mapper->setId($id);
         $where = $mapper->getWhere();
     } else {
         if (count($filters) > 0) {
             $where = new ZendT_Db_Where($filterOp);
             foreach ($filters as $filter) {
                 $where->addFilter($filter->field, $filter->value, $filter->operation, $filter->mapperName);
             }
         } elseif ($filter->field && $filter->value) {
             $where = new ZendT_Db_Where($filterOp);
             $where->addFilter($filter->field, $filter->value, $filter->operation, $filter->mapperName);
         }
     }
     return $where;
 }
Example #18
0
 public function setDefaultPrivilege($id, $idCopyFrom = '')
 {
     if ($id) {
         $_objectViewPriv = new Profile_DataView_ObjectViewPriv_MapperView();
         if (!$idCopyFrom) {
             $idInfo = $this->getIdPapelInformatica();
             if ($idInfo) {
                 $_objectViewPriv->setIdProfileObjectView($id)->setIdPapel($idInfo)->setTipo("O")->insert();
                 return true;
             }
         } else {
             $_where = new ZendT_Db_Where();
             $_where->addFilter("id_profile_object_view", $idCopyFrom);
             $_objectViewPriv->findAll($_where, "*");
             while ($_objectViewPriv->fetch()) {
                 $_objectViewPriv->setIdProfileObjectView($id)->insert();
             }
         }
     }
     return false;
 }
Example #19
0
 /**
  * 
  * @return int|ZendT_Type
  */
 public function save($updateIfExists = false)
 {
     $id = 0;
     $this->_beforeSave();
     $hashcode = $this->getHashcode();
     $where = new ZendT_Db_Where();
     $where->addFilter('img_arquivo.hashcode', $hashcode);
     if ($this->exists($where)) {
         if ($updateIfExists) {
             $this->update();
         }
         $id = $this->getId();
     } else {
         if ($this->getId(true)->toPhp()) {
             $id = $this->getId();
         } else {
             $this->insert();
             $id = $this->getId();
         }
     }
     $this->_afterSave();
     return $id;
 }
Example #20
0
 public function getWhereSeekerSearch($value, $field = '')
 {
     $where = new ZendT_Db_Where('AND');
     $result = array();
     $result['column'] = '';
     $result['operation'] = '';
     $result['mapper'] = $this->getMapperName();
     if (count($this->_primary) == 1) {
         if (is_numeric($value)) {
             $result['column'] = $this->_name . "." . $this->_primary[0];
             $result['operation'] = '=';
         }
     }
     if ($field == 'id') {
         $result['column'] = $this->_name . ".id";
         $result['operation'] = '=';
     }
     if ($result['column'] == '') {
         $_usuario = new Auth_DataView_Conta_MapperView();
         $where = new ZendT_Db_Where('AND');
         $where->addFilter('papel.descricao', $value, '?%', 'Auth_Model_Conta_Mapper');
         $data = $_usuario->getDataGrid($where, array());
         $row = $data->getRow();
         if ($row) {
             $result['column'] = $this->_name . ".descricao";
             $result['operation'] = '?%';
         } else {
             $result['column'] = $this->_name . "." . $this->_search;
             $result['operation'] = '?%';
         }
     }
     if ($value) {
         $where = new ZendT_Db_Where('AND');
         $where->addFilter($result['column'], $value, $result['operation'], $result['mapper']);
     }
     return $where;
 }
Example #21
0
 public function findCategoria($idCategoria = '', $idCategoriaPai = '', $orderBy = '', $_where = '')
 {
     if (!$orderBy) {
         $orderBy = 'id';
     }
     if (!$_where instanceof ZendT_Db_Where) {
         $_where = new ZendT_Db_Where();
     }
     if ($idCategoria) {
         $_where->addFilter("cms_categoria.id", $idCategoria);
     }
     if ($idCategoriaPai) {
         $_where->addFilter("cms_categoria.id_categoria_pai", $idCategoriaPai);
     }
     $_where->addFilter("cms_categoria.status", "A");
     $_categoria = new Cms_DataView_Categoria_MapperView();
     $_categoria->findAll($_where, "*", $orderBy);
     return $_categoria;
 }
Example #22
0
 public function _afterSave()
 {
     parent::_afterSave();
     if (count($this->_others['item_pedido']) > 0 && $this->_others['item_pedido']['id_produto']) {
         $_itemPedido = new Vendas_DataView_ItemPedido_MapperView();
         $_itemPedido->setIdPedido($this->getId())->setIdProduto($this->_others['item_pedido']['id_produto'])->setQtdItem($this->_others['item_pedido']['qtd_item']);
         if (!$_itemPedido->exists()) {
             $_itemPedido->insert();
         }
     }
     if (count($this->_others['pagamento']) > 0 && $this->_others['pagamento']['id_forma_pagto']) {
         $_pagamento = new Vendas_DataView_Pagamento_MapperView();
         $_pagamento->setIdPedido($this->getId())->setIdFormaPagto($this->_others['pagamento']['id_forma_pagto']);
         if (!$_pagamento->exists()) {
             $_pagamento->insert();
         }
     }
     if ($this->getStatus(true)->toPhp() == 'E') {
         $_pagtoLanc = new Vendas_DataView_PagtoLanc_MapperView();
         $_where = new ZendT_Db_Where();
         $_where->addFilter('pagto_pedido.id_pedido', $this->getId());
         $_pagtoLanc->findAll($_where);
         if (!$_pagtoLanc->fetch()) {
             $this->_pagamento->efetivar($this->getId());
         }
     }
     if ($this->getStatus(true)->toPhp() == 'C') {
         $_pagtoLanc = new Vendas_DataView_PagtoLanc_MapperView();
         $_where = new ZendT_Db_Where();
         $_where->addFilter('pagto_pedido.id_pedido', $this->getId());
         $_pagtoLanc->findAll($_where);
         if ($_pagtoLanc->fetch()) {
             $this->_pagamento->cancelar($this->getId());
         }
     }
 }
Example #23
0
 public static function get($objectName, $type, $profile = '')
 {
     $_priv = new Profile_Model_ObjectViewPriv_Mapper();
     $sqlPriv = $_priv->getSqlPriv();
     $config = array();
     $row = false;
     $idUsuario = Auth_Session_User::getInstance()->getId();
     $idProfile = '';
     $_profile = new Profile_DataView_ObjectView_MapperView();
     $request = Zend_Controller_Front::getInstance()->getRequest();
     if (is_object($request)) {
         if (!$profile) {
             $profile = $request->getParam('profile');
         }
         $parentId = $request->getParam('profile_parent_id');
         $profileKey = $request->getParam('profile_key');
     }
     if ($parentId && is_numeric($parentId)) {
         $_profile->newRow()->setId($parentId)->retrieve();
         $chave = $_profile->getChave()->get();
         /**
          * 
          */
         $_where = new ZendT_Db_Where('AND');
         $_where->addFilter('profile_object_view.objeto', $objectName);
         $_where->addFilter('profile_object_view.chave', $chave);
         if (is_array($type)) {
             $_where->addFilter('profile_object_view.tipo', $type, 'in');
         } else {
             if ($type) {
                 $_where->addFilter('profile_object_view.tipo', $type);
             }
         }
         $_whereSec = new ZendT_Db_Where('OR');
         $_whereSec->addFilter('profile_object_view.id_usuario', $idUsuario);
         $_whereSec->addFilter('acesso_liberado', new Zend_Db_Expr($sqlPriv), 'EXISTS');
         $_whereGroup = new ZendT_Db_Where_Group();
         $_whereGroup->addWhere($_whereSec);
         $_whereGroup->addWhere($_where);
         $row = $_profile->retriveRow($_whereGroup);
         if ($row) {
             $profile = $row['id']->get();
         }
     }
     if (!$profile) {
         if ($profileKey) {
             $_where = new ZendT_Db_Where('AND');
             $_where->addFilter('profile_object_view.objeto', $objectName);
             $_where->addFilter('profile_object_view.chave', $profileKey);
             if (is_array($type)) {
                 $_where->addFilter('profile_object_view.tipo', $type, 'in');
             } else {
                 if ($type) {
                     $_where->addFilter('profile_object_view.tipo', $type);
                 }
             }
             $row = $_profile->retriveRow($_where);
             if ($row) {
                 $profile = $row['id']->get();
             }
         }
     }
     if ($profile) {
         if (!is_numeric($profile)) {
             $_where = new ZendT_Db_Where('AND');
             $_where->addFilter('profile_object_view.objeto', $objectName);
             $_where->addFilter('profile_object_view.chave', $profile, '=');
             $row = $_profile->retriveRow($_where);
             if ($row) {
                 $profile = $row['id']->get();
             }
         }
         $idProfile = $profile;
     }
     if (isset($_COOKIE['profile-' . $objectName . '-' . $type]) && $idProfile == '') {
         $idProfile = $_COOKIE['profile-' . $objectName . '-' . $type];
     }
     if (isset($_COOKIE['profile-' . $objectName]) && $idProfile == '') {
         $idProfile = $_COOKIE['profile-' . $objectName];
     }
     if (isset($_SESSION['profile-' . $objectName]) && $idProfile == '') {
         $idProfile = $_SESSION['profile-' . $objectName];
     }
     if ($idProfile) {
         $_where = new ZendT_Db_Where();
         $_where->addFilter('profile_object_view.id', $idProfile);
         $_whereSec = new ZendT_Db_Where('OR');
         $_whereSec->addFilter('profile_object_view.id_usuario', $idUsuario);
         $_whereSec->addFilter('acesso_liberado', new Zend_Db_Expr($sqlPriv), 'EXISTS');
         $_whereGroup = new ZendT_Db_Where_Group();
         $_whereGroup->addWhere($_whereSec);
         $_whereGroup->addWhere($_where);
         $row = $_profile->retriveRow($_whereGroup);
     }
     if ($idUsuario && !$row) {
         $_where = new ZendT_Db_Where('AND');
         $_where->addFilter('profile_object_view.objeto', $objectName);
         $_where->addFilter('profile_object_view.padrao', 'S');
         if (is_array($type)) {
             $_where->addFilter('profile_object_view.tipo', $type, 'in');
         } else {
             if ($type) {
                 $_where->addFilter('profile_object_view.tipo', $type);
             }
         }
         $_whereSec = new ZendT_Db_Where('OR');
         $_whereSec->addFilter('profile_object_view.id_usuario', $idUsuario);
         $_whereSec->addFilter('acesso_liberado', new Zend_Db_Expr($sqlPriv), 'EXISTS');
         $_whereGroup = new ZendT_Db_Where_Group();
         $_whereGroup->addWhere($_whereSec);
         $_whereGroup->addWhere($_where);
         $row = $_profile->retriveRow($_whereGroup);
     }
     if ($idUsuario && !$row) {
         $_where = new ZendT_Db_Where('AND');
         $_where->addFilter('profile_object_view.objeto', $objectName);
         if (is_array($type)) {
             $_where->addFilter('profile_object_view.tipo', $type, 'in');
         } else {
             if ($type) {
                 $_where->addFilter('profile_object_view.tipo', $type);
             }
         }
         $_whereSec = new ZendT_Db_Where('OR');
         $_whereSec->addFilter('profile_object_view.id_usuario', $idUsuario);
         $_whereSec->addFilter('acesso_liberado', new Zend_Db_Expr($sqlPriv), 'EXISTS');
         $_whereGroup = new ZendT_Db_Where_Group();
         $_whereGroup->addWhere($_whereSec);
         $_whereGroup->addWhere($_where);
         $row = $_profile->retrieveRow($_whereGroup);
     }
     if ($row) {
         $config = unserialize(html_entity_decode($row['config']->get()));
         $config['id'] = $row['id']->get();
         $config['tipo'] = $row['tipo']->toPhp();
         $config['title'] = $row['nome']->get();
     }
     return $config;
 }
Example #24
0
 /**
  * 
  * @param string $aliasColumn
  * @param array|string $value
  * @return ZendT_Db_Where
  */
 public function mountWhere($aliasColumn, $value)
 {
     $value = explode(';', $value);
     $where = new ZendT_Db_Where();
     if ($this->_columns[$aliasColumn]['expression']) {
         $where->addFilter(new Zend_Db_Expr($this->_columns[$aliasColumn]['expression']), $value, 'in', $this->_columns['mapperName']);
     } else {
         $where->addFilter($this->_columns[$aliasColumn]['aliasTable'] . '.' . $this->_columns[$aliasColumn]['columnName'], $value, 'in', $this->_columns['mapperName']);
     }
     return $where;
 }
Example #25
0
 public function remove($idConteudo, $idUsuario = '', $deleteFilhos = true)
 {
     if (!$idUsuario) {
         $idUsuario = Zend_Auth::getInstance()->getStorage()->read()->getId();
     }
     $this->setIdConteudo($idConteudo)->setIdUsuario($idUsuario)->delete(null);
     if ($deleteFilhos) {
         $_conteudo = new Cms_DataView_Conteudo_MapperView();
         $_where = new ZendT_Db_Where();
         $_where->addFilter("cms_conteudo.id_conteudo_pai", $this->getIdConteudo(true)->get());
         $_conteudo->findAll($_where, '*');
         while ($_conteudo->fetch()) {
             $this->remove($_conteudo->getId());
         }
     }
 }
Example #26
0
 /**
  * 
  * @param string|int $categoria
  * @param string $orderBy
  * @return array
  */
 protected function _list($categoria, $idConteudoPai = '', $orderBy = '')
 {
     $this->_removeLob = false;
     $_fileSystem = new Ged_Model_Arquivo_FileSystem();
     $idUsuario = Auth_Session_User::getInstance()->getId();
     $_auth = new Auth_Model_Usuario_Mapper();
     $_auth->setLogin('GUEST')->retrieve();
     $avatarGuest = $_auth->getAvatar(true)->toPhp();
     /**
      * caso seja uma string retorna o id
      */
     $idCategoria = $this->_getIdCategoria($categoria);
     if (!$orderBy) {
         $orderBy = 'cms_conteudo.dh_ini_pub';
     }
     $_whereGroup = new ZendT_Db_Where_Group('AND');
     $_where = new ZendT_Db_Where();
     $_where->addFilter("cms_conteudo.id_categoria", $idCategoria);
     if ($idConteudoPai) {
         $_where->addFilter("cms_conteudo.id_conteudo_pai", $idConteudoPai);
     }
     $_where->addFilter("cms_conteudo.dh_ini_pub", ZendT_Type_Date::nowDateTime(), "<=");
     $_where->addFilter("status.acao", "A");
     $_whereGroup->addWhere($_where);
     $_where = new ZendT_Db_Where('OR');
     $_where->addFilter("cms_conteudo.dh_fim_pub", ZendT_Type_Date::nowDateTime(), ">=");
     $_where->addFilter("cms_conteudo.dh_fim_pub", "", "NULL");
     $_whereGroup->addWhere($_where);
     //($where, $retrieve = false, $found = false, $orderBy='1')
     $_recordset = $this->recordset($_whereGroup, false, false, $orderBy);
     $data = array();
     $result = array();
     while ($data = $_recordset->getRow()) {
         $data['url'] = ZendT_Url::getBaseUrl() . '/cms/conteudo/view/id/' . $data['id']->toPhp();
         $thumbnail = $data['thumbnail']->toPhp();
         if (!$thumbnail) {
             $_conteudo = new Cms_Model_Conteudo_Mapper();
             $_conteudo->setChave('generic')->retrieve();
             $thumbnail = $_conteudo->getThumbnail(true)->toPhp();
         }
         $data['thumbnail'] = $_fileSystem->getDirectoryAdress($thumbnail);
         $data['banner'] = $_fileSystem->getDirectoryAdress($data['banner']->toPhp());
         $avatar = $data['avatar_usuario_inc']->toPhp();
         if (!$avatar) {
             $avatar = $avatarGuest;
             //avatar genérico
         }
         $data['avatar_usuario_inc'] = $_fileSystem->getDirectoryAdress($avatar);
         $data['html_like'] = Cms_Helper_Likes::button($data['id']);
         $data['html_comment'] = Cms_Helper_Feeds::button($data['id']);
         if ($data['id_usuario_inc']->toPhp() == $idUsuario) {
             $data['nome_usuario_inc'] = 'Você';
         }
         $result[] = $data;
     }
     return $result;
 }
Example #27
0
 public function runLaudos($where = array())
 {
     $this->_log('Iniciado: ' . date('d/m/Y H:s:i'));
     Auth_Session_User::refresh('JOB_VSP');
     $this->_token = $this->_doLogin();
     $_pedido = new Vendas_DataView_Pedido_MapperView();
     $_vistoria = new Vendas_DataView_Vistoria_MapperView();
     $_where = new ZendT_Db_Where();
     $_where->addFilter('pedido.id_empresa', Auth_Session_User::getInstance()->getIdEmpresa());
     if (isset($where['placa'])) {
         $_where->addFilter('veiculo.placa', $where['placa']);
     } else {
         $_where->addFilter('pedido.status_edi', 'N');
     }
     if (isset($where['cnpj_cliente']) && $where['cnpj_cliente']) {
         $_where->addFilter('cliente.codigo', $where['cnpj_cliente']);
         //33164021000100
     }
     if (isset($where['dt_emis']) && $where['dt_emis']) {
         if (!is_array($where['dt_emis'])) {
             $where['dt_emis'] = array($where['dt_emis']);
         }
         $where['dt_emis'][0] = new ZendT_Type_Date($where['dt_emis'][0], 'Date');
         if (!isset($where['dt_emis'][1])) {
             $where['dt_emis'][1] = $where['dt_emis'][0];
         } else {
             $where['dt_emis'][1] = new ZendT_Type_Date($where['dt_emis'][1], 'Date');
         }
         $_where->addFilter('pedido.dt_emis', $where['dt_emis'], 'BETWEEN');
     }
     $sql = "(SELECT 1" . "  FROM " . Vendas_DataView_Vistoria_MapperView::$table . " as vistoria " . " WHERE vistoria.id_pedido = pedido.id" . "   AND vistoria.laudo IS NULL)";
     $_where->addFilterExists($sql);
     $_pedido->findAll($_where, '*');
     $total = $_pedido->getCountRows();
     $seq = 1;
     while ($row = $_pedido->fetch()) {
         try {
             $this->_log("Processando " . $seq . " de " . $total . ", Placa: " . $row['placa_veiculo']);
             $_vistoria->newRow();
             $_vistoria->setIdPedido($row['id'])->retrieve();
             if ($_vistoria->getLaudo(true)->toPhp() == '' && $_vistoria->getNumero(true)->toPhp() != '') {
                 $laudo = $this->_laudo($_vistoria->getNumero()->get());
                 if ($laudo) {
                     $_laudo = new ZendT_File(str_replace(array('-', '/'), '_', $_vistoria->getNumero()->get()) . '.pdf', $laudo, 'application/pdf');
                     $dataLaudo = array();
                     $dataLaudo['file'] = $_laudo;
                     $_vistoria->setLaudo($dataLaudo);
                     $_vistoria->update();
                 }
             }
         } catch (Exception $ex) {
             $message = 'Mensagem: ' . $ex->getMessage() . "\n";
             $message .= 'Erro: ' . $ex->getTraceAsString() . "\n";
             Vendas_Model_LogPedido_Mapper::log($_pedido->getId(), $ex->getMessage());
             Tools_Model_LogErro_Mapper::log('Vendas_Interface_Vsp_Tokio', $message);
             $this->_log('Placa: ' . $row['placa_veiculo'] . ', Erro: ' . $message);
         }
         $seq++;
     }
     $this->_log('Finalizado: ' . date('d/m/Y H:s:i'));
     echo "OK";
 }
Example #28
0
 public function runAction()
 {
     $_job = new Profile_Model_Job_Mapper();
     $_job->setId($this->getRequest()->getParam('id'))->retrive()->setDhUltExec("SYSDATE")->update();
     $_view = new Profile_DataView_Job_Users();
     $where = new ZendT_Db_Where();
     $where->addFilter('profile_job.id', $this->getRequest()->getParam('id'));
     $where->addFilter('usuario.email', "", "!NULL");
     $data = $_view->recordset($where);
     while ($row = $data->getRow()) {
         try {
             $uri = $row['uri']->get();
             if ($uri == '') {
                 $uri = ZendT_Lib::convertObjectToUri($row['objeto']->get());
             }
             $uriOriginal = $uri . '/dynamic/profile/' . $row['id_profile']->get();
             $uri .= '/found/profile/' . $row['id_profile']->get() . '/no_location/1?' . $row['uri_token']->get();
             $client = new Zend_Http_Client($uri, array('timeout' => '80'));
             $response = $client->request();
             if ($response->getBody() == 'OK') {
                 $mail = new ZendT_Mail();
                 $mail->addTo($row['email_usuario']->get(), $row['nome_usuario']->get());
                 $mail->addFrom('*****@*****.**', 'Transportadora Americana');
                 $mail->setTitle($row['nome']->get());
                 $mail->setSubject($row['nome']->get());
                 $comment = $row['observacao']->get();
                 if (!$comment) {
                     $comment = $row['nome']->get();
                 }
                 $comment .= '<br><br>Para acessar o relatório clique <a href = "' . str_replace(array('/found/', '/no_location/1'), array('/dynamic/', ''), $uri) . '">aqui</a>';
                 $mail->setComment($comment);
                 $body = '<br>';
                 $user = array();
                 $user['id'] = $row['id_usuario']->get();
                 $user['role'] = $row['nome_papel']->get();
                 $listProfile = ZendT_Profile::listProfile($row['objeto']->get(), '', $user);
                 if (count($listProfile) > 0) {
                     $body .= '<style type="text/css">';
                     $body .= '    <!--';
                     $body .= '    td {';
                     $body .= '            font-family: Arial, Helvetica, sans-serif;';
                     $body .= '            font-size: 12px;';
                     $body .= '    }';
                     $body .= '    .TitleTable {';
                     $body .= '            font-weight: bold;';
                     $body .= '            border-bottom: 0px;';
                     $body .= '    }';
                     $body .= '    .viewTitle {';
                     $body .= '            background-color: #F9F9F9;';
                     $body .= '            font-weight: bold;';
                     $body .= '    }';
                     $body .= '    .viewTable {';
                     $body .= '            border:1px solid #CCCCCC;';
                     $body .= '    }';
                     $body .= '    -->';
                     $body .= '</style>';
                     $body .= '<table width="100%" border="0" cellpadding="5" cellspacing="0" class="viewTable">';
                     $body .= '	<tr >';
                     $body .= '		<td class="viewTitle">Visões Disponíveis</td>';
                     $body .= '	</tr>';
                     $body .= '	<tr>';
                     $body .= '		<td>';
                     $body .= '			<table width="100%" border="0" cellpadding="5" cellspacing="0">';
                     $body .= '				<tr>';
                     $body .= '					<td class="TitleTable">Tipo</td>';
                     $body .= '					<td class="TitleTable">Visão</td>';
                     $body .= '					<td class="TitleTable">Observação</td>';
                     $body .= '				</tr>';
                     foreach ($listProfile as $profile => $detailProfile) {
                         $uri = ZendT_Lib::convertObjectToUri($row['objeto']->get()) . '/found/profile/' . $profile . '?' . $row['uri_token']->get();
                         $body .= '				<tr>';
                         $body .= '					<td>' . $detailProfile['tipoDescricao'] . '</td>';
                         $body .= '					<td><a href = "' . str_replace('/found/', '/dynamic/', $uri) . '">' . $detailProfile['nome'] . '</a></td>';
                         $body .= '					<td>' . $detailProfile['observacao'] . '</td>';
                         $body .= '				</tr>';
                     }
                     $body .= '			</table>';
                     $body .= '		</td>';
                     $body .= '	</tr>';
                     $body .= '</table>';
                 }
                 $mail->setBody($body);
                 $mail->save();
             }
         } catch (Exception $ex) {
             $mail = new ZendT_Mail();
             /* $mail->addTo("*****@*****.**"); */
             $mail->addTo("*****@*****.**");
             $mail->addFrom('*****@*****.**', 'Transportadora Americana');
             $mail->setTitle('Erro no envio de e-mail pelo agendamento de tarefa');
             $mail->setSubject($mail->getTitle());
             $comment = $row['nome']->get() . '<br><br>Para acessar o relatório clique <a href = "' . $uriOriginal . '">aqui</a>';
             $mail->setComment($comment);
             $mail->setBody($ex->getMessage());
             $mail->save();
             /*echo 'Erro';
               exit;*/
         }
     }
     echo 'Processado';
     exit;
 }
Example #29
0
 public function cancelar($idPedido = false)
 {
     if (!$idPedido) {
         $idPedido = $this->getIdPedido();
     }
     $_lancamento = new Financeiro_DataView_Lancamento_MapperView();
     $_where = new ZendT_Db_Where();
     $_where->addFilter('item_pedido.id_pedido', $idPedido);
     $_itemLanc = new Vendas_DataView_ItemLanc_MapperView();
     $_itemLanc->findAll($_where, '*');
     while ($_itemLanc->fetch()) {
         $_lancamento->setId($_itemLanc->getIdLancamento())->retrieve()->cancelar();
     }
     $_where = new ZendT_Db_Where();
     $_where->addFilter('pagto_pedido.id_pedido', $idPedido);
     $_pagtoLanc = new Vendas_DataView_PagtoLanc_MapperView();
     $_pagtoLanc->findAll($_where, '*');
     while ($_pagtoLanc->fetch()) {
         $_lancamento->setId($_pagtoLanc->getIdLancamento())->retrieve()->cancelar();
     }
     return true;
 }
Example #30
0
 /**
  * Cria um campo texto com autocomplete customizado
  *
  * @param  string $id
  * @param  string $value
  * @param  array  $params jQuery Widget Parameters
  * @param  array  $attribs HTML Element Attributes
  * @return string
  */
 public function autoselect($id, $value = null, array $attribs = array())
 {
     $params = $attribs['jQueryParams'];
     $attribs['class'] .= ' ui-input-auto';
     unset($attribs['jQueryParams']);
     unset($attribs['autocomplete']);
     unset($attribs['options']);
     unset($attribs['button']);
     //unset($attribs['fields']);
     unset($attribs['propId']);
     unset($attribs['propSearch']);
     unset($attribs['autoComplete']);
     unset($attribs['belongsTo']);
     /*echo '<pre>';
       print_r($attribs);
       echo '</pre>';*/
     $this->view->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . '/layout/jquery/widget/TAutoSelect.js');
     $params = array();
     $fields = array();
     foreach ($attribs['fields'] as $field) {
         array_push($fields, $field);
     }
     if ($attribs['mapperView']) {
         $_mapper = new $attribs['mapperView']();
         $_where = new ZendT_Db_Where();
         if ($attribs['where']) {
             if (substr($attribs['where'], 0, 11) == 'expression:') {
                 $_where->addFilter(' ', substr($attribs['where'], 11), 'EXPRESSION');
             } else {
                 $_where->addFilter('id', $attribs['where']);
             }
         }
         if ($attribs['fieldLevel']) {
             $fields[] = $attribs['fieldLevel'];
         }
         if ($attribs['fieldOrder']) {
             $order = $attribs['fieldOrder'];
         } else {
             $order = $fields[1];
         }
         Zend_Controller_Front::getInstance()->getRequest()->setParam('autoselectFilter', true);
         $_mapper->findAll($_where, $fields, $order);
         Zend_Controller_Front::getInstance()->getRequest()->setParam('autoselectFilter', false);
         $sourceData = array();
         while ($_mapper->fetch()) {
             $data = $_mapper->getData();
             $row = array();
             $row['value'] = $data[$fields[0]]->get();
             $row['desc'] = $data[$fields[1]]->get();
             if ($attribs['fieldLevel']) {
                 $row['level'] = $data[$fields[2]]->toPhp();
             } else {
                 $row['level'] = 0;
             }
             $sourceData[] = $row;
             if ($value == $row['value']) {
                 $params['loadValue'] = $row['desc'];
             }
         }
     }
     if (isset($attribs['sourceData'])) {
         $sourceData = $attribs['sourceData'];
         unset($attribs['sourceData']);
     }
     /*if (count($sourceData) == 0 || !is_array($sourceData)){
           throw new ZendT_Exception('Propriedade "sourceData" não definida!');
       }*/
     if ($attribs['suffix']) {
         $nameId = 'id_' . $attribs['suffix'];
     }
     if ($attribs['prefix']) {
         $nameId = $attribs['prefix'] . '_id';
     }
     /**
      * @todo encontrar a melhor maneira de implementação
      */
     $required = $attribs['required'];
     $attribs['class'] = str_replace('required', '', $attribs['class']);
     unset($attribs['fields']);
     unset($attribs['mapperView']);
     unset($attribs['suffix']);
     unset($attribs['prefix']);
     unset($attribs['caption']);
     unset($attribs['required']);
     unset($attribs['where']);
     unset($attribs['fieldLevel']);
     unset($attribs['fieldOrder']);
     $params['sourceData'] = $sourceData;
     $params['fieldValue'] = $nameId;
     $attribs['TAutoSelect'] = '1';
     $attribs['role'] = '';
     //var_dump($params);
     $params = ZendT_JS_Json::encode($params);
     $this->jquery->addOnLoad('jQuery("#' . $id . '").TAutoSelect(' . $params . ');');
     return $this->view->formText($id, '', $attribs) . $this->view->formHidden($nameId, '', array('required' => $required, 'TAutoSelect' => '1', 'role' => $id));
 }