TestAction.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. class TestAction {
  3. function doEcho($data){
  4. return $data;
  5. }
  6. function multiply($num){
  7. if(!is_numeric($num)){
  8. throw new Exception('Call to multiply with a value that is not a number');
  9. }
  10. return $num*8;
  11. }
  12. function getTree($id){
  13. $out = array();
  14. if($id == "root"){
  15. for($i = 1; $i <= 5; ++$i){
  16. array_push($out, array(
  17. 'id'=>'n' . $i,
  18. 'text'=>'Node ' . $i,
  19. 'leaf'=>false
  20. ));
  21. }
  22. }else if(strlen($id) == 2){
  23. $num = substr($id, 1);
  24. for($i = 1; $i <= 5; ++$i){
  25. array_push($out, array(
  26. 'id'=>$id . $i,
  27. 'text'=>'Node ' . $num . '.' . $i,
  28. 'leaf'=>true
  29. ));
  30. }
  31. }
  32. return $out;
  33. }
  34. function getGrid($params){
  35. $sort = $params->sort[0];
  36. $field = $sort->property;
  37. $direction = $sort->direction;
  38. /*
  39. * Here we would apply a proper sort from the DB, but since
  40. * it's such a small dataset we will just sort by hand here.
  41. */
  42. if ($field == 'name') {
  43. $data = array(array(
  44. 'name'=>'ABC Accounting',
  45. 'turnover'=>50000
  46. ), array(
  47. 'name'=>'Ezy Video Rental',
  48. 'turnover'=>106300
  49. ), array(
  50. 'name'=>'Greens Fruit Grocery',
  51. 'turnover'=>120000
  52. ), array(
  53. 'name'=>'Icecream Express',
  54. 'turnover'=>73000
  55. ), array(
  56. 'name'=>'Ripped Gym',
  57. 'turnover'=>88400
  58. ), array(
  59. 'name'=>'Smith Auto Mechanic',
  60. 'turnover'=>222980
  61. ));
  62. } else {
  63. $data = array(array(
  64. 'name'=>'ABC Accounting',
  65. 'turnover'=>50000
  66. ), array(
  67. 'name'=>'Icecream Express',
  68. 'turnover'=>73000
  69. ), array(
  70. 'name'=>'Ripped Gym',
  71. 'turnover'=>88400
  72. ), array(
  73. 'name'=>'Ezy Video Rental',
  74. 'turnover'=>106300
  75. ), array(
  76. 'name'=>'Greens Fruit Grocery',
  77. 'turnover'=>120000
  78. ), array(
  79. 'name'=>'Smith Auto Mechanic',
  80. 'turnover'=>222980
  81. ));
  82. }
  83. if ($direction == 'DESC') {
  84. $data = array_reverse($data);
  85. }
  86. return $data;
  87. }
  88. function showDetails($data){
  89. $first = $data->firstName;
  90. $last = $data->lastName;
  91. $age = $data->age;
  92. return "Hi $first $last, you are $age years old.";
  93. }
  94. }