本文整理汇总了PHP中forum::get_group_mode方法的典型用法代码示例。如果您正苦于以下问题:PHP forum::get_group_mode方法的具体用法?PHP forum::get_group_mode怎么用?PHP forum::get_group_mode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forum
的用法示例。
在下文中一共展示了forum::get_group_mode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
/**
* Shared logic that works out whether a particular subscriber receives a
* discussion or not.
* @param forum $forum Forum
* @param forum_discussion $discussion Discussion
* @param object $subscriber Subscriber
*/
function subscriber_receives_discussion($forum, $discussion, $subscriber)
{
// Did they subscribe specifically to this discussion?
$explicitsubscribed = array_key_exists($discussion->get_id(), $subscriber->discussionids);
// Did they subscribe to the group this discussion belongs to
$explicitsubscribedtogroup = in_array($discussion->get_group_id(), $subscriber->groupids);
$groupid = $discussion->get_group_id();
$visiblegroups = $forum->get_group_mode() == VISIBLEGROUPS;
// Conditions for each subscriber to get this discussion
$result = ($subscriber->wholeforum || $explicitsubscribed || $explicitsubscribedtogroup) && (!$groupid || $subscriber->accessallgroups || $visiblegroups || array_key_exists($groupid, $subscriber->groups)) && $forum->get_type()->can_view_discussion($discussion, $subscriber->id);
return $result;
}
示例2: copy
/**
* Copy the discussion and its posts to another forum and/or group.
* @param forum $targetforum Forum to copy the discussion to
* @param int $groupid If 'All participants' has been selected from the
* Separate groups dropdown box, use default value 0
*/
function copy($targetforum, $groupid)
{
global $SESSION, $CFG;
$oldforum = $this->get_forum();
$oldforumid = $oldforum->get_id();
$oldcourseid = $oldforum->get_course_id();
$targetforumid = $targetforum->get_id();
$targetcourseid = $targetforum->get_course_id();
//Clone the old discussion
$discussionobj = clone $this->discussionfields;
unset($discussionobj->id);
//update the forumid and gruopid to the target forumid and selected groupid
$discussionobj->forumid = $targetforumid;
unset($discussionobj->groupid);
if ($targetforum->get_group_mode() && $groupid) {
$discussionobj->groupid = $groupid;
}
forum_utils::start_transaction();
$newdiscussionid = forum_utils::insert_record('forumng_discussions', $discussionobj);
$rs = forum_utils::get_recordset('forumng_posts', 'discussionid', $this->get_id());
//$newids and $parentused are temp arrays used to
//$newids is a array of new postids using the indices of its old postids
//update the parentid of the post records copied over
//$hasattachments is a temp array for record the posts which has attachments.
$newids = array();
$parentsused = array();
$hasattachments = array();
while ($postrec = rs_fetch_next_record($rs)) {
$oldpostid = $postrec->id;
unset($postrec->id);
$postrec->discussionid = $newdiscussionid;
$postrec->mailstate = forum::MAILSTATE_DIGESTED;
$postrec->subject = addslashes($postrec->subject);
$postrec->message = addslashes($postrec->message);
$newpostid = forum_utils::insert_record('forumng_posts', $postrec);
$newids[$oldpostid] = $newpostid;
if ($postrec->parentpostid) {
$parentsused[$postrec->parentpostid] = true;
}
if ($postrec->attachments == 1) {
$hasattachments[$oldpostid] = $newpostid;
}
}
rs_close($rs);
//Update the postid and lastpostid in the discussion table no matter if they are null or not
$newpostid = $newids[$discussionobj->postid];
$newlastpostid = $newids[$discussionobj->lastpostid];
forum_utils::execute_sql("UPDATE {$CFG->prefix}forumng_discussions SET " . "postid=" . $newpostid . ", lastpostid=" . $newlastpostid . " WHERE id=" . $newdiscussionid);
foreach ($parentsused as $key => $value) {
$newparentpostid = $newids[$key];
//Update the parentpostids which have just been copied over
forum_utils::execute_sql("UPDATE {$CFG->prefix}forumng_posts SET " . "parentpostid=" . $newparentpostid . " WHERE parentpostid=" . $key . "AND discussionid = " . $newdiscussionid);
}
//Copy attachments
foreach ($hasattachments as $key => $value) {
$oldfolder = forum_post::get_any_attachment_folder($oldcourseid, $oldforumid, $this->get_id(), $key);
$newfolder = forum_post::get_any_attachment_folder($targetcourseid, $targetforumid, $newdiscussionid, $value);
$handle = forum_utils::opendir($oldfolder);
$created = false;
while (false !== ($name = readdir($handle))) {
//Get attachment file name one by one instead of using the get_attachment_names() to
//avoid creating a post object
if ($name != '.' && $name != '..') {
if (!is_dir("{$oldfolder}/{$name}")) {
// creating target folders and copying files
if (!$created) {
if (!check_dir_exists($newfolder, true, true)) {
throw new forum_exception("Failed to create attachment folder {$newfolder}");
}
$created = true;
}
forum_utils::copy("{$oldfolder}/{$name}", "{$newfolder}/{$name}");
}
}
}
closedir($handle);
}
forum_utils::finish_transaction();
}