SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Controllers/Admin/ContentSubscriptionAdminController.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. namespace Sprout\Controllers\Admin;
  14.  
  15. use Sprout\Helpers\ColModifierContentSubscription;
  16. use Sprout\Helpers\ColModifierDate;
  17. use Sprout\Helpers\Itemlist;
  18. use Sprout\Helpers\RefineBar;
  19. use Sprout\Helpers\RefineWidgetSelect;
  20. use Sprout\Helpers\RefineWidgetTextbox;
  21. use Sprout\Helpers\View;
  22.  
  23.  
  24. class ContentSubscriptionAdminController extends ManagedAdminController
  25. {
  26. protected $controller_name = 'content_subscription';
  27. protected $friendly_name = 'Content subscriptions';
  28. protected $main_add = false;
  29. protected $main_delete = true;
  30. protected $main_order = 'item.date_added DESC';
  31.  
  32.  
  33. /**
  34.   * Constructor
  35.   **/
  36. public function __construct()
  37. {
  38. parent::__construct();
  39.  
  40. $this->main_columns = [
  41. 'Name' => 'name',
  42. 'Email' => 'email',
  43. 'Module' => [new ColModifierContentSubscription(), 'id'],
  44. 'Date' => [new ColModifierDate('d/m/Y - h:i a'), 'date_added'],
  45. ];
  46.  
  47. $this->refine_bar = new RefineBar();
  48. $this->refine_bar->addWidget(new RefineWidgetTextbox('name', 'Name'));
  49. $this->refine_bar->addWidget(new RefineWidgetTextbox('email', 'Email'));
  50. }
  51.  
  52. public function _getTools() { return null; }
  53. public function _getNavigation() { return null; }
  54. public function _getVisibilityFields() { return []; }
  55.  
  56. /**
  57.   * Formats a resultset of items into an Itemlist
  58.   *
  59.   * @param Traversable $items The items to render.
  60.   * @param anything $unused Not used in this controller, but used by has_categories
  61.   **/
  62. public function _getContentsViewList($items, $unused)
  63. {
  64. // Create the itemlist
  65. $itemlist = new Itemlist();
  66. $itemlist->main_columns = $this->main_columns;
  67. $itemlist->items = $items;
  68. $itemlist->setCheckboxes(true);
  69. $itemlist->setOrdering(true);
  70. $itemlist->setActionsClasses('button button-small');
  71.  
  72. // Add the actions
  73. foreach ($this->main_actions as $name => $url) {
  74. $itemlist->addAction($name, $url, 'button-grey');
  75. }
  76. if ($this->getDuplicateEnabled()) {
  77. $itemlist->addAction('Duplicate', "SITE/admin/duplicate/{$this->controller_name}/%%", 'button-grey icon-before icon-add');
  78. }
  79. if ($this->main_delete) {
  80. $itemlist->addAction('Delete', "SITE/admin/delete/{$this->controller_name}/%%", 'button button-red icon-before icon-delete');
  81. }
  82.  
  83. // Add classes based on visibility fields
  84. $visibility = $this->_getVisibilityFields();
  85. $itemlist->setRowClassesFunc(function($row) use($visibility) {
  86. $out = '';
  87. foreach ($visibility as $name => $label) {
  88. $out .= "main-list--{$name}-{$row[$name]} ";
  89. }
  90. return rtrim($out);
  91. });
  92.  
  93. // Prepare view which renders the main content area
  94. $outer = new View("sprout/admin/generic_itemlist_outer");
  95.  
  96. // Build the outer view
  97. $outer->controller_name = $this->controller_name;
  98. $outer->friendly_name = $this->friendly_name;
  99. $outer->itemlist = $itemlist->render();
  100. $outer->allow_add = $this->main_add;
  101. $outer->allow_del = $this->main_delete;
  102.  
  103. return $outer->render();
  104. }
  105. }
  106.