Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
 public function listConfigAction()
 {
     Zend_Layout::getMvcInstance()->setLayout('window');
     $idUsuario = Auth_Session_User::getInstance()->getId();
     $login = Auth_Session_User::getInstance()->getLogin();
     $role = Auth_Session_User::getInstance()->getRole();
     $id = $this->getRequest()->getParam('id');
     if (!$id) {
         $id = $this->getRequest()->getParam('id_profile');
     }
     $tipo = $this->getRequest()->getParam('tipo');
     if (!$tipo) {
         $tipo = $this->getRequest()->getParam('tipo_profile');
     }
     $objeto = $this->getRequest()->getParam('objeto');
     if (!$objeto) {
         $objeto = $this->getRequest()->getParam('objeto_profile');
     }
     $uri = $this->getRequest()->getParam('uri');
     if (!$uri) {
         $uri = $this->getRequest()->getParam('uri_profile');
     }
     $chave = $this->getRequest()->getParam('chave');
     if (!$chave) {
         $chave = $this->getRequest()->getParam('chave_profile');
     }
     $_where = new ZendT_Db_Where();
     $_where->addFilter('profile_object_view.objeto', $objeto, '=', $this->getModel()->getMapperName());
     $_where->addFilter('profile_object_view.tipo', $tipo, '=', $this->getModel()->getMapperName());
     $_whereSec = new ZendT_Db_Where('OR');
     $_whereSec->addFilter('profile_object_view.id_usuario', $idUsuario);
     $_whereSec->addFilter('acesso_liberado', new Zend_Db_Expr("(\n                SELECT 1\n                    FROM " . Profile_Model_ObjectViewPriv_Mapper::$table . " po\n                    JOIN " . Auth_Model_Conta_Mapper::$table . " p ON (po.id_papel = p.id)\n                    WHERE po.id_profile_object_view = profile_object_view.id\n                    AND po.tipo = 'O'\n                    AND " . $this->getModel()->getAdapter()->quote($role) . " LIKE p.nome || '%'\n            )"), 'EXISTS');
     $_whereGroup = new ZendT_Db_Where_Group('AND');
     $_whereGroup->addWhere($_where);
     $_whereGroup->addWhere($_whereSec);
     $this->view->arrTipos = $this->getModel()->getListOptions('tipo');
     $tipos = new ZendT_View_Select('tipoVisao', $tipo, $this->view->arrTipos);
     $this->view->tipos = $tipos;
     $this->view->tipo = $tipo;
     $this->view->rows = $this->getMapper()->getDataGrid($_whereGroup, array('noPage' => true));
     $this->view->objeto = $objeto;
     $this->view->id = $id;
     $this->view->role = $role;
     $this->view->login = $login;
     $this->view->idUsuario = $idUsuario;
     $this->view->uri = $uri;
     $this->view->chave = $chave;
     $formAdvanced = new Profile_Form_ObjectView_Dynamic();
     $formAdvanced->loadElements();
     $this->view->formAdvanced = $formAdvanced;
 }
Ejemplo n.º 4
0
 /**
  * Propriedade tem como finalidade executar 
  * a consulta SQL colocando o recordset sobre a mémoria 
  * desse objeto permitindo assim usar o fetch
  * para posicionar as linhas e realizar alteração sobre
  * elas
  *
  * @param ZendT_Db_Where $where
  * @return \ZendT_Db_Mapper 
  */
 public function findAll($where = null, $fields = array('id'), $orderBy = array('1'))
 {
     if ($where == null) {
         $where = $this->getWhere();
     }
     /**
      * Monta a base do SQL 
      */
     $cmdSelect = " SELECT " . $this->getColumns(true)->getColumnsSelect(true, $fields);
     $cmdFrom = "   FROM " . $this->_getSqlBase();
     /**
      * Trata a entrada do Where para ser um Grupo de Where 
      */
     if ($where instanceof ZendT_Db_Where_Group) {
         $whereGroup = $where;
     } else {
         if ($where instanceof ZendT_Db_Where) {
             $whereGroup = new ZendT_Db_Where_Group();
             $whereGroup->addWhere($where);
         } else {
             $whereGroup = new ZendT_Db_Where_Group();
         }
     }
     /**
      * Avalia se existe algum Where específico do MapperView
      * colocando o mesmo dentro do objeto que agrupa os wheres
      */
     $_whereMapperView = $this->_getWhere($postData, $where);
     if ($_whereMapperView) {
         $whereGroup->addWhere($_whereMapperView);
     }
     /**
      * Monta o comando Where
      */
     $binds = $whereGroup->getBinds();
     $cmdWhere = "  WHERE " . $whereGroup->getSqlWhere();
     /**
      * 
      */
     if (!is_array($orderBy)) {
         $orderBy = array($orderBy);
     }
     /**
      * Configura o range de dados que será buscado
      */
     $sql = $cmdSelect . $cmdFrom . $cmdWhere . ' ORDER BY ' . implode(',', $orderBy);
     $this->_prepareSql($sql, $binds, 'full');
     /**
      * Pega os dados
      */
     //$this->_record = $this->getModel()->getAdapter()->query($sql, $binds);
     $this->_rows = $this->getModel()->getAdapter()->fetchAll($sql, $binds);
     $this->_iRows = -1;
     return $this;
 }
Ejemplo n.º 5
0
 /**
  * Ação para buscar os dados para uma Seeker
  * Pode retornar o dado para preenchimento ou
  * retornar um PostData com os dados usados
  * para pesquisa
  */
 public function seekerSearchAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     $json = new ZendT_Json_Result();
     try {
         $value = ltrim($this->getRequest()->getParam('value'));
         $field = $this->getRequest()->getParam('field');
         if ($value) {
             if (method_exists($this->getMapper(), 'getWhereSeekerSearch')) {
                 $where = $this->getMapper()->getWhereSeekerSearch($value, $field);
             } else {
                 $where = $this->getModel()->getWhereSeekerSearch($value, $field);
             }
         } else {
             $where = new ZendT_Db_Where();
         }
         $whereGroup = new ZendT_Db_Where_Group('AND');
         $whereGroup->addWhere($where);
         /**
          * Pega o filtro usado usado em json
          */
         $filterJson = $this->getRequest()->getParam('filter_json');
         if ($filterJson) {
             $whereFilter = ZendT_Db_Where::fromJson($filterJson);
             $whereGroup->addWhere($whereFilter);
         }
         if ($this->_mapper instanceof ZendT_Db_View) {
             $dataGrid = $this->getMapper()->getDataGrid($whereGroup, array());
         } else {
             $dataGrid = $this->getModel()->getDataGrid($whereGroup, array());
         }
         $data = true;
         if ($dataGrid->getNumRows() == 1 && $this->getRequest()->getParam('makePostData') != '1') {
             $data = array();
             if ($dataGrid->isRowFormated()) {
                 $data['row'] = $dataGrid->getRow();
                 foreach ($data['row'] as $key => $row) {
                     if ($row instanceof ZendT_Type) {
                         $data['row'][$key] = $row->get();
                     }
                 }
             } else {
                 $row = $dataGrid->getRow();
                 foreach ($this->getColumns() as $column) {
                     $data['row'][strtolower($column->getName())] = $column->format($row[strtolower($column->getName())]);
                 }
             }
             $this->_prepareRetrieveRow($data['row']);
         } else {
             $data = array('postData' => $where->toJsonPostData(), 'numRows' => $dataGrid->getNumRows());
         }
         $json->setResult($data);
     } catch (Exception $Ex) {
         $json->setException($Ex);
     }
     echo $json->render();
 }