orderByAsc('descripcion')->findMany(); return view('temas.add', compact('proyectos')); } public static function agregar() { $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); $data = [ "proyecto_id" => post('proyecto'), "inicio" => $f->format('Y-m-d'), "texto" => post('texto') ]; $tema = model(Tema::class)->create($data); $tema->save(); header('Location: ' . url('', ['p' => 'temas', 'a' => 'list'])); } public static function list() { $temas = model(Tema::class)->findMany(); $t = Carbon::today(config('app.timezone')); foreach ($temas as $i => $tema) { if ($tema->cierre()->year != -1 and $t->diff($tema->cierre())->days > 10) { unset($temas[$i]); } } $temas = array_values($temas); usort($temas, function($a, $b) { $p = strcmp($a->proyecto()->descripcion, $b->proyecto()->descripcion); if ($p == 0) { $f = $b->inicio()->diff($a->inicio())->format('%r%a'); if ($f == 0) { return $a->id - $b->id; } return $f; } return $p; }); return view('temas.list', compact('temas')); } public static function edit() { $id = get('tema'); $tema = model(Tema::class)->findOne($id); $proyectos = model(Proyecto::class)->orderByAsc('descripcion')->findMany(); return view('temas.edit', compact('tema', 'proyectos')); } public static function editar() { $id = get('tema'); $tema = model(Tema::class)->findOne($id); $proyecto = post('proyecto'); $changed = false; if ($tema->proyecto_id != $proyecto) { $tema->proyecto_id = $proyecto; $changed = true; } $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); if ($tema->inicio() != $f) { $tema->inicio = $f->format('Y-m-d'); $changed = true; } $texto = post('texto'); if ($tema->texto != $texto) { $tema->texto = $texto; $changed = true; } if ($changed) { $tema->save(); } header('Location: ' . url('', ['p' => 'temas', 'a' => 'list'])); } public static function cerrar() { $id = get('tema'); $tema = model(Tema::class)->findOne($id); $f = Carbon::today(config('app.timezone')); $tema->cierre = $f->format('Y-m-d'); $tema->save(); header('Location: ' . url('', ['p' => 'temas', 'a' => 'list'])); } public static function abrir() { $id = get('tema'); $tema = model(Tema::class)->findOne($id)->as_array(); unset($tema['id'], $tema['cierre'], $tema['created_at'], $tema['updated_at']); $tema = model(Tema::class)->create($tema); $tema->save(); header('Location: ' . url('', ['p' => 'temas', 'a' => 'list'])); } } ?>