SproutCMS

This is the code documentation for the SproutCMS project

source of /modules/Demo/Controllers/Admin/WordAdminController.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace SproutModules\Karmabunny\Demo\Controllers\Admin;
  15.  
  16. use InvalidArgumentException;
  17.  
  18. use Sprout\Controllers\Admin\HasCategoriesAdminController;
  19. use Sprout\Helpers\ColModifierBinary;
  20.  
  21.  
  22. /**
  23.  * Handles admin processing for Words
  24.  */
  25. class WordAdminController extends HasCategoriesAdminController
  26. {
  27. protected $controller_name = 'word';
  28. protected $friendly_name = 'Words';
  29. protected $add_defaults = [
  30. 'active' => 1,
  31. ];
  32. protected $main_columns = [];
  33. protected $main_delete = true;
  34.  
  35.  
  36. /**
  37.   * Constructor
  38.   **/
  39. public function __construct()
  40. {
  41. $this->main_columns = [
  42. 'Name' => 'name',
  43. 'Active' => [new ColModifierBinary(), 'active'],
  44. ];
  45.  
  46. $this->initRefineBar();
  47.  
  48. parent::__construct();
  49. }
  50.  
  51.  
  52. /**
  53.   * Pre-render hook for adding
  54.   **/
  55. protected function _addPreRender($view)
  56. {
  57. parent::_addPreRender($view);
  58. }
  59.  
  60.  
  61. /**
  62.   * Return the sub-actions for adding; for spec {@see AdminController::renderSubActions}
  63.   * @return array
  64.   */
  65. public function _getAddSubActions()
  66. {
  67. $actions = parent::_getAddSubActions();
  68. // Add your actions here, like this: $actions[] = [ ... ];
  69. return $actions;
  70. }
  71.  
  72.  
  73. /**
  74.   * Saves the provided POST data into a new record in the database
  75.   *
  76.   * @param int $item_id After saving, the new record id will be returned in this parameter
  77.   * @param bool True on success, false on failure
  78.   */
  79. public function _addSave(&$item_id)
  80. {
  81. return parent::_addSave($item_id);
  82. }
  83.  
  84.  
  85.  
  86. /**
  87.   * Pre-render hook for editing
  88.   **/
  89. protected function _editPreRender($view, $item_id)
  90. {
  91. parent::_editPreRender($view, $item_id);
  92. }
  93.  
  94.  
  95. /**
  96.   * Return the sub-actions for editing; for spec {@see AdminController::renderSubActions}
  97.   * @return array
  98.   */
  99. public function _getEditSubActions($item_id)
  100. {
  101. $actions = parent::_getEditSubActions($item_id);
  102. // Add your actions here, like this: $actions[] = [ ... ];
  103. return $actions;
  104. }
  105.  
  106.  
  107. /**
  108.   * Process the saving of a record.
  109.   *
  110.   * @param int $item_id The record to save
  111.   * @return boolean True on success, false on failure
  112.   */
  113. public function _editSave($item_id)
  114. {
  115. $item_id = (int) $item_id;
  116. if ($item_id <= 0) throw new InvalidArgumentException('$item_id must be greater than 0');
  117.  
  118. return parent::_editSave($item_id);
  119. }
  120.  
  121. }
  122.  
  123.  
  124.