Created
February 14, 2021 23:47
-
-
Save Oxicode/b5f8dca50eaefd1480b64b848cf5382c to your computer and use it in GitHub Desktop.
php artisan check:action_comments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Models; | |
use App\Enums\UserType; | |
use Carbon\Carbon; | |
use DB; | |
use Illuminate\Database\Eloquent\Collection; | |
use Illuminate\Database\Eloquent\Model; | |
use Illuminate\Database\Eloquent\SoftDeletes; | |
/** | |
* Class Videoconferencium | |
* | |
* @property int $id | |
* @property string $nombre_conferencia | |
* @property Carbon $fecha | |
* @property string $hora_ini | |
* @property string $hora_fin | |
* @property int $id_profesor | |
* @property int $id_grado | |
* @property int $estado | |
* @property Carbon|null $fecha_creacion | |
* @property Carbon|null $fecha_modificacion | |
* @property string|null $clave | |
* @property int|null $profesor_entro | |
* @property string|null $link | |
* @property string|null $tipo_video | |
* @property string|null $deleted_at | |
* | |
* @property MaestraGrado $maegrado | |
* @property RelacionAulaDocente $relauladocente | |
* @property Collection|VideoconferenciaAlumno[] $videoconferencia_alumnos | |
* @property Collection|VideoconferenciaSeccion[] $videoconferencia_secciones | |
* | |
* @package App\Models | |
*/ | |
class Videoconferencia extends Model | |
{ | |
use SoftDeletes; | |
const CREATED_AT = 'fecha_creacion'; | |
const UPDATED_AT = 'fecha_modificacion'; | |
protected $table = 'videoconferencia'; | |
protected $casts = [ | |
'id_profesor' => 'int', | |
'id_grado' => 'int', | |
'estado' => 'boolean', | |
'profesor_entro' => 'boolean', | |
]; | |
protected $dates = [ | |
'fecha', | |
'fecha_creacion', | |
'fecha_modificacion', | |
]; | |
protected $fillable = [ | |
'nombre_conferencia', | |
'fecha', | |
'hora_ini', | |
'hora_fin', | |
'id_profesor', | |
'id_grado', | |
'id_curso', | |
'estado', | |
'fecha_creacion', | |
'fecha_modificacion', | |
'clave', | |
'profesor_entro', | |
'link', | |
'tipo_video', | |
]; | |
/** | |
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo | |
*/ | |
public function maestra_grados() | |
{ | |
return $this->belongsTo(\App\Models\MaestraGrado::class, 'id_grado'); | |
} | |
/** | |
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo | |
*/ | |
public function relacion_aula_docentes() | |
{ | |
return $this->belongsTo(\App\Models\RelacionAulaDocente::class, 'id_profesor', 'id_persona'); | |
} | |
/** | |
* @return \Illuminate\Database\Eloquent\Relations\HasMany | |
*/ | |
public function videoconferencia_alumnos() | |
{ | |
return $this->hasMany(\App\Models\VideoconferenciaAlumno::class, 'id_videoconferencia'); | |
} | |
/** | |
* @return \Illuminate\Database\Eloquent\Relations\HasMany | |
*/ | |
public function videoconferencia_secciones() | |
{ | |
return $this->hasMany(\App\Models\VideoconferenciaSeccion::class, 'id_videoconferencia'); | |
} | |
public static function search(int $role_usuario, int $id_persona, string $search, int $id_curso) | |
{ | |
$tableVideoconferencia = (new Videoconferencia())->getTable(); | |
$tableVideoconferenciaSeccion = (new VideoconferenciaSeccion())->getTable(); | |
$tableMaestraSeccion = (new MaestraSeccion())->getTable(); | |
$tableVideoconferenciaAlumno = (new VideoconferenciaAlumno())->getTable(); | |
$tableMaestraPersona = (new MaestraPersona())->getTable(); | |
$tableMaestraGrado = (new MaestraGrado())->getTable(); | |
$select = [ | |
"{$tableVideoconferencia}.id", | |
'nombre_conferencia', | |
'fecha', | |
DB::raw("CONCAT(fecha, ' ', hora_ini) as fecha_hora"), | |
'hora_ini', | |
'hora_fin', | |
'id_profesor', | |
'id_grado', | |
"{$tableVideoconferencia}.estado", | |
'fecha_creacion', | |
'fecha_modificacion', | |
'clave', | |
'profesor_entro', | |
"{$tableMaestraPersona}.ape_pat_per AS nombre_profesor", | |
DB::raw("(SELECT GROUP_CONCAT(m.nom_seccion) FROM {$tableVideoconferenciaSeccion} vs | |
INNER JOIN {$tableMaestraSeccion} m ON m.id = vs.id_seccion | |
WHERE {$tableVideoconferencia}.id = vs.id_videoconferencia) AS secciones"), | |
DB::raw('(CASE WHEN id_profesor != ' . $id_persona . ' THEN 1 ELSE 0 END) AS es_invitado'), | |
DB::raw("CONCAT(nombre_conferencia, ' ', {$tableMaestraPersona}.ape_pat_per) as conferencia_alumno"), | |
DB::raw("(SELECT leido FROM {$tableVideoconferenciaAlumno} WHERE {$tableVideoconferenciaAlumno}.id_videoconferencia = {$tableVideoconferencia}.id AND {$tableVideoconferenciaAlumno}.id_alumno = " . $id_persona . ') AS leido'), | |
'link', | |
'tipo_video', 'nom_grado', | |
DB::raw("(CASE WHEN {$tableVideoconferencia}.estado = 1 THEN 'PENDIENTE' WHEN {$tableVideoconferencia}.estado = 2 THEN 'EN PROCESO' WHEN {$tableVideoconferencia}.estado = 3 THEN 'FINALIZADO' END) AS nom_estado"), | |
]; | |
$list = Videoconferencia::select($select) | |
->leftJoin($tableMaestraGrado, "{$tableVideoconferencia}.id_grado", '=', "{$tableMaestraGrado}.id") | |
->join($tableMaestraPersona, "{$tableVideoconferencia}.id_profesor", '=', "{$tableMaestraPersona}.id"); | |
switch ($role_usuario) { | |
case UserType::ESTUDIANTE: | |
$list->where(function ($q) use ($id_persona, $tableVideoconferencia, $tableVideoconferenciaAlumno) { | |
$q->from($tableVideoconferenciaAlumno) | |
->selectRaw("count({$tableVideoconferenciaAlumno}.id)") | |
->whereRaw("{$tableVideoconferenciaAlumno}.id_videoconferencia = {$tableVideoconferencia}.id") | |
->where('id_alumno', $id_persona); | |
}, '>=', DB::raw('1')); | |
break; | |
case UserType::DOCENTE: | |
$list->where(function ($q) use ($id_persona, $tableVideoconferencia, $tableVideoconferenciaAlumno) { | |
$q->where('id_profesor', $id_persona) | |
->orWhere(function ($q) use ($id_persona, $tableVideoconferencia, $tableVideoconferenciaAlumno) { | |
$q->from($tableVideoconferenciaAlumno) | |
->selectRaw("count({$tableVideoconferenciaAlumno}.id)") | |
->whereRaw("{$tableVideoconferenciaAlumno}.id_videoconferencia = {$tableVideoconferencia}.id") | |
->where('id_alumno', $id_persona); | |
}, '>=', DB::raw('1')); | |
}); | |
break; | |
default: | |
$list->where('id_profesor', $id_persona); | |
break; | |
} | |
if ($search !== null && trim($search) != '') { | |
$list->where(function ($q) use ($search, $tableMaestraPersona) { | |
$q->where('nombre_conferencia', 'like', '%' . $search . '%') | |
->orWhere("{$tableMaestraPersona}.ape_pat_per", 'like', '%' . $search . '%'); | |
}); | |
} | |
if ((int) $id_curso !== 0) { | |
$list->where('id_curso', $id_curso); | |
} | |
$list->whereNull("{$tableVideoconferencia}.deleted_at"); | |
return $list; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Tests\Feature; | |
use Illuminate\Support\Facades\Session; | |
use Tests\TestCase; | |
class VideoconferenciasTest extends TestCase | |
{ | |
protected $userEstudiante; | |
public function testNoLogin(): void | |
{ | |
$response1 = $this->get(route('videoconference.index')); | |
$response1->assertStatus(302); | |
$response2 = $this->get(route('videoconference.mis_conferencias')); | |
$response2->assertStatus(302); | |
$response3 = $this->get(route('videoconference.form', 0)); | |
$response3->assertStatus(302); | |
} | |
public function testNoAutorizadoEstudiante(): void | |
{ | |
$userDocente = $this->fakeLoginDocente(); | |
$response2 = $this->actingAs($userDocente)->get(route('videoconference.mis_conferencias')); | |
$response2->assertStatus(403); | |
} | |
public function testNoAutorizadoDocente(): void | |
{ | |
$userEstudiante = $this->fakeLoginEstudiante(); | |
$response2 = $this->actingAs($userEstudiante)->get(route('videoconference.index')); | |
$response2->assertStatus(403); | |
} | |
public function testIndex(): void | |
{ | |
$userDocente = $this->fakeLoginDocente(); | |
$response = $this->actingAs($userDocente)->get(route('videoconference.index')); | |
$response->assertSee('Tiempo fuera de lo programado para acceder a la vídeo conferencia'); | |
} | |
public function testMisConferencias(): void | |
{ | |
$userEstudiante = $this->fakeLoginEstudiante(); | |
$response = $this->actingAs($userEstudiante)->get(route('videoconference.mis_conferencias')); | |
$response->assertSee('Tiempo fuera de lo programado para acceder a la vídeo conferencia'); | |
} | |
public function testVideoconferenceNew(): void | |
{ | |
$userDocente = $this->fakeLoginDocente(); | |
$response1 = $this->actingAs($userDocente)->get(route('videoconference.form', 0)); | |
$response1->assertSee('Título de video conferencia', 'Para iniciar nueva'); | |
} | |
public function testVideoconferenceExistente(): void | |
{ | |
$userDocente1 = $this->fakeLoginDocente(); | |
$VideconferenceRandom = \App\Models\Videoconferencia::inRandomOrder()->first(); | |
$response2 = $this->actingAs($userDocente1)->get(route('videoconference.form', $VideconferenceRandom->id)); | |
$response2->assertStatus(200); | |
} | |
public function testVideoconferenceNoExistente(): void | |
{ | |
$userDocente1 = $this->fakeLoginDocente(); | |
$response3 = $this->actingAs($userDocente1)->get(route('videoconference.form', 9999)); | |
$response3->assertStatus(404); | |
} | |
public function testApiLoadCursos(): void | |
{ | |
$userDocente = $this->fakeLoginDocente(); | |
$id_grado = Session::get('session_user')->aulas[0]->id_grado; | |
$response1 = $this->actingAs($userDocente) | |
->post('/api/videoconference-loadCursos', ['id_grado' => $id_grado]) | |
->assertStatus(200); | |
$this->assertEquals($response1['result'], 'ok'); | |
$this->assertEquals($response1['data'][0]['id_grado'], $id_grado); | |
} | |
public function testApiSearchFake(): void | |
{ | |
$userDocente = $this->fakeLoginDocente(); | |
$response1 = $this->actingAs($userDocente) | |
->post('/api/videoconference-search?search=randomString', []) | |
->assertStatus(200); | |
$this->assertEquals($response1['recordsTotal'], 0); | |
} | |
public function testApiSearch(): void | |
{ | |
$userEstudiante = $this->fakeLoginEstudiante(); | |
$totalCreated = \App\Models\Videoconferencia::where('nombre_conferencia', 'LIKE', 'Conferencia')->where('id_grado', Session::get('id_grado'))->count(); | |
$this->actingAs($userEstudiante) | |
->post('/api/videoconference-search?search=Conferencia', []) | |
->assertStatus(200); | |
#$this->assertEquals($response1['recordsTotal'], $totalCreated); | |
} | |
public function testApiSearchUser(): void | |
{ | |
$userEstudiante = $this->fakeLoginEstudiante(); | |
$this->actingAs($userEstudiante) | |
->post('/api/search-users', [ | |
'tipo_usuario' => Session::get('session_user')->role_usuario, | |
'id_grado' => Session::get('session_user')->id_grado, | |
'secciones' => Session::get('session_user')->id_seccion, | |
'modulo' => 'videoconferencia', | |
]) | |
->assertStatus(200) | |
->assertSee('id_persona'); | |
} | |
// Todo Falta el apoderado | |
public function testApiSaveNew(): void | |
{ | |
$userDocente = $this->fakeLoginDocente(); | |
$trama = [ | |
'id' => 0, | |
'nombre_conferencia' => 'Conferencia Fake Gmeet', | |
'fecha' => '01/01/2021', | |
'hora_ini' => '08:00', | |
'hora_fin' => '09:00', | |
'link' => 'https://fake.url/demo', | |
'tipo_video' => \App\Enums\VideoconferenciaType::GOOGLE_MEET, | |
'tipo_usuario' => \App\Enums\UserType::ESTUDIANTE, | |
'id_grado' => Session::get('session_user')->aulas[0]->id_grado, | |
'id_curso' => Session::get('session_user')->aulas[0]->id_seccion, | |
]; | |
$response = $this->actingAs($userDocente) | |
->post('/api/videoconference-save', $trama) | |
->assertStatus(200); | |
$this->assertEquals($response['result'], 'ok'); | |
$trama = [ | |
'nombre_conferencia' => 'Conferencia Fake Zoom', | |
'fecha' => '01/01/2021', | |
'hora_ini' => '08:00', | |
'hora_fin' => '09:00', | |
'id' => 0, | |
'link' => 'https://fake.url/demo', | |
'tipo_video' => \App\Enums\VideoconferenciaType::ZOOM, | |
'tipo_usuario' => \App\Enums\UserType::ESTUDIANTE, | |
'id_grado' => Session::get('session_user')->aulas[0]->id_grado, | |
'id_curso' => Session::get('session_user')->aulas[0]->id_seccion, | |
]; | |
$response = $this->actingAs($userDocente) | |
->post('/api/videoconference-save', $trama) | |
->assertStatus(200); | |
$this->assertEquals($response['result'], 'ok'); | |
} | |
public function testApiSaveUpdate(): void | |
{ | |
$userDocente = $this->fakeLoginDocente(); | |
$VideoconferenciaRandom = \App\Models\Videoconferencia::inRandomOrder()->first(); | |
$trama = [ | |
'nombre_conferencia' => 'Conferencia (Update)', | |
'fecha' => '01/01/2021', | |
'hora_ini' => '09:30', | |
'hora_fin' => '10:30', | |
'id' => $VideoconferenciaRandom->id, | |
'link' => 'https://fake.url/demo2', | |
'tipo_video' => \App\Enums\VideoconferenciaType::GOOGLE_MEET, | |
]; | |
$response = $this->actingAs($userDocente) | |
->post('/api/videoconference-save', $trama) | |
->assertStatus(200); | |
$this->assertEquals($response['result'], 'ok'); | |
} | |
public function testApiDeleteRandom(): void | |
{ | |
$userDocente = $this->fakeLoginDocente(); | |
$VideoconferenciaRandom = \App\Models\Videoconferencia::inRandomOrder()->first(); | |
$trama = [ | |
'id' => $VideoconferenciaRandom->id, | |
]; | |
$response = $this->actingAs($userDocente) | |
->post('/api/videoconference-delete', $trama) | |
->assertStatus(200); | |
$this->assertEquals($response['result'], 'ok'); | |
} | |
public function testApiDeleteGhost(): void | |
{ | |
$userDocente = $this->fakeLoginDocente(); | |
$this->actingAs($userDocente) | |
->post('/api/videoconference-delete', ['id' => 9999]) | |
->assertStatus(404); | |
} | |
public function testApiEntered(): void | |
{ | |
$userDocente = $this->fakeLoginDocente(); | |
$VideoconferenciaRandom = \App\Models\Videoconferencia::inRandomOrder()->first(); | |
$trama = [ | |
'id' => $VideoconferenciaRandom->id, | |
'es_invitado' => 1, | |
]; | |
$response = $this->actingAs($userDocente) | |
->post('/api/videoconference-entered', $trama) | |
->assertStatus(200); | |
$this->assertEquals($response['result'], 'ok'); | |
} | |
public function testApiEnteredInvitado(): void | |
{ | |
$userDocente = $this->fakeLoginDocente(); | |
$VideoconferenciaRandom = \App\Models\Videoconferencia::inRandomOrder()->first(); | |
$trama = [ | |
'id' => $VideoconferenciaRandom->id, | |
'es_invitado' => 0, | |
]; | |
$response = $this->actingAs($userDocente) | |
->post('/api/videoconference-entered', $trama) | |
->assertStatus(200); | |
$this->assertEquals($response['result'], 'ok'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment