diff --git a/app/controllers/calendarios_controller.php b/app/controllers/calendarios_controller.php index 16ff1a9..170493b 100755 --- a/app/controllers/calendarios_controller.php +++ b/app/controllers/calendarios_controller.php @@ -2,70 +2,208 @@ class CalendariosController extends AppController { var $name = 'Calendarios'; - - function beforeFilter() { - parent::beforeFilter(); - $this->Auth->allow("*"); + var $uses = array('Curso','Disciplina','Turma','Polo','Tipoevento','Evento','Conflito','Calendario'); + var $helpers = array('Javascript','Date'); + var $components = array('Date','RequestHandler','Aula', 'EventosHelper'); + + + function beforeRender(){ + // prevent useless warnings for Ajax + if($this->RequestHandler->isAjax()){ + Configure::write('debug', 0); + } } - - function index() { - $this->Calendario->recursive = 0; - $this->set('calendarios', $this->paginate()); + + function index(){ + //$this->layout = "teste"; + $cursos = $this->Curso->find('list',array('fields' => array('Curso.id','Curso.nome'))); + $this->set('cursos', $cursos); + //file_put_contents("/Users/luiz/tes/teste","adashdada"); } + + function add(){ + $cursos = $this->Curso->find('list',array('fields' => array('Curso.id','Curso.nome'))); + $this->set('cursos', $cursos); + + if(!empty($this->data)){ + //$this->Calendario->criarCalendario($this->data); + $this->Evento->saveAll($this->EventosHelper->gerar_aulas($this->data)); + $this->Evento->saveAll($this->EventosHelper->gerar_encontros($this->data)); - function view($id = null) { - if (!$id) { - $this->Session->setFlash(__('Invalid calendario', true)); - $this->redirect(array('action' => 'index')); + //$this->Session->setFlash(__('The evento has been saved', true)); + $this->redirect(array('action' => 'view',$this->data['Calendario']['turma_id'])); + } - $this->set('calendario', $this->Calendario->read(null, $id)); + } - - function add() { - if (!empty($this->data)) { - $this->Calendario->create(); - if ($this->Calendario->save($this->data)) { - $this->Session->setFlash(__('The calendario has been saved', true)); - $this->redirect(array('action' => 'index')); - } else { - $this->Session->setFlash(__('The calendario could not be saved. Please, try again.', true)); - } + + function view($turma_id = null){ + + $this->Evento->recursive = -1; + //$this->layout = "ajax"; + + $this->set('turma_id', $turma_id); + + $conflitos = $this->Conflito->find('all',array('conditions' => array('Conflito.turma_id' => $turma_id))); + $this->set('conflitos', $conflitos); + + $detalhes_turma = $this->Turma->findById($turma_id); + $this->set("detalhes_turma",$detalhes_turma); + + $disciplinas = array(); + foreach($detalhes_turma['Disciplina'] as $disciplina){ + $disciplinas[$disciplina['id']] = $disciplina['nome']; } - $cursos = $this->Calendario->Curso->find('list'); - $this->set(compact('cursos')); + + $this->set("disciplinas",$disciplinas); + + + } + + function imprimir($turma_id = null, $disc_id = null){ + $this->Evento->recursive= -1; + $conditions = array('Evento.turma_id' => $turma_id,'Evento.disciplina_id' => $disc_id); + $eventos = $this->Evento->find('all', array('conditions' => $conditions,'order' => array('Evento.inicio asc'))); + $this->set("eventos",$eventos); + } + + + /** + * + *AJAX REQUESTS + */ + + function feed($turma_id=null){ + $start = date( 'Y-m-d H:i:s', $this->params['url']['start']); + $end = date( 'Y-m-d H:i:s', $this->params['url']['end']); + + // $start = "2011-04-01"; + // $end = "2011-04-30"; + + $this->Evento->recursive = 0; + $conditions = array('Evento.inicio BETWEEN ? AND ?' => array($start,$end), + 'Evento.tipoevento_id NOT' => "5", + 'Evento.turma_id' => $turma_id); + + + + $events = $this->Evento->find('all',array('conditions' =>$conditions)); + + //debug($events); + + //3. Create the json array + $rows = array(); + for ($a=0; count($events)> $a; $a++) { - function edit($id = null) { - if (!$id && empty($this->data)) { - $this->Session->setFlash(__('Invalid calendario', true)); - $this->redirect(array('action' => 'index')); + //Is it an all day event? + $all = ($events[$a]['Evento']['diatodo'] == 1); + + //Create an event entry + $rows[] = array('id' => $events[$a]['Evento']['id'], + 'title' => $events[$a]['Tipoevento']['descricao']." - ".$events[$a]['Disciplina']['nome'], + 'start' => date('Y-m-d H:i', strtotime($events[$a]['Evento']['inicio'])), + 'end' => date('Y-m-d H:i',strtotime($events[$a]['Evento']['fim'])), + 'allDay' => $all, + ); } - if (!empty($this->data)) { - if ($this->Calendario->save($this->data)) { - $this->Session->setFlash(__('The calendario has been saved', true)); - $this->redirect(array('action' => 'index')); + + //4. Return as a json array + Configure::write('debug', 0); + $this->autoRender = false; + $this->autoLayout = false; + $this->header('Content-Type: application/json'); + echo json_encode($rows); + + } + + function move($id=null, $dayDelta, $minDelta, $allDay){ + Configure::write('debug', 0); + $this->autoRender = false; + $this->autoLayout = false; + $this->Evento->recursive = -1; + + if ($id!=null) { + $ev = $this->Evento->findById($id); //1 - locate the event in the DB + if ($allDay=='true') { //2- handle all day events + $ev['Evento']['diatodo'] = 1; } else { - $this->Session->setFlash(__('The calendario could not be saved. Please, try again.', true)); + $ev['Evento']['diatodo'] = 0; } + $dia_conflito = $ev['Evento']['inicio']; + + //3 - Start + $ev['Evento']['fim']=date('Y-m-d H:i:s',strtotime(''.$dayDelta.' days '.$minDelta.' minutes',strtotime($ev['Evento']['fim']))); + $ev['Evento']['inicio']=date('Y-m-d H:i:s',strtotime(''.$dayDelta.' days '.$minDelta.' minutes',strtotime($ev['Evento']['inicio']))); + $this->Evento->create(); + + $this->Evento->save($ev); //4 - Save the event with the new data + + + if($response = $this->EventosHelper->remover_conflito($dia_conflito, $ev['Evento']['turma_id'])){ + echo $response; } - if (empty($this->data)) { - $this->data = $this->Calendario->read(null, $id); + + //$this->redirect(array('action'=>'index')); + //5 - redirect and reload + //$this->redirect(array('controller' => "calendarios", 'action' => "view",substr($ev['Evento']['inicio'],0,4),substr($ev['Evento']['inicio'],5,2),substr($ev['Evento']['inicio'],8,2))); + } - $cursos = $this->Calendario->Curso->find('list'); - $this->set(compact('cursos')); } - - function delete($id = null) { - if (!$id) { - $this->Session->setFlash(__('Invalid id for calendario', true)); - $this->redirect(array('action'=>'index')); + + function edit_evento($evento_id = null){ + + $this->autoRender = false; + + + $hora = date('H:i:s', strtotime($_REQUEST['velhaData'])); + + $inicio = $_REQUEST['novaData']." ".$hora; + $fim = date('Y-m-d H:i:s', strtotime('+4 hours', strtotime($inicio))); + + + $this->data['Evento']['id'] = $evento_id; + $this->data['Evento']['inicio'] = $inicio; + $this->data['Evento']['fim'] = $fim; + + // $this->log("Inicio: ".$inicio." Fim: ".$fim,'date'); + + $this->Evento->create(); + + if($this->Evento->save($this->data)){ + $this->Session->setFlash('Evento editado corretamente','default',array("class" => "success")); } - if ($this->Calendario->delete($id)) { - $this->Session->setFlash(__('Calendario deleted', true)); - $this->redirect(array('action'=>'index')); + + } + + function getTurmasByCurso($curso_id){ + $this->layout = 'ajax'; + $this->beforeRender(); + $this->autoRender = false; + $turmas = $this->Turma->find("list",array('conditions' => array('Turma.curso_id' => $curso_id), + 'fields' => array('Turma.id','Turma.nome'))); + echo ""; + foreach($turmas as $key => $val) { + echo ""; + } + } + + function getDisciplinasByTurma($turma_id){ + $this->layout = 'ajax'; + $this->beforeRender(); + $this->autoRender = false; + $turma = $this->Turma->findById($turma_id); + $disciplinas = $turma['Disciplina']; + + echo ""; + foreach($disciplinas as $disciplina){ + $id = $disciplina['id']; + $nome = $disciplina['nome']; + echo ""; } - $this->Session->setFlash(__('Calendario was not deleted', true)); - $this->redirect(array('action' => 'index')); } + + } + ?> \ No newline at end of file diff --git a/app/controllers/components/aula.php b/app/controllers/components/aula.php index 377b92d..6a49bb7 100755 --- a/app/controllers/components/aula.php +++ b/app/controllers/components/aula.php @@ -4,7 +4,7 @@ class AulaComponent extends Object { public function __construct() { $this->Evento = ClassRegistry::init('Evento'); - $this->Conflito = ClassRegistry::init('Conflito'); + $this->Conflito = ClassRegistry::init('Conflito'); } diff --git a/app/controllers/components/eventos_helper.php b/app/controllers/components/eventos_helper.php new file mode 100644 index 0000000..69fd605 --- /dev/null +++ b/app/controllers/components/eventos_helper.php @@ -0,0 +1,158 @@ +Evento = ClassRegistry::init('Evento'); + $this->Disciplina = ClassRegistry::init('Disciplina'); + $this->Conflito = ClassRegistry::init('Conflito'); + + } + + function gerar_aulas($dados){ + $this->Disciplina->recursive = 2; + $disciplina = $this->Disciplina->findById($dados['Calendario']['disciplina_id']); + $polos_disciplina = $disciplina["Turma"]["0"]['Polo']; + $numSemanas = $disciplina['Disciplina']['numsemanas']; + $data_inicio_disciplina = $dados['Calendario']['inicio']; + $data_inicio = $data_inicio_disciplina; + + + $aulas = array(); + + //CRIA ARRAY DOS POLOS DA DISCIPLINA + $polos['Polo'] = array(); + foreach($polos_disciplina as $polo){ + array_push($polos['Polo'],$polo['id']); + } + + //ADICIONA TODOS OS EVENTOS NUM ARRAY + for($i = 1; $i <= $numSemanas; $i++){ + + $aula; + $aula['Evento']['tipoevento_id'] = 5; + $aula['Evento']['disciplina_id'] = $dados['Calendario']['disciplina_id']; + $aula['Evento']['turma_id'] = $dados['Calendario']['turma_id']; + $aula['Evento']['carga_horaria'] = 0; + $aula['Evento']['diatodo'] = 0; + + + //É necessário o condicional pois se mandar pegar o próximo domingo, ele irá pegar o imediatamente após o dia inicial + //e faz-se necessário pegar o domingo da semana seguinte + if($i == 1){ + + $aula['Evento']['inicio'] = $data_inicio; + + $data_fim = $this->Date->format('next Sunday',$this->Date->format('+1 day',$data_inicio_disciplina)); + $aula['Evento']['fim'] = $data_fim; + + }else{ + $data_inicio = $this->Date->format('+1 day',$data_fim); + $aula['Evento']['inicio'] = $data_inicio; + + $data_fim = $this->Date->format('next Sunday',$data_inicio); + $aula['Evento']['fim'] = $data_fim; + + } + + //ADICIONA OS POLOS PARA CADA EVENTO + $aula['Polo'] = $polos; + + //ADICIONA OS EVENTOS NO ARRAY + array_push($aulas,$aula); + + } + return $aulas; + } + + function gerar_encontros($dados){ + $this->Disciplina->recursive = 2; + $disciplina = $this->Disciplina->findById($dados['Calendario']['disciplina_id']); + $polos_disciplina = $disciplina["Turma"]["0"]['Polo']; + $numSemanas = $disciplina['Disciplina']['numsemanas']; + + $data_inicio_disciplina = $dados['Calendario']['inicio']; + $data_fim_disciplina = $dados['Calendario']['fim']; + + //CRIA ARRAY DOS POLOS DA DISCIPLINA + $polos['Polo'] = array(); + foreach($polos_disciplina as $polo){ + array_push($polos['Polo'],$polo['id']); + } + + $encontros = array(); + + switch ($disciplina['Disciplina']['numsemanas']) { + case 4: + $this->Aula->gerar_aula_40_horas($encontros, + $polos, + $dados['Calendario']['turma_id'], + $dados['Calendario']['disciplina_id'], + $data_inicio_disciplina, + $data_fim_disciplina); + break; + case 6: + $this->Aula->gerar_aula_60_horas($encontros, + $polos, + $dados['Calendario']['turma_id'], + $dados['Calendario']['disciplina_id'], + $data_inicio_disciplina, + $data_fim_disciplina); + break; + case 8: + $this->Aula->gerar_aula_80_horas($encontros, + $polos, + $dados['Calendario']['turma_id'], + $dados['Calendario']['disciplina_id'], + $data_inicio_disciplina, + $data_fim_disciplina); + break; + case 10: + $this->Aula->gerar_aula_100_horas($encontros, + $polos, + $dados['Calendario']['turma_id'], + $dados['Calendario']['disciplina_id'], + $data_inicio_disciplina, + $data_fim_disciplina); + break; + } + + + return $encontros; + + } + + function remover_conflito($dia,$turma_id){ + $this->Evento->recursive = -1; + $dia = date('Y-m-d',strtotime($dia)); + + $eventos = $this->Evento->find('all', array('conditions' => array('Evento.inicio BETWEEN ? AND ?' => array($dia." 00:00:00",$dia." 23:59:59"), + 'Evento.turma_id' => $turma_id, + 'Evento.tipoevento_id NOT' => 5))); + + $num_eventos = count($eventos); + + if($num_eventos <= 2){ + + $conflito = $this->Conflito->findByDia($dia); + if($this->Conflito->delete($conflito['Conflito']['id'])) { + + $conflitos = $this->Conflito->find('all',array('conditions' => array('Conflito.turma_id' => $turma_id))); + + $response = ($conflitos != null)? "":"-"; + foreach($conflitos as $conflito){ + $response .= "
  • ".$conflito['Conflito']['dia']."
  • "; + } + return $response; + + } + } + + return null; + + } +} + +?> diff --git a/app/models/calendario.php b/app/models/calendario.php index eedb422..238d682 100644 --- a/app/models/calendario.php +++ b/app/models/calendario.php @@ -1,7 +1,7 @@ array( - 'className' => 'Tipoevento', - 'foreignKey' => 'tipoevento_id', - 'conditions' => '', - 'fields' => '', - 'order' => '' - ), - 'Disciplina' => array( - 'className' => 'Disciplina', - 'foreignKey' => 'disciplina_id', - 'conditions' => '', - 'fields' => '', - 'order' => '' - ), - 'Turma' => array( - 'className' => 'Turma', - 'foreignKey' => 'turma_id', - 'conditions' => '', - 'fields' => '', - 'order' => '' - ) - ); - - var $hasAndBelongsToMany = array( - 'Polo' => array( - 'className' => 'Polo', - 'joinTable' => 'eventos_polos', - 'foreignKey' => 'evento_id', - 'associationForeignKey' => 'polo_id', - 'unique' => true, - 'conditions' => '', - 'fields' => '', - 'order' => '', - 'limit' => '', - 'offset' => '', - 'finderQuery' => '', - 'deleteQuery' => '', - 'insertQuery' => '' - ) - ); + + var $belongsTo = array('Tipoevento', 'Disciplina', 'Turma', 'Calendario'); + + var $hasAndBelongsToMany = array('Polo'); + + + /* + function salvarAulas($dados){ + + } + + + function criarCalendario($dados){ + + $inicio = $dados["Calendario"]["inicio"].explode('/'); + $ano = $inicio[2]; + + + if($inicio[0] <= 6) + $semestre = 1; + else + $semestre = 2; + + + $calendario["Calendario"] = array("curso_id" => $dados["Calendario"]["curso"], + "ano" => $ano, + "semestre" => $semestre + ); + + $this->Calendario->create(); + $this->Calendario->save($calendario); + + $lastCalendario= $this->Calendario->find('first', array('order' => array('Calendario.created DESC'))); + return $lastCalendario; + }*/ + + } ?> \ No newline at end of file diff --git a/app/views/calendarios/add.ctp b/app/views/calendarios/add.ctp index 93968d3..f606b9e 100755 --- a/app/views/calendarios/add.ctp +++ b/app/views/calendarios/add.ctp @@ -1,21 +1,76 @@ -
    -Form->create('Calendario');?> -
    - - Form->input('curso_id'); - echo $this->Form->input('ano'); - echo $this->Form->input('semestre'); - ?> -
    -Form->end(__('Submit', true));?> -
    -
    -

    - -
    \ No newline at end of file +link(array("/js/jquery/jquery-1.5.2.min","/js/jquery/jquery-ui-1.8.16.custom.min"),false); ?> +Html->css(array('jquery-ui-1.8.13.custom',"bootstrap")); ?> + + + + + + +
    + +
    +
    +
    + +

    Adicionar calendário

    +
    + +
    + Form->create('Calendario', array("class" => "form-stacked"));?> + + + Form->input('curso',array('options' => $cursos,'empty' => 'Selecione...','class' => "normalSelect", "label" => false)); + ?> + + + Form->input('turma_id',array('class' => "styled","label" => false)); ?> + + + Form->input('disciplina_id',array('class' => "styled","label" => false)); ?> + + + + + + + +

    + +

    + + + +
    + +
    +
    + +
    + + + + diff --git a/app/views/calendarios/index.ctp b/app/views/calendarios/index.ctp index 8b257f5..594b08f 100755 --- a/app/views/calendarios/index.ctp +++ b/app/views/calendarios/index.ctp @@ -1,55 +1,47 @@ -
    -

    - - - - - - - - - - > - - - - - - - -
    Paginator->sort('id');?>Paginator->sort('curso_id');?>Paginator->sort('ano');?>Paginator->sort('semestre');?>
      - Html->link($calendario['Curso']['id'], array('controller' => 'cursos', 'action' => 'view', $calendario['Curso']['id'])); ?> -    - Html->link(__('View', true), array('action' => 'view', $calendario['Calendario']['id'])); ?> - Html->link(__('Edit', true), array('action' => 'edit', $calendario['Calendario']['id'])); ?> - Html->link(__('Delete', true), array('action' => 'delete', $calendario['Calendario']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $calendario['Calendario']['id'])); ?> -
    -

    - Paginator->counter(array( - 'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true) - )); - ?>

    +link(array('jquery/jquery-1.5.2.min.js','jquery/jquery-ui-1.8.13.custom.min.js'),false); ?> +Html->css(array('jquery-ui-1.8.13.custom','bootstrap','custom')); ?> -
    - Paginator->prev('<< ' . __('previous', true), array(), null, array('class'=>'disabled'));?> - | Paginator->numbers();?> - | - Paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled'));?> -
    -
    -
    -

    - -
    \ No newline at end of file + + +
    + +
    +
    +
    + +

    Selecionar turma

    +
    + +
    + +
    + Form->input('curso',array('options' => $cursos,'empty' => 'Selecione...','class' => "styled"));?> +

    Form->input('turma_id',array('type' => "select",'empty' => 'Selecione...','class' => "styled")); ?>

    + + +
    +

    + +

    + +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/calendarios/view.ctp b/app/views/calendarios/view.ctp index d99166a..ca0a556 100755 --- a/app/views/calendarios/view.ctp +++ b/app/views/calendarios/view.ctp @@ -1,36 +1,270 @@ -
    -

    -
    - > - > - -   - - > - > - Html->link($calendario['Curso']['id'], array('controller' => 'cursos', 'action' => 'view', $calendario['Curso']['id'])); ?> -   - - > - > - -   - - > - > - -   - -
    +Html->charset(); ?> +link(array('jquery/jquery-1.5.2.min','jquery/jquery-ui-1.8.13.custom.min', + 'fullcalendar/fullcalendar')); + echo $html->css(array("bootstrap",'jquery-ui-1.8.13.custom','fullcalendar',"reset",'custom' + )); +?> + + + + +
    + +
    +
    +
    + +

    Calendário:

    +
    + +
    + +

    Este calendário possui algum conflito. Por favor, verifique as datas logo abaixo.

    + + +
    + +
    +
    +

    input('Disciplina',array('options' => $disciplinas, + 'empty' => 'Selecione...', + 'class' => "styled")); ?>

    + +
    + +
    + + +
    + +
    +
    + +
    + + +
    + +
    +
    +
    + +

    Conflitos

    +
    + +
    + +
    + +
      + +
    • + +
    +
    + +
    + +
    +
    + +
    + + + +
    +
    +
    +

    +

    +
    + +
    -
    -

    - + + + +
    + +
    + + + \ No newline at end of file diff --git a/app/views/layouts/default.ctp b/app/views/layouts/default.ctp index edcdb8d..37d3d20 100755 --- a/app/views/layouts/default.ctp +++ b/app/views/layouts/default.ctp @@ -9,25 +9,6 @@ - - -
    @@ -137,7 +118,23 @@ - - + +