4
0

categoryController.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Controller to handle actions relative to categories.
  4. * User needs to be connected.
  5. */
  6. class FreshRSS_category_Controller extends Minz_ActionController {
  7. /**
  8. * This action is called before every other action in that class. It is
  9. * the common boiler plate for every action. It is triggered by the
  10. * underlying framework.
  11. *
  12. */
  13. public function firstAction() {
  14. if (!$this->view->loginOk) {
  15. Minz_Error::error(
  16. 403,
  17. array('error' => array(_t('access_denied')))
  18. );
  19. }
  20. $catDAO = new FreshRSS_CategoryDAO();
  21. $catDAO->checkDefault();
  22. }
  23. /**
  24. * This action creates a new category.
  25. *
  26. * URL parameter is:
  27. * - new-category
  28. */
  29. public function createAction() {
  30. $catDAO = new FreshRSS_CategoryDAO();
  31. $url_redirect = array('c' => 'configure', 'a' => 'categorize');
  32. if (Minz_Request::isPost()) {
  33. invalidateHttpCache();
  34. $cat_name = Minz_Request::param('new-category');
  35. if (!$cat_name) {
  36. Minz_Request::bad(_t('category_no_name'), $url_redirect);
  37. }
  38. $cat = new FreshRSS_Category($cat_name);
  39. if ($catDAO->searchByName($cat->name()) != null) {
  40. Minz_Request::bad(_t('category_name_exists'), $url_redirect);
  41. }
  42. $values = array(
  43. 'id' => $cat->id(),
  44. 'name' => $cat->name(),
  45. );
  46. if ($catDAO->addCategory($values)) {
  47. Minz_Request::good(_t('category_created', $cat->name()), $url_redirect);
  48. } else {
  49. Minz_Request::bad(_t('category_not_created'), $url_redirect);
  50. }
  51. }
  52. Minz_Request::forward($url_redirect, true);
  53. }
  54. }