SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/module_template/tree/Controllers/Admin/CNAMEAdminController.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\AUTHOR\MODULE\Controllers\Admin;
  15.  
  16. use InvalidArgumentException;
  17.  
  18. use Sprout\Controllers\Admin\TreeAdminController;
  19. use Sprout\Helpers\ColModifierBinary;
  20. use Sprout\Helpers\Pdb;
  21.  
  22.  
  23. /**
  24.  * Handles admin processing for PNICE
  25.  */
  26. class CNAMEAdminController extends TreeAdminController
  27. {
  28. protected $controller_name = 'SNAME';
  29. protected $friendly_name = 'PNICE';
  30. protected $add_defaults = [
  31. 'active' => 1,
  32. ];
  33. protected $main_columns = [];
  34.  
  35.  
  36. /**
  37.   * Constructor
  38.   **/
  39. public function __construct()
  40. {
  41. $this->main_columns = [
  42. FIELDS_MAIN
  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. Pdb::transact();
  82. if (!parent::_addSave($item_id)) return false;
  83.  
  84. $this->fixRecordOrder($item_id);
  85. Pdb::commit();
  86. return true;
  87. }
  88.  
  89.  
  90. /**
  91.   * Pre-render hook for editing
  92.   **/
  93. protected function _editPreRender($view, $item_id)
  94. {
  95. parent::_editPreRender($view, $item_id);
  96. }
  97.  
  98.  
  99. /**
  100.   * Return the sub-actions for editing; for spec {@see AdminController::renderSubActions}
  101.   * @return array
  102.   */
  103. public function _getEditSubActions($item_id)
  104. {
  105. $actions = parent::_getEditSubActions($item_id);
  106. // Add your actions here, like this: $actions[] = [ ... ];
  107. return $actions;
  108. }
  109.  
  110.  
  111. /**
  112.   * Saves the provided POST data into the specified record
  113.   *
  114.   * @param int $item_id The record to update
  115.   * @param bool True on success, false on failure
  116.   */
  117. public function _editSave($item_id)
  118. {
  119. $item_id = (int) $item_id;
  120. if ($item_id <= 0) throw new InvalidArgumentException('$item_id must be greater than 0');
  121.  
  122. $q = "SELECT parent_id FROM ~{$this->table_name} WHERE id = ?";
  123. $parent_id = Pdb::query($q, [$item_id], 'val');
  124.  
  125. Pdb::transact();
  126. if (!parent::_editSave($item_id)) return false;
  127.  
  128. if ($parent_id != $_POST['parent_id']) $this->fixRecordOrder($item_id);
  129.  
  130. Pdb::commit();
  131. return true;
  132. }
  133.  
  134. }
  135.  
  136.