changeYearForm.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. class changeYearForm extends Staple_Form
  3. {
  4. public function _start()
  5. {
  6. //$this->setLayout('');
  7. $this->setName('changeYearForm')
  8. ->setAction($this->link(array('timesheet','changeyear')));
  9. $year = new Staple_Form_FoundationSelectElement('year','Year');
  10. $year->setRequired()
  11. ->addOptionsArray($this->getYears())
  12. ->addValidator(new Staple_Form_Validate_InArray($this->getYears()));
  13. if(count($this->getYears()) == 0)
  14. {
  15. $year->addOption(date('Y'),date('Y'));
  16. }
  17. $submit = new Staple_Form_FoundationSubmitElement('submit','Submit');
  18. $submit->addClass('button expand radius');
  19. $this->addField($year,$submit);
  20. }
  21. function getYears()
  22. {
  23. $db = Staple_DB::get();
  24. //Get user ID from Auth
  25. $user = new userModel();
  26. $userId = $user->getId();
  27. //$sql = "SELECT YEAR(FROM_UNIXTIME(inTime)) AS 'year' FROM timeEntries WHERE userId = $userId GROUP BY year ORDER by year ASC";
  28. $sql = "SELECT YEAR(FROM_UNIXTIME(inTime)) AS 'year' FROM timeEntries GROUP BY year ORDER by year ASC";
  29. if($db->query($sql)->num_rows > 0)
  30. {
  31. $query = $db->query($sql);
  32. $data = array();
  33. while($result = $query->fetch_assoc())
  34. {
  35. $data[$result['year']] = $result['year'];
  36. }
  37. return $data;
  38. }
  39. else
  40. {
  41. return array();
  42. }
  43. }
  44. }
  45. ?>