]> git.mjollnir.org Git - moodle.git/commitdiff
mod-forum MDL-17550 Converted subscribers.php to use the new user_selector control
authorSam Hemelryk <sam@moodle.com>
Thu, 10 Dec 2009 02:11:28 +0000 (02:11 +0000)
committerSam Hemelryk <sam@moodle.com>
Thu, 10 Dec 2009 02:11:28 +0000 (02:11 +0000)
At the same time I also converted weblib.php::check_theme_arrows to use UTF8 arrows rather than entities.

lib/weblib.php
mod/forum/forum.css [new file with mode: 0644]
mod/forum/lib.php
mod/forum/renderer.php [new file with mode: 0644]
mod/forum/subscriber.html [deleted file]
mod/forum/subscribers.php
user/selector/lib.php

index d175fcc6d7927c77dff56964c152c01b1dc50364..e993a751b790f851c50288f6e5b0d8b83b4e8809 100644 (file)
@@ -1926,8 +1926,8 @@ function check_theme_arrows() {
     if (!isset($THEME->rarrow) and !isset($THEME->larrow)) {
         // Default, looks good in Win XP/IE 6, Win/Firefox 1.5, Win/Netscape 8...
         // Also OK in Win 9x/2K/IE 5.x
-        $THEME->rarrow = '&#x25BA;';
-        $THEME->larrow = '&#x25C4;';
+        $THEME->rarrow = '►'; // &#x25BA;
+        $THEME->larrow = '◄'; // &#x25C4;
         if (empty($_SERVER['HTTP_USER_AGENT'])) {
             $uagent = '';
         } else {
@@ -1937,12 +1937,12 @@ function check_theme_arrows() {
             || false !== strpos($uagent, 'Mac')) {
             // Looks good in Win XP/Mac/Opera 8/9, Mac/Firefox 2, Camino, Safari.
             // Not broken in Mac/IE 5, Mac/Netscape 7 (?).
-            $THEME->rarrow = '&#x25B6;';
-            $THEME->larrow = '&#x25C0;';
+            $THEME->rarrow = '▶'; // &#x25B6;
+            $THEME->larrow = '◀'; // &#x25C0;
         }
         elseif (false !== strpos($uagent, 'Konqueror')) {
-            $THEME->rarrow = '&rarr;';
-            $THEME->larrow = '&larr;';
+            $THEME->rarrow = '→'; // &rarr;
+            $THEME->larrow = '←'; // &larr;
         }
         elseif (isset($_SERVER['HTTP_ACCEPT_CHARSET'])
             && false === stripos($_SERVER['HTTP_ACCEPT_CHARSET'], 'utf-8')) {
diff --git a/mod/forum/forum.css b/mod/forum/forum.css
new file mode 100644 (file)
index 0000000..4e2dde0
--- /dev/null
@@ -0,0 +1,26 @@
+#mod-forum-subscribers .subscriberdiv,
+#mod-forum-subscribers .subscribertable {
+    width:100%;
+    background-color:#EEEEEE;
+    border:1px solid #BBBBBB;
+}
+#mod-forum-subscribers .subscriberdiv,
+#mod-forum-subscribers .subscribertable tr td {
+    vertical-align:top;
+    padding:0.2em 0.3em;
+}
+#mod-forum-subscribers .subscribertable tr td.existing {
+    width:42%;
+}
+#mod-forum-subscribers .subscribertable tr td.actions {
+    width:16%;
+    padding-top:3em;
+}
+#mod-forum-subscribers .subscribertable tr td.actions .actionbutton {
+    margin:0.3em 0;
+    padding:0.5em 0;
+    width:100%;
+}
+#mod-forum-subscribers .subscribertable tr td.potential {
+    width:42%;
+}
\ No newline at end of file
index 5daec0e17e0f4b5b5d27e3909be35ac5e52b5bf7..4406e729bcf29324d15e83ac48d688b6cf543e66 100644 (file)
@@ -16,7 +16,7 @@
 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
- * @package   mod-forum
+ * @package   forum
  * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
@@ -26,6 +26,7 @@ require_once($CFG->libdir.'/filelib.php');
 require_once($CFG->libdir.'/eventslib.php');
 require_once($CFG->libdir.'/portfoliolib.php');
 require_once($CFG->libdir . '/completionlib.php');
