PageRenderTime 306ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/api/1/restricted/food.php

https://github.com/dreamhackcrew/API
PHP | 47 lines | 32 code | 8 blank | 7 comment | 4 complexity | c149968d0c2443c889cbb3f0761df000 MD5 | raw file
  1. <?php
  2. class food extends service {
  3. function _list($fid = null){
  4. // Select event/events
  5. if(!isset($_GET['event'])){
  6. $events = db()->fetchSingle("SELECT id,name,start,end,active FROM events WHERE active ='Y' AND end >= CURRENT_DATE() ORDER BY start LIMIT 1");
  7. $event = $events['id'];
  8. }
  9. else
  10. $event = $_GET['event'];
  11. // Find all the meals
  12. $data = db()->fetchAll("SELECT * FROM user_food LEFT JOIN user_food_selected USING(fid) WHERE user_food.event=%d ",$event);
  13. // Rearrange the struct and group it by meal
  14. $ret = array();
  15. if($data)
  16. foreach($data as $line){
  17. $ret[$line['fid']]['datetime'] = $line['when'];
  18. $ret[$line['fid']]['name'] = $line['name'];
  19. $ret[$line['fid']]['fid'] = $line['fid'];
  20. if($line['eaten'])
  21. $ret[$line['fid']]['eaten'][] = (int) $line['uid'];
  22. else
  23. $ret[$line['fid']]['registered'][] = (int) $line['uid'];
  24. }
  25. // Send the data
  26. return $ret;
  27. }
  28. function _checkin($uid,$fid){
  29. // Check that the user have access to check in peope
  30. $this->requireFlag('matincheckning');
  31. // Find the meal
  32. if ( !$data = db()->fetchSingle("SELECT * FROM user_food_selected WHERE uid=%d AND fid=%d",$uid,$fid) )
  33. trigger_error('Selected user not found on selected meal');
  34. // Check in the user to the selected meal
  35. $tmp = db()->query('UPDATE user_food_selected SET eaten=1 WHERE uid=%d AND fid=%d',$uid,$fid);
  36. return db()->affectedRows();
  37. }
  38. }
  39. ?>