PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/fuel/category_tool/fuel/app/classes/controller/buzzword.php

https://github.com/connvoi/dev
PHP | 162 lines | 130 code | 32 blank | 0 comment | 9 complexity | 408fccb86aad5ad5ad975283bfe607b5 MD5 | raw file
Possible License(s): MIT, BSD-3-Clause
  1. <?php
  2. class Controller_Buzzword extends Controller_Template
  3. {
  4. public function action_index()
  5. {
  6. $data['buzzwords'] = Model_Buzzword::find('all');
  7. $this->template->title = "Buzzwords";
  8. $this->template->content = View::forge('buzzword/index', $data);
  9. }
  10. public function action_view($id = null)
  11. {
  12. $data['buzzword'] = Model_Buzzword::find($id);
  13. is_null($id) and Response::redirect('Buzzword');
  14. $this->template->title = "Buzzword";
  15. $this->template->content = View::forge('buzzword/view', $data);
  16. }
  17. public function action_create()
  18. {
  19. if (Input::method() == 'POST')
  20. {
  21. $val = Model_Buzzword::validate('create');
  22. if ($val->run())
  23. {
  24. $buzzword = Model_Buzzword::forge(array(
  25. 'word' => Input::post('word'),
  26. 'child' => Input::post('child'),
  27. 'related_word' => Input::post('related_word'),
  28. 'related_url' => Input::post('related_url'),
  29. 'related_hash' => Input::post('related_hash'),
  30. 'category1' => Input::post('category1'),
  31. 'cname1' => Input::post('cname1'),
  32. 'category2' => Input::post('category2'),
  33. 'cname2' => Input::post('cname2'),
  34. 'category3' => Input::post('category3'),
  35. 'cname3' => Input::post('cname3'),
  36. 'category4' => Input::post('category4'),
  37. 'cname4' => Input::post('cname4'),
  38. 'judge' => Input::post('judge'),
  39. 'comment' => Input::post('comment'),
  40. ));
  41. if ($buzzword and $buzzword->save())
  42. {
  43. Session::set_flash('success', 'Added buzzword #'.$buzzword->id.'.');
  44. Response::redirect('buzzword');
  45. }
  46. else
  47. {
  48. Session::set_flash('error', 'Could not save buzzword.');
  49. }
  50. }
  51. else
  52. {
  53. Session::set_flash('error', $val->show_errors());
  54. }
  55. }
  56. $this->template->title = "Buzzwords";
  57. $this->template->content = View::forge('buzzword/create');
  58. }
  59. public function action_edit($id = null)
  60. {
  61. is_null($id) and Response::redirect('Buzzword');
  62. $buzzword = Model_Buzzword::find($id);
  63. $val = Model_Buzzword::validate('edit');
  64. if ($val->run())
  65. {
  66. $buzzword->word = Input::post('word');
  67. $buzzword->child = Input::post('child');
  68. $buzzword->related_word = Input::post('related_word');
  69. $buzzword->related_url = Input::post('related_url');
  70. $buzzword->related_hash = Input::post('related_hash');
  71. $buzzword->category1 = Input::post('category1');
  72. $buzzword->cname1 = Input::post('cname1');
  73. $buzzword->category2 = Input::post('category2');
  74. $buzzword->cname2 = Input::post('cname2');
  75. $buzzword->category3 = Input::post('category3');
  76. $buzzword->cname3 = Input::post('cname3');
  77. $buzzword->category4 = Input::post('category4');
  78. $buzzword->cname4 = Input::post('cname4');
  79. $buzzword->judge = Input::post('judge');
  80. $buzzword->comment = Input::post('comment');
  81. if ($buzzword->save())
  82. {
  83. Session::set_flash('success', 'Updated buzzword #' . $id);
  84. Response::redirect('buzzword');
  85. }
  86. else
  87. {
  88. Session::set_flash('error', 'Could not update buzzword #' . $id);
  89. }
  90. }
  91. else
  92. {
  93. if (Input::method() == 'POST')
  94. {
  95. $buzzword->word = $val->validated('word');
  96. $buzzword->child = $val->validated('child');
  97. $buzzword->related_word = $val->validated('related_word');
  98. $buzzword->related_url = $val->validated('related_url');
  99. $buzzword->related_hash = $val->validated('related_hash');
  100. $buzzword->category1 = $val->validated('category1');
  101. $buzzword->cname1 = $val->validated('cname1');
  102. $buzzword->category2 = $val->validated('category2');
  103. $buzzword->cname2 = $val->validated('cname2');
  104. $buzzword->category3 = $val->validated('category3');
  105. $buzzword->cname3 = $val->validated('cname3');
  106. $buzzword->category4 = $val->validated('category4');
  107. $buzzword->cname4 = $val->validated('cname4');
  108. $buzzword->judge = $val->validated('judge');
  109. $buzzword->comment = $val->validated('comment');
  110. Session::set_flash('error', $val->show_errors());
  111. }
  112. $this->template->set_global('buzzword', $buzzword, false);
  113. }
  114. $this->template->title = "Buzzwords";
  115. $this->template->content = View::forge('buzzword/edit');
  116. }
  117. public function action_delete($id = null)
  118. {
  119. if ($buzzword = Model_Buzzword::find($id))
  120. {
  121. $buzzword->delete();
  122. Session::set_flash('success', 'Deleted buzzword #'.$id);
  123. }
  124. else
  125. {
  126. Session::set_flash('error', 'Could not delete buzzword #'.$id);
  127. }
  128. Response::redirect('buzzword');
  129. }
  130. }