public function postVideo() { ini_set('max_execution_time', 300); $userid = Auth::user()->id; $idcurso = Input::get('idcurso'); $recurso = new Recurso(); $recurso->nombre = Input::get('nombre'); $recurso->descripcion = Input::get('descripcion'); //$file = Input::file('image'); $recurso->activo = Input::get('activo'); $recurso->id_user = 1; $recurso->id_curso = $idcurso; $recurso->save(); $the_id = $recurso->id; $recurso = Recurso::find($the_id); $destinationPath = 'temp/'; $file = Input::file('video'); $filename = $userid . "" . $file->getClientOriginalName(); Input::file('video')->move($destinationPath, $filename); $file = ParseFile::createFromFile($destinationPath . "/" . $filename, $filename); $file->save(); $url = $file->getURL(); $recurso->URL = "" . $url; $jobApplication = new ParseObject("recursos"); $jobApplication->set("myid", $the_id); $jobApplication->set("res", $file); $jobApplication->save(); $recurso->save(); File::delete($destinationPath . "/" . $filename); }
public function show($id) { $this->layout->title = 'Mostrar Recurso'; $this->layout->titulo = 'Gestión de Proyectos'; $recurso = Recurso::find($id); $medida = $recurso->medida; $this->layout->nest('content', 'recursos.show', array('recurso' => $recurso, 'medida' => $medida)); }
public function playVideo($id, $rs) { switch (Auth::user()->tipo) { case 0: return Redirect::to('admin'); break; case 2: $recursos = Curso::find($id)->recursos; $recurso = Recurso::find($rs); $curso = Curso::find($id); return View::make('cursante.reproductor', array('curso' => $curso, 'recurso' => $recurso, 'recursos' => $recursos)); break; } // para buscar al usuario utilizamos el metido find que nos proporciona Laravel // este método devuelve un objete con toda la información que contiene un usuario }
public function validate($data) { //$this->data = $data; //return false; //formatear fechas if (!empty($data['fEvento'])) { $date = DateTime::createFromFormat('d-m-Y', $data['fEvento']); $data['fEvento'] = $date->format('Y-m-d'); } if (!empty($data['fInicio'])) { $date = DateTime::createFromFormat('d-m-Y', $data['fInicio']); $data['fInicio'] = $date->format('Y-m-d'); } if (!empty($data['fFin'])) { $date = DateTime::createFromFormat('d-m-Y', $data['fFin']); $data['fFin'] = $date->format('Y-m-d'); } //mensages //req1: alumno solo pueden reservar entre firstMonday y lastFriday (por implementar) if (Auth::user()->isUser()) { setlocale(LC_ALL, 'es_ES@euro', 'es_ES', 'esp'); $this->messages['fInicio.req1'] = '<br />Puedes reservar entre el <strong>' . strftime('%A, %d de %B de %Y', sgrCalendario::fristMonday()) . '</strong> y el <strong>' . strftime('%A, %d de %B de %Y', sgrCalendario::lastFriday()) . '</strong><br />'; } if (Auth::user()->isAvanceUser()) { setlocale(LC_ALL, 'es_ES@euro', 'es_ES', 'esp'); $this->messages['fInicio.req5'] = 'Puedes reservar a partir del <strong>' . strftime('%A, %d de %B de %Y', sgrCalendario::fristMonday()) . '</strong><br />'; } if (Auth::user()->isTecnico()) { setlocale(LC_ALL, 'es_ES@euro', 'es_ES', 'esp'); $tsToday = strtotime('today'); $this->messages['fInicio.req6'] = 'Puedes reservar a partir del <strong>' . strftime('%A, %d de %B de %Y', $tsToday) . '</strong><br />'; } if (isset($data['dias']) && in_array('6', $data['dias'])) { $this->messages['dias.req4'] = $this->messages['dias.req4'] . " No se puede reservar en <strong>sábado</strong><br />"; } if (isset($data['dias']) && in_array('0', $data['dias'])) { $this->messages['dias.req4'] = $this->messages['dias.req4'] . " No se puede reservar en <strong>domingo</strong><br />"; } if (!empty($data['fFin'])) { $this->messages['fFin.datefincurso'] = 'Las reservas deben de finalizar dentro del curso académico actual. (Fecha limite: ' . date('d-m-Y', strtotime(Config::get('options.fin_cursoAcademico'))) . ')'; } if (!empty($data['fInicio'])) { $this->messages['fInicio.dateiniciocurso'] = 'No es posible realizar reservas hasta que se finalice la carga del POD: fecha prevista a partir del día ' . date('d-m-Y', strtotime(Config::get('options.inicio_gestiondesatendida'))); } if (!empty($data['reservarParaUvus'])) { $this->messages['reservarParaUvus.existeuvus'] = 'Usuario "' . $data['reservarParaUvus'] . '" no registrado.'; } //fin mensages // make a new validator object $v = Validator::make($data, $this->rules, $this->messages); //requisito: reserva para otro usuario -> debe de existir en la Base de Datos if (!empty($data['reservarParaUvus'])) { $v->sometimes('reservarParaUvus', 'existeuvus', function ($data) { if (User::where('username', '=', $data['reservarParaUvus'])->count() == 0) { return true; } }); } //requisito: alumnos no pueden reservar dos recurso a la misma hora, mismo día if (!empty($data['fEvento']) && !empty($data['hFin']) && !empty($data['hInicio'])) { $v->sometimes('fEvento', 'reservaunica', function ($data) { if (Auth::user()->capacidad == '1') { //setlocale(LC_ALL,'es_ES@euro','es_ES','esp'); //determinar si tiene reserva en otro recurso con misma fechaEvento, horainicio y horafin solapadas. $id_recurso = Recurso::find($data['id_recurso'])->id; $where = " (( horaInicio <= '" . $data['hInicio'] . "' and horaFin >= '" . $data['hFin'] . "' ) "; $where .= " or ( horaFin > '" . $data['hFin'] . "' and horaInicio < '" . $data['hFin'] . "')"; $where .= " or ( horaInicio > '" . $data['hInicio'] . "' and horaInicio < '" . $data['hFin'] . "')"; $where .= " or horaFin < '" . $data['hFin'] . "' and horaFin > '" . $data['hInicio'] . "')"; $where .= " and recurso_id != " . $id_recurso; $numEventosOtroRecurso = Evento::where('user_id', '=', Auth::user()->id)->where('fechaEvento', '=', date('Y-m-d', strtotime($data['fEvento'])))->whereRaw($where)->count(); if ($numEventosOtroRecurso > 0) { return true; } } }); } //req1: alumno solo pueden reservar entre firstMonday y lastFriday if (!empty($data['fInicio']) && strtotime($data['fInicio']) != false) { $v->sometimes('fInicio', 'req1', function ($data) { if (Auth::user()->isUser()) { if (sgrCalendario::fristMonday() > strtotime($data['fInicio']) || sgrCalendario::lastFriday() < strtotime($data['fInicio'])) { return true; } } }); } //req2: alumno supera el máximo de horas a la semana (12) // empty($data['action'] -> solo se comprueba en la reserva nueva (add) if (!empty($data['hFin']) && !empty($data['hInicio']) && empty($data['action'])) { $v->sometimes('hFin', 'req2', function ($data) { if (Auth::user()->isUser()) { $nh = Auth::user()->numHorasReservadas(); //Número de horas ya reservadas $nh2 = sgrDate::diffHours($data['hInicio'], $data['hFin']); //números de horas que se quiere reservar $maximo = Config::get('options.max_horas'); $credito = $maximo - $nh; //número de horas que aún puede el alumno reservar if ($credito < $nh2) { return true; } } }); } //deshabilitado if (isset($data['id_recurso']) && $data['id_recurso'] != 0) { $v->sometimes('titulo', 'deshabilitado', function ($data) { if (1 == Recurso::findOrFail($data['id_recurso'])->disabled) { return true; } }); } //req3: if (isset($data['fInicio']) && strtotime($data['fInicio']) != false && isset($data['dias'])) { $v->sometimes('titulo', 'req3', function ($data) { $idrecurso = $data['id_recurso']; $recurso = Recurso::findOrFail($idrecurso); $sgrRecurso = RecursoFactory::getRecursoInstance($recurso->tipo); $sgrRecurso->setRecurso($recurso); $excluyeId = ''; if (isset($data['idSerie'])) { $excluyeId = $data['idSerie']; } return $sgrRecurso->recursoOcupado($data, $excluyeId); }); } //req4: Sábados y domingos no se puede reservar if (isset($data['dias'])) { $v->sometimes('dias', 'req4', function ($data) { $dias = $data['dias']; // 0 = domingo, 6 = sábado if (in_array('0', $dias) || in_array('6', $dias)) { return true; } }); } //Req5: // --> alumnos y pdi (capacidades 1 y 2): solo pueden reservar a partir de firstmonday if (!empty($data['fInicio']) && strtotime($data['fInicio']) != false) { $v->sometimes('fInicio', 'req5', function ($data) { if (Auth::user()->isAvanceUser()) { if (sgrCalendario::fristMonday() > strtotime($data['fInicio'])) { return true; } } }); } //Req6: // --> técnicos (capacidad 3, 4 y 5): reservas a partir del día de hoy (para mañana) if (!empty($data['fInicio']) && strtotime($data['fInicio']) != false) { $v->sometimes('fInicio', 'req6', function ($data) { if (Auth::user()->isTecnico()) { if (strtotime('today') > strtotime($data['fInicio'])) { return true; } } }); } //after: fInicio & fFin > today if (!empty($data['fInicio']) && strtotime($data['fInicio']) != false) { $intFinicio = strtotime($data['fInicio']); $intNow = strtotime('now'); $intDiaAnterior = strtotime('-1 day', $intFinicio); //fecha posterior al día actual $v->sometimes('fInicio', 'after:' . date('d-m-Y', $intDiaAnterior), function ($data) { return true; }); //fecha fin mayor o igual que fecha inicio => mayor que el día anterior a fecha inicio if ($data['repetir'] == 'CS') { $v->sometimes('fFin', 'required|date|date_format:Y-m-d|after:' . date('d-m-Y', $intDiaAnterior), function ($data) { return true; }); } } //after:hinicio < hfin if (!empty($data['hInicio'])) { $aHini = explode(':', $data['hInicio']); $timehorainicio = mktime($aHini[0], $aHini[1]); $v->sometimes('hFin', 'required|date_format:H:i|after:' . date('H:i', $timehorainicio), function ($data) { return true; }); } // requisito: reservas debe finalizar dentro del curso académico actual (Restringido a todos los usuarios menos a los validadores) if (!empty($data['fFin']) && !empty($data['repetir']) && !Auth::user()->isValidador()) { $v->sometimes('fFin', 'datefincurso', function ($data) { $fechaFinCurso = Config::get('options.fin_cursoAcademico'); $fechaMaximaEvento = $data['fEvento']; if ($data['repetir'] == 'CS') { $fechaMaximaEvento = $data['fFin']; } //Reptición cada semana if (strtotime($fechaMaximaEvento) > strtotime($fechaFinCurso)) { return true; } }); } // requisito dateiniciocurso: lasreservas debe de ser posteriores a la fecha de inicio curso actual (Restringido a usuarios alumnos, pdi, administradores y tecnicos) if (!empty($data['fInicio']) && !Auth::user()->isValidador() && !Auth::user()->isAdmin()) { $v->sometimes('fInicio', 'dateiniciocurso', function ($data) { $hoy = strtotime('today'); $diaInicio = strtotime(Config::get('options.inicio_gestiondesatendida')); if ($diaInicio > $hoy) { return true; } }); } // check for failure if ($v->fails()) { $this->errors = $v->messages()->toArray(); return false; } $this->data = $data; //return false; // validation pass return true; }
/** * * //devuelve array objetc User que son validadores del grupo || recurso con identificador $id * @param $idgrupo int identificador de grupo || recurso * @param $tipo string en Config::get('options.objectWithRelation') * @return array() **/ public function ajaxGetValidadores() { //:) //input $id = Input::get('id', ''); $tipo = Input::get('tipo', ''); //Output $result = array('errors' => array(), 'validadores' => '', 'error' => false); //Validate $rules = array('id' => 'required', 'tipo' => 'required|in:' . Config::get('options.objectWithRelation')); $messages = array('required' => 'El campo <strong>:attribute</strong> es obligatorio.', 'in' => 'Tipo de objeto no reconocido'); $validator = Validator::make(Input::all(), $rules, $messages); //Save Input or return error if ($validator->fails()) { $result['errors'] = $validator->errors()->toArray(); $result['error'] = true; return $result; } else { if ($tipo == 'grupo') { $result['validadores'] = grupoRecurso::find($id)->validadores->toArray(); } elseif ($tipo == 'recurso') { $result['validadores'] = Recurso::find($id)->validadores->toArray(); } } return $result; }
public function imprime() { //!!!***Validar parámetros de entrada***!!! //get Input or default $viewActive = Input::get('view', 'month'); $day = Input::get('day', date('d')); $month = Input::get('month', date('m')); $year = Input::get('year', date('Y')); $id_recurso = Input::get('idRecurso', ''); //$id_grupo = Input::get('groupID',''); $id_item = Input::get('item', 0); //Todos los items (equipos o puestos) $titulo = Input::get('titulo', false); $nombre = Input::get('nombre', false); $colectivo = Input::get('colectivo', false); $total = Input::get('total', false); //Total de puestos o equipos de una reserva $datatoprint = array('titulo' => $titulo, 'nombre' => $nombre, 'colectivo' => $colectivo, 'total' => $total); //Información a imprimir seleccionada por el usuario //Output $table = array('tCaption' => '', 'tHead' => '', 'tBody' => ''); $fecha = new DateTime($year . '-' . $month . '-1'); $recurso = Recurso::findOrFail($id_recurso); $sgrRecurso = RecursoFactory::getRecursoInstance($recurso->tipo); $sgrRecurso->setRecurso($recurso); $sgrCalendario = new sgrCalendario($fecha, $sgrRecurso); $table['tCaption'] = CalendarController::caption($viewActive, $day, $sgrCalendario->nombreMes(), $sgrCalendario->year()); switch ($viewActive) { case 'month': $table['tHead'] = CalendarController::head($viewActive, $sgrCalendario); $table['tBody'] = View::make('calendario.printBodyMonth')->with('sgrCalendario', $sgrCalendario)->with('id_recurso', $id_recurso)->with('id_grupo', '')->with('datatoprint', $datatoprint); break; case 'week': $horas = array('8:30', '9:30', '10:30', '11:30', '12:30', '13:30', '14:30', '15:30', '16:30', '17:30', '18:30', '19:30', '20:30', '21:30'); $sgrWeek = $sgrCalendario->sgrWeek(strtotime($year . '-' . $month . '-' . $day)); $table['tHead'] = View::make('calendario.print.weekhead')->with('sgrWeek', $sgrWeek); //$table['tBody'] = View::make('calendario.printBodyWeek')->with('horas',$horas)->with('sgrWeek',$sgrWeek)->with('id_recurso',$id_recurso)->with('id_grupo','')->with('datatoprint',$datatoprint); $table['tBody'] = (string) View::make('calendario.print.weekbody')->with('sgrCalendario', $sgrCalendario); break; default: # code... break; } if (0 != $id_recurso) { $nombre = Recurso::find($id_recurso)->nombre; } else { $recurso = Recurso::where('grupo_id', '=', $id_grupo)->first(); $nombre = $recurso->grupo; } $html = View::make('pdf.calendario')->with(compact('table', 'nombre')); //return $html; $nombreFichero = $day . '-' . $month . '-' . $year . '_' . $nombre; //return $html; $result = myPDF::getPDF($html, $nombreFichero); return Response::make($result)->header('Content-Type', 'application/pdf'); }
public function valida() { $sortby = Input::get('sortby', 'estado'); $order = Input::get('order', 'desc'); $id_recurso = Input::get('id_recurso', '0'); $id_user = Input::get('id_user', '0'); $evento_id = Input::get('evento_id', ''); $action = Input::get('action', ''); $idRecurso = Input::get('idRecurso', '0'); $verpendientes = Input::get('verpendientes'); $veraprobadas = Input::get('veraprobadas'); $verdenegadas = Input::get('verdenegadas'); //$iduser = Input::get('idUser','0';) $espaciosConValidacion = $this->espaciosConValidacion(); //por ejemplo array('10,'11,'21') DONDE 10 -> Salón de actos,11->Sala de juntas, 21->Seminario B2 //validamos (aprobar o denegar) evento $solapamientos = false; $msgforuser = ''; if ($action == 'aprobar') { //vemos si hay solapamientos con solicitudes ya aprobadas $events = Evento::where('evento_id', '=', $evento_id)->get(); foreach ($events as $event) { $where = "fechaEvento = '" . $event->fechaEvento . "' and "; $where .= " (( horaInicio <= '" . $event->horaInicio . "' and horaFin >= '" . $event->horaFin . "' ) "; $where .= " or ( horaFin > '" . $event->horaFin . "' and horaInicio < '" . $event->horaFin . "')"; $where .= " or ( horaInicio > '" . $event->horaInicio . "' and horaInicio < '" . $event->horaFin . "')"; $where .= " or horaFin < '" . $event->horaFin . "' and horaFin > '" . $event->horaInicio . "')"; $where .= " and evento_id != '" . $evento_id . "'"; $where .= " and estado = 'aprobada'"; $numSolapamientos = Recurso::find($idRecurso)->events()->whereRaw($where)->count(); if ($numSolapamientos > 0) { $solapamientos = true; } } if (!$solapamientos) { //update column estado en BD $filasAfectadas = Evento::where('evento_id', '=', $evento_id)->update(array('estado' => 'aprobada')); $accion = 'aprobar'; $solapamientos = false; $msgforuser = '******'; //Aquí mail to -> user_id && validadores de recurso_id ($accion = aprobar | denegar) $sgrMail = new sgrMail(); $sgrMail->notificaValidacion($accion, $evento_id); } else { $solapamientos = true; } } else { Evento::where('evento_id', '=', $evento_id)->update(array('estado' => 'denegada')); $accion = 'denegar'; $msgforuser = '******'; //Aquí mail to -> user_id && validadores de recurso_id ($accion = aprobar | denegar) $sgrMail = new sgrMail(); $sgrMail->notificaValidacion($accion, $evento_id); } return Redirect::to(route('validadorHome.html', array('solapamientos' => $solapamientos, 'sortby' => $sortby, 'order' => $order, 'id_recurso' => $id_recurso, 'id_user' => $id_user, 'idEventoValidado' => $evento_id, 'verpendientes' => $verpendientes, 'veraprobadas' => $veraprobadas, 'verdenegadas' => $verdenegadas, 'msgforuser' => $msgforuser))); }
private function setEstado($idGrupo, $idRecurso, $currentfecha, $hi, $hf) { $estado = 'denegada'; $self = new self(); //si modo automatico validacion = false if (!Recurso::find($idRecurso)->validacion()) { //Ocupado??; -> Solo busco solapamientos con solicitudes ya aprobadas $condicionEstado = 'aprobada'; //$currentFecha tiene formato d-m-Y $numEvents = $self->solapa($idGrupo, $idRecurso, $currentfecha, $hi, $hf, $condicionEstado); //si ocupado if ($numEvents > 0) { //si ocupado $estado = 'denegada'; } else { $estado = 'aprobada'; } } else { //ocupado??; estado = aprobado | pendiente | solapada (cualquiera de los posibles) $condicionEstado = ''; $numEvents = $self->solapa($idGrupo, $idRecurso, $currentfecha, $hi, $hf, $condicionEstado); if ($numEvents > 0) { //si ocupado $estado = 'pendiente'; } else { //si libre // Validadores realizan reservas no solicitudes if (!Auth::user()->isValidador()) { $estado = 'pendiente'; } else { $estado = 'aprobada'; } } } return $estado; }
/** * //Devuelve el campo descripción dado un idrecurso * @param Input::get('idrecurso','') int identificador de recurso * * @return $descripcion string */ public function getDescripcion() { // precindible ?? //Input $idRecurso = Input::get('idrecurso', ''); //Output $result = array('errors' => array(), 'descripcion' => '', 'error' => false); //Validate $rules = array('idrecurso' => 'required|exists:recursos,id'); $messages = array('required' => 'El campo <strong>:attribute</strong> es obligatorio.', 'exists' => 'No existe identificador de recurso en BD.'); $validator = Validator::make(Input::all(), $rules, $messages); //Obtener descripción or return error if ($validator->fails()) { $result['errors'] = $validator->errors()->toArray(); $result['error'] = true; } else { $recurso = Recurso::find($idRecurso); if (empty($recurso->descripcion)) { $result['descripcion'] = $recurso->grupo->descripcion; } else { $result['descripcion'] = $recurso->descripcion; } //descripción del elemento } return $result; }
/** * // Añade recursos existentes sin grupo asisagnado a un grupo * * @param Input::get('grupo_id') int indetificador de grupo * @param Input::get('idrecursos') array indentificadores de recursos añadir al grupo * * @return $result array(boleano,string) */ public function ajaxAddrecursoSingrupo() { // :) //Input $id = Input::get('grupo_id', ''); $idrecursos = Input::get('idrecursos', array()); //Output $result = array('errors' => array(), 'msg' => '', 'error' => false); //Validate $rules = array('grupo_id' => 'required|exists:grupoRecursos,id'); $messages = array('required' => 'El campo <strong>:attribute</strong> es obligatorio....', 'exists' => Config::get('msg.idnotfound')); $validator = Validator::make(Input::all(), $rules, $messages); //Save Input or return error if ($validator->fails()) { $result['errors'] = $validator->errors()->toArray(); $result['error'] = true; } else { foreach ($idrecursos as $idrecurso) { Recurso::find($idrecurso)->update(array('grupo_id' => $id)); } $result['msg'] = (string) View::make('msg.success')->with(array('msg' => Config::get('msg.success'))); } return $result; }