SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Controllers/Admin/RedirectAdminController.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 Sprout\Helpers\ColModifierLnk;
  17. use Sprout\Helpers\ColModifierLookupTable;
  18. use Sprout\Helpers\Enc;
  19. use Sprout\Helpers\RefineBar;
  20. use Sprout\Helpers\RefineWidgetTextbox;
  21. use Sprout\Helpers\Validator;
  22.  
  23.  
  24. /**
  25. * Handles most processing for Redirects
  26. **/
  27. class RedirectAdminController extends HasCategoriesAdminController
  28. {
  29. protected $controller_name = 'redirect';
  30. protected $friendly_name = 'Redirects';
  31. protected $add_defaults = array(
  32. 'active' => 1,
  33. 'type' => 'Temporary',
  34. );
  35. protected $main_order = 'item.path_exact';
  36.  
  37. /**
  38.   * Constructor
  39.   **/
  40. public function __construct()
  41. {
  42. $this->main_columns = [
  43. 'Conditions' => function($row) {
  44. $conds = [];
  45. if ($row['path_exact']) {
  46. $conds[] = 'path exactly matches "' . Enc::html($row['path_exact']) . '"';
  47. }
  48. if ($row['path_contains']) {
  49. $conds[] = 'path contains "' . Enc::html($row['path_contains']) . '"';
  50. }
  51. if ($row['domain_contains']) {
  52. $conds[] = 'domain contains "' . Enc::html($row['domain_contains']) . '"';
  53. }
  54. return ucfirst(implode(' and ', $conds));
  55. },
  56.  
  57. 'Subsite' => [new ColModifierLookupTable('subsites'), 'subsite_id'],
  58. 'Destination' => [new ColModifierLnk(), 'destination'],
  59. ];
  60.  
  61. $this->refine_bar = new RefineBar();
  62. $this->refine_bar->setGroup('Redirect');
  63. $this->refine_bar->addWidget(new RefineWidgetTextbox('path_exact', 'Path exact match'));
  64. $this->refine_bar->addWidget(new RefineWidgetTextbox('path_contains', 'Path contains'));
  65.  
  66. parent::__construct();
  67. }
  68.  
  69.  
  70. /**
  71.   * Do any additional validation prior to saving the record
  72.   *
  73.   * @param int $id Record ID or 0 for adds
  74.   * @param Validator $validator Validator instance to attach your errors to
  75.   * @return void
  76.   */
  77. protected function jsonExtraValidate($id, Validator $validator)
  78. {
  79. $validator->multipleCheck(
  80. ['path_exact', 'path_contains', 'subsite_id', 'domain_contains'],
  81. 'Validity::oneRequired'
  82. );
  83. }
  84.  
  85. }
  86.