Commit 49c6eaf0b8737e2474ef29549a00b5893c250eec

Authored by Thieres Tembra
1 parent 27018e9e
Exists in master

Modificado a rotina de Lançamento de Faltas/Notas para:

1) Agrupar os Componentes Curriculares por Área de Conhecimento. O
agrupamento é feito de duas formas, de acordo com o modo de
preenchimento que o usuário escolher:
   * Caso selecione o Componente Curricular: Já no menu de seleção foram
criados grupos (<optgroup/>) para cada Área de Conhecimento. No
carregamento da tela de preenchimento das faltas/notas, é inserido uma
nova coluna (<td/>) na primeira posição da tabela superior, informando a
Área de Conhecimento do Componente Curricular selecionado.
   * Caso não selecione o Componente Curricular: É inserido uma nova
linha (<tr/>) na listagem, antes do primeiro Componente Curricular de
cada Área de Conhecimento.

2) Ordenar os Componentes Curriculares alfabeticamente por:
   * Nome da Área de Conhecimento, e;
   * Nome do Componente Curricular.

/*
 * Modificações por arquivo
 */

[1] File: /ieducar/modules/Avaliacao/Views/DiarioApiController.php
    - Adicionado a função "strtoupper()" no conteúdo da variável
"$componente['nome']"
    - Adicionado segundo parâmetro como "false", no método
"safeString()" utilizado no conteúdo da variável "$componente['nome']"
    - Criado novo método "getAreaConhecimento($componenteCurricularId)"
com visibilidade "protected", para retornar uma classe com o Id e o Nome
da Área de Conhecimento do Componente Curricular cujo Id foi passado
pelo parâmetro
    - Criado nova posição "area_id" no array "$componente" para gravar o
Id da Área de Conhecimento
    - Criado nova posição "area_nome" no array "$componente" para gravar
o Nome da Área de Conhecimento
    - Criado nova posição temporária "my_order" no array "$componente"
para ordenar alfabeticamente através do método "sortByKey" os
Componentes Curriculares pelo Nome da Área de Conhecimento e pelo Nome
do Componente Curricular, respectivamente e sem acentos. Esta posição é
removida após a ordenação para que não seja enviada na requisição.


[2] File: /ieducar/modules/Avaliacao/Assets/Diario.js
    - Criado na função "setTableSearchDetails()" um novo elemento <th/>
com o conteúdo "Área de Conhecimento"
    - Criado na função "setTableSearchDetails()" um novo elemento <td/>
com o Nome da Área de Conhecimento, recuperado através do atributo
"label" do elemento pai (<optgroup/> criado no arquivo [7]) do <option/>
selecionado
    - Adicionado seletor "optgroup" na função "setTableSearchDetails()",
no jQuery que busca o Nome do Componente Curricular selecionado, para
considerar a existência do(s) <optgroup/> criado(s) no arquivo [7]
    - Adicionado seletor ":not(.area-conhecimento)" na função
"handleSearch()", no jQuery que busca os elementos que possuem o
atributo "colspan"
    - Criado na função "updateComponenteCurriculares()" array de
controle "areas" para salvar o Id das Áreas de Conhecimento já exibidas,
obtidas no arquivo [1]
    - Criado na função "updateComponenteCurriculares()" variável
"areaColspan" para salvar a quantidade de colunas da linha do cabeçalho
    - Criado na função "updateComponenteCurriculares()" novo elemento
<tr/> referente a linha da Área de Conhecimento
    - Criado na função "updateComponenteCurriculares()" novo elemento
<td/> referente ao Nome da Área de Conhecimento obtido no arquivo [1], e
atribuído a classe "area-conhecimento" criada no arquivo [3]
    - Criado nova função "myNextValid($selectElement)", para ir para o
próximo <option/> após o selecionado, considerando agora a existência
do(s) <optgroup/> criado(s) no arquivo [7]
    - Alterado conteúdo da variável $nextOption na função
"selectNextOption()" para realizar chamada a nova função "myNextValid()"
mencionada acima


