Source for file module_blog.php
Documentation is available at module_blog.php
// This file is part of the Sloodle project (www.sloodle.org)
* This file defines a blog module for Sloodle.
* @copyright Copyright (c) 2008 Sloodle (various contributors)
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
* @contributor Peter R. Bloomfield
/** The Sloodle module base. */
require_once(SLOODLE_LIBROOT.
'/modules/module_base.php');
/** General Sloodle functions. */
require_once(SLOODLE_LIBROOT.
'/general.php');
/** Blog visibility identifier for private posts. (These can only be viewed by the person who posted them) */
define('SLOODLE_BLOG_VISIBILITY_PRIVATE', 'draft');
/** Blog visibility identifier for site posts. (These can be viewed by anybody who is registered on the site) */
define('SLOODLE_BLOG_VISIBILITY_SITE', 'site');
/** Blog visibility identifier for public posts. (These can be viewed by anybody) */
define('SLOODLE_BLOG_VISIBILITY_PUBLIC', 'public');
* The Sloodle blog module class.
parent::$constructor($_session);
* Checks if blogging is enabled on the site.
* @return bool True if blogging is enabled, or false otherwise
// If blog level is not specified, then blogging is disabled
if (empty($CFG->bloglevel)) return false;
* Checks if the currently logged-in user has permission to create blog entries.
* @return bool True if user has permission, or false otherwise
return has_capability('moodle/blog:create', get_context_instance(CONTEXT_SYSTEM, SITEID));
* Attempts to write a new blog entry to the database, attributed to the user currently loaded in the {@link SloodleSession}.
* All of the text provided in parameters _must_ be database-safe!
* @param string $subject The subject line of the post
* @param string $body The body of the post
* @param string $visibility The visibility identifier of the post (defaults to site level)
* @return bool True if successful or false otherwise
function add_entry($subject, $body, $visibility =
'')
// Make sure a user is loaded
if (!isset
($this->_session)) return false;
if (!$this->_session->user->is_user_loaded()) return false;
// Make sure the parameters are not empty
if (empty($subject) ||
empty($body)) return false;
// Convert 'private' to 'draft' visibility
// Create a new database record
$blogEntry =
new stdClass();
$blogEntry->subject =
$subject;
$blogEntry->summary =
$body;
$blogEntry->module =
'blog';
$blogEntry->userid =
$this->_session->user->get_user_id();
$blogEntry->publishstate =
$visibility;
$blogEntry->lastmodified =
time();
$blogEntry->created =
time();
$blogEntry->courseid =
0;
$blogEntry->moduleid =
0;
$blogEntry->coursemoduleid =
0;
$blogEntry->uniquehash =
'';
// Attempt to insert it into the database
$blogEntry->id =
insert_record('post', $blogEntry);
if (!$blogEntry->id) return false;
add_to_log(SITEID, 'blog', 'add', 'index.php?userid='.
$blogEntry->userid.
'&postid='.
$blogEntry->id, "Entry posted from SL via Sloodle: \"{$blogEntry->subject}\"
", $blogEntry->userid);
* Gets the identified post.
* @param mixed $id The unique site-wide identifier of the post.
* @return SloodleBlogPost|boolReturns a {@link SloodleBlogPost} object, or FALSE if unsuccessful.
// Attempt to fetch the data from the database
$rec =
get_record('post', id, $id);
* Gets the most recent public post.
* @return SloodleBlogPost|boolReturns a {@link SloodleBlogPost} object, or FALSE if unsuccessful.
// Attempt to fetch the data from the database
$rec =
get_records_select('post', "publishstate = 'public'", 'created DESC', '*', 0, 1);
$post->load_data($rec[0]);
* Gets the most recent public/site level post.
* @return SloodleBlogPost|boolReturns a {@link SloodleBlogPost} object, or FALSE if unsuccessful.
// Attempt to fetch the data from the database
$rec =
get_records_select('post', "publishstate = 'site' OR publishstate = 'public'", 'created DESC', '*', 0, 1);
$post->load_data($rec[0]);
* Gets the most recent post by a particular user, regardless of visibility.
* @param SloodleUser $user The user to search for. Uses the current {@link SloodleSession} user if unspecified.
* @return SloodleBlogPost|boolReturns a {@link SloodleBlogPost} object, or FALSE if unsuccessful.
// Get the user data from the Session, if needed
if (!$user->is_user_loaded()) return false;
// Attempt to fetch the data from the database
$userid = (int)
$user->get_user_id();
$rec =
get_records_select('post', "userid = $userid", 'created DESC', '*', 0, 1);
$post->load_data($rec[0]);
* Gets the name of this module instance.
* @return string The name of this controller
* Gets the intro description of this module instance, if available.
* @return string The intro description of this controller
* Gets the identifier of the course this controller belongs to.
* @return mixed Course identifier. Type depends on VLE. (In Moodle, it will be an integer).
* Gets the time at which this instance was created, or 0 if unknown.
* Gets the time at which this instance was last modified, or 0 if unknown.
* Gets the short type name of this instance.
* Gets the full type name of this instance, according to the current language pack, if available.
* Note: should be overridden by sub-classes.
* @return string Full type name if possible, or the short name otherwise.
* Represents a single blog post
* Constructor - initialises members.
* @param mixed $id The ID of this message - type depends on VLE, but is typically an integer
* @param string $subject The subject line of this post
* @param string $body The body text of this post
* @param SloodleUser $user The user who posted this entry
* @param string $visibility The visibility identifier of this post
* @param int $timestamp_created Time when this post was first made
* @param int $timestamp_modified Time when this post was last modified
function SloodleChatMessage($id=
0, $subject=
'', $body=
'', $user=
null, $visibility=
'', $timestamp_created=
0, $timestamp_modified=
0)
* Accessor - set all members in a single call.
* @param mixed $id The ID of this message - type depends on VLE, but is typically an integer
* @param string $subject The subject line of this post
* @param string $body The body text of this post
* @param SloodleUser $user The user who posted this entry
* @param string $visibility The visibility identifier of this post
* @param int $timestamp_created Time when this post was first made
* @param int $timestamp_modified Time when this post was last modified
function set($id, $subject, $body, $user, $visibility, $timestamp_created, $timestamp_modified)
* Loads the data from a post record object.
* @param object $rec Database record object contain the data required
$this->body =
$rec->summary;
* The type depends on the VLE, but typically is an integer.
* The subject of the post.
* The user who wrote this message.
* The visibility of this post.
* Timestamp of when this message was created.
* Timestamp of when this message was last modified.
Documentation generated on Fri, 17 Jul 2009 11:01:54 +0100 by phpDocumentor 1.4.0