public function participar($idEve) { $vdt = new Validate\Validator(); $vdt->addRule('idEve', new Validate\Rule\NumNatural())->addFilter('presente', FilterFactory::booleanFilter())->addFilter('publico', FilterFactory::booleanFilter()); $req = $this->request; $data = array_merge(array('idEve' => $idEve), $req->post()); if (!$vdt->validate($data)) { throw new TurnbackException($vdt->getErrors()); } $usuario = $this->session->getUser(); $evento = Evento::findOrFail($idEve); $hoy = Carbon\Carbon::now(); if ($hoy->gt($evento->fecha)) { throw new TurnbackException('El evento ya ha ocurrido.'); } $sumaPost = $vdt->getData('presente') ? 3 : 1; $participe = $evento->usuarios()->where('usuario_id', $usuario->id)->first(); if (is_null($participe)) { $evento->usuarios()->attach($usuario->id, ['presente' => $vdt->getData('presente'), 'publico' => $vdt->getData('publico')]); } else { $participe->pivot->presente = $vdt->getData('presente'); $participe->pivot->publico = $vdt->getData('publico'); $participe->pivot->save(); $sumaPost -= $participe->pivot->presente ? 3 : 1; } if ($sumaPost != 0) { $evento->contenido()->increment('puntos', $sumaPost); } $this->flash('success', 'Su participación fue registrada exitosamente.'); $this->redirectTo('shwEvento', array('idEve' => $evento->id)); }
/** * //Devulve los datos de un evennto dado su identificador ($id) * @param $id int (identificador de evento) * @return $result array */ public function getbyId() { $result = array('event' => array(), 'usernameReservadoPor' => '', 'usernameReservadoPara' => '', 'nombreRecursoReservado' => ''); $event = Evento::findOrFail(Input::get('id')); $result['event'] = $event->toArray(); $result['usernameReservadoPara'] = $event->user->username; $result['usernameReservadoPor'] = $event->reservadoPor->username; $result['nombreRecursoReservado'] = $event->recurso->nombre; return $result; }
/** * Update the specified evento in storage. * * @param int $id * @return Response */ public function update($id) { $evento = Evento::findOrFail($id); $validator = Validator::make($data = Input::all(), Evento::$rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } $evento->update($data); return Redirect::route('eventos.index'); }
public function anularEvento() { $result = array('error' => false, 'msgError' => '', 'msgSuccess' => ''); $idEvento = Input::get('idevento', ''); if (empty($idEvento)) { $result['error'] = true; $result['msgError'] = Config::get('msg.idempty'); return $result; } //$finalizarEvento = new FinalizarEvento; $evento = Evento::findOrFail($idEvento); //$evento->estado = 'anulado'; $evento->delete(); //Softdelete $result['msgSuccess'] = Config::get('msg.actionSuccess'); return $result; }