[3] File: /ieducar/intranet/styles/mytdt.css
    - Novo arquivo criado para contemplar o CSS das contribuições da
MyTDT Corp. para o i-Educar
    - Adicionado estilo para a classe "area-conhecimento" utilizada no
<td/> do arquivo [2]


[4] File: /ieducar/intranet/templates/nvp_htmlhead.tpl
    - Adicionado novo elemento <link/> para incluir o novo arquivo de
estilo (CSS) criado [3]


[5] File: /ieducar/lib/Portabilis/Business/Professor.php
    - Modificado as queries dos métodos
"componentesCurricularesTurmaAlocado()" e
"componentesCurricularesCursoAlocado()":
      * Adicionado campo (SELECT) "ac.nome as area_conhecimento"
      * Adicionado tabela (FROM) "modules.area_conhecimento as ac"
      * Adicionado condição (WHERE) "and cc.area_conhecimento_id =
ac.id"
      * Adicionado ordenamento (ORDER) "order by ac.nome, cc.nome"


[6] File:
/ieducar/modules/DynamicInput/Views/ComponenteCurricularController.php
    - Modificado as duas queries do método
"getComponentesCurriculares()":
      * Adicionado campo (SELECT) "ac.nome as area_conhecimento"
      * Adicionado tabela (FROM) "modules.area_conhecimento as ac"
      * Adicionado condição (WHERE) "and cc.area_conhecimento_id =
ac.id"
      * Adicionado ordenamento (ORDER) "order by ac.nome, cc.nome"
    - Alterado conteúdo da variável "$options[]" para um array
associativo (que será convertido para um objeto JSON), conforme segue:
      * Chave "value": Se utilizado um array associativo a mesma deve
existir, pois será o conteúdo do <option/> a ser gerado
      * Chave "group": Criada com intuito de salvar o conteúdo do campo
"area_conhecimento" retornado por uma das queries mencionada acima ou no
arquivo [5], que será utilizada no arquivo [7]
      * OBS: Assim como a chave "group", poderá ser criado qualquer
outra chave no array associativo que o conteúdo da mesma estará
acessível no <option/> através do atributo "data-*" onde "*" é o nome da
chave criada


[7] File:
/ieducar/modules/DynamicInput/Assets/Javascripts/DynamicInput.js
    - Criado na função "updateSelect()" array de controle "groups" para
salvar o Nome das Áreas de Conhecimento que já possuem <optgroup/>,
obtidas no arquivo [6]
    - Criado na função "updateSelect()" variável "optgroup" para salvar
o último elemento <optgroup/> criado
    - Modificado a função "updateSelect()" para verificar se existe o
atributo "data-group" no elemento <option/>, onde, caso exista:
      * Irá gerar um novo elemento <optgroup/> com o atributo "label"
preenchido com o conteúdo do "data-group" obtido no arquivo [6] e
definido pela função "jsonResourcesToSelectOptions()" neste mesmo
arquivo [7]
      * O elemento <option/> será adicionado como filho do novo elemento
<optgroup/> acima citado
      * O elemento <optgroup/> por sua vez, que será adicionado ao
<select/>
    - Modificado a função "jsonResourcesToSelectOptions()" para
verificar se o atributo "value" retornado pela requisição é do tipo
objeto, onde, caso seja:
      * Irá adicionar ao elemento <option/> o(s) atributo(s) "data-*"
com o conteúdo extraído conforme modificação realizada no item [6]
      * Irá adicionar ao contéudo do <option/> conforme mencionado em
[6] a chave "value", referente ao Nome do Componente Curricular

Change-Id: Ie93c75ef7fe1d6e390a7e0e14de69b991be902c9
Signed-off-by: Thieres Tembra <tdt@mytdt.com.br>
ieducar/intranet/styles/mytdt.css 0 → 100644
@@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
  1 +/*
  2 + * Module: Avaliacao
  3 + * Controller: Diario
  4 + *
  5 + * Referente a linha adicionada na tabela de Lançamentos
  6 + * de Faltas/Notas para a Área de Conhecimento
  7 + *
  8 + * @author Thieres Tembra
  9 + * @company MyTDT Corporation [http://www.mytdt.com.br]
  10 + */
  11 +td.area-conhecimento {
  12 + background-color: #546C76;
  13 + color: #FFF;
  14 + font-weight: bold;
  15 + text-align: left;
  16 +}
