Commit 7420e63378629c58f81dfb735af9dbacb34f72be

Authored by Lucas Schmoeller da Silva
1 parent cb732f19
Exists in master

Criado relação de assuntos x obras

Também foi removido vinculo de assunto com biblioteca, deixado essa classificação ser geral;

portabilis/ieducar#122
ieducar/intranet/educar_acervo_assunto_cad.php
... ... @@ -55,7 +55,6 @@ class indice extends clsCadastro
55 55 var $data_cadastro;
56 56 var $data_exclusao;
57 57 var $ativo;
58   - var $ref_cod_biblioteca;
59 58  
60 59 function Inicializar()
61 60 {
... ... @@ -98,8 +97,6 @@ class indice extends clsCadastro
98 97 // primary keys
99 98 $this->campoOculto( "cod_acervo_assunto", $this->cod_acervo_assunto );
100 99  
101   - //foreign keys
102   - $this->inputsHelper()->dynamic(array('instituicao', 'escola', 'biblioteca'));
103 100  
104 101 // text
105 102 $this->campoTexto( "nm_assunto", "Assunto", $this->nm_assunto, 30, 255, true );
... ... @@ -116,7 +113,7 @@ class indice extends clsCadastro
116 113 $obj_permissoes->permissao_cadastra( 592, $this->pessoa_logada, 11, "educar_acervo_assunto_lst.php" );
117 114  
118 115  
119   - $obj = new clsPmieducarAcervoAssunto( null, null, $this->pessoa_logada, $this->nm_assunto, $this->descricao, null, null, 1, $this->ref_cod_biblioteca );
  116 + $obj = new clsPmieducarAcervoAssunto( null, null, $this->pessoa_logada, $this->nm_assunto, $this->descricao, null, null, 1);
120 117 $cadastrou = $obj->cadastra();
121 118 if( $cadastrou )
122 119 {
... ... @@ -141,7 +138,7 @@ class indice extends clsCadastro
141 138 $obj_permissoes->permissao_cadastra( 592, $this->pessoa_logada, 11, "educar_acervo_assunto_lst.php" );
142 139  
143 140  
144   - $obj = new clsPmieducarAcervoAssunto($this->cod_acervo_assunto, $this->pessoa_logada, null, $this->nm_assunto, $this->descricao, null, null, 1, $this->ref_cod_biblioteca);
  141 + $obj = new clsPmieducarAcervoAssunto($this->cod_acervo_assunto, $this->pessoa_logada, null, $this->nm_assunto, $this->descricao, null, null, 1);
145 142 $editou = $obj->edita();
146 143 if( $editou )
147 144 {
... ...
ieducar/intranet/educar_acervo_assunto_lst.php
... ... @@ -78,7 +78,6 @@ class indice extends clsListagem
78 78 var $data_cadastro;
79 79 var $data_exclusao;
80 80 var $ativo;
81   - var $ref_cod_biblioteca;
82 81  
83 82 function Gerar()
84 83 {
... ... @@ -95,17 +94,12 @@ class indice extends clsListagem
95 94  
96 95 $this->addCabecalhos( array(
97 96 "Assunto",
98   - "Biblioteca"
  97 + "Descrição"
99 98 ) );
100 99  
101   - // Filtros de Foreign Keys
102   - $get_escola = true;
103   - $get_biblioteca = true;
104   - $get_cabecalho = "lista_busca";
105   - include("include/pmieducar/educar_campo_lista.php");
106   -
107 100 // outros Filtros
108 101 $this->campoTexto( "nm_assunto", "Assunto", $this->nm_assunto, 30, 255, false );
  102 + $this->campoTexto( "descricao", "Descrição", $this->descricao, 30, 255, false );
109 103  
110 104 // Paginador
111 105 $this->limite = 20;
... ... @@ -126,13 +120,12 @@ class indice extends clsListagem
126 120 null,
127 121 null,
128 122 $this->nm_assunto,
  123 + $this->descricao,
129 124 null,
130 125 null,
131 126 null,
132 127 null,
133   - null,
134   - 1,
135   - $this->ref_cod_biblioteca
  128 + 1
136 129 );
137 130  
138 131 $total = $obj_acervo_assunto->_total;
... ... @@ -142,12 +135,9 @@ class indice extends clsListagem
142 135 {
143 136 foreach ( $lista AS $registro )
144 137 {
145   - $obj_biblioteca = new clsPmieducarBiblioteca($registro['ref_cod_biblioteca']);
146   - $det_biblioteca = $obj_biblioteca->detalhe();
147   - $registro['ref_cod_biblioteca'] = $det_biblioteca['nm_biblioteca'];
148 138 $this->addLinhas( array(
149 139 "<a href=\"educar_acervo_assunto_det.php?cod_acervo_assunto={$registro["cod_acervo_assunto"]}\">{$registro["nm_assunto"]}</a>",
150   - "<a href=\"educar_acervo_assunto_det.php?cod_acervo_assunto={$registro["cod_acervo_assunto"]}\">{$registro['ref_cod_biblioteca']}</a>"
  140 + "<a href=\"educar_acervo_assunto_det.php?cod_acervo_assunto={$registro["cod_acervo_assunto"]}\">{$registro['descricao']}</a>"
151 141 ) );
152 142 }
153 143 }
... ...
ieducar/intranet/educar_acervo_cad.php
... ... @@ -388,6 +388,11 @@ class indice extends clsCadastro
388 388 $this->campoTexto( "titulo", "T&iacute;tulo", $this->titulo, 40, 255, true );
389 389 $this->campoTexto( "sub_titulo", "Subt&iacute;tulo", $this->sub_titulo, 40, 255, false );
390 390 $this->campoTexto( "estante", "Estante", $this->estante, 20, 15, false );
  391 + $helperOptions = array('objectName' => 'assuntos');
  392 + $options = array('label' => 'Assuntos', 'size' => 50, 'required' => false,
  393 + 'options' => array('value' => null));
  394 +
  395 + $this->inputsHelper()->multipleSearchAssuntos('', $options, $helperOptions);
391 396 $this->campoTexto( "cdd", "CDD", $this->cdd, 20, 15, false );
392 397 $this->campoTexto( "cdu", "CDU", $this->cdu, 20, 15, false );
393 398 $this->campoTexto( "cutter", "Cutter", $this->cutter, 20, 15, false );
... ... @@ -413,6 +418,7 @@ class indice extends clsCadastro
413 418 $cadastrou = $obj->cadastra();
414 419 if( $cadastrou )
415 420 {
  421 + $this->gravaAssuntos($cadastrou);
416 422 //-----------------------CADASTRA AUTOR------------------------//
417 423 foreach ( $this->acervo_autor AS $autor )
418 424 {
... ... @@ -459,6 +465,8 @@ class indice extends clsCadastro
459 465 $editou = $obj->edita();
460 466 if( $editou )
461 467 {
  468 +
  469 + $this->gravaAssuntos($this->cod_acervo);
462 470 //-----------------------EDITA AUTOR------------------------//
463 471  
464 472 $obj = new clsPmieducarAcervoAcervoAutor( null, $this->cod_acervo );
... ... @@ -519,6 +527,17 @@ class indice extends clsCadastro
519 527 echo "<!--\nErro ao excluir clsPmieducarAcervo\nvalores obrigatorios\nif( is_numeric( $this->cod_acervo ) && is_numeric( $this->pessoa_logada ) )\n-->";
520 528 return false;
521 529 }
  530 +
  531 + function gravaAssuntos($cod_acervo){
  532 + $objAssunto = new clsPmieducarAcervoAssunto();
  533 + $objAssunto->deletaAssuntosDaObra($cod_acervo);
  534 + foreach ($this->getRequest()->assuntos as $assuntoId) {
  535 + if (! empty($assuntoId)) {
  536 + $objAssunto = new clsPmieducarAcervoAssunto();
  537 + $objAssunto->cadastraAssuntoParaObra($cod_acervo, $assuntoId);
  538 + }
  539 + }
  540 + }
522 541 }
523 542  
524 543 // cria uma extensao da classe base
... ... @@ -741,5 +760,51 @@ function fixupPrincipalCheckboxes() {
741 760 }
742 761  
743 762 fixupPrincipalCheckboxes();
  763 +function fixupAssuntosSize(){
  764 +
  765 + $j('#assuntos_chzn ul').css('width', '307px');
  766 +
  767 +}
  768 +
  769 +fixupAssuntosSize();
  770 +
  771 + $assuntos = $j('#assuntos');
  772 +
  773 + $assuntos.trigger('liszt:updated');
  774 + var testezin;
  775 +
  776 +var handleGetAssuntos = function(dataResponse) {
  777 + testezin = dataResponse['assuntos'];
  778 +
  779 + $j.each(dataResponse['assuntos'], function(id, value) {
  780 +
  781 + $assuntos.children("[value=" + value + "]").attr('selected', '');
  782 + });
  783 +
  784 + $assuntos.trigger('liszt:updated');
  785 +}
  786 +
  787 +var getAssuntos = function() {
  788 +
  789 + var $cod_acervo = $j('#cod_acervo').val();
  790 +
  791 + if ($j('#cod_acervo').val()!='') {
  792 +
  793 + var additionalVars = {
  794 + id : $j('#cod_acervo').val(),
  795 + };
  796 +
  797 + var options = {
  798 + url : getResourceUrlBuilder.buildUrl('/module/Api/assunto', 'assunto', additionalVars),
  799 + dataType : 'json',
  800 + data : {},
  801 + success : handleGetAssuntos,
  802 + };
  803 +
  804 + getResource(options);
  805 + }
  806 +}
  807 +
  808 +getAssuntos();
744 809  
745 810 </script>
... ...
ieducar/intranet/educar_acervo_det.php
... ... @@ -316,6 +316,16 @@ class indice extends clsDetalhe
316 316 $this->addDetalhe( array( "ISBN", "{$registro["isbn"]}") );
317 317 }
318 318  
  319 + $obj = new clsPmieducarAcervoAssunto();
  320 + $obj = $obj->listaAssuntosPorObra($this->cod_acervo);
  321 + if (count($obj)){
  322 + foreach ($obj as $reg) {
  323 + $assuntos.= '<span style="background-color: #A1B3BD; padding: 2px;"><b>'.$reg['nome'].'</b></span>&nbsp; ';
  324 + }
  325 + if(!empty($assuntos))
  326 + $this->addDetalhe( array( "Assuntos", "{$assuntos}") );
  327 + }
  328 +
319 329 $obj_permissoes = new clsPermissoes();
320 330 if( $obj_permissoes->permissao_cadastra( 598, $this->pessoa_logada, 11 ) )
321 331 {
... ...
ieducar/intranet/educar_acervo_lst.php
... ... @@ -91,6 +91,7 @@ class indice extends clsListagem
91 91 var $data_exclusao;
92 92 var $ativo;
93 93 var $ref_cod_biblioteca;
  94 + var $ref_cod_assunto_acervo;
94 95  
95 96 function Gerar()
96 97 {
... ... @@ -165,6 +166,17 @@ class indice extends clsListagem
165 166 $this->campoLista("ref_cod_exemplar_tipo", "Tipo Exemplar", $opcoes_exemplar, $this->ref_cod_exemplar_tipo, "", false, "", "", false, false);
166 167 $this->campoLista("ref_cod_acervo_editora", "Editora", $opcoes_editora, $this->ref_cod_acervo_editora, "", false, "", "", false, false);
167 168  
  169 + $objTemp = new clsPmieducarAcervoAssunto();
  170 + $lista = $objTemp->lista();
  171 +
  172 + if (is_array($lista) && count($lista)) {
  173 + foreach ($lista as $registro) {
  174 + $opcoes[$registro['cod_acervo_assunto']] = $registro['nm_assunto'];
  175 + }
  176 + }
  177 +
  178 + $this->campoLista('ref_cod_assunto_acervo', 'Assunto', $opcoes, $this->ref_cod_assunto_acervo, '', FALSE, '',
  179 + '', FALSE, FALSE);
168 180  
169 181 $this->campoTexto( "titulo_livro", "Titulo", $this->titulo_livro, 30, 255, false );
170 182  
... ... @@ -182,6 +194,7 @@ class indice extends clsListagem
182 194 $obj_acervo = new clsPmieducarAcervo();
183 195 $obj_acervo->setOrderby( "titulo ASC" );
184 196 $obj_acervo->setLimite( $this->limite, $this->offset );
  197 + $obj_acervo->ref_cod_acervo_assunto = $this->ref_cod_assunto_acervo;
185 198  
186 199  
187 200  
... ...
ieducar/intranet/include/pmieducar/clsPmieducarAcervo.inc.php
... ... @@ -898,6 +898,12 @@ class clsPmieducarAcervo
898 898 $whereAnd = " AND ";
899 899 }
900 900  
  901 + if( is_numeric( $this->ref_cod_acervo_assunto ) )
  902 + {
  903 + $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";
  904 + $whereAnd = " AND ";
  905 + }
  906 +
901 907 if(is_string($str_titulo))
902 908 {
903 909 $filtros .= "{$whereAnd} titulo LIKE '%{$str_titulo}%'";
... ...
ieducar/intranet/include/pmieducar/clsPmieducarAcervoAssunto.inc.php
... ... @@ -212,7 +212,7 @@ class clsPmieducarAcervoAssunto
212 212 */
213 213 function cadastra()
214 214 {
215   - if( is_numeric( $this->ref_usuario_cad ) && is_string( $this->nm_assunto ) && is_numeric($this->ref_cod_biblioteca) )
  215 + if( is_numeric( $this->ref_usuario_cad ) && is_string( $this->nm_assunto ) )
216 216 {
217 217 $db = new clsBanco();
218 218  
... ... @@ -451,6 +451,51 @@ class clsPmieducarAcervoAssunto
451 451 }
452 452 return false;
453 453 }
  454 +
  455 +
  456 + /**
  457 + * Deleta todos assuntos de uma determinada obra.
  458 + *
  459 + * @return boolean
  460 + */
  461 + function deletaAssuntosDaObra($acervoId){
  462 + $db = new clsBanco();
  463 + $db->Consulta( "DELETE FROM pmieducar.acervo_acervo_assunto WHERE ref_cod_acervo = {$acervoId}" );
  464 + return true;
  465 + }
  466 +
  467 + /**
  468 + * Cadastra um determinado assunto para uma determinada obra.
  469 + *
  470 + * @return boolean
  471 + */
  472 + function cadastraAssuntoParaObra($acervoId, $assuntoId){
  473 + $db = new clsBanco();
  474 + $db->Consulta( "INSERT INTO pmieducar.acervo_acervo_assunto (ref_cod_acervo, ref_cod_acervo_assunto) VALUES ({$acervoId},{$assuntoId})" );
  475 + return true;
  476 + }
  477 +
  478 + /**
  479 + * Cadastra um determinado assunto para uma determinada obra.
  480 + *
  481 + * @return array
  482 + */
  483 + function listaAssuntosPorObra($acervoId){
  484 + $db = new clsBanco();
  485 + $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} " );
  486 +
  487 + while ( $db->ProximoRegistro() )
  488 + {
  489 + $resultado[] = $db->Tupla();
  490 + }
  491 +
  492 + if( count( $resultado ) )
  493 + {
  494 + return $resultado;
  495 + }
  496 +
  497 + return false;
  498 + }
454 499  
455 500 /**
456 501 * Retorna um array com os dados de um registro
... ...
ieducar/lib/Portabilis/View/Helper/Input/Resource/MultipleSearchAssuntos.php 0 → 100644
... ... @@ -0,0 +1,74 @@
  1 +<?php
  2 +#error_reporting(E_ALL);
  3 +#ini_set("display_errors", 1);]
  4 +/**
  5 + * i-Educar - Sistema de gestão escolar
  6 + *
  7 + * Copyright (C) 2006 Prefeitura Municipal de Itajaí
  8 + * <ctima@itajai.sc.gov.br>
  9 + *
  10 + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo
  11 + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free
  12 + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério)
  13 + * qualquer versão posterior.
  14 + *
  15 + * Este programa é distribuí­do na expectativa de que seja útil, porém, SEM
  16 + * NENHUMA GARANTIA; nem mesmo a garantia implí­cita de COMERCIABILIDADE OU
  17 + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral
  18 + * do GNU para mais detalhes.
  19 + *
  20 + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto
  21 + * com este programa; se não, escreva para a Free Software Foundation, Inc., no
  22 + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
  23 + *
  24 + * @author Lucas Schmoeller da Silva <lucas@portabilis.com.br>
  25 + * @category i-Educar
  26 + * @license @@license@@
  27 + * @package Portabilis
  28 + * @since 11/2013
  29 + * @version $Id$
  30 + */
  31 +
  32 +require_once 'lib/Portabilis/View/Helper/Input/MultipleSearch.php';
  33 +require_once 'lib/Portabilis/Utils/Database.php';
  34 +require_once 'lib/Portabilis/String/Utils.php';
  35 +
  36 +/**
  37 + * Portabilis_View_Helper_Input_MultipleSearchAssuntos class.
  38 + *
  39 + * @author Lucas Schmoeller da Silva <lucas@portabilis.com.br>
  40 + * @category i-Educar
  41 + * @license @@license@@
  42 + * @package Portabilis
  43 + * @since 11/2013
  44 + * @version @@package_version@@
  45 + */
  46 +class Portabilis_View_Helper_Input_Resource_MultipleSearchAssuntos extends Portabilis_View_Helper_Input_MultipleSearch {
  47 +
  48 + protected function getOptions($resources) {
  49 + if (empty($resources)) {
  50 + $resources = new clsPmieducarAcervoAssunto();
  51 + $resources = $resources->lista();
  52 + $resources = Portabilis_Array_Utils::setAsIdValue($resources, 'cod_acervo_assunto', 'nm_assunto');
  53 + }
  54 + return $this->insertOption(null, '', $resources);
  55 + }
  56 +
  57 + public function multipleSearchAssuntos($attrName, $options = array()) {
  58 + $defaultOptions = array('objectName' => 'assuntos',
  59 + 'apiController' => 'Assunto',
  60 + 'apiResource' => 'assunto-search');
  61 + $options = $this->mergeOptions($options, $defaultOptions);
  62 + $options['options']['resources'] = $this->getOptions($options['options']['resources']);
  63 + //var_dump($options['options']['options']);
  64 + $this->placeholderJs($options);
  65 + parent::multipleSearch($options['objectName'], $attrName, $options);
  66 + }
  67 +
  68 + protected function placeholderJs($options) {
  69 + $optionsVarName = "multipleSearch" . Portabilis_String_Utils::camelize($options['objectName']) . "Options";
  70 + $js = "if (typeof $optionsVarName == 'undefined') { $optionsVarName = {} };
  71 + $optionsVarName.placeholder = safeUtf8Decode('Selecione os assuntos');";
  72 + Portabilis_View_Helper_Application::embedJavascript($this->viewInstance, $js, $afterReady = true);
  73 + }
  74 +}
0 75 \ No newline at end of file
... ...
ieducar/lib/Portabilis/View/Helper/Inputs.php
... ... @@ -212,6 +212,10 @@ class Portabilis_View_Helper_Inputs {
212 212 $this->multipleSearchResourceInput('multipleSearchDeficiencias', $attrName, $inputOptions, $helperOptions);
213 213 }
214 214  
  215 + public function multipleSearchAssuntos($attrName, $inputOptions = array(), $helperOptions = array()) {
  216 + $this->multipleSearchResourceInput('multipleSearchAssuntos', $attrName, $inputOptions, $helperOptions);
  217 + }
  218 +
215 219 // resource input helpers
216 220  
217 221 public function religiao($inputOptions = array(), $helperOptions = array()) {
... ...
ieducar/modules/Api/Views/AssuntoController.php 0 → 100644
... ... @@ -0,0 +1,73 @@
  1 +<?php
  2 +
  3 +#error_reporting(E_ALL);
  4 +#ini_set("display_errors", 1);
  5 +
  6 +/**
  7 + * i-Educar - Sistema de gestão escolar
  8 + *
  9 + * Copyright (C) 2006 Prefeitura Municipal de Itajaí
  10 + * <ctima@itajai.sc.gov.br>
  11 + *
  12 + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo
  13 + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free
  14 + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério)
  15 + * qualquer versão posterior.
  16 + *
  17 + * Este programa é distribuí­do na expectativa de que seja útil, porém, SEM
  18 + * NENHUMA GARANTIA; nem mesmo a garantia implí­cita de COMERCIABILIDADE OU
  19 + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral
  20 + * do GNU para mais detalhes.
  21 + *
  22 + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto
  23 + * com este programa; se não, escreva para a Free Software Foundation, Inc., no
  24 + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
  25 + *
  26 + * @author Lucas Schmoeller da Silva <lucas@portabilis.com.br>
  27 + * @category i-Educar
  28 + * @license @@license@@
  29 + * @package Api
  30 + * @subpackage Modules
  31 + * @since Arquivo disponível desde a versão ?
  32 + * @version $Id$
  33 + */
  34 +
  35 +require_once 'lib/Portabilis/Controller/ApiCoreController.php';
  36 +require_once 'lib/Portabilis/Array/Utils.php';
  37 +require_once 'lib/Portabilis/String/Utils.php';
  38 +require_once 'intranet/include/pmieducar/clsPmieducarAcervoAssunto.inc.php';
  39 +
  40 +class AssuntoController extends ApiCoreController
  41 +{
  42 + // search options
  43 +
  44 + protected function searchOptions() {
  45 + return array('namespace' => 'pmieducar', 'labelAttr' => 'nm_assunto', 'idAttr' => 'cod_acervo_assunto');
  46 + }
  47 +
  48 + protected function formatResourceValue($resource) {
  49 + return $this->toUtf8($resource['name'], array('transform' => true));
  50 + }
  51 +
  52 + protected function getAssunto() {
  53 +
  54 + $obj = new clsPmieducarAcervoAssunto();
  55 + $arrayAssuntos;
  56 +
  57 + foreach ($obj->listaAssuntosPorObra($this->getRequest()->id) as $reg) {
  58 + $arrayAssuntos[] = $reg['ref_cod_acervo_assunto'];
  59 + }
  60 +
  61 +
  62 + return array('assuntos' => $arrayAssuntos);
  63 + }
  64 +
  65 + public function Gerar() {
  66 + if ($this->isRequestFor('get', 'assunto-search'))
  67 + $this->appendResponse($this->search());
  68 + elseif ($this->isRequestFor('get', 'assunto'))
  69 + $this->appendResponse($this->getAssunto());
  70 + else
  71 + $this->notImplementedOperationError();
  72 + }
  73 +}
0 74 \ No newline at end of file
... ...
ieducar/modules/Portabilis/Assets/Javascripts/Frontend/Inputs/MultipleSearch.js
... ... @@ -38,11 +38,13 @@ var multipleSearch = {
38 38 $input.attr('multiple', '');
39 39 $input.attr('data-placeholder', options.get('placeholder'));
40 40  
  41 + var objectName = options.get('objectName');
  42 +
41 43 // jquery scope
42 44 $input.chosen(options.get('chosenOptions'), multipleSearch.handleSearch);
43 45  
44 46 // fixup to API receive all ids
45   - $j("#deficiencias").attr('name', $j("#deficiencias").attr('name') + '[]');
  47 + $j("#"+objectName).attr('name', $j("#"+objectName).attr('name') + '[]');
46 48 }
47 49 };
48 50  
... ...