Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 402] [Versions 400 and 403]

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