Skip to content

Commit

Permalink
Develop (#1)
Browse files Browse the repository at this point in the history
* Agrega soporte para usar run de alumno como nombre de usuario

* Corrección de Mensaje de configuración

* Agrega Logo de SENCE en el bloque

* Ajuste de Actualización

* Actualiza Logo SENCE
  • Loading branch information
fauzcategui authored Jul 13, 2020
1 parent 4301761 commit 4ba5410
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 21 deletions.
Binary file added assets/sence-logo.webp
Binary file not shown.
10 changes: 7 additions & 3 deletions block_sence.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,41 @@ public function get_content() {

if( !$sence->existen_campos_sence() ){
$this->content->text = $sence->formatea_html_error( get_string('error_campos', 'block_sence') );
$this->content->footer = $sence->print_logo();
return $this->content;
}

if( !$sence->es_alumno() ){
$this->content->text = $sence->formatea_html_correcto( get_string('bienvenido', 'block_sence'). ' ' . $USER->firstname );
$this->content->footer = $sence->print_logo();
return $this->content;
}

if( !$sence->tiene_run() ){
$this->content->text = $sence->formatea_html_error( get_string('error_run', 'block_sence') );
$this->content->footer = $sence->style_blocker();
$this->content->footer = $sence->print_logo() . $sence->style_blocker();
return $this->content;
}

if( !$sence->es_alumno_sence() ){
$this->content->text = $sence->formatea_html_correcto( get_string('bienvenido', 'block_sence'). ' ' . $USER->firstname );
$this->content->footer = $sence->exige_asistencia() ? $sence->style_blocker() : '';
$this->content->footer = $sence->exige_asistencia() ? $sence->print_logo() . $sence->style_blocker() : $sence->print_logo();
return $this->content;
}
if( $sence->tiene_asistencia() ){
$this->content->text = $sence->formatea_html_correcto( get_string('bienvenido', 'block_sence'). ' ' . $USER->firstname . '<br>¡Ya registraste tu asistencia!' );
$this->content->footer = $sence->print_logo();
return $this->content;
}

if( isset( $_POST['RunAlumno'] ) ){
$this->content->text = $sence->procesa_respuesta( $_POST, $this->page->url );
$this->content->footer = $sence->print_logo();
return $this->content;
}

$this->content->text = $sence->prepare_form( $this->page->url );
$this->content->footer = $sence->style_blocker();
$this->content->footer = $sence->print_logo() . $sence->style_blocker();
return $this->content;
}

Expand Down
21 changes: 21 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* File containing Sence Module Block class.
*
* @package block_sence
* @copyright 2020 onwards Felipe Uzcátegui
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

/**
* Upgrade code for the HTML block.
*
* @param int $oldversion
*/
function xmldb_block_sence_upgrade($oldversion) {
global $CFG;

return true;
}
31 changes: 25 additions & 6 deletions engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
class Engine{

private $alumnos = [];
private $runAlumno;
private $CodSence;
private $lineadecap;
private $urlInicioTest = 'https://sistemas.sence.cl/rcetest/Registro/IniciarSesion';
Expand All @@ -53,7 +54,7 @@ public function procesa_respuesta( $req, $currenturl ){
$LineaCapacitacion = isset($req['LineaCapacitacion']) ? $req['LineaCapacitacion'] : 0;
$GlosaError = isset($req['GlosaError']) ? $req['GlosaError'] : 0;
if( $GlosaError > 0 ){
return $this->describe_error( $GlosaError ) . '<br>' . $this->prepare_form( $currenturl );
return $this->describe_error( $GlosaError ) . $this->prepare_form( $currenturl );
}
$this->registra_asistencia_moodle();
return $this->formatea_html_correcto('Asistencia SENCE Registrada!');
Expand Down Expand Up @@ -120,7 +121,7 @@ public function es_alumno_sence(){
$this->alumnos = $this->parsear_codigo_alumnos( $blockinstance->config->alumnos );
$this->lineadecap = $blockinstance->config->lineadecap;

return array_key_exists( strtolower($USER->idnumber), $this->alumnos);
return array_key_exists( strtolower($this->runAlumno ), $this->alumnos);
}

public function es_alumno(){
Expand All @@ -131,18 +132,29 @@ public function es_alumno(){

public function tiene_run(){
global $USER;
$run = explode('-', $USER->idnumber );
return count($run) == 2;

if( preg_match('/\d*-[0-9kK]/', $USER->username) ){
$this->runAlumno = strtolower($USER->username);
return true;
}

if( preg_match('/\d*-[0-9kK]/', $USER->idnumber) ){
$this->runAlumno = strtolower($USER->idnumber);
return true;
}

return false;

}

public function prepare_form( $currenturl ){
global $USER, $CFG, $COURSE;
$RunAlumno = strtolower($USER->idnumber);
$RunAlumno = $this->runAlumno;
$CodigoCurso = $this->alumnos[ $RunAlumno ];
$IdSesionAlumno = '2';
$CodSence = $this->CodSence;

return '<form method="POST" action="'.$this->urlInicio.'">
return '<form style="text-align:center;" method="POST" action="'.$this->urlInicio.'">
<button type="submit" style="padding:10px;background:#0056a8;color:#fff;font-weight:700;border-radius:5px;border:0px;">
Iniciar Sesión
</button>
Expand Down Expand Up @@ -217,4 +229,11 @@ public function formatea_html_error($string){
public function formatea_html_correcto($string){
return '<div style="padding:10px; background-color:#ebf2b8; border-radius:5px;">'. $string .'</div>';
}

public function print_logo(){
global $CFG;
return '<div style="width:100%; text-align:center;">
<image style="width:50%;" src="'.$CFG->wwwroot.'/blocks/sence/assets/sence-logo.webp">
</div>';
}
}
2 changes: 1 addition & 1 deletion lang/en/block_sence.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
$string['codigocurso'] = 'Código SENCE del Curso';
$string['lineadecap'] = 'Líneas de Capacitación';
$string['confalumnos'] = 'Lista de Alumnos ';
$string['permit'] = 'Al tildar esta opción estarás permitiendo que alumnos que no esten en el listado inferior puedan ver el curso';
$string['permit'] = 'Habilitar curso solo para alumnos con código SENCE';
$string['instrucciones'] = 'Instrucciones de como agregar a los alumnos para que puedan usar SENCE';
$string['sence:myaddinstance'] = 'Integrar SENCE';
$string['sence:addinstance'] = 'Integrar SENCE';
Expand Down
2 changes: 1 addition & 1 deletion lang/es/block_sence.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
$string['codigocurso'] = 'Código SENCE del Curso';
$string['lineadecap'] = 'Líneas de Capacitación';
$string['confalumnos'] = 'Lista de Alumnos ';
$string['permit'] = 'Al tildar esta opción estarás permitiendo que alumnos que no esten en el listado inferior puedan ver el curso';
$string['permit'] = 'Habilitar curso solo para alumnos con código SENCE';
$string['instrucciones'] = 'Instrucciones de como agregar a los alumnos para que puedan usar SENCE';
$string['sence:myaddinstance'] = 'Integrar SENCE';
$string['sence:addinstance'] = 'Integrar SENCE';
Expand Down
10 changes: 0 additions & 10 deletions tests/TestCase.php

This file was deleted.

0 comments on commit 4ba5410

Please sign in to comment.