edit_form.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. * Form for editing RSS client block instances.
  18. *
  19. * @package block_rss_client
  20. * @copyright 2009 Tim Hunt
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. /**
  24. * Form for editing RSS client block instances.
  25. *
  26. * @copyright 2009 Tim Hunt
  27. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  28. */
  29. class block_rss_client_edit_form extends block_edit_form {
  30. protected function specific_definition($mform) {
  31. global $CFG, $DB, $USER;
  32. // Fields for editing block contents.
  33. $mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
  34. $mform->addElement('selectyesno', 'config_display_description', get_string('displaydescriptionlabel', 'block_rss_client'));
  35. $mform->setDefault('config_display_description', 0);
  36. $mform->addElement('text', 'config_shownumentries', get_string('shownumentrieslabel', 'block_rss_client'), array('size' => 5));
  37. $mform->setType('config_shownumentries', PARAM_INT);
  38. $mform->addRule('config_shownumentries', null, 'numeric', null, 'client');
  39. if (!empty($CFG->block_rss_client_num_entries)) {
  40. $mform->setDefault('config_shownumentries', $CFG->block_rss_client_num_entries);
  41. } else {
  42. $mform->setDefault('config_shownumentries', 5);
  43. }
  44. $insql = '';
  45. $params = array('userid' => $USER->id);
  46. $rssconfig = unserialize(base64_decode($this->block->instance->configdata));
  47. if ($rssconfig && !empty($rssconfig->rssid)) {
  48. list($insql, $inparams) = $DB->get_in_or_equal($rssconfig->rssid, SQL_PARAMS_NAMED);
  49. $insql = "OR id $insql ";
  50. $params += $inparams;
  51. }
  52. $titlesql = "CASE WHEN preferredtitle = '' THEN {$DB->sql_compare_text('title', 64)} ELSE preferredtitle END";
  53. $rssfeeds = $DB->get_records_sql_menu("
  54. SELECT id, $titlesql
  55. FROM {block_rss_client}
  56. WHERE userid = :userid OR shared = 1 $insql
  57. ORDER BY $titlesql",
  58. $params);
  59. if ($rssfeeds) {
  60. $select = $mform->addElement('select', 'config_rssid', get_string('choosefeedlabel', 'block_rss_client'), $rssfeeds);
  61. $select->setMultiple(true);
  62. } else {
  63. $mform->addElement('static', 'config_rssid_no_feeds', get_string('choosefeedlabel', 'block_rss_client'),
  64. get_string('nofeeds', 'block_rss_client'));
  65. }
  66. if (has_any_capability(array('block/rss_client:manageanyfeeds', 'block/rss_client:manageownfeeds'), $this->block->context)) {
  67. $mform->addElement('static', 'nofeedmessage', '',
  68. '<a href="' . $CFG->wwwroot . '/blocks/rss_client/managefeeds.php?courseid=' . $this->page->course->id . '">' .
  69. get_string('feedsaddedit', 'block_rss_client') . '</a>');
  70. }
  71. $mform->addElement('text', 'config_title', get_string('uploadlabel'));
  72. $mform->setType('config_title', PARAM_NOTAGS);
  73. $mform->addElement('selectyesno', 'config_block_rss_client_show_channel_link', get_string('clientshowchannellinklabel', 'block_rss_client'));
  74. $mform->setDefault('config_block_rss_client_show_channel_link', 0);
  75. $mform->addElement('selectyesno', 'config_block_rss_client_show_channel_image', get_string('clientshowimagelabel', 'block_rss_client'));
  76. $mform->setDefault('config_block_rss_client_show_channel_image', 0);
  77. }
  78. }