time.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * CRUD -- Time input for RESTful objects
  4. *
  5. * @package Lorea
  6. * @subpackage CRUD
  7. *
  8. * Copyright 2012-2013 Lorea Faeries <federation@lorea.org>
  9. *
  10. * This program is free software: you can redistribute it and/or
  11. * modify it under the terms of the GNU Affero General Public License
  12. * as published by the Free Software Foundation, either version 3 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public
  21. * License along with this program. If not, see
  22. * <http://www.gnu.org/licenses/>.
  23. */
  24. $value = $vars['value'];
  25. if (is_numeric($value)) {
  26. $hour = floor($value/60);
  27. $minute = floor($value%60);
  28. } else {
  29. $hour = 0;
  30. $minute = 0;
  31. }
  32. $hours = array();
  33. $minutes = array();
  34. for ($h=0; $h<=23; $h++) {
  35. $hours[$h] = $h;
  36. }
  37. for($m=0; $m<60; $m+=5) {
  38. $mt = sprintf("%02d",$m);
  39. $minutes[$m] = $mt;
  40. }
  41. echo elgg_view('input/dropdown', array(
  42. 'name' => $vars['name'] . '_hour',
  43. 'value' => $hour,
  44. 'options_values' => $hours,
  45. ));
  46. echo " <b>:</b> ";
  47. echo elgg_view('input/dropdown', array(
  48. 'name' => $vars['name'] . '_minute',
  49. 'value' => $minute,
  50. 'options_values' => $minutes,
  51. ));