session_model.lib.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. class SessionModel extends Model
  3. {
  4. public $columns = array(
  5. 'id',
  6. 'id_coach',
  7. 'name',
  8. 'nbr_courses',
  9. 'nbr_users',
  10. 'nbr_classes',
  11. 'session_admin_id',
  12. 'visibility',
  13. 'session_category_id',
  14. 'promotion_id',
  15. 'display_start_date',
  16. 'display_end_date',
  17. 'access_start_date',
  18. 'access_end_date',
  19. 'coach_access_start_date',
  20. 'coach_access_end_date',
  21. );
  22. public function __construct()
  23. {
  24. $this->table = Database::get_main_table(TABLE_MAIN_SESSION);
  25. }
  26. public function clean_parameters($params)
  27. {
  28. //Convert dates
  29. $params['display_start_date'] = isset($params['display_start_date']) ? api_get_utc_datetime(
  30. $params['display_start_date'],
  31. true
  32. ) : null;
  33. $params['display_end_date'] = isset($params['display_end_date']) ? api_get_utc_datetime(
  34. $params['display_end_date'],
  35. true
  36. ) : null;
  37. $params['access_start_date'] = isset($params['access_start_date']) ? api_get_utc_datetime(
  38. $params['access_start_date'],
  39. true
  40. ) : null;
  41. $params['access_end_date'] = isset($params['access_end_date']) ? api_get_utc_datetime(
  42. $params['access_end_date'],
  43. true
  44. ) : null;
  45. $params['coach_access_start_date'] = isset($params['coach_access_start_date']) ? api_get_utc_datetime(
  46. $params['coach_access_start_date'],
  47. true
  48. ) : null;
  49. $params['coach_access_end_date'] = isset($params['coach_access_end_date']) ? api_get_utc_datetime(
  50. $params['coach_access_end_date'],
  51. true
  52. ) : null;
  53. $params['id_coach'] = is_array(
  54. $params['id_coach']
  55. ) ? $params['id_coach'][0] : $params['id_coach'];
  56. if (empty($params['access_end_date'])) {
  57. $params['visibility'] = SessionManager::DEFAULT_VISIBILITY;
  58. }
  59. unset($params['submit']);
  60. return $params;
  61. }
  62. function save($params, $show_query = false)
  63. {
  64. $params = self::clean_parameters($params);
  65. return parent::save($params, $show_query);
  66. }
  67. function update($params)
  68. {
  69. $params = self::clean_parameters($params);
  70. $result = parent::update($params);
  71. return $result;
  72. }
  73. }