SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Controllers/Admin/DocumentTypeAdminController.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 Sprout\Controllers\Admin;
  15.  
  16. use InvalidArgumentException;
  17.  
  18. use Sprout\Helpers\Pdb;
  19.  
  20.  
  21. /**
  22.  * Handles admin processing for Document types
  23.  */
  24. class DocumentTypeAdminController extends ListAdminController
  25. {
  26. protected $controller_name = 'document_type';
  27. protected $friendly_name = 'Document types';
  28. protected $add_defaults = [];
  29. protected $main_columns = [];
  30.  
  31.  
  32. /**
  33.   * Constructor
  34.   **/
  35. public function __construct()
  36. {
  37. $this->main_columns = [
  38. 'Name' => 'name',
  39. ];
  40.  
  41. $this->initRefineBar();
  42.  
  43. parent::__construct();
  44. }
  45.  
  46.  
  47. /**
  48.   * Return the fields to show in the sidebar when adding or editing a record.
  49.   * These fields are shown under a heading of "Visibility"
  50.   * @return array Key is the field name, value is the field label
  51.   */
  52. public function _getVisibilityFields()
  53. {
  54. return [];
  55. }
  56.  
  57.  
  58. /**
  59.   * Pre-render hook for adding
  60.   **/
  61. protected function _addPreRender($view)
  62. {
  63. parent::_addPreRender($view);
  64. }
  65.  
  66.  
  67. /**
  68.   * Return the sub-actions for adding; for spec {@see AdminController::renderSubActions}
  69.   * @return array
  70.   */
  71. public function _getAddSubActions()
  72. {
  73. $actions = parent::_getAddSubActions();
  74. // Add your actions here, like this: $actions[] = [ ... ];
  75. return $actions;
  76. }
  77.  
  78.  
  79. /**
  80.   * Saves the provided POST data into a new record in the database
  81.   *
  82.   * @param int $item_id After saving, the new record id will be returned in this parameter
  83.   * @param bool True on success, false on failure
  84.   */
  85. public function _addSave(&$item_id)
  86. {
  87. Pdb::transact();
  88. if (!parent::_addSave($item_id)) return false;
  89.  
  90. $this->fixRecordOrder($item_id);
  91. Pdb::commit();
  92. return true;
  93. }
  94.  
  95.  
  96. /**
  97.   * Pre-render hook for editing
  98.   **/
  99. protected function _editPreRender($view, $item_id)
  100. {
  101. parent::_editPreRender($view, $item_id);
  102. }
  103.  
  104.  
  105. /**
  106.   * Return the sub-actions for editing; for spec {@see AdminController::renderSubActions}
  107.   * @return array
  108.   */
  109. public function _getEditSubActions($item_id)
  110. {
  111. $actions = parent::_getEditSubActions($item_id);
  112. // Add your actions here, like this: $actions[] = [ ... ];
  113. return $actions;
  114. }
  115.  
  116.  
  117. /**
  118.   * Saves the provided POST data into the specified record
  119.   *
  120.   * @param int $item_id The record to update
  121.   * @param bool True on success, false on failure
  122.   */
  123. public function _editSave($item_id)
  124. {
  125. $item_id = (int) $item_id;
  126. if ($item_id <= 0) throw new InvalidArgumentException('$item_id must be greater than 0');
  127.  
  128. return parent::_editSave($item_id);
  129. }
  130.  
  131. }
  132.