From 7420e63378629c58f81dfb735af9dbacb34f72be Mon Sep 17 00:00:00 2001 From: Lucas Schmoeller da Silva Date: Wed, 18 Mar 2015 17:54:38 -0300 Subject: [PATCH] Criado relação de assuntos x obras --- ieducar/intranet/educar_acervo_assunto_cad.php | 7 ++----- ieducar/intranet/educar_acervo_assunto_lst.php | 20 +++++--------------- ieducar/intranet/educar_acervo_cad.php | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ieducar/intranet/educar_acervo_det.php | 10 ++++++++++ ieducar/intranet/educar_acervo_lst.php | 13 +++++++++++++ ieducar/intranet/include/pmieducar/clsPmieducarAcervo.inc.php | 6 ++++++ ieducar/intranet/include/pmieducar/clsPmieducarAcervoAssunto.inc.php | 47 ++++++++++++++++++++++++++++++++++++++++++++++- ieducar/lib/Portabilis/View/Helper/Input/Resource/MultipleSearchAssuntos.php | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ieducar/lib/Portabilis/View/Helper/Inputs.php | 4 ++++ ieducar/modules/Api/Views/AssuntoController.php | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ieducar/modules/Portabilis/Assets/Javascripts/Frontend/Inputs/MultipleSearch.js | 4 +++- 11 files changed, 301 insertions(+), 22 deletions(-) create mode 100644 ieducar/lib/Portabilis/View/Helper/Input/Resource/MultipleSearchAssuntos.php create mode 100644 ieducar/modules/Api/Views/AssuntoController.php diff --git a/ieducar/intranet/educar_acervo_assunto_cad.php b/ieducar/intranet/educar_acervo_assunto_cad.php index 024e849..66efba3 100644 --- a/ieducar/intranet/educar_acervo_assunto_cad.php +++ b/ieducar/intranet/educar_acervo_assunto_cad.php @@ -55,7 +55,6 @@ class indice extends clsCadastro var $data_cadastro; var $data_exclusao; var $ativo; - var $ref_cod_biblioteca; function Inicializar() { @@ -98,8 +97,6 @@ class indice extends clsCadastro // primary keys $this->campoOculto( "cod_acervo_assunto", $this->cod_acervo_assunto ); - //foreign keys - $this->inputsHelper()->dynamic(array('instituicao', 'escola', 'biblioteca')); // text $this->campoTexto( "nm_assunto", "Assunto", $this->nm_assunto, 30, 255, true ); @@ -116,7 +113,7 @@ class indice extends clsCadastro $obj_permissoes->permissao_cadastra( 592, $this->pessoa_logada, 11, "educar_acervo_assunto_lst.php" ); - $obj = new clsPmieducarAcervoAssunto( null, null, $this->pessoa_logada, $this->nm_assunto, $this->descricao, null, null, 1, $this->ref_cod_biblioteca ); + $obj = new clsPmieducarAcervoAssunto( null, null, $this->pessoa_logada, $this->nm_assunto, $this->descricao, null, null, 1); $cadastrou = $obj->cadastra(); if( $cadastrou ) { @@ -141,7 +138,7 @@ class indice extends clsCadastro $obj_permissoes->permissao_cadastra( 592, $this->pessoa_logada, 11, "educar_acervo_assunto_lst.php" ); - $obj = new clsPmieducarAcervoAssunto($this->cod_acervo_assunto, $this->pessoa_logada, null, $this->nm_assunto, $this->descricao, null, null, 1, $this->ref_cod_biblioteca); + $obj = new clsPmieducarAcervoAssunto($this->cod_acervo_assunto, $this->pessoa_logada, null, $this->nm_assunto, $this->descricao, null, null, 1); $editou = $obj->edita(); if( $editou ) { diff --git a/ieducar/intranet/educar_acervo_assunto_lst.php b/ieducar/intranet/educar_acervo_assunto_lst.php index 85b4e2d..73ea11e 100644 --- a/ieducar/intranet/educar_acervo_assunto_lst.php +++ b/ieducar/intranet/educar_acervo_assunto_lst.php @@ -78,7 +78,6 @@ class indice extends clsListagem var $data_cadastro; var $data_exclusao; var $ativo; - var $ref_cod_biblioteca; function Gerar() { @@ -95,17 +94,12 @@ class indice extends clsListagem $this->addCabecalhos( array( "Assunto", - "Biblioteca" + "Descrio" ) ); - // Filtros de Foreign Keys - $get_escola = true; - $get_biblioteca = true; - $get_cabecalho = "lista_busca"; - include("include/pmieducar/educar_campo_lista.php"); - // outros Filtros $this->campoTexto( "nm_assunto", "Assunto", $this->nm_assunto, 30, 255, false ); + $this->campoTexto( "descricao", "Descrio", $this->descricao, 30, 255, false ); // Paginador $this->limite = 20; @@ -126,13 +120,12 @@ class indice extends clsListagem null, null, $this->nm_assunto, + $this->descricao, null, null, null, null, - null, - 1, - $this->ref_cod_biblioteca + 1 ); $total = $obj_acervo_assunto->_total; @@ -142,12 +135,9 @@ class indice extends clsListagem { foreach ( $lista AS $registro ) { - $obj_biblioteca = new clsPmieducarBiblioteca($registro['ref_cod_biblioteca']); - $det_biblioteca = $obj_biblioteca->detalhe(); - $registro['ref_cod_biblioteca'] = $det_biblioteca['nm_biblioteca']; $this->addLinhas( array( "{$registro["nm_assunto"]}", - "{$registro['ref_cod_biblioteca']}" + "{$registro['descricao']}" ) ); } } diff --git a/ieducar/intranet/educar_acervo_cad.php b/ieducar/intranet/educar_acervo_cad.php index 12fac82..63e7f3a 100644 --- a/ieducar/intranet/educar_acervo_cad.php +++ b/ieducar/intranet/educar_acervo_cad.php @@ -388,6 +388,11 @@ class indice extends clsCadastro $this->campoTexto( "titulo", "Título", $this->titulo, 40, 255, true ); $this->campoTexto( "sub_titulo", "Subtítulo", $this->sub_titulo, 40, 255, false ); $this->campoTexto( "estante", "Estante", $this->estante, 20, 15, false ); + $helperOptions = array('objectName' => 'assuntos'); + $options = array('label' => 'Assuntos', 'size' => 50, 'required' => false, + 'options' => array('value' => null)); + + $this->inputsHelper()->multipleSearchAssuntos('', $options, $helperOptions); $this->campoTexto( "cdd", "CDD", $this->cdd, 20, 15, false ); $this->campoTexto( "cdu", "CDU", $this->cdu, 20, 15, false ); $this->campoTexto( "cutter", "Cutter", $this->cutter, 20, 15, false ); @@ -413,6 +418,7 @@ class indice extends clsCadastro $cadastrou = $obj->cadastra(); if( $cadastrou ) { + $this->gravaAssuntos($cadastrou); //-----------------------CADASTRA AUTOR------------------------// foreach ( $this->acervo_autor AS $autor ) { @@ -459,6 +465,8 @@ class indice extends clsCadastro $editou = $obj->edita(); if( $editou ) { + + $this->gravaAssuntos($this->cod_acervo); //-----------------------EDITA AUTOR------------------------// $obj = new clsPmieducarAcervoAcervoAutor( null, $this->cod_acervo ); @@ -519,6 +527,17 @@ class indice extends clsCadastro echo ""; return false; } + + function gravaAssuntos($cod_acervo){ + $objAssunto = new clsPmieducarAcervoAssunto(); + $objAssunto->deletaAssuntosDaObra($cod_acervo); + foreach ($this->getRequest()->assuntos as $assuntoId) { + if (! empty($assuntoId)) { + $objAssunto = new clsPmieducarAcervoAssunto(); + $objAssunto->cadastraAssuntoParaObra($cod_acervo, $assuntoId); + } + } + } } // cria uma extensao da classe base @@ -741,5 +760,51 @@ function fixupPrincipalCheckboxes() { } fixupPrincipalCheckboxes(); +function fixupAssuntosSize(){ + + $j('#assuntos_chzn ul').css('width', '307px'); + +} + +fixupAssuntosSize(); + + $assuntos = $j('#assuntos'); + + $assuntos.trigger('liszt:updated'); + var testezin; + +var handleGetAssuntos = function(dataResponse) { + testezin = dataResponse['assuntos']; + + $j.each(dataResponse['assuntos'], function(id, value) { + + $assuntos.children("[value=" + value + "]").attr('selected', ''); + }); + + $assuntos.trigger('liszt:updated'); +} + +var getAssuntos = function() { + + var $cod_acervo = $j('#cod_acervo').val(); + + if ($j('#cod_acervo').val()!='') { + + var additionalVars = { + id : $j('#cod_acervo').val(), + }; + + var options = { + url : getResourceUrlBuilder.buildUrl('/module/Api/assunto', 'assunto', additionalVars), + dataType : 'json', + data : {}, + success : handleGetAssuntos, + }; + + getResource(options); + } +} + +getAssuntos(); diff --git a/ieducar/intranet/educar_acervo_det.php b/ieducar/intranet/educar_acervo_det.php index 6e2faaf..3a088af 100644 --- a/ieducar/intranet/educar_acervo_det.php +++ b/ieducar/intranet/educar_acervo_det.php @@ -316,6 +316,16 @@ class indice extends clsDetalhe $this->addDetalhe( array( "ISBN", "{$registro["isbn"]}") ); } + $obj = new clsPmieducarAcervoAssunto(); + $obj = $obj->listaAssuntosPorObra($this->cod_acervo); + if (count($obj)){ + foreach ($obj as $reg) { + $assuntos.= ''.$reg['nome'].'  '; + } + if(!empty($assuntos)) + $this->addDetalhe( array( "Assuntos", "{$assuntos}") ); + } + $obj_permissoes = new clsPermissoes(); if( $obj_permissoes->permissao_cadastra( 598, $this->pessoa_logada, 11 ) ) { diff --git a/ieducar/intranet/educar_acervo_lst.php b/ieducar/intranet/educar_acervo_lst.php index b0e889b..82b33af 100644 --- a/ieducar/intranet/educar_acervo_lst.php +++ b/ieducar/intranet/educar_acervo_lst.php @@ -91,6 +91,7 @@ class indice extends clsListagem var $data_exclusao; var $ativo; var $ref_cod_biblioteca; + var $ref_cod_assunto_acervo; function Gerar() { @@ -165,6 +166,17 @@ class indice extends clsListagem $this->campoLista("ref_cod_exemplar_tipo", "Tipo Exemplar", $opcoes_exemplar, $this->ref_cod_exemplar_tipo, "", false, "", "", false, false); $this->campoLista("ref_cod_acervo_editora", "Editora", $opcoes_editora, $this->ref_cod_acervo_editora, "", false, "", "", false, false); + $objTemp = new clsPmieducarAcervoAssunto(); + $lista = $objTemp->lista(); + + if (is_array($lista) && count($lista)) { + foreach ($lista as $registro) { + $opcoes[$registro['cod_acervo_assunto']] = $registro['nm_assunto']; + } + } + + $this->campoLista('ref_cod_assunto_acervo', 'Assunto', $opcoes, $this->ref_cod_assunto_acervo, '', FALSE, '', + '', FALSE, FALSE); $this->campoTexto( "titulo_livro", "Titulo", $this->titulo_livro, 30, 255, false ); @@ -182,6 +194,7 @@ class indice extends clsListagem $obj_acervo = new clsPmieducarAcervo(); $obj_acervo->setOrderby( "titulo ASC" ); $obj_acervo->setLimite( $this->limite, $this->offset ); + $obj_acervo->ref_cod_acervo_assunto = $this->ref_cod_assunto_acervo; diff --git a/ieducar/intranet/include/pmieducar/clsPmieducarAcervo.inc.php b/ieducar/intranet/include/pmieducar/clsPmieducarAcervo.inc.php index 505527a..e6a0ada 100644 --- a/ieducar/intranet/include/pmieducar/clsPmieducarAcervo.inc.php +++ b/ieducar/intranet/include/pmieducar/clsPmieducarAcervo.inc.php @@ -898,6 +898,12 @@ class clsPmieducarAcervo $whereAnd = " AND "; } + if( is_numeric( $this->ref_cod_acervo_assunto ) ) + { + $filtros .= "{$whereAnd} (SELECT 1 FROM pmieducar.acervo_acervo_assunto WHERE ref_cod_acervo = cod_acervo AND ref_cod_acervo_assunto = {$this->ref_cod_acervo_assunto} ) IS NOT NULL"; + $whereAnd = " AND "; + } + if(is_string($str_titulo)) { $filtros .= "{$whereAnd} titulo LIKE '%{$str_titulo}%'"; diff --git a/ieducar/intranet/include/pmieducar/clsPmieducarAcervoAssunto.inc.php b/ieducar/intranet/include/pmieducar/clsPmieducarAcervoAssunto.inc.php index f0d7d04..e472425 100644 --- a/ieducar/intranet/include/pmieducar/clsPmieducarAcervoAssunto.inc.php +++ b/ieducar/intranet/include/pmieducar/clsPmieducarAcervoAssunto.inc.php @@ -212,7 +212,7 @@ class clsPmieducarAcervoAssunto */ function cadastra() { - if( is_numeric( $this->ref_usuario_cad ) && is_string( $this->nm_assunto ) && is_numeric($this->ref_cod_biblioteca) ) + if( is_numeric( $this->ref_usuario_cad ) && is_string( $this->nm_assunto ) ) { $db = new clsBanco(); @@ -451,6 +451,51 @@ class clsPmieducarAcervoAssunto } return false; } + + + /** + * Deleta todos assuntos de uma determinada obra. + * + * @return boolean + */ + function deletaAssuntosDaObra($acervoId){ + $db = new clsBanco(); + $db->Consulta( "DELETE FROM pmieducar.acervo_acervo_assunto WHERE ref_cod_acervo = {$acervoId}" ); + return true; + } + + /** + * Cadastra um determinado assunto para uma determinada obra. + * + * @return boolean + */ + function cadastraAssuntoParaObra($acervoId, $assuntoId){ + $db = new clsBanco(); + $db->Consulta( "INSERT INTO pmieducar.acervo_acervo_assunto (ref_cod_acervo, ref_cod_acervo_assunto) VALUES ({$acervoId},{$assuntoId})" ); + return true; + } + + /** + * Cadastra um determinado assunto para uma determinada obra. + * + * @return array + */ + function listaAssuntosPorObra($acervoId){ + $db = new clsBanco(); + $db->Consulta( "SELECT aas.*, (SELECT nm_assunto FROM pmieducar.acervo_assunto WHERE cod_acervo_assunto = aas.ref_cod_acervo_assunto) as nome FROM pmieducar.acervo_acervo_assunto aas WHERE ref_cod_acervo = {$acervoId} " ); + + while ( $db->ProximoRegistro() ) + { + $resultado[] = $db->Tupla(); + } + + if( count( $resultado ) ) + { + return $resultado; + } + + return false; + } /** * Retorna um array com os dados de um registro diff --git a/ieducar/lib/Portabilis/View/Helper/Input/Resource/MultipleSearchAssuntos.php b/ieducar/lib/Portabilis/View/Helper/Input/Resource/MultipleSearchAssuntos.php new file mode 100644 index 0000000..c33eb2e --- /dev/null +++ b/ieducar/lib/Portabilis/View/Helper/Input/Resource/MultipleSearchAssuntos.php @@ -0,0 +1,74 @@ + + * + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério) + * qualquer versão posterior. + * + * Este programa é distribuí­do na expectativa de que seja útil, porém, SEM + * NENHUMA GARANTIA; nem mesmo a garantia implí­cita de COMERCIABILIDADE OU + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral + * do GNU para mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto + * com este programa; se não, escreva para a Free Software Foundation, Inc., no + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. + * + * @author Lucas Schmoeller da Silva + * @category i-Educar + * @license @@license@@ + * @package Portabilis + * @since 11/2013 + * @version $Id$ + */ + +require_once 'lib/Portabilis/View/Helper/Input/MultipleSearch.php'; +require_once 'lib/Portabilis/Utils/Database.php'; +require_once 'lib/Portabilis/String/Utils.php'; + +/** + * Portabilis_View_Helper_Input_MultipleSearchAssuntos class. + * + * @author Lucas Schmoeller da Silva + * @category i-Educar + * @license @@license@@ + * @package Portabilis + * @since 11/2013 + * @version @@package_version@@ + */ +class Portabilis_View_Helper_Input_Resource_MultipleSearchAssuntos extends Portabilis_View_Helper_Input_MultipleSearch { + + protected function getOptions($resources) { + if (empty($resources)) { + $resources = new clsPmieducarAcervoAssunto(); + $resources = $resources->lista(); + $resources = Portabilis_Array_Utils::setAsIdValue($resources, 'cod_acervo_assunto', 'nm_assunto'); + } + return $this->insertOption(null, '', $resources); + } + + public function multipleSearchAssuntos($attrName, $options = array()) { + $defaultOptions = array('objectName' => 'assuntos', + 'apiController' => 'Assunto', + 'apiResource' => 'assunto-search'); + $options = $this->mergeOptions($options, $defaultOptions); + $options['options']['resources'] = $this->getOptions($options['options']['resources']); + //var_dump($options['options']['options']); + $this->placeholderJs($options); + parent::multipleSearch($options['objectName'], $attrName, $options); + } + + protected function placeholderJs($options) { + $optionsVarName = "multipleSearch" . Portabilis_String_Utils::camelize($options['objectName']) . "Options"; + $js = "if (typeof $optionsVarName == 'undefined') { $optionsVarName = {} }; + $optionsVarName.placeholder = safeUtf8Decode('Selecione os assuntos');"; + Portabilis_View_Helper_Application::embedJavascript($this->viewInstance, $js, $afterReady = true); + } +} \ No newline at end of file diff --git a/ieducar/lib/Portabilis/View/Helper/Inputs.php b/ieducar/lib/Portabilis/View/Helper/Inputs.php index 4872121..6346522 100644 --- a/ieducar/lib/Portabilis/View/Helper/Inputs.php +++ b/ieducar/lib/Portabilis/View/Helper/Inputs.php @@ -212,6 +212,10 @@ class Portabilis_View_Helper_Inputs { $this->multipleSearchResourceInput('multipleSearchDeficiencias', $attrName, $inputOptions, $helperOptions); } + public function multipleSearchAssuntos($attrName, $inputOptions = array(), $helperOptions = array()) { + $this->multipleSearchResourceInput('multipleSearchAssuntos', $attrName, $inputOptions, $helperOptions); + } + // resource input helpers public function religiao($inputOptions = array(), $helperOptions = array()) { diff --git a/ieducar/modules/Api/Views/AssuntoController.php b/ieducar/modules/Api/Views/AssuntoController.php new file mode 100644 index 0000000..2d10c82 --- /dev/null +++ b/ieducar/modules/Api/Views/AssuntoController.php @@ -0,0 +1,73 @@ + + * + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério) + * qualquer versão posterior. + * + * Este programa é distribuí­do na expectativa de que seja útil, porém, SEM + * NENHUMA GARANTIA; nem mesmo a garantia implí­cita de COMERCIABILIDADE OU + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral + * do GNU para mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto + * com este programa; se não, escreva para a Free Software Foundation, Inc., no + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. + * + * @author Lucas Schmoeller da Silva + * @category i-Educar + * @license @@license@@ + * @package Api + * @subpackage Modules + * @since Arquivo disponível desde a versão ? + * @version $Id$ + */ + +require_once 'lib/Portabilis/Controller/ApiCoreController.php'; +require_once 'lib/Portabilis/Array/Utils.php'; +require_once 'lib/Portabilis/String/Utils.php'; +require_once 'intranet/include/pmieducar/clsPmieducarAcervoAssunto.inc.php'; + +class AssuntoController extends ApiCoreController +{ + // search options + + protected function searchOptions() { + return array('namespace' => 'pmieducar', 'labelAttr' => 'nm_assunto', 'idAttr' => 'cod_acervo_assunto'); + } + + protected function formatResourceValue($resource) { + return $this->toUtf8($resource['name'], array('transform' => true)); + } + + protected function getAssunto() { + + $obj = new clsPmieducarAcervoAssunto(); + $arrayAssuntos; + + foreach ($obj->listaAssuntosPorObra($this->getRequest()->id) as $reg) { + $arrayAssuntos[] = $reg['ref_cod_acervo_assunto']; + } + + + return array('assuntos' => $arrayAssuntos); + } + + public function Gerar() { + if ($this->isRequestFor('get', 'assunto-search')) + $this->appendResponse($this->search()); + elseif ($this->isRequestFor('get', 'assunto')) + $this->appendResponse($this->getAssunto()); + else + $this->notImplementedOperationError(); + } +} \ No newline at end of file diff --git a/ieducar/modules/Portabilis/Assets/Javascripts/Frontend/Inputs/MultipleSearch.js b/ieducar/modules/Portabilis/Assets/Javascripts/Frontend/Inputs/MultipleSearch.js index ee73b10..84797d1 100644 --- a/ieducar/modules/Portabilis/Assets/Javascripts/Frontend/Inputs/MultipleSearch.js +++ b/ieducar/modules/Portabilis/Assets/Javascripts/Frontend/Inputs/MultipleSearch.js @@ -38,11 +38,13 @@ var multipleSearch = { $input.attr('multiple', ''); $input.attr('data-placeholder', options.get('placeholder')); + var objectName = options.get('objectName'); + // jquery scope $input.chosen(options.get('chosenOptions'), multipleSearch.handleSearch); // fixup to API receive all ids - $j("#deficiencias").attr('name', $j("#deficiencias").attr('name') + '[]'); + $j("#"+objectName).attr('name', $j("#"+objectName).attr('name') + '[]'); } }; -- libgit2 0.21.2