Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.
/blog/ -> locallib.php (source)

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402]

Classes for Blogs.

Copyright: 2009 Nicolas Connault
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1181 lines (41 kb)
Included or required:0 times
Referenced: 3 times
Includes or requires: 0 files

Defines 10 classes

blog_entry:: (14 methods):
  __construct()
  prepare_render()
  get_attachments()
  process_attachment()
  add()
  edit()
  delete()
  add_associations()
  add_association()
  remove_associations()
  delete_attachments()
  can_user_edit()
  can_user_view()
  get_applicable_publish_states()

blog_listing:: (6 methods):
  __construct()
  get_entries()
  count_entries()
  get_entry_fetch_sql()
  print_entries()
  get_baseurl()

blog_filter:: (2 methods):
  __construct()
  get_instance()

blog_filter_context:: (1 method):
  __construct()

blog_filter_user:: (1 method):
  __construct()

blog_filter_tag:: (1 method):
  __construct()

blog_filter_entry:: (1 method):
  __construct()

blog_filter_since:: (1 method):
  __construct()

blog_filter_search:: (1 method):
  __construct()

blog_entry_attachment:: (1 method):
  __construct()


Class: blog_entry  - X-Ref

Blog_entry class. Represents an entry in a user's blog. Contains all methods for managing this entry.
This class does not contain any HTML-generating code. See blog_listing sub-classes for such code.
This class follows the Object Relational Mapping technique, its member variables being mapped to
the fields of the post table.

__construct($id=null, $params=null, $form=null)   X-Ref
Constructor. If given an id, will fetch the corresponding record from the DB.

param: mixed $idorparams A blog entry id if INT, or data for a new entry if array

prepare_render()   X-Ref
Gets the required data to print the entry


get_attachments()   X-Ref
Gets the entry attachments list

return: array List of blog_entry_attachment instances

process_attachment($form)   X-Ref
Inserts this entry in the database. Access control checks must be done by calling code.

param: mform $form Used for attachments
return: void

add()   X-Ref
Inserts this entry in the database. Access control checks must be done by calling code.
TODO Set the publishstate correctly

return: void

edit($params=array()   X-Ref
Updates this entry in the database. Access control checks must be done by calling code.

param: array       $params            Entry parameters.
param: moodleform  $form              Used for attachments.
param: array       $summaryoptions    Summary options.
param: array       $attachmentoptions Attachment options.
return: void

delete()   X-Ref
Deletes this entry from the database. Access control checks must be done by calling code.

return: void

add_associations($unused = null)   X-Ref
Function to add all context associations to an entry.

param: string $unused This does nothing, do not use it.

add_association($contextid, $unused = null)   X-Ref
Add a single association for a blog entry

param: int $contextid - id of context to associate with the blog entry.
param: string $unused This does nothing, do not use it.

remove_associations()   X-Ref
remove all associations for a blog entry

return: void

delete_attachments()   X-Ref
Deletes all the user files in the attachments area for an entry

return: void

can_user_edit($userid=null)   X-Ref
User can edit a blog entry if this is their own blog entry and they have
the capability moodle/blog:create, or if they have the capability
moodle/blog:manageentries.
This also applies to deleting of entries.

param: int $userid Optional. If not given, $USER is used
return: boolean

can_user_view($targetuserid)   X-Ref
Checks to see if a user can view the blogs of another user.
Only blog level is checked here, the capabilities are enforced
in blog/index.php

param: int $targetuserid ID of the user we are checking
return: bool

get_applicable_publish_states()   X-Ref
Use this function to retrieve a list of publish states available for
the currently logged in user.

return: array This function returns an array ideal for sending to moodles'

Class: blog_listing  - X-Ref

Abstract Blog_Listing class: used to gather blog entries and output them as listings. One of the subclasses must be used.

__construct($filters=array()   X-Ref
Constructor

param: array $filters An associative array of filtername => filterid

get_entries($start=0, $limit=10)   X-Ref
Fetches the array of blog entries.

return: array

count_entries()   X-Ref
Finds total number of blog entries

return: int

get_entry_fetch_sql($count=false, $sort='lastmodified DESC', $userid = false)   X-Ref
No description

print_entries()   X-Ref
Outputs all the blog entries aggregated by this blog listing.

return: void

get_baseurl()   X-Ref
No description

Class: blog_filter  - X-Ref

Abstract class for blog_filter objects.
A set of core filters are implemented here. To write new filters, you need to subclass
blog_filter and give it the name of the type you want (for example, blog_filter_entry).
The blog_filter abstract class will automatically use it when the filter is added to the
URL. The first parameter of the constructor is the ID of your filter, but it can be a string
or have any other meaning you wish it to have. The second parameter is called $type and is
used as a sub-type for filters that have a very similar implementation (see blog_filter_context for an example)

__construct($id, $type=null)   X-Ref
An array of filter types which this particular filter type overrides: their conditions will not be evaluated


get_instance($id, $type)   X-Ref
TODO This is poor design. A parent class should not know anything about its children.
The default case helps to resolve this design issue


Class: blog_filter_context  - X-Ref

This filter defines the context level of the blog entries being searched: site, course, module

__construct($id=null, $type='site')   X-Ref
Constructor

param: string $type
param: int    $id

Class: blog_filter_user  - X-Ref

This filter defines the user level of the blog entries being searched: a userid or a groupid.
It can be combined with a context filter in order to refine the search.

__construct($id=null, $type='user')   X-Ref
Constructor

param: string $type
param: int    $id

Class: blog_filter_tag  - X-Ref

This filter defines a tag by which blog entries should be searched.

__construct($id)   X-Ref
Constructor

return: void

Class: blog_filter_entry  - X-Ref

This filter defines a specific blog entry id.

__construct($id)   X-Ref
No description

Class: blog_filter_since  - X-Ref

This filter restricts the results to a time interval in seconds up to time()

__construct($interval)   X-Ref
No description

Class: blog_filter_search  - X-Ref

Filter used to perform full-text search on an entry's subject, summary and content

__construct($searchterm)   X-Ref
No description

Class: blog_entry_attachment  - X-Ref

Renderable class to represent an entry attachment

__construct($file, $entryid)   X-Ref
Gets the file data

param: stored_file $file
param: int $entryid Attachment entry id