本文整理匯總了PHP中mod_forum\subscriptions::get_potential_subscribers方法的典型用法代碼示例。如果您正苦於以下問題:PHP subscriptions::get_potential_subscribers方法的具體用法?PHP subscriptions::get_potential_subscribers怎麽用?PHP subscriptions::get_potential_subscribers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mod_forum\subscriptions
的用法示例。
在下文中一共展示了subscriptions::get_potential_subscribers方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: forum_update_instance
/**
* Given an object containing all the necessary data,
* (defined by the form in mod_form.php) this function
* will update an existing instance with new data.
*
* @global object
* @param object $forum forum instance (with magic quotes)
* @return bool success
*/
function forum_update_instance($forum, $mform)
{
global $DB, $OUTPUT, $USER;
$forum->timemodified = time();
$forum->id = $forum->instance;
if (empty($forum->assessed)) {
$forum->assessed = 0;
}
if (empty($forum->ratingtime) or empty($forum->assessed)) {
$forum->assesstimestart = 0;
$forum->assesstimefinish = 0;
}
$oldforum = $DB->get_record('forum', array('id' => $forum->id));
// MDL-3942 - if the aggregation type or scale (i.e. max grade) changes then recalculate the grades for the entire forum
// if scale changes - do we need to recheck the ratings, if ratings higher than scale how do we want to respond?
// for count and sum aggregation types the grade we check to make sure they do not exceed the scale (i.e. max score) when calculating the grade
if ($oldforum->assessed != $forum->assessed or $oldforum->scale != $forum->scale) {
forum_update_grades($forum);
// recalculate grades for the forum
}
if ($forum->type == 'single') {
// Update related discussion and post.
$discussions = $DB->get_records('forum_discussions', array('forum' => $forum->id), 'timemodified ASC');
if (!empty($discussions)) {
if (count($discussions) > 1) {
echo $OUTPUT->notification(get_string('warnformorepost', 'forum'));
}
$discussion = array_pop($discussions);
} else {
// try to recover by creating initial discussion - MDL-16262
$discussion = new stdClass();
$discussion->course = $forum->course;
$discussion->forum = $forum->id;
$discussion->name = $forum->name;
$discussion->assessed = $forum->assessed;
$discussion->message = $forum->intro;
$discussion->messageformat = $forum->introformat;
$discussion->messagetrust = true;
$discussion->mailnow = false;
$discussion->groupid = -1;
$message = '';
forum_add_discussion($discussion, null, $message);
if (!($discussion = $DB->get_record('forum_discussions', array('forum' => $forum->id)))) {
print_error('cannotadd', 'forum');
}
}
if (!($post = $DB->get_record('forum_posts', array('id' => $discussion->firstpost)))) {
print_error('cannotfindfirstpost', 'forum');
}
$cm = get_coursemodule_from_instance('forum', $forum->id);
$modcontext = context_module::instance($cm->id, MUST_EXIST);
$post = $DB->get_record('forum_posts', array('id' => $discussion->firstpost), '*', MUST_EXIST);
$post->subject = $forum->name;
$post->message = $forum->intro;
$post->messageformat = $forum->introformat;
$post->messagetrust = trusttext_trusted($modcontext);
$post->modified = $forum->timemodified;
$post->userid = $USER->id;
// MDL-18599, so that current teacher can take ownership of activities.
if ($mform and $draftid = file_get_submitted_draft_itemid('introeditor')) {
// Ugly hack - we need to copy the files somehow.
$options = array('subdirs' => true);
// Use the same options as intro field!
$post->message = file_save_draft_area_files($draftid, $modcontext->id, 'mod_forum', 'post', $post->id, $options, $post->message);
}
$DB->update_record('forum_posts', $post);
$discussion->name = $forum->name;
$DB->update_record('forum_discussions', $discussion);
}
$DB->update_record('forum', $forum);
$modcontext = context_module::instance($forum->coursemodule);
if ($forum->forcesubscribe == FORUM_INITIALSUBSCRIBE && $oldforum->forcesubscribe != $forum->forcesubscribe) {
$users = \mod_forum\subscriptions::get_potential_subscribers($modcontext, 0, 'u.id, u.email', '');
foreach ($users as $user) {
\mod_forum\subscriptions::subscribe_user($user->id, $forum, $modcontext);
}
}
forum_grade_item_update($forum);
return true;
}
示例2: fetch_subscribed_users
/**
* Returns a list of user objects who are subscribed to this forum.
*
* @param stdClass $forum The forum record.
* @param int $groupid The group id if restricting subscriptions to a group of users, or 0 for all.
* @param context_module $context the forum context, to save re-fetching it where possible.
* @param string $fields requested user fields (with "u." table prefix).
* @param boolean $includediscussionsubscriptions Whether to take discussion subscriptions and unsubscriptions into consideration.
* @return array list of users.
*/
public static function fetch_subscribed_users($forum, $groupid = 0, $context = null, $fields = null, $includediscussionsubscriptions = false)
{
global $CFG, $DB;
if (empty($fields)) {
$allnames = get_all_user_name_fields(true, 'u');
$fields = "u.id,\n u.username,\n {$allnames},\n u.maildisplay,\n u.mailformat,\n u.maildigest,\n u.imagealt,\n u.email,\n u.emailstop,\n u.city,\n u.country,\n u.lastaccess,\n u.lastlogin,\n u.picture,\n u.timezone,\n u.theme,\n u.lang,\n u.trackforums,\n u.mnethostid";
}
// Retrieve the forum context if it wasn't specified.
$context = forum_get_context($forum->id, $context);
if (self::is_forcesubscribed($forum)) {
$results = \mod_forum\subscriptions::get_potential_subscribers($context, $groupid, $fields, "u.email ASC");
} else {
// Only active enrolled users or everybody on the frontpage.
list($esql, $params) = get_enrolled_sql($context, '', $groupid, true);
$params['forumid'] = $forum->id;
if ($includediscussionsubscriptions) {
$params['sforumid'] = $forum->id;
$params['dsforumid'] = $forum->id;
$params['unsubscribed'] = self::FORUM_DISCUSSION_UNSUBSCRIBED;
$sql = "SELECT {$fields}\n FROM (\n SELECT userid FROM {forum_subscriptions} s\n WHERE\n s.forum = :sforumid\n UNION\n SELECT userid FROM {forum_discussion_subs} ds\n WHERE\n ds.forum = :dsforumid AND ds.preference <> :unsubscribed\n ) subscriptions\n JOIN {user} u ON u.id = subscriptions.userid\n JOIN ({$esql}) je ON je.id = u.id\n ORDER BY u.email ASC";
} else {
$sql = "SELECT {$fields}\n FROM {user} u\n JOIN ({$esql}) je ON je.id = u.id\n JOIN {forum_subscriptions} s ON s.userid = u.id\n WHERE\n s.forum = :forumid\n ORDER BY u.email ASC";
}
$results = $DB->get_records_sql($sql, $params);
}
// Guest user should never be subscribed to a forum.
unset($results[$CFG->siteguest]);
// Apply the activity module availability resetrictions.
$cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course);
$modinfo = get_fast_modinfo($forum->course);
$info = new \core_availability\info_module($modinfo->get_cm($cm->id));
$results = $info->filter_user_list($results);
return $results;
}
示例3: forum_get_potential_subscribers
/**
* Get the list of potential subscribers to a forum.
*
* @param object $forumcontext the forum context.
* @param integer $groupid the id of a group, or 0 for all groups.
* @param string $fields the list of fields to return for each user. As for get_users_by_capability.
* @param string $sort sort order. As for get_users_by_capability.
* @return array list of users.
* @deprecated since Moodle 2.8 use \mod_forum\subscriptions::get_potential_subscribers() instead
*/
function forum_get_potential_subscribers($forumcontext, $groupid, $fields, $sort = '')
{
debugging("forum_get_potential_subscribers() has been deprecated, please use \\mod_forum\\subscriptions::get_potential_subscribers() instead.", DEBUG_DEVELOPER);
\mod_forum\subscriptions::get_potential_subscribers($forumcontext, $groupid, $fields, $sort);
}
示例4: print_error
$forums = $modinfo->get_instances_of('forum');
if (!array_key_exists($forumto->id, $forums)) {
print_error('cannotmovetonotfound', 'forum', $return);
}
$cmto = $forums[$forumto->id];
if (!$cmto->uservisible) {
print_error('cannotmovenotvisible', 'forum', $return);
}
$destinationctx = context_module::instance($cmto->id);
require_capability('mod/forum:startdiscussion', $destinationctx);
if (!forum_move_attachments($discussion, $forum->id, $forumto->id)) {
echo $OUTPUT->notification("Errors occurred while moving attachment directories - check your file permissions");
}
// For each subscribed user in this forum and discussion, copy over per-discussion subscriptions if required.
$discussiongroup = $discussion->groupid == -1 ? 0 : $discussion->groupid;
$potentialsubscribers = \mod_forum\subscriptions::get_potential_subscribers($modcontext, $discussiongroup, 'u.id');
// Pre-seed the subscribed_discussion caches.
// Firstly for the forum being moved to.
\mod_forum\subscriptions::fill_subscription_cache($forumto->id);
// And also for the discussion being moved.
\mod_forum\subscriptions::fill_subscription_cache($forum->id);
$subscriptionchanges = array();
foreach ($potentialsubscribers as $subuser) {
$userid = $subuser->id;
$targetsubscription = \mod_forum\subscriptions::is_subscribed($userid, $forumto);
if (\mod_forum\subscriptions::is_subscribed($userid, $forum, $discussion->id)) {
if (!$targetsubscription) {
$subscriptionchanges[$userid] = \mod_forum\subscriptions::FORUM_DISCUSSION_SUBSCRIBED;
}
} else {
if ($targetsubscription) {
示例5: require_sesskey
require_sesskey();
switch ($mode) {
case FORUM_CHOOSESUBSCRIBE:
// 0
\mod_forum\subscriptions::set_subscription_mode($forum->id, FORUM_CHOOSESUBSCRIBE);
redirect($returnto, get_string("everyonecannowchoose", "forum"), 1);
break;
case FORUM_FORCESUBSCRIBE:
// 1
\mod_forum\subscriptions::set_subscription_mode($forum->id, FORUM_FORCESUBSCRIBE);
redirect($returnto, get_string("everyoneisnowsubscribed", "forum"), 1);
break;
case FORUM_INITIALSUBSCRIBE:
// 2
if ($forum->forcesubscribe != FORUM_INITIALSUBSCRIBE) {
$users = \mod_forum\subscriptions::get_potential_subscribers($context, 0, 'u.id, u.email', '');
foreach ($users as $user) {
\mod_forum\subscriptions::subscribe_user($user->id, $forum, $context);
}
}
\mod_forum\subscriptions::set_subscription_mode($forum->id, FORUM_INITIALSUBSCRIBE);
redirect($returnto, get_string("everyoneisnowsubscribed", "forum"), 1);
break;
case FORUM_DISALLOWSUBSCRIBE:
// 3
\mod_forum\subscriptions::set_subscription_mode($forum->id, FORUM_DISALLOWSUBSCRIBE);
redirect($returnto, get_string("noonecansubscribenow", "forum"), 1);
break;
default:
print_error(get_string('invalidforcesubscribe', 'forum'));
}