当前位置: 首页>>代码示例>>PHP>>正文


PHP forum_add_attachment函数代码示例

本文整理汇总了PHP中forum_add_attachment函数的典型用法代码示例。如果您正苦于以下问题:PHP forum_add_attachment函数的具体用法?PHP forum_add_attachment怎么用?PHP forum_add_attachment使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了forum_add_attachment函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: forum_add_discussion

/**
 * Given an object containing all the necessary data,
 * create a new discussion and return the id
 */
function forum_add_discussion($discussion, &$message)
{
    global $USER, $CFG;
    $timenow = time();
    // The first post is stored as a real post, and linked
    // to from the discuss entry.
    $forum = get_record('forum', 'id', $discussion->forum);
    $post = new object();
    $post->discussion = 0;
    $post->parent = 0;
    $post->userid = $USER->id;
    $post->created = $timenow;
    $post->modified = $timenow;
    $post->mailed = 0;
    $post->subject = $discussion->name;
    $post->message = $discussion->intro;
    $post->attachment = "";
    $post->forum = $forum->id;
    // speedup
    $post->course = $forum->course;
    // speedup
    $post->format = $discussion->format;
    $post->mailnow = $discussion->mailnow;
    if (!($post->id = insert_record("forum_posts", $post))) {
        return 0;
    }
    if ($post->attachment = forum_add_attachment($post, 'attachment', $message)) {
        set_field("forum_posts", "attachment", $post->attachment, "id", $post->id);
        //ignore errors
    }
    // Now do the main entry for the discussion,
    // linking to this first post
    $discussion->firstpost = $post->id;
    $discussion->timemodified = $timenow;
    $discussion->usermodified = $post->userid;
    $discussion->userid = $USER->id;
    if (!($post->discussion = insert_record("forum_discussions", $discussion))) {
        delete_records("forum_posts", "id", $post->id);
        return 0;
    }
    // Finally, set the pointer on the post.
    if (!set_field("forum_posts", "discussion", $post->discussion, "id", $post->id)) {
        delete_records("forum_posts", "id", $post->id);
        delete_records("forum_discussions", "id", $post->discussion);
        return 0;
    }
    if (forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum)) {
        forum_tp_mark_post_read($post->userid, $post, $post->forum);
    }
    return $post->discussion;
}
开发者ID:r007,项目名称:PMoodle,代码行数:55,代码来源:lib.php

示例2: forum_add_discussion

/**
 * Given an object containing all the necessary data,
 * create a new discussion and return the id
 *
 * @param object $post
 * @param mixed $mform
 * @param string $unused
 * @param int $userid
 * @return object
 */
function forum_add_discussion($discussion, $mform=null, $unused=null, $userid=null) {
    global $USER, $CFG, $DB;

    $timenow = time();

    if (is_null($userid)) {
        $userid = $USER->id;
    }

    // The first post is stored as a real post, and linked
    // to from the discuss entry.

    $forum = $DB->get_record('forum', array('id'=>$discussion->forum));
    $cm    = get_coursemodule_from_instance('forum', $forum->id);

    $post = new stdClass();
    $post->discussion    = 0;
    $post->parent        = 0;
    $post->userid        = $userid;
    $post->created       = $timenow;
    $post->modified      = $timenow;
    $post->mailed        = FORUM_MAILED_PENDING;
    $post->subject       = $discussion->name;
    $post->message       = $discussion->message;
    $post->messageformat = $discussion->messageformat;
    $post->messagetrust  = $discussion->messagetrust;
    $post->attachments   = isset($discussion->attachments) ? $discussion->attachments : null;
    $post->forum         = $forum->id;     // speedup
    $post->course        = $forum->course; // speedup
    $post->mailnow       = $discussion->mailnow;

    $post->id = $DB->insert_record("forum_posts", $post);

    // TODO: Fix the calling code so that there always is a $cm when this function is called
    if (!empty($cm->id) && !empty($discussion->itemid)) {   // In "single simple discussions" this may not exist yet
        $context = context_module::instance($cm->id);
        $text = file_save_draft_area_files($discussion->itemid, $context->id, 'mod_forum', 'post', $post->id,
                mod_forum_post_form::editor_options(), $post->message);
        $DB->set_field('forum_posts', 'message', $text, array('id'=>$post->id));
    }

    // Now do the main entry for the discussion, linking to this first post

    $discussion->firstpost    = $post->id;
    $discussion->timemodified = $timenow;
    $discussion->usermodified = $post->userid;
    $discussion->userid       = $userid;

    $post->discussion = $DB->insert_record("forum_discussions", $discussion);

    // Finally, set the pointer on the post.
    $DB->set_field("forum_posts", "discussion", $post->discussion, array("id"=>$post->id));

    if (!empty($cm->id)) {
        forum_add_attachment($post, $forum, $cm, $mform, $unused);
    }

    if (forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum)) {
        forum_tp_mark_post_read($post->userid, $post, $post->forum);
    }

    // Let Moodle know that assessable content is uploaded (eg for plagiarism detection)
    if (!empty($cm->id)) {
        forum_trigger_content_uploaded_event($post, $cm, 'forum_add_discussion');
    }

    return $post->discussion;
}
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:78,代码来源:lib.php

示例3: forum_add_discussion

/**
 * Given an object containing all the necessary data,
 * create a new discussion and return the id
 */
function forum_add_discussion($discussion, $mform = null, &$message = null)
{
    global $USER, $CFG, $DB;
    $timenow = time();
    // The first post is stored as a real post, and linked
    // to from the discuss entry.
    $forum = $DB->get_record('forum', array('id' => $discussion->forum));
    $cm = get_coursemodule_from_instance('forum', $forum->id);
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    $post = new object();
    $post->discussion = 0;
    $post->parent = 0;
    $post->userid = $USER->id;
    $post->created = $timenow;
    $post->modified = $timenow;
    $post->mailed = 0;
    $post->subject = $discussion->name;
    $post->message = $discussion->intro;
    $post->messageformat = $discussion->messageformat;
    $post->messagetrust = $discussion->messagetrust;
    $post->attachments = $discussion->attachments;
    $post->forum = $forum->id;
    // speedup
    $post->course = $forum->course;
    // speedup
    $post->mailnow = $discussion->mailnow;
    if (!($post->id = $DB->insert_record("forum_posts", $post))) {
        return 0;
    }
    $text = file_save_draft_area_files($discussion->itemid, $context->id, 'forum_post', $post->id, array('subdirs' => true), $post->message);
    $DB->set_field('forum_posts', 'message', $text, array('id' => $post->id));
    // Now do the main entry for the discussion, linking to this first post
    $discussion->firstpost = $post->id;
    $discussion->timemodified = $timenow;
    $discussion->usermodified = $post->userid;
    $discussion->userid = $USER->id;
    if (!($post->discussion = $DB->insert_record("forum_discussions", $discussion))) {
        $DB->delete_records("forum_posts", array("id" => $post->id));
        return 0;
    }
    // Finally, set the pointer on the post.
    if (!$DB->set_field("forum_posts", "discussion", $post->discussion, array("id" => $post->id))) {
        $DB->delete_records("forum_posts", array("id" => $post->id));
        $DB->delete_records("forum_discussions", array("id" => $post->discussion));
        return 0;
    }
    if (!empty($cm->id)) {
        forum_add_attachment($post, $forum, $cm, $mform, $message);
    }
    if (forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum)) {
        forum_tp_mark_post_read($post->userid, $post, $post->forum);
    }
    return $post->discussion;
}
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:58,代码来源:lib.php


注:本文中的forum_add_attachment函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。