public function execute(array $args)
 {
     if (isset($args['e_id'])) {
     } else {
         $usersMaper = MySQLEntityManager::createMaper(User::class);
         $body = $usersMaper->select('id, nombre, rol_id')->with('rol');
     }
     return $this->responseInfo = ['body' => $body->toArray(), 'status' => self::STATUS_OK];
 }
 public function execute(array $args)
 {
     $maper = MySQLEntityManager::createMaper(SolicitudPQR::class);
     if ($maper->delete(['id' => $args['pqr_id']])) {
         return $this->responseInfo = ['body' => '', 'status' => self::STATUS_OK];
     } else {
         return false;
     }
 }
 public function execute(array $args)
 {
     $maper = MySQLEntityManager::createMaper(SolicitudPQR::class);
     $data = $maper->get($args['pqr_id'])->toArray();
     if ($data) {
         return $this->responseInfo = ['body' => $data, 'status' => self::STATUS_OK];
     } else {
         return false;
     }
 }
 public function execute(array $args)
 {
     $data = json_decode($this->request->getBody());
     $maper = MySQLEntityManager::createMaper(SolicitudPQR::class);
     $result = $maper->create(['cedula_empleado' => $data->cedula_empleado, 'mensaje' => $data->mensaje]);
     if ($result) {
         return $this->responseInfo = ['body' => $result, 'status' => self::STATUS_CREATED];
     } else {
         return false;
     }
 }
 public function execute(array $args)
 {
     $data = json_decode($this->request->getBody());
     $mapper = MySQLEntityManager::createMaper(User::class);
     $user = $mapper->checkUser($data);
     $tokenId = base64_encode(mcrypt_create_iv(32));
     if ($user) {
         $signer = new Sha256();
         $token = (new Builder())->setId($tokenId, true)->setIssuedAt(time())->set('user', $user)->sign($signer, getenv("SECRET_KEY"))->getToken();
         return $this->responseInfo = ['body' => ['token' => "{$token}"], 'status' => self::STATUS_OK];
     } else {
         return $this->responseInfo = ['body' => ['msj' => 'credenciales incorrestas'], 'status' => self::STATUS_UNAUTHORIZED];
     }
 }
 public function execute(array $args)
 {
     $data = json_decode($this->request->getBody());
     $mapper = MySQLEntityManager::createMaper(User::class);
     $user = $mapper->checkUser($data->id_user, $data->username);
     if ($user) {
         $user = $mapper->get($data->id_user);
         $user->contrasena = password_hash($data->new_password, PASSWORD_BCRYPT);
         $mapper->update($user);
         return $this->responseInfo = ['body' => ['body' => 'contraseña actualizada'], 'status' => self::STATUS_OK];
     } else {
         return false;
     }
 }
 public function execute(array $args)
 {
     $data = json_decode($this->request->getBody());
     $maper = MySQLEntityManager::createMaper(SolicitudPQR::class);
     $solicitud_pqr = $maper->get($data->id);
     if ($solicitud_pqr) {
         $solicitud_pqr->respuesta = $data->respuesta;
         $solicitud_pqr->fecha_respuesta = new \DateTime();
         $solicitud_pqr->usuario_que_responde = $data->user_id;
         $maper->update($solicitud_pqr);
         return $this->responseInfo = ['body' => '', 'status' => self::STATUS_OK];
     } else {
         return false;
     }
 }
 public function execute(array $args)
 {
     $manager = MySQLEntityManager::createMaper(Periodo::class);
     $periodos = $manager->where(['anio' => $args['anio']]);
     if (count($periodos) == 0) {
         $periodo = 1;
         for ($i = 1; $i <= 12; $i++) {
             $mes = $i < 10 ? "0{$i}" : $i;
             $periodo1 = $manager->create(['anio' => $args['anio'], 'numero' => $periodo, 'fecha_inicial' => new \DateTime($args['anio'] . '-' . $mes . '-01'), 'fecha_final' => new \DateTime($args['anio'] . '-' . $mes . '-15')]);
             $periodo++;
             $periodo2 = $manager->create(['anio' => $args['anio'], 'numero' => $periodo, 'fecha_inicial' => new \DateTime($args['anio'] . '-' . $mes . '-16'), 'fecha_final' => new \DateTime($args['anio'] . '-' . $mes . '-' . date("d", mktime(0, 0, 0, $mes + 1, 1, $args['anio']) - 1))]);
             $periodo++;
         }
         $periodos = $manager->where(['anio' => $args['anio']]);
     }
     return $this->responseInfo = ['body' => $periodos->toArray(), 'status' => self::STATUS_CREATED];
 }
 public function execute(array $args)
 {
     $maper = MySQLEntityManager::createMaper(SolicitudPQR::class);
     $solicitudes_pqr = $maper->query('SELECT s1.* FROM solicitudes_pqr s1 ORDER BY s1.fecha');
     $data = [];
     foreach ($solicitudes_pqr as $solicitud) {
         $s = $solicitud->toArray();
         $empleado = new Empleado($solicitud->cedula_empleado);
         $s['empleado'] = $empleado->getData();
         array_push($data, $s);
     }
     if ($data) {
         return $this->responseInfo = ['body' => $data, 'status' => self::STATUS_OK];
     } else {
         return false;
     }
 }
 public function getCertificado(array $args)
 {
     if (isset($args['crt_id'])) {
         // TODO: implementar metodo para la validacion de los certificados
     } elseif (isset($args['e_id']) && isset($args['tipo_crt'])) {
         $certificado_id = $this->getCertificadoId($args['e_id'], $args['tipo_crt']);
         $certificadosMaper = MySQLEntityManager::createMaper(Certificado::class);
         $certificado = $certificadosMaper->get($certificado_id);
         if ($certificado) {
             return $certificado;
         } else {
             $certificado = $certificadosMaper->create(['id' => $certificado_id, 'cedula_empleado' => $args['e_id'], 'tipo' => $args['tipo_crt']]);
             return $certificado;
         }
     } else {
         return false;
     }
 }
Exemplo n.º 11
0
 public function execute(array $args)
 {
     $usersMaper = MySQLEntityManager::createMaper(User::class);
     $rolesMaper = MySQLEntityManager::createMaper(Rol::class);
     $count_nuevos = 0;
     $count_actualizados = 0;
     $empleados = EmpleadosMaper::all();
     $rolEmpleados = $rolesMaper->first(['nombre' => 'EMPL_ORD']);
     $rolEmpleadosTemporales = $rolesMaper->first(['nombre' => 'EMPL_ORD_TEMP']);
     $rolEmpleadosInactivos = $rolesMaper->first(['nombre' => 'EMPL_ORD_INACTIVO']);
     foreach ($empleados as $empleado) {
         $usuario = null;
         if (!($usuario = $usersMaper->first(['nombre' => $empleado->cedula]))) {
             $vinculacion_empleado = $empleado->vinculacion();
             if ($vinculacion_empleado['CODIGO'] == '01') {
                 if ($empleado->estadoC() == 'R') {
                     $usuario = $usersMaper->build(['nombre' => $empleado->cedula, 'contrasena' => password_hash($empleado->cedula, PASSWORD_BCRYPT), 'rol_id' => $rolEmpleadosInactivos->id]);
                 } else {
                     $usuario = $usersMaper->build(['nombre' => $empleado->cedula, 'contrasena' => password_hash($empleado->cedula, PASSWORD_BCRYPT), 'rol_id' => $rolEmpleados->id]);
                 }
             } else {
                 $usuario = $usersMaper->build(['nombre' => $empleado->cedula, 'contrasena' => password_hash($empleado->cedula, PASSWORD_BCRYPT), 'rol_id' => $rolEmpleadosTemporales->id]);
             }
             $usersMaper->save($usuario);
             ++$count_nuevos;
         } else {
             $vinculacion_empleado = $empleado->vinculacion();
             if ($vinculacion_empleado['CODIGO'] == '01') {
                 if ($empleado->estadoC() == 'R') {
                     $usuario->rol_id = $rolEmpleadosInactivos->id;
                 } else {
                     $usuario->rol_id = $rolEmpleados->id;
                 }
             } else {
                 $usuario->rol_id = $rolEmpleadosTemporales->id;
             }
             $usersMaper->save($usuario);
             ++$count_actualizados;
         }
     }
     $body = ['empleados agregados' => $count_nuevos, 'empleados actualizados' => $count_actualizados, 'total_empleados' => count($empleados)];
     return $this->responseInfo = ['body' => $body, 'status' => self::STATUS_CREATED];
 }
 public function execute(array $args)
 {
     $maper = MySQLEntityManager::createMaper(SolicitudPQR::class);
     if (isset($args['e_id'])) {
         $solicitud_pqr = $maper->where(['cedula_empleado' => $args['e_id']])->order(['fecha' => 'DESC'])->first();
         $data = $solicitud_pqr ? $solicitud_pqr : $maper->build(['id' => -1, 'cedula_empleado' => $args['e_id']]);
     } else {
         $solicitudes_pqr = $maper->query('SELECT s1.* FROM solicitudes_pqr s1 ORDER BY s1.fecha');
         $data = [];
         foreach ($solicitudes_pqr as $solicitud) {
             $s = $solicitud->toArray();
             $s['empleado'] = new Empleado($solicitud->cedula_empleado);
             array_push($data, $s);
         }
     }
     if ($data) {
         return $this->responseInfo = ['body' => $data, 'status' => self::STATUS_OK];
     } else {
         return false;
     }
 }
 public function execute(array $args)
 {
     $manager = MySQLEntityManager::createMaper(Periodo::class);
     $periodo = $manager->getActual();
     return $this->responseInfo = ['body' => $periodo, 'status' => self::STATUS_CREATED];
 }
 public function __invoke(Request $request, Response $response, $args)
 {
     $decoded_jwt = $args["decoded"];
     $mapper = MySQLEntityManager::createMaper(User::class);
     return $mapper->checkUser($decoded_jwt->user->id, $decoded_jwt->user->nombre);
 }