StateController.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace App\Geo\State;
  3. use \App\Core\Template\Output as Output;
  4. use \App\Geo\State\Classes\State as State;
  5. class StateController
  6. {
  7. /**
  8. * Index
  9. * Show the main State list
  10. */
  11. function index()
  12. {
  13. $list = array();
  14. for ($i = 0; $i <= 10; $i++) {
  15. $obj = array();
  16. $obj['id'] = $i;
  17. $obj['value'] = md5($i);
  18. $obj['description'] = sha1($i);
  19. $list[] = $obj;
  20. }
  21. Output::render('list', $list);
  22. }
  23. /**
  24. * Create
  25. *
  26. * Render the main State formulary
  27. */
  28. function create()
  29. {
  30. Output::setView('form', ['id' => 0]);
  31. Output::render();
  32. }
  33. /**
  34. * Store
  35. *
  36. * Store the param on the database
  37. * @param State $state
  38. */
  39. function store(State $state)
  40. {
  41. }
  42. /**
  43. * Search
  44. *
  45. * Store the param on the database
  46. * @param State $state
  47. */
  48. function search()
  49. {
  50. $states = State::findAll(['id', 'shortname']);
  51. $return = "<option value='0'>Selecione</option>";
  52. foreach ($states as $state) {
  53. if ($state->id == $_GET['value']) {
  54. $return .= "<option value='$state->id' selected>$state->shortname</option>";
  55. } else {
  56. $return .= "<option value='$state->id'>$state->shortname</option>";
  57. }
  58. }
  59. echo $return;
  60. }
  61. /**
  62. * Show
  63. *
  64. * Render one register
  65. *
  66. * @param State $state
  67. */
  68. function show(State $state)
  69. {
  70. \RR\Response::json($state)->send();
  71. }
  72. /**
  73. * Edit
  74. *
  75. * Render the formular for a database State
  76. *
  77. * @param State $state
  78. */
  79. function edit(State $state)
  80. {
  81. Output::setView('form', $state);
  82. Output::render();
  83. }
  84. /**
  85. * Update
  86. * Store the changes of the param on the database
  87. *
  88. * @param State $state
  89. */
  90. function update(State $state)
  91. {
  92. }
  93. /**
  94. * Destroy
  95. * If the object has soft delete.
  96. *
  97. * @param State $state
  98. */
  99. function destroy(State $state)
  100. {
  101. }
  102. /**
  103. * Purge
  104. * Remove object even with soft delete.
  105. *
  106. * @param State $state
  107. */
  108. function purge(State $state)
  109. {
  110. }
  111. function loadSelect()
  112. {
  113. //ddd(State::findMany(['country_id' => ['=', '25']])->get());
  114. Output::render(
  115. 'select',
  116. [
  117. 'states' => State::findMany(['country_id' => ['=', '25']])->get(),
  118. //'selected' => $_GET['value']
  119. ]
  120. );
  121. }
  122. }