SupportManagerKbArticles extends SupportManagerModel
SupportManagerKbArticles model
Table of Contents
Methods
| __construct() | Constructor |
| add() | Creates a new knowledge base category |
| delete() | Deletes a knowledge base article |
| edit() | Updates a knowledge base category |
| get() | Retrieves an article |
| getAccessTypes() | Retrieves a list of article access types and their language |
| getAll() | Retrieves a list of all articles in the given company or category |
| getCategories() | Retrieves content for an article in the given language |
| getContent() | Retrieves content for an article in the given language |
| getContentTypes() | Retrieves a list of article content types and their language |
| getPopular() | Fetches a set of popular articles as determined by votes cast on the article |
| getSearchCount() | Fetches the number of results that match the given query |
| search() | Searches for articles that match the given query |
| validateCategoriesCompany() | Validates whether every given category belongs to the same company as the article |
| validateContentGiven() | Validates that at least one language set (lang, title, body) is entered, and that all others are given as well, or empty |
| vote() | Adds a vote for an article |
| addCategory() | Adds an article category |
| addContent() | Adds or updates article content. Removes content if the title and body are empty, but the language is given |
| deleteCategories() | Deletes all categories assigned to an article |
| deleteContent() | Deletes article content for the given language |
| getArticles() | Partially constructs a Record object for fetching articles |
| getRules() | Retrieves rules for validating adding/editing a article |
| searchArticles() | Partially constructs a Record object to search articles |
Methods
__construct()
Constructor
public
__construct() : mixed
add()
Creates a new knowledge base category
public
add(array<string|int, mixed> $vars) : stdClass
Parameters
- $vars : array<string|int, mixed>
-
A list of article fields including:
- company_id The ID of the company to assign this article to
- access The type of access to give to this article ("public", "private", "hidden", or "staff"; optional, default public)
- content A numerically-indexed array containing article content, including:
- lang The language code in ISO 639-1 ISO 3166-1 alpha-2 concatenated format (e.g. "en_us")
- title The title of this article
- body The body content of this article
- content_type The type of body content set ('html' or 'text')
- categories A numerically-indexed array of category IDs to assign this article to (optional)
Return values
stdClass —An stdClass object representing the article, or void on error
delete()
Deletes a knowledge base article
public
delete(int $article_id) : mixed
Parameters
- $article_id : int
-
The ID of the article to delete
edit()
Updates a knowledge base category
public
edit(int $article_id, array<string|int, mixed> $vars) : stdClass
Parameters
- $article_id : int
-
The ID of the article to edit
- $vars : array<string|int, mixed>
-
A list of article fields including:
- access The type of access to give to this category ("public", "private", "hidden", or "staff"; optional)
- content A numerically-indexed array containing article content.
If title and body are blank, the content will be deleted. Fields required include:
- lang The language code in ISO 639-1 ISO 3166-1 alpha-2 concatenated format (e.g. "en_us")
- title The title of this article
- body The body content of this article
- content_type The type of body content set ('html' or 'text')
- categories A numerically-indexed array of category IDs to assign this article to (optional)
Return values
stdClass —An stdClass object representing the article, or void on error
get()
Retrieves an article
public
get(int $article_id) : mixed
Parameters
- $article_id : int
-
The ID of the article to fetch
Return values
mixed —An stdClass object representing the article, or false if it does not exist
getAccessTypes()
Retrieves a list of article access types and their language
public
getAccessTypes() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array of access types and their language
getAll()
Retrieves a list of all articles in the given company or category
public
getAll([int $company_id = null ][, int $category_id = null ][, mixed $access = null ]) : array<string|int, mixed>
Parameters
- $company_id : int = null
-
The ID of the company to fetch articles from (optional)
- $category_id : int = null
-
The ID of the category to fetch articles from (optional, default null for the base/home category)
- $access : mixed = null
-
A numerically-indexed array containing the access levels of articles that can be fetched, or null for all (i.e. "public", "private", "hidden", or "staff"; optional, default null for all)
Return values
array<string|int, mixed> —An array of stdClass objects each repreresting an article
getCategories()
Retrieves content for an article in the given language
public
getCategories(int $article_id) : array<string|int, mixed>
Parameters
- $article_id : int
-
The ID of the article to fetch assigned articles for
Return values
array<string|int, mixed> —An array of stdClass objects representing each category
getContent()
Retrieves content for an article in the given language
public
getContent(int $article_id[, string $lang = null ]) : array<string|int, mixed>
Parameters
- $article_id : int
-
The ID of the article to fetch content for
- $lang : string = null
-
The language code in ISO 639-1 ISO 3166-1 alpha-2 concatenated format (e.g. "en_us"; optional)
Return values
array<string|int, mixed> —An array of stdClass objects representing the articles' content in each language
getContentTypes()
Retrieves a list of article content types and their language
public
getContentTypes() : An
Return values
An —array of content types and their language
getPopular()
Fetches a set of popular articles as determined by votes cast on the article
public
getPopular([int $company_id = null ][, int $category_id = null ][, mixed $access = null ][, int $max_articles = 5 ]) : array<string|int, mixed>
Parameters
- $company_id : int = null
-
The ID of the company to fetch articles from (optional)
- $category_id : int = null
-
The ID of the category to fetch articles from (optional, default null to fetch from all articles)
- $access : mixed = null
-
A numerically-indexed array containing the access levels of articles that can be fetched, or null for all (i.e. "public", "private", "hidden", or "staff"; optional, default null for all)
- $max_articles : int = 5
-
The maximum number of articles to fetch (optional, default 5)
Return values
array<string|int, mixed> —An array of stdClass objects each repreresting an article
getSearchCount()
Fetches the number of results that match the given query
public
getSearchCount(int $company_id, string $query[, mixed $access = null ]) : array<string|int, mixed>
Parameters
- $company_id : int
-
The ID of the company to fetch articles from
- $query : string
-
The query to search articles for
- $access : mixed = null
-
A numerically-indexed array containing the access levels of articles that can be fetched, or null for all (i.e. "public", "private", "hidden", or "staff"; optional, default null for all)
Return values
array<string|int, mixed> —An array of stdClass objects representing each matching article
search()
Searches for articles that match the given query
public
search(int $company_id, string $query[, mixed $access = null ][, int $page = 1 ]) : array<string|int, mixed>
Parameters
- $company_id : int
-
The ID of the company to fetch articles from
- $query : string
-
The query to search articles for
- $access : mixed = null
-
A numerically-indexed array containing the access levels of articles that can be fetched, or null for all (i.e. "public", "private", "hidden", or "staff"; optional, default null for all)
- $page : int = 1
-
The page number of search results to fetch (optional, default 1)
Return values
array<string|int, mixed> —An array of stdClass objects representing each matching article
validateCategoriesCompany()
Validates whether every given category belongs to the same company as the article
public
validateCategoriesCompany(array<string|int, mixed> $categories[, int $company_id = null ][, int $article_id = null ]) : bool
Parameters
- $categories : array<string|int, mixed>
-
A numerically-indexed array of category IDs
- $company_id : int = null
-
The ID of the company that the article is assigned (optional, required if $article_id not given)
- $article_id : int = null
-
The ID of the article to check against the categories (optional, requride if $company_id not given)
Return values
bool —False if the categories given do not exist or are not assigned the same company as the article; true otherwise
validateContentGiven()
Validates that at least one language set (lang, title, body) is entered, and that all others are given as well, or empty
public
validateContentGiven(array<string|int, mixed> $article_content) : bool
Parameters
- $article_content : array<string|int, mixed>
-
An array of article content in multiple languages, containing:
- lang The language code in ISO 639-1 ISO 3166-1 alpha-2 concatenated format (e.g. "en_us")
- title The title of this article
- body The body content of this article
Return values
bool —True if at least one article content is complete and there are no others partially complete, otherwise false
vote()
Adds a vote for an article
public
vote(int $article_id[, string $direction = 'up' ]) : mixed
Parameters
- $article_id : int
-
The ID of the article to add the vote for
- $direction : string = 'up'
-
The type of vote to add to the article (i.e. "up" or "down"; optional, default up)
addCategory()
Adds an article category
private
addCategory(int $article_id, int $category_id) : mixed
Parameters
- $article_id : int
-
The ID of the article to assign the category
- $category_id : int
-
The ID of the category to add
Tags
addContent()
Adds or updates article content. Removes content if the title and body are empty, but the language is given
private
addContent(int $article_id, array<string|int, mixed> $content) : mixed
Parameters
- $article_id : int
-
The ID of the article to add content to
- $content : array<string|int, mixed>
-
The article content to add including:
- lang The language code in ISO 639-1 ISO 3166-1 alpha-2 concatenated format (e.g. "en_us")
- title The title of this article
- body The body content of this article
- content_type The type of body content set ('html' or 'text')
Tags
deleteCategories()
Deletes all categories assigned to an article
private
deleteCategories(int $article_id) : mixed
Parameters
- $article_id : int
-
The ID of the article whose categories to remove
Tags
deleteContent()
Deletes article content for the given language
private
deleteContent(int $article_id, string $lang) : mixed
Parameters
- $article_id : int
-
The ID of the article to add content to
- $lang : string
-
The language code in ISO 639-1 ISO 3166-1 alpha-2 concatenated format (e.g. "en_us")
getArticles()
Partially constructs a Record object for fetching articles
private
getArticles([mixed $article_id = null ][, mixed $company_id = null ]) : Record
Parameters
- $article_id : mixed = null
- $company_id : mixed = null
Return values
Record —A partially-constructed Record object
getRules()
Retrieves rules for validating adding/editing a article
private
getRules(array<string|int, mixed> $vars[, bool $edit = false ]) : array<string|int, mixed>
Parameters
- $vars : array<string|int, mixed>
-
A set of input data
- $edit : bool = false
-
True to fetch the edit rules, or false for the add rules (optional, default false)
Return values
array<string|int, mixed> —A set of validation rules
searchArticles()
Partially constructs a Record object to search articles
private
searchArticles(int $company_id, string $query[, mixed $access = null ]) : Record
Parameters
- $company_id : int
-
The ID of the company to fetch articles from
- $query : string
-
The query to search articles for
- $access : mixed = null
-
A numerically-indexed array containing the access levels of articles that can be fetched, or null for all (i.e. "public", "private", "hidden", or "staff"; optional, default null for all)
Return values
Record —A partially-constructed Record object for searching articles