+require_once($CFG->dirroot.'/user/selector/lib.php');
 
 /// CONSTANTS ///////////////////////////////////////////////////////////
 
@@ -7964,7 +7965,7 @@ function forum_get_extra_capabilities() {
 }
 
 /**
- * @package   mod-forum
+ * @package   forum
  * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
@@ -8499,3 +8500,123 @@ function forum_extend_settings_navigation($settingsnav, $module=null) {
 
     return $forumkey;
 }
+
+abstract class forum_subscriber_selector_base extends user_selector_base {
+
+    protected $forumid = null;
+    protected $context = null;
+    protected $currentgroup = null;
+
+    public function __construct($name, $options) {
+        parent::__construct($name, $options);
+        if (isset($options['context'])) {
+            $this->context = $options['context'];
+        }
+        if (isset($options['currentgroup'])) {
+            $this->currentgroup = $options['currentgroup'];
+        }
+        if (isset($options['forumid'])) {
+            $this->forumid = $options['forumid'];
+        }
+    }
+
+    protected function get_options() {
+        global $CFG;
+        $options = parent::get_options();
+        $options['file'] =  substr(__FILE__, strlen($CFG->dirroot.'/'));
+        $options['context'] = $this->context;
+        $options['currentgroup'] = $this->currentgroup;
+        $options['forumid'] = $this->forumid;
+        return $options;
+    }
+
+}
+
+class forum_potential_subscriber_selector extends forum_subscriber_selector_base {
+
+    protected $forcesubscribed = false;
+    protected $existingsubscribers = array();
+
+    public function  __construct($name, $options) {
+        parent::__construct($name, $options);
+        if (isset($options['forcesubscribed'])) {
+            $this->forcesubscribed=true;
+        }
+    }
+
+    protected function get_options() {
+        $options = parent::get_options();
+        if ($this->forcesubscribed===true) {
+            $options['forcesubscribed']=1;
+        }
+        return $options;
+    }
+
+    public function find_users($search) {
+        global $DB;
+
+        $availableusers = forum_get_potential_subscribers($this->context, $this->currentgroup, $this->required_fields_sql('u'), 'firstname ASC, lastname ASC');
+
+        if (empty($availableusers)) {
+            $availableusers = array();
+        } else if ($search) {
+            $search = strtolower($search);
+            foreach ($availableusers as $key=>$user) {
+                if (stripos($user->firstname, $search) === false && stripos($user->lastname, $search) === false) {
+                    unset($availableusers[$key]);
+                }
+            }
+        }
+
+        // Unset any existing subscribers
+        if (count($this->existingsubscribers)>0 && !$this->forcesubscribed) {
+            foreach ($this->existingsubscribers as $group) {
+                foreach ($group as $user) {
+                    if (array_key_exists($user->id, $availableusers)) {
+                        unset($availableusers[$user->id]);
+                    }
+                }
+            }
+        }
+
+        if ($this->forcesubscribed) {
+            return array(get_string("existingsubscribers", 'forum') => $availableusers);
+        } else {
+            return array(get_string("potentialsubscribers", 'forum') => $availableusers);
+        }
+    }
+
+    public function set_existing_subscribers(array $users) {
+        $this->existingsubscribers = $users;
+    }
+
+    public function set_force_subscribed($setting=true) {
+        $this->forcesubscribed = true;
+    }
+}
+
+class forum_existing_subscriber_selector extends forum_subscriber_selector_base {
+
+    public function find_users($search) {
+        global $DB;
+        list($wherecondition, $params) = $this->search_sql($search, 'u');
+
+        $fields = 'SELECT ' . $this->required_fields_sql('u');
+        $from = ' FROM {user} u LEFT JOIN {forum_subscriptions} s ON s.userid=u.id';
+        $wherecondition .= ' AND s.forum=?';
+        $params[] = $this->forumid;
+        $order = ' ORDER BY lastname ASC, firstname ASC';
+
+        if ($this->currentgroup) {
+            $from .= ", {groups_members} gm ";
+            $wherecondition .= " AND gm.groupid = ? AND u.id = gm.userid";
+            $params[] = $this->currentgroup;
+        }
+        if (!$subscribers = $DB->get_records_sql($fields.$from.' WHERE '.$wherecondition.$order, $params)) {
+            $subscribers = array();
+        }
+        
+        return array(get_string("existingsubscribers", 'forum') => $subscribers);
+    }
+
+}
\ No newline at end of file
diff --git a/mod/forum/renderer.php b/mod/forum/renderer.php
new file mode 100644 (file)
index 0000000..c1f4ade
--- /dev/null
@@ -0,0 +1,136 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This file contains a custom renderer class used by the forum module.
+ *
+ * @package   forum
+ * @copyright 2009 Sam Hemelryk
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+/**
+ * A custom renderer class that extends the moodle_renderer_base and
+ * is used by the forum module.
+ * 
+ * @package   forum
+ * @copyright 2009 Sam Hemelryk
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ **/
+class moodle_mod_forum_renderer extends moodle_renderer_base {
+
+    /**
+     * A reference to the current general renderer probably {@see moodle_core_renderer}
+     * @var moodle_renderer_base
+     */
+    protected $output;
+
+    /**
+     * Contructor method, calls the parent constructor
+     * @param moodle_page $page
+     * @param moodle_renderer_base $output Probably moodle_core_renderer
+     */
+    public function __construct($page, $output) {
+        parent::__construct($page);
+        $this->output = $output;
+    }
+
+    /**
+     * This method is used to generate HTML for a subscriber selection form that
+     * uses two user_selector controls
+     *
+     * @param user_selector_base $existinguc
+     * @param user_selector_base $potentialuc
+     * @return string
+     */
+    public function subscriber_selection_form(user_selector_base $existinguc, user_selector_base $potentialuc) {
+        $output = '';
+        $formattributes = array();
+        $formattributes['id'] = 'subscriberform';
+        $formattributes['action'] = '';
+        $formattributes['method'] = 'post';
+        $output .= $this->output_start_tag('form', $formattributes);
+        $output .= $this->output_empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey()));
+
+        $existingcell = new html_table_cell();
+        $existingcell->text = $existinguc->display(true);
+        $existingcell->set_classes(array('existing'));
+        $actioncell = new html_table_cell();
+        $actioncell->text  = $this->output_start_tag('div', array());
+        $actioncell->text .= $this->output_empty_tag('input', array('type'=>'submit', 'name'=>'subscribe', 'value'=>$this->page->theme->larrow.' '.get_string('add'), 'class'=>'actionbutton'));
+        $actioncell->text .= $this->output_empty_tag('br', array());
+        $actioncell->text .= $this->output_empty_tag('input', array('type'=>'submit', 'name'=>'unsubscribe', 'value'=>$this->page->theme->rarrow.' '.get_string('remove'), 'class'=>'actionbutton'));
+        $actioncell->text .= $this->output_end_tag('div', array());
+        $actioncell->set_classes(array('actions'));
+        $potentialcell = new html_table_cell();
+        $potentialcell->text = $potentialuc->display(true);
+        $potentialcell->set_classes(array('potential'));
+
+        $table = new html_table();
+        $table->set_classes(array('subscribertable','boxaligncenter'));
+        $table->data = array(html_table_row::make(array($existingcell, $actioncell, $potentialcell)));
+        $output .= $this->output->table($table);
+        
+        $output .= $this->output_end_tag('form');
+        return $output;
+    }
+
+    /**
+     * This function generates HTML to display a subscriber overview, primarily used on
+     * the subscribers page if editing was turned off
+     *
+     * @param array $users
+     * @param object $forum
+     * @param object $course
+     * @return string
+     */
+    public function subscriber_overview($users, $forum , $course) {
+        $output = '';
+        if (!$users || !is_array($users) || count($users)===0) {
+            $output .= $this->output->heading(get_string("nosubscribers", "forum"));
+        } else {
+            $output .= $this->output->heading(get_string("subscribersto","forum", "'".format_string($forum->name)."'"));
+            $table = new html_table();
+            $table->cellpadding = 5;
+            $table->cellspacing = 5;
+            $table->tablealign = 'center';
+            $table->data = array();
+            foreach ($users as $user) {
+                $table->data[] = array($this->output->user_picture(moodle_user_picture::make($user, $course->id)), fullname($user), $user->email);
+            }
+            $output .= $this->output->table($table);
+        }
+        return $output;
+    }
+
+    /**
+     * This is used to display a control containing all of the subscribed users so that
+     * it can be searched
+     *
+     * @param user_selector_base $existingusers
+     * @return string
+     */
+    public function subscribed_users(user_selector_base $existingusers) {
+        $output  = $this->output->box_start('subscriberdiv boxaligncenter');
+        $output .= $this->output_tag('p', array(), get_string('forcessubscribe', 'forum'));
+        $output .= $existingusers->display(true);
+        $output .= $this->output->box_end();
+        return $output;
+    }
+        
+
+}
\ No newline at end of file
diff --git a/mod/forum/subscriber.html b/mod/forum/subscriber.html
deleted file mode 100644 (file)
index 5ea4b0f..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-
-<form id="subscriberform" method="post" action="subscribers.php">
-<input type="hidden" name="id" value="<?php echo $id?>" />
-<input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" />
-  <table align="center" border="0" cellpadding="5" cellspacing="0">
-    <tr>
-      <td valign="top">
-          <?php echo count($subscribers) . " ". $strexistingsubscribers ?>
-      </td>
-      <td></td>
-      <td valign="top">
-          <?php echo $strpotentialsubscribers ?>
-      </td>
-    </tr>
-    <tr>
-      <td valign="top">
-          <select name="removeselect[]" size="20" id="removeselect" multiple="multiple"
-                  onFocus="getElementById('subscriberform').add.disabled=true;
-                           getElementById('subscriberform').remove.disabled=false;
-                           getElementById('subscriberform').addselect.selectedIndex=-1;">
-          <?php
-              foreach ($subscribers as $subscriber) {
-                  $fullname = fullname($subscriber, true);
-                  echo "<option value=\"$subscriber->id\">".$fullname.", ".$subscriber->email."</option>\n";
-              }
-          ?>
-
-          </select></td>
-      <td valign="top">
-        <br />
-        <input name="add" type="submit" id="add" value="&larr;" />
-        <br />
-        <input name="remove" type="submit" id="remove" value="&rarr;" />
-        <br />
-      </td>
-      <td valign="top">
-          <select name="addselect[]" size="20" id="addselect" multiple="multiple"
-                  onFocus="getElementById('subscriberform').add.disabled=false;
-                           getElementById('subscriberform').remove.disabled=true;
-                           getElementById('subscriberform').removeselect.selectedIndex=-1;">
-          <?php
-              if (isset($searchusers)) {
-                  echo "<optgroup label=\"$strsearchresults (" . count($searchusers) . ")\">\n";
-                  foreach ($searchusers as $user) {
-                      $fullname = fullname($user, true);
-                      echo "<option value=\"$user->id\">".$fullname.", ".$user->email."</option>\n";
-                  }
-                  echo "</optgroup>\n";
-              }
-              if (!empty($users)) {
-                  foreach ($users as $user) {
-                      $fullname = fullname($user, true);
-                      echo "<option value=\"$user->id\">".$fullname.", ".$user->email."</option>\n";
-                  }
-              }
-          ?>
-         </select>
-         <br />
-         <input type="text" name="searchtext" size="30" value="<?php p($searchtext, true) ?>" />
-         <input name="search" id="search" type="submit" value="<?php p($strsearch) ?>" />
-         <?php
-              if (isset($searchusers)) {
-                  echo '<input name="showall" id="showall" type="submit" value="'.s($strshowall).'" />'."\n";
-              }
-         ?>
-       </td>
-    </tr>
-  </table>
-</form>
-
-
index f3e50e72a65ba3c5803a22376ecd487fcb70b698..477c4db004cce1675c4218acf5127fa889535878 100644 (file)
@@ -1,5 +1,28 @@
 <?php
 
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This file is used to display and organise forum subscribers
+ *
+ * @package   forum
+ * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
 require_once("../../config.php");
 require_once("lib.php");
 
