block.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Contains class block_rss_client\output\block
  18. *
  19. * @package block_rss_client
  20. * @copyright 2015 Howard County Public School System
  21. * @author Brendan Anderson <brendan_anderson@hcpss.org>
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. namespace block_rss_client\output;
  25. defined('MOODLE_INTERNAL') || die();
  26. /**
  27. * Class to help display an RSS Feeds block
  28. *
  29. * @package block_rss_client
  30. * @copyright 2016 Howard County Public School System
  31. * @author Brendan Anderson <brendan_anderson@hcpss.org>
  32. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33. */
  34. class block implements \renderable, \templatable {
  35. /**
  36. * An array of renderable feeds
  37. *
  38. * @var array
  39. */
  40. protected $feeds;
  41. /**
  42. * Contruct
  43. *
  44. * @param array $feeds An array of renderable feeds
  45. */
  46. public function __construct(array $feeds = array()) {
  47. $this->feeds = $feeds;
  48. }
  49. /**
  50. * Prepare data for use in a template
  51. *
  52. * @param \renderer_base $output
  53. * @return array
  54. */
  55. public function export_for_template(\renderer_base $output) {
  56. $data = array('feeds' => array());
  57. foreach ($this->feeds as $feed) {
  58. $data['feeds'][] = $feed->export_for_template($output);
  59. }
  60. return $data;
  61. }
  62. /**
  63. * Add a feed
  64. *
  65. * @param \block_rss_client\output\feed $feed
  66. * @return \block_rss_client\output\block
  67. */
  68. public function add_feed(feed $feed) {
  69. $this->feeds[] = $feed;
  70. return $this;
  71. }
  72. /**
  73. * Set the feeds
  74. *
  75. * @param array $feeds
  76. * @return \block_rss_client\output\block
  77. */
  78. public function set_feeds(array $feeds) {
  79. $this->feeds = $feeds;
  80. return $this;
  81. }
  82. /**
  83. * Get feeds
  84. *
  85. * @return array
  86. */
  87. public function get_feeds() {
  88. return $this->feeds;
  89. }
  90. }