Skip to content

Model: Blog posts factory

Ricky edited this page Jul 30, 2020 · 2 revisions

Initialisation

Factory models should be initialised through the BlogCMS class, this ensures there is only ever one instance of the class:

$postsModel = BlogCMS::model("rbwebdesigns\blogcms\BlogPosts\model\Posts");

$postsModel->getPostById(17);

See Post model for documentation on the data model for individual blog posts.

This class extends rbwebdesigns\core\RBFactory - see the wiki documentation for RBFactory for more information.

Public methods

Get single post

Method signature Return type Notes
getPostById (int $postID) \rbwebdesigns\HamletCMS\BlogPosts\Post
getPostByURL (string $link, int $blogID) \rbwebdesigns\HamletCMS\BlogPosts\Post
getLatestPost (string $link, int $blogID) \rbwebdesigns\HamletCMS\BlogPosts\Post latest (published) blog post
getNextPost (int $blogID, int $currentPostTimestamp) \rbwebdesigns\HamletCMS\BlogPosts\Post Get next post in chronological order
getPreviousPost (int $blogID, int $currentPostTimestamp) \rbwebdesigns\HamletCMS\BlogPosts\Post Get previous post in chronological order

Get multiple posts

Method signature Return type Notes
search (int $blogID, string $searchterm) \rbwebdesigns\HamletCMS\BlogPosts\Post[] Posts matching free text search term and blog ID
getAllPostsOnBlog (int $blogID, bool $drafts=0, bool $future=0) \rbwebdesigns\HamletCMS\BlogPosts\Post[] returns all the posts on a blog
getPostsByBlog (int $blogID, int $page=1, int $num=10, bool $drafts=0, bool $future=0, string $sort=”) \rbwebdesigns\HamletCMS\BlogPosts\Post[] returns selection of posts on a blog
getRecentPosts (array $blogs, int $daysSincePostLimit=7) \rbwebdesigns\HamletCMS\BlogPosts\Post[] returns the posts for multiple blogs within a number of days - this is made to source data for a users news feed
getTrendingPosts (int $blogID, string $startDate=null, string $endDate=null) \rbwebdesigns\HamletCMS\BlogPosts\Post[] Get posts with the most views between 2 dates
countPostsOnBlog (int $blogID, $incDrafts=false, $incfutures=false) int
getPostCountByUser (int $blogID) array Returns how many posts each contributor to a blog has made with the last post date

Create, update posts

Method signature Return type Notes
createPost (array $newValues) boolean Creates a new post with values supplied in array, success returned
clonePost (int $postID) int Clones a post in the database and returns the new post ID
updatePost (int $postid, array $newValues) boolean Updates the values in database for a post
createSafePostUrl (string $text) string Converts title into a url (stripping non alphanumeric characters)

Tags

Method signature Return type Notes
countAllTagsByBlog (int $blogid, string $sortby=’text’) int[] Returns a grouped count of all tags belonging to posts on the blog
getAllTagsByBlog (int $blogID) string[] returns a list of all tags that have been added to posts on a blog
getBlogPostsByTag (int $blogid, string $ptag) \rbwebdesigns\HamletCMS\BlogPosts\Post[]

Post views

Method signature Return type Notes
getViewsByPost (int $postID) string[] Returns list of users (IP addresses) that have viewed a blog post
incrementUserView (int $postid, string $userip) \rbwebdesigns\HamletCMS\BlogPosts\Post Increments the tally of page views for a blog post + IP address
recordUserView (int $postid, string $userip) \rbwebdesigns\HamletCMS\BlogPosts\Post Creates a new record in the user views table

Autosaves (moved to new class)

Method signature Return type Notes
autosavePost (int $postID, array $data) int/boolean Creates or updates an automatically saved blog post - could be previously saved post or completely new
removeAutosave (int $postID) boolean Remove an automatically saved blog post
autosaveExists (int $postID) boolean Check if an automatically saved blog post exists
getAutosave (int $postID) \rbwebdesigns\HamletCMS\BlogPosts\Post Get automatically saved data for a blog post