@@ -16,14 +39,8 @@ if ($edit !== 0) {
 }
 $PAGE->set_url($url);
 
-if (! $forum = $DB->get_record('forum', array('id'=>$id))) {
-    print_error('invalidforumid', 'forum');
-}
-
-if (! $course = $DB->get_record('course', array('id'=>$forum->course))) {
-    print_error('invalidcourseid');
-}
-
+$forum = $DB->get_record('forum', array('id'=>$id), '*', MUST_EXIST);
+$course = $DB->get_record('course', array('id'=>$forum->course), '*', MUST_EXIST);
 if (! $cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) {
     $cm->id = 0;
 }
@@ -31,7 +48,6 @@ if (! $cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) {
 require_login($course->id, false, $cm);
 
 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
-
 if (!has_capability('mod/forum:viewsubscribers', $context)) {
     print_error('nopermissiontosubscribe', 'forum');
 }
@@ -40,13 +56,45 @@ unset($SESSION->fromdiscussion);
 
 add_to_log($course->id, "forum", "view subscribers", "subscribers.php?id=$forum->id", $forum->id, $cm->id);
 
-$strsubscribeall = get_string("subscribeall", "forum");
-$strsubscribenone = get_string("subscribenone", "forum");
-$strsubscribers = get_string("subscribers", "forum");
-$strforums = get_string("forums", "forum");
+$forumoutput = $PAGE->theme->get_renderer('mod_forum', $PAGE);
+$currentgroup = groups_get_activity_group($cm);
+$options = array('forumid'=>$forum->id, 'currentgroup'=>$currentgroup, 'context'=>$context);
+$existingselector = new forum_existing_subscriber_selector('existingsubscribers', $options);
+$subscriberselector = new forum_potential_subscriber_selector('potentialsubscribers', $options);
+$subscriberselector->set_existing_subscribers($existingselector->find_users(''));
+
+if (data_submitted()) {
+    require_sesskey();
+    $subscribe = (bool)optional_param('subscribe', false, PARAM_RAW);
+    $unsubscribe = (bool)optional_param('unsubscribe', false, PARAM_RAW);
+    /** It has to be one or the other, not both or neither */
+    if (!($subscribe xor $unsubscribe)) {
+        print_error('invalidaction');
+    }
+    if ($subscribe) {
+        $users = $subscriberselector->get_selected_users();
+        foreach ($users as $user) {
+            if (!forum_subscribe($user->id, $id)) {
+                print_error('cannotaddsubscriber', 'forum', '', $user->id);
+            }
+        }
+    } else if ($unsubscribe) {
+        $users = $existingselector->get_selected_users();
+        foreach ($users as $user) {
+            if (!forum_unsubscribe($user->id, $id)) {
+                print_error('cannotremovesubscriber', 'forum', '', $user->id);
+            }
+        }
+    }
+    $subscriberselector->invalidate_selected_users();
+    $existingselector->invalidate_selected_users();
+    $subscriberselector->set_existing_subscribers($existingselector->find_users(''));
+}
 
+$strsubscribers = get_string("subscribers", "forum");
 $PAGE->navbar->add($strsubscribers);
 $PAGE->set_title($strsubscribers);
+$PAGE->requires->css('mod/forum/forum.css');
 if (has_capability('mod/forum:managesubscriptions', $context)) {
     $PAGE->set_button(forum_update_subscriptions_button($course->id, $id));
     if ($edit != -1) {
@@ -56,108 +104,13 @@ if (has_capability('mod/forum:managesubscriptions', $context)) {
     unset($USER->subscriptionsediting);
 }
 echo $OUTPUT->header();
-
-/// Check to see if groups are being used in this forum
-groups_print_activity_menu($cm, $CFG->wwwroot . "/mod/forum/subscribers.php?id=$forum->id");
-$currentgroup = groups_get_activity_group($cm);
-$groupmode = groups_get_activity_groupmode($cm);
-
-if (empty($USER->subscriptionsediting)) {         /// Display an overview of subscribers
-
-    if (! $users = forum_subscribed_users($course, $forum, $currentgroup, $context) ) {
-
-        echo $OUTPUT->heading(get_string("nosubscribers", "forum"));
-
-    } else {
-
-        echo $OUTPUT->heading(get_string("subscribersto","forum", "'".format_string($forum->name)."'"));
-
-        echo '<table align="center" cellpadding="5" cellspacing="5">';
-        foreach ($users as $user) {
-            echo '<tr><td>';
-            echo $OUTPUT->user_picture(moodle_user_picture::make($user, $course->id));
-            echo '</td><td>';
-            echo fullname($user);
-            echo '</td><td>';
-            echo $user->email;
-            echo '</td></tr>';
-        }
-        echo "</table>";
-    }
-
-    echo $OUTPUT->footer();
-    exit;
-}
-
-/// We are in editing mode.
-
-$strexistingsubscribers   = get_string("existingsubscribers", 'forum');
-$strpotentialsubscribers  = get_string("potentialsubscribers", 'forum');
-$straddsubscriber    = get_string("addsubscriber", 'forum');
-$strremovesubscriber = get_string("removesubscriber", 'forum');
-$strsearch        = get_string("search");
-$strsearchresults  = get_string("searchresults");
-$strshowall = get_string("showall");
-$strsubscribers = get_string("subscribers", "forum");
-$strforums      = get_string("forums", "forum");
-
-$searchtext = optional_param('searchtext', '', PARAM_RAW);
-if ($frm = data_submitted() and confirm_sesskey()) {
-
-/// A form was submitted so process the input
-    if (!empty($frm->add) and !empty($frm->addselect)) {
-        foreach ($frm->addselect as $addsubscriber) {
-            if (! forum_subscribe($addsubscriber, $id)) {
-                print_error('cannotaddsubscriber', 'forum', '', $addsubscriber);
-            }
-        }
-    } else if (!empty($frm->remove) and !empty($frm->removeselect)) {
-        foreach ($frm->removeselect as $removesubscriber) {
-            if (! forum_unsubscribe($removesubscriber, $id)) {
-                print_error('cannotremovesubscriber', 'forum', '', $removesubscriber);
-            }
-        }
-    } else if (!empty($frm->showall)) {
-        $searchtext = '';
-    }
-}
-
-/// Get all existing subscribers for this forum.
-if (!$subscribers = forum_subscribed_users($course, $forum, $currentgroup, $context)) {
-    $subscribers = array();
-}
-
-/// Get all the potential subscribers excluding users already subscribed
-$users = forum_get_potential_subscribers($context, $currentgroup, 'id,email,firstname,lastname', 'firstname ASC, lastname ASC');
-if (!$users) {
-    $users = array();
-}
-foreach ($subscribers as $subscriber) {
-    unset($users[$subscriber->id]);
-}
-
-/// This is yucky, but do the search in PHP, becuase the list we are using comes from get_users_by_capability,
-/// which does not allow searching in the database. Fortunately the list is only this list of users in this
-/// course, which is normally OK, except on the site course of a big site. But before you can enter a search
-/// term, you have already seen a page that lists everyone, since this code never does paging, so you have probably
-/// already crashed your server if you are going to. This will be fixed properly for Moodle 2.0: MDL-17550.
-if ($searchtext) {
-    $searchusers = array();
-    $lcsearchtext = moodle_strtolower($searchtext);
-    foreach ($users as $userid => $user) {
-        if (strpos(moodle_strtolower($user->email), $lcsearchtext) !== false ||
-                strpos(moodle_strtolower($user->firstname . ' ' . $user->lastname), $lcsearchtext) !== false) {
-            $searchusers[$userid] = $user;
-        }
-        unset($users[$userid]);
-    }
+echo $OUTPUT->heading(get_string('forum', 'forum').' '.$strsubscribers);
+if (empty($USER->subscriptionsediting)) {
+    echo $forumoutput->subscriber_overview(forum_subscribed_users($course, $forum, $currentgroup, $context), $forum, $course);
+} else if (forum_is_forcesubscribed($forum)) {
+    $subscriberselector->set_force_subscribed(true);
+    echo $forumoutput->subscribed_users($subscriberselector);
+} else {
+    echo $forumoutput->subscriber_selection_form($existingselector, $subscriberselector);
 }
-
-echo $OUTPUT->box_start('generalbox boxaligncenter');
-
-include('subscriber.html');
-
-echo $OUTPUT->box_end();
-
-echo $OUTPUT->footer();
-
+echo $OUTPUT->footer();
\ No newline at end of file
index 587f5b817e9137aec81117a3d42fe46066cbd78e..46c5f05b6603bbe536583279992e75a06ecd4ed8 100644 (file)
@@ -63,9 +63,9 @@ abstract class user_selector_base {
     /** When searching, do we only match the starts of fields (better performace)
      * or do we match occurrences anywhere? */
     protected $searchanywhere = false;
-
     // This is used by get selected users,
-    private $validatinguserids = null;
+    protected $validatinguserids = null;
+    
     // Used to ensure we only output the search options for one user selector on
     // each page.
     private static $searchoptionsoutput = false;
@@ -372,7 +372,7 @@ abstract class user_selector_base {
         $users = array();
         foreach ($groupedusers as $group) {
             foreach ($group as $user) {
-                if (!isset($users[$user->id]) && empty($user->disabled)) {
+                if (!isset($users[$user->id]) && empty($user->disabled) && in_array($user->id, $userids)) {
                     $users[$user->id] = $user;
                 }
             }