No Description

SemestersController.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. class SemestersController extends \BaseController {
  3. public function filterSemesters()
  4. {
  5. $semesters_ids = array();
  6. $semesters_info = array();
  7. if(count(Input::get('semesters_ids')))
  8. {
  9. // For each selected semester, fetch its info to add to the Session arrays
  10. foreach (Input::get('semesters_ids') as $semester_id) {
  11. $semesters_ids[] = $semester_id;
  12. $semester = Semester::find($semester_id);
  13. $semesters_info[] = $semester->name.' ('.$semester->code.')';
  14. }
  15. // Put semesters information arrays into Session
  16. Session::forget('semesters_ids');
  17. Session::put('semesters_ids', $semesters_ids);
  18. Session::forget('semesters_info');
  19. Session::put('semesters_info', $semesters_info);
  20. }
  21. return Redirect::back();
  22. }
  23. public function edit()
  24. {
  25. $title = "Semester Management";
  26. $semesters = Semester::all();
  27. return View::make('local.managers.admins.semesters', compact('title', 'semesters'));
  28. }
  29. public function update()
  30. {
  31. /** Validate data */
  32. $validator = Validator::make(
  33. Input::all(),
  34. array(
  35. 'id'=>'required|integer',
  36. 'start'=>'required|date_format:m/d/y H:i:s',
  37. 'end'=>'required|date_format:m/d/y H:i:s',
  38. 'visible'=>'required|integer',
  39. ),
  40. array(
  41. 'start.date_format' => 'The start date must be in this format: mm/dd/yyyy hh:mm:ss',
  42. 'end.date_format' => 'The end date must be in this format: mm/dd/yyyy hh:mm:ss',
  43. )
  44. );
  45. if(!$validator->fails())
  46. {
  47. $semester = Semester::find(Input::get('id'));
  48. $semester->start = date('Y-m-d H:i:s', strtotime(Input::get('start')));
  49. $semester->end = date('Y-m-d H:i:s', strtotime(Input::get('end')));
  50. // $semester->start = strtotime(Input::get('start'));
  51. // $semester->end = strtotime(Input::get('end'));
  52. $semester->is_visible = Input::get('visible');
  53. try
  54. {
  55. if($semester->save())
  56. {
  57. Session::flash('status', 'success');
  58. Session::flash('message', $semester->name.' updated ('.date('m/d/y h:i:s a').').');
  59. }
  60. else
  61. {
  62. Session::flash('status', 'danger');
  63. Session::flash('message', 'Error updating '.$semester->name.'. Try again later. If the problem persists, contact a super-administrator ('.date('m/d/y h:i:s a').').');
  64. }
  65. } catch (Exception $e) {
  66. Session::flash('status', 'danger');
  67. Session::flash('message', 'Error updating '.$semester->name.'. Contact a super-administrator ('.date('m/d/y h:i:s a').').');
  68. }
  69. }
  70. else
  71. {
  72. /** Prepare error message */
  73. $message = '<ul>';
  74. foreach ($validator->messages()->all('<li>:message</li>') as $validationError)
  75. {
  76. $message.=$validationError;
  77. }
  78. $message.='</ul>';
  79. Session::flash('status', 'danger');
  80. Session::flash('message', $message);
  81. }
  82. }
  83. }