/**
 * Updates the fulltext search information for a post which is being added or
 * updated.
 * @param object $post Post data, including slashes for database. Must have
 *   fields id,userid,groupid (if applicable), title, message
 * @param object $cm Course-module
 * @return True if search update was successful
 */
function oublog_search_update($post, $cm)
{
    // Do nothing if OU search is not installed
    if (!oublog_search_installed()) {
        return true;
    }
    // Get search document
    $doc = oublog_get_search_document($post, $cm);
    // Sort out tags for use as extrastrings
    $taglist = oublog_get_post_tags($post, true);
    if (count($taglist) == 0) {
        $taglist = null;
    }
    // Update information about this post (works ok for add or edit)
    $doc->update($post->title, $post->message, null, null, $taglist);
    return true;
}
示例#2
0
function oublog_do_delete($course, $cm, $oublog, $post)
{
    global $DB, $USER;
    $updatepost = (object) array('id' => $post->id, 'deletedby' => $USER->id, 'timedeleted' => time());
    $transaction = $DB->start_delegated_transaction();
    $DB->update_record('oublog_posts', $updatepost);
    if (!oublog_update_item_tags($post->oubloginstancesid, $post->id, array(), $post->visibility)) {
        print_error('tagupdatefailed', 'oublog');
    }
    if (oublog_search_installed()) {
        $doc = oublog_get_search_document($updatepost, $cm);
        $doc->delete();
    }
    // Inform completion system, if available.
    $completion = new completion_info($course);
    if ($completion->is_enabled($cm) && $oublog->completionposts) {
        $completion->update_state($cm, COMPLETION_INCOMPLETE, $post->userid);
    }
    $transaction->allow_commit();
}
    $viewurl = 'view.php?user='******'course';
    $viewurl = 'view.php?id=' . $cm->id;
}
if (!empty($postid) && !empty($confirm)) {
    $expost = get_record('oublog_posts', 'id', $postid);
    $updatepost = (object) array('id' => $postid, 'deletedby' => $USER->id, 'timedeleted' => time());
    $tw = new transaction_wrapper();
    update_record('oublog_posts', $updatepost);
    if (!oublog_update_item_tags($expost->oubloginstancesid, $expost->id, array(), $expost->visibility)) {
        $tw->rollback();
        error('Failed to update tags');
    }
    if (oublog_search_installed()) {
        $doc = oublog_get_search_document($updatepost, $cm);
        $doc->delete();
    }
    // Inform completion system, if available
    if (class_exists('ouflags')) {
        if (completion_is_enabled($course, $cm) && $oublog->completionposts) {
            completion_update_state($course, $cm, COMPLETION_INCOMPLETE, $postauthor);
        }
    }
    $tw->commit();
    redirect($viewurl);
    exit;
}
/// Get Strings
$stroublogs = get_string('modulenameplural', 'oublog');
$stroublog = get_string('modulename', 'oublog');