ieducar/intranet/templates/nvp_htmlhead.tpl
@@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
17 <!--link rel=stylesheet type='text/css' href='styles/reset.css' /> 17 <!--link rel=stylesheet type='text/css' href='styles/reset.css' />
18 <link rel=stylesheet type='text/css' href='styles/portabilis.css' /--> 18 <link rel=stylesheet type='text/css' href='styles/portabilis.css' /-->
19 <link rel=stylesheet type='text/css' href='styles/min-portabilis.css' /> 19 <link rel=stylesheet type='text/css' href='styles/min-portabilis.css' />
  20 + <link rel=stylesheet type='text/css' href='styles/mytdt.css' />
20 21
21 <!-- #&ESTILO&# --> 22 <!-- #&ESTILO&# -->
22 23
ieducar/lib/Portabilis/Business/Professor.php
@@ -102,13 +102,14 @@ class Portabilis_Business_Professor { @@ -102,13 +102,14 @@ class Portabilis_Business_Professor {
102 102
103 103
104 protected static function componentesCurricularesTurmaAlocado($turmaId, $anoLetivo, $userId) { 104 protected static function componentesCurricularesTurmaAlocado($turmaId, $anoLetivo, $userId) {
105 - $sql = "select cc.id, cc.nome  
106 - from modules.componente_curricular_turma as cct, pmieducar.turma, modules.componente_curricular as cc, 105 + $sql = "select cc.id, cc.nome, ac.nome as area_conhecimento
  106 + from modules.componente_curricular_turma as cct, pmieducar.turma, modules.componente_curricular as cc, modules.area_conhecimento as ac,
107 pmieducar.escola_ano_letivo as al, pmieducar.servidor_disciplina as scc 107 pmieducar.escola_ano_letivo as al, pmieducar.servidor_disciplina as scc
108 where turma.cod_turma = $1 and cct.turma_id = turma.cod_turma and cct.escola_id = turma.ref_ref_cod_escola 108 where turma.cod_turma = $1 and cct.turma_id = turma.cod_turma and cct.escola_id = turma.ref_ref_cod_escola
109 and cct.componente_curricular_id = cc.id and al.ano = $2 and cct.escola_id = al.ref_cod_escola and 109 and cct.componente_curricular_id = cc.id and al.ano = $2 and cct.escola_id = al.ref_cod_escola and
110 scc.ref_ref_cod_instituicao = turma.ref_cod_instituicao and scc.ref_cod_servidor = $3 and 110 scc.ref_ref_cod_instituicao = turma.ref_cod_instituicao and scc.ref_cod_servidor = $3 and
111 - scc.ref_cod_curso = turma.ref_cod_curso and scc.ref_cod_disciplina = cc.id"; 111 + scc.ref_cod_curso = turma.ref_cod_curso and scc.ref_cod_disciplina = cc.id and cc.area_conhecimento_id = ac.id
  112 + order by ac.nome, cc.nome";
112 113
113 $options = array('params' => array($turmaId, $anoLetivo, $userId)); 114 $options = array('params' => array($turmaId, $anoLetivo, $userId));
114 115
@@ -117,14 +118,15 @@ class Portabilis_Business_Professor { @@ -117,14 +118,15 @@ class Portabilis_Business_Professor {
117 118
118 119
119 protected static function componentesCurricularesCursoAlocado($turmaId, $anoLetivo, $userId) { 120 protected static function componentesCurricularesCursoAlocado($turmaId, $anoLetivo, $userId) {
120 - $sql = "select cc.id as id, cc.nome as nome from pmieducar.serie, pmieducar.escola_serie_disciplina as esd,  
121 - pmieducar.turma, modules.componente_curricular as cc, pmieducar.escola_ano_letivo as al, 121 + $sql = "select cc.id as id, cc.nome as nome, ac.nome as area_conhecimento from pmieducar.serie, pmieducar.escola_serie_disciplina as esd,
  122 + pmieducar.turma, modules.componente_curricular as cc, modules.area_conhecimento as ac, pmieducar.escola_ano_letivo as al,
122 pmieducar.servidor_disciplina as scc where turma.cod_turma = $1 and serie.cod_serie = 123 pmieducar.servidor_disciplina as scc where turma.cod_turma = $1 and serie.cod_serie =
123 turma.ref_ref_cod_serie and esd.ref_ref_cod_escola = turma.ref_ref_cod_escola and esd.ref_ref_cod_serie = 124 turma.ref_ref_cod_serie and esd.ref_ref_cod_escola = turma.ref_ref_cod_escola and esd.ref_ref_cod_serie =
124 serie.cod_serie and esd.ref_cod_disciplina = cc.id and al.ano = $2 and esd.ref_ref_cod_escola = 125 serie.cod_serie and esd.ref_cod_disciplina = cc.id and al.ano = $2 and esd.ref_ref_cod_escola =
125 al.ref_cod_escola and serie.ativo = 1 and esd.ativo = 1 and al.ativo = 1 and scc.ref_ref_cod_instituicao = 126 al.ref_cod_escola and serie.ativo = 1 and esd.ativo = 1 and al.ativo = 1 and scc.ref_ref_cod_instituicao =
126 turma.ref_cod_instituicao and scc.ref_cod_servidor = $3 and scc.ref_cod_curso = serie.ref_cod_curso and 127 turma.ref_cod_instituicao and scc.ref_cod_servidor = $3 and scc.ref_cod_curso = serie.ref_cod_curso and
127 - scc.ref_cod_disciplina = cc.id"; 128 + scc.ref_cod_disciplina = cc.id and cc.area_conhecimento_id = ac.id
  129 + order by ac.nome, cc.nome";
128 130
129 $options = array('params' => array($turmaId, $anoLetivo, $userId)); 131 $options = array('params' => array($turmaId, $anoLetivo, $userId));
130 132
@@ -142,4 +144,4 @@ class Portabilis_Business_Professor { @@ -142,4 +144,4 @@ class Portabilis_Business_Professor {
142 protected static function fetchPreparedQuery($sql, $options = array()) { 144 protected static function fetchPreparedQuery($sql, $options = array()) {
143 return Portabilis_Utils_Database::fetchPreparedQuery($sql, $options); 145 return Portabilis_Utils_Database::fetchPreparedQuery($sql, $options);
144 } 146 }
145 -}  
146 \ No newline at end of file 147 \ No newline at end of file
  148 +}
ieducar/modules/Avaliacao/Assets/Javascripts/Diario.js
@@ -453,8 +453,10 @@ function setTableSearchDetails($tableSearchDetails, dataDetails) { @@ -453,8 +453,10 @@ function setTableSearchDetails($tableSearchDetails, dataDetails) {
453 //set headers table 453 //set headers table
454 var $linha = $j('<tr />'); 454 var $linha = $j('<tr />');
455 455
456 - if (componenteCurricularSelected) 456 + if (componenteCurricularSelected) {
  457 + $j('<th />').html('&Aacute;rea de Conhecimento').appendTo($linha);
457 $j('<th />').html('Componente curricular').appendTo($linha); 458 $j('<th />').html('Componente curricular').appendTo($linha);
  459 + }
458 460
459 $j('<th />').html('Etapa').appendTo($linha); 461 $j('<th />').html('Etapa').appendTo($linha);
460 $j('<th />').html('Turma').appendTo($linha); 462 $j('<th />').html('Turma').appendTo($linha);
@@ -470,8 +472,10 @@ function setTableSearchDetails($tableSearchDetails, dataDetails) { @@ -470,8 +472,10 @@ function setTableSearchDetails($tableSearchDetails, dataDetails) {
470 472
471 var $linha = $j('<tr />').addClass('cellColor'); 473 var $linha = $j('<tr />').addClass('cellColor');
472 474
473 - if (componenteCurricularSelected)  
474 - $j('<td />').html(safeToUpperCase($j('#ref_cod_componente_curricular').children("[selected='selected']").html())).appendTo($linha); 475 + if (componenteCurricularSelected) {
  476 + $j('<td />').html(safeToUpperCase($j('#ref_cod_componente_curricular optgroup').children("[selected='selected']").parent().attr('label'))).appendTo($linha);
  477 + $j('<td />').html(safeToUpperCase($j('#ref_cod_componente_curricular optgroup').children("[selected='selected']").html())).appendTo($linha);
  478 + }
475 479
476 $j('<td />').html(safeToUpperCase($j('#etapa').children("[selected='selected']").html())).appendTo($linha); 480 $j('<td />').html(safeToUpperCase($j('#etapa').children("[selected='selected']").html())).appendTo($linha);
477 $j('<td />').html(safeToUpperCase($j('#ref_cod_turma').children("[selected='selected']").html())).appendTo($linha); 481 $j('<td />').html(safeToUpperCase($j('#ref_cod_turma').children("[selected='selected']").html())).appendTo($linha);
@@ -547,7 +551,7 @@ function handleSearch($resultTable, dataResponse) { @@ -547,7 +551,7 @@ function handleSearch($resultTable, dataResponse) {
547 // seta colspan [th, td].aluno quando exibe nota exame 551 // seta colspan [th, td].aluno quando exibe nota exame
548 if ($tableSearchDetails.data('details').tipo_nota != 'nenhum' && 552 if ($tableSearchDetails.data('details').tipo_nota != 'nenhum' &&
549 $tableSearchDetails.data('details').quantidade_etapas == $j('#etapa').val()) { 553 $tableSearchDetails.data('details').quantidade_etapas == $j('#etapa').val()) {
550 - $resultTable.find('[colspan]').attr('colspan', componenteCurricularSelected ? 1 : 5); 554 + $resultTable.find('[colspan]:not(.area-conhecimento)').attr('colspan', componenteCurricularSelected ? 1 : 5);
551 } 555 }
552 556
553 $resultTable.find('tr:even').addClass('even'); 557 $resultTable.find('tr:even').addClass('even');
@@ -709,14 +713,29 @@ function updateComponenteCurriculares($targetElement, matriculaId, componentesCu @@ -709,14 +713,29 @@ function updateComponenteCurriculares($targetElement, matriculaId, componentesCu
709 var useNota = $tableSearchDetails.data('details').tipo_nota != 'nenhum'; 713 var useNota = $tableSearchDetails.data('details').tipo_nota != 'nenhum';
710 var useParecer = $tableSearchDetails.data('details').tipo_parecer_descritivo != 'nenhum'; 714 var useParecer = $tableSearchDetails.data('details').tipo_parecer_descritivo != 'nenhum';
711 715
  716 + var areas = new Array();
  717 +
712 var $ccHeader = $j('<tr />').addClass('strong'); 718 var $ccHeader = $j('<tr />').addClass('strong');
713 719
714 $j('<td />').addClass('center').html('Componente curricular').appendTo($ccHeader); 720 $j('<td />').addClass('center').html('Componente curricular').appendTo($ccHeader);
715 updateComponenteCurricularHeaders($ccHeader, $j('<td />')); 721 updateComponenteCurricularHeaders($ccHeader, $j('<td />'));
716 722
717 $ccHeader.appendTo($targetElement); 723 $ccHeader.appendTo($targetElement);
  724 +
  725 + var areaColspan = $j('td', $ccHeader).length;
  726 +
718 727
719 $j.each(componentesCurriculares, function(index, cc) { 728 $j.each(componentesCurriculares, function(index, cc) {
  729 + if (areas.indexOf(cc.area_id) == -1) {
  730 + areas.push(cc.area_id);
  731 +
  732 + var $areaRow = $j('<tr />');
  733 +
  734 + $j('<td />').addClass('area-conhecimento').attr('colspan', areaColspan).html(cc.area_nome).appendTo($areaRow);
  735 +
  736 + $areaRow.appendTo($targetElement);
  737 + }
  738 +
720 var $ccRow = $j('<tr />'); 739 var $ccRow = $j('<tr />');
721 740
722 $j('<td />').addClass('center').html(cc.nome).appendTo($ccRow); 741 $j('<td />').addClass('center').html(cc.nome).appendTo($ccRow);
@@ -764,9 +783,23 @@ function canSearch(){ @@ -764,9 +783,23 @@ function canSearch(){
764 return true; 783 return true;
765 } 784 }
766 785
  786 +function myNextValid($selectElement) {
  787 + var a = $selectElement.find('option:selected');
  788 + if (a.next('option').length == 0) {
  789 + b = a.parent();
  790 + if (b.prop('tagName').toUpperCase() == 'SELECT') {
  791 + return null;
  792 + } else {
  793 + return b.next().children('option:first');
  794 + }
  795 + } else {
  796 + return a.next('option');
  797 + }
  798 +}
  799 +
767 function selectNextOption($selectElement){ 800 function selectNextOption($selectElement){
768 - var $nextOption = $selectElement.find('option:selected').next('option');  
769 - 801 + var $nextOption = myNextValid($selectElement);
  802 +
770 if ($nextOption.val() != undefined) { 803 if ($nextOption.val() != undefined) {
771 $selectElement.val($nextOption.val()); 804 $selectElement.val($nextOption.val());
772 805
ieducar/modules/Avaliacao/Views/DiarioApiController.php
@@ -748,20 +748,57 @@ class DiarioApiController extends ApiCoreController @@ -748,20 +748,57 @@ class DiarioApiController extends ApiCoreController
748 $componente = array(); 748 $componente = array();
749 749
750 $componente['id'] = $_componente->get('id'); 750 $componente['id'] = $_componente->get('id');
751 - $componente['nome'] = $this->safeString($_componente->get('nome')); 751 + $componente['nome'] = $this->safeString(strtoupper($_componente->get('nome')), false);
752 $componente['nota_atual'] = $this->getNotaAtual($etapa = null, $componente['id']); 752 $componente['nota_atual'] = $this->getNotaAtual($etapa = null, $componente['id']);
753 $componente['nota_exame'] = $this->getNotaExame($componente['id']); 753 $componente['nota_exame'] = $this->getNotaExame($componente['id']);
754 //$componente['nota_necessaria_exame'] = $this->getNotaNecessariaExame($componente['id']); 754 //$componente['nota_necessaria_exame'] = $this->getNotaNecessariaExame($componente['id']);
755 $componente['falta_atual'] = $this->getFaltaAtual($etapa = null, $componente['id']); 755 $componente['falta_atual'] = $this->getFaltaAtual($etapa = null, $componente['id']);
756 $componente['parecer_atual'] = $this->getParecerAtual($componente['id']); 756 $componente['parecer_atual'] = $this->getParecerAtual($componente['id']);
757 $componente['situacao'] = $this->getSituacaoMatricula($componente['id']); 757 $componente['situacao'] = $this->getSituacaoMatricula($componente['id']);
  758 +
  759 + //buscando pela área do conhecimento
  760 + $area = $this->getAreaConhecimento($componente['id']);
  761 + $componente['area_id'] = $area->id;
  762 + $componente['area_nome'] = $this->safeString(strtoupper($area->nome), false);
  763 +
  764 + //criando chave para ordenamento temporário
  765 + //área de conhecimento + componente curricular
  766 + $componente['my_order'] = Portabilis_String_Utils::unaccent(strtoupper($area->nome)) . Portabilis_String_Utils::unaccent(strtoupper($_componente->get('nome')));
758 767
759 $componentesCurriculares[] = $componente; 768 $componentesCurriculares[] = $componente;
760 } 769 }
761 770
762 - // ordenado por id, da mesma maneira que nos boletins,  
763 - // obs: poderá ainda ocorrer diferença entre a ordem das areas de conhecimento?  
764 - return Portabilis_Array_Utils::sortByKey('id', $componentesCurriculares); 771 + //ordenando pela chave temporária criada
  772 + $componentesCurriculares = Portabilis_Array_Utils::sortByKey('my_order', $componentesCurriculares);
  773 +
  774 + //removendo chave temporária
  775 + $len = count($componentesCurriculares);
  776 + for ($i = 0; $i < $len; $i++) {
  777 + unset($componentesCurriculares[$i]['my_order']);
  778 + }
  779 + return $componentesCurriculares;
  780 + }
  781 +
  782 + protected function getAreaConhecimento($componenteCurricularId = null) {
  783 + if (is_null($componenteCurricularId))
  784 + $componenteCurricularId = $this->getRequest()->componente_curricular_id;
  785 +
  786 + if (! is_numeric($componenteCurricularId)) {
  787 + throw new Exception('Não foi possível obter a área de conhecimento pois não foi recebido o id do componente curricular.');
  788 + }
  789 +
  790 + require_once 'ComponenteCurricular/Model/ComponenteDataMapper.php';
  791 + $mapper = new ComponenteCurricular_Model_ComponenteDataMapper();
  792 +
  793 + $where = array('id' => $componenteCurricularId);
  794 +
  795 + $area = $mapper->findAll(array('area_conhecimento'), $where);
  796 +
  797 + $areaConhecimento = new stdClass();
  798 + $areaConhecimento->id = $area[0]->area_conhecimento->id;
  799 + $areaConhecimento->nome = $area[0]->area_conhecimento->nome;
  800 +
  801 + return $areaConhecimento;
765 } 802 }
766 803
767 804
ieducar/modules/DynamicInput/Assets/Javascripts/DynamicInput.js
1 function updateSelect($targetElement, options, emptyOptionHtml) { 1 function updateSelect($targetElement, options, emptyOptionHtml) {
2 $targetElement.children().not('[value=""]').remove(); 2 $targetElement.children().not('[value=""]').remove();
3 - 3 +
  4 + var groups = new Array();
  5 + var optgroup = null;
  6 +
4 $j.each(options, function(index, value){ 7 $j.each(options, function(index, value){
5 - $j(value).appendTo($targetElement); 8 + if ($j(value).data('group')) {
  9 + if (groups.indexOf($j(value).data('group')) == -1) {
  10 + if (optgroup != null) {
  11 + optgroup.appendTo($targetElement);
  12 + }
  13 + optgroup = $j('<optgroup />').attr('label', $j(value).data('group'));
  14 + groups.push($j(value).data('group'));
  15 + }
  16 + $j(value).appendTo(optgroup);
  17 + } else {
  18 + $j(value).appendTo($targetElement);
  19 + }
6 }); 20 });
  21 + if (optgroup != null) {
  22 + optgroup.appendTo($targetElement);
  23 + }
7 24
8 if (options.length > 0) { 25 if (options.length > 0) {
9 $targetElement.removeAttr('disabled'); 26 $targetElement.removeAttr('disabled');
@@ -56,8 +73,23 @@ function jsonResourcesToSelectOptions(resources) { @@ -56,8 +73,23 @@ function jsonResourcesToSelectOptions(resources) {
56 73
57 if (id.indexOf && id.substr && id.indexOf('__') == 0) 74 if (id.indexOf && id.substr && id.indexOf('__') == 0)
58 id = id.substr(2); 75 id = id.substr(2);
59 -  
60 - options.push($j('<option />').attr('value', id).html(safeCapitalize(value))); 76 +
  77 + var opt = $j('<option />').attr('value', id);
  78 +
  79 + var newValue = value;
  80 + if (typeof(value) == 'object') {
  81 + $j.each(value, function(optId, optValue) {
  82 + if (optId != 'value') {
  83 + opt.data(optId, optValue);
  84 + } else {
  85 + newValue = optValue;
  86 + }
  87 + });
  88 + }
  89 +
  90 + opt.html(safeCapitalize(newValue));
  91 +
  92 + options.push(opt);
61 }); 93 });
62 94
63 return options; 95 return options;
ieducar/modules/DynamicInput/Views/ComponenteCurricularController.php
@@ -71,29 +71,35 @@ class ComponenteCurricularController extends ApiCoreController @@ -71,29 +71,35 @@ class ComponenteCurricularController extends ApiCoreController
71 } 71 }
72 72
73 else { 73 else {
74 - $sql = "select cc.id, cc.nome  
75 - from pmieducar.turma, modules.componente_curricular_turma as cct, modules.componente_curricular as cc, 74 + $sql = "select cc.id, cc.nome, ac.nome as area_conhecimento
  75 + from pmieducar.turma, modules.componente_curricular_turma as cct, modules.componente_curricular as cc, modules.area_conhecimento as ac,
76 pmieducar.escola_ano_letivo as al where turma.cod_turma = $1 and cct.turma_id = turma.cod_turma and 76 pmieducar.escola_ano_letivo as al where turma.cod_turma = $1 and cct.turma_id = turma.cod_turma and
77 cct.escola_id = turma.ref_ref_cod_escola and cct.componente_curricular_id = cc.id and al.ano = $2 77 cct.escola_id = turma.ref_ref_cod_escola and cct.componente_curricular_id = cc.id and al.ano = $2
78 - and cct.escola_id = al.ref_cod_escola"; 78 + and cct.escola_id = al.ref_cod_escola and cc.area_conhecimento_id = ac.id
  79 + order by ac.nome, cc.nome";
79 80
80 $componentesCurriculares = $this->fetchPreparedQuery($sql, array($turmaId, $ano)); 81 $componentesCurriculares = $this->fetchPreparedQuery($sql, array($turmaId, $ano));
81 82
82 if (count($ComponentesCurriculares) < 1) { 83 if (count($ComponentesCurriculares) < 1) {
83 - $sql = "select cc.id, cc.nome from 84 + $sql = "select cc.id, cc.nome, ac.nome as area_conhecimento from
84 pmieducar.turma as t, pmieducar.escola_serie_disciplina as esd, modules.componente_curricular 85 pmieducar.turma as t, pmieducar.escola_serie_disciplina as esd, modules.componente_curricular
85 - as cc, pmieducar.escola_ano_letivo as al where t.cod_turma = $1 and esd.ref_ref_cod_escola = 86 + as cc, modules.area_conhecimento as ac, pmieducar.escola_ano_letivo as al where t.cod_turma = $1 and esd.ref_ref_cod_escola =
86 t.ref_ref_cod_escola and esd.ref_ref_cod_serie = t.ref_ref_cod_serie and esd.ref_cod_disciplina = 87 t.ref_ref_cod_escola and esd.ref_ref_cod_serie = t.ref_ref_cod_serie and esd.ref_cod_disciplina =
87 cc.id and al.ano = $2 and esd.ref_ref_cod_escola = al.ref_cod_escola and t.ativo = 1 and 88 cc.id and al.ano = $2 and esd.ref_ref_cod_escola = al.ref_cod_escola and t.ativo = 1 and
88 - esd.ativo = 1 and al.ativo = 1"; 89 + esd.ativo = 1 and al.ativo = 1 and cc.area_conhecimento_id = ac.id
  90 + order by ac.nome, cc.nome";
89 91
90 $componentesCurriculares = $this->fetchPreparedQuery($sql, array($turmaId, $ano)); 92 $componentesCurriculares = $this->fetchPreparedQuery($sql, array($turmaId, $ano));
91 } 93 }
92 } 94 }
93 95
94 $options = array(); 96 $options = array();
95 - foreach ($componentesCurriculares as $componenteCurricular)  
96 - $options['__' . $componenteCurricular['id']] = $this->toUtf8($componenteCurricular['nome']); 97 + foreach ($componentesCurriculares as $componenteCurricular) {
  98 + $options['__' . $componenteCurricular['id']] = array(
  99 + 'value' => $this->toUtf8($componenteCurricular['nome']),
  100 + 'group' => $this->toUtf8($componenteCurricular['area_conhecimento'])
  101 + );
  102 + }
97 103
98 return array('options' => $options); 104 return array('options' => $options);
99 } 105 }