PHP Class DiscussionModel, vanilla

Inheritance: extends VanillaModel, use trait StaticInitializer
ファイルを表示 Open project: vanilla/vanilla Class Usage Examples

Public Properties

Property Type Description
$Watching boolean

Protected Properties

Property Type Description
$allowedFilters The filters that are accessible via GET. Each filter corresponds with a where clause. You can have multiple filter sets. Every filter must be added to a filter set. Each filter set has the following properties: - **key**: string - The key name of the filter set. Appears in the query string, should be url-friendly. - **name**: string - The display name of the filter set. Usually appears in the UI. - **filters**: array - The filters in the set. Each filter in the array has the following properties: - **key**: string - The key name of the filter. Appears in the query string, should be url-friendly. - **setKey**: string - The key name of the filter set. - **name**: string - The display name of the filter. Usually appears as an option in the UI. - **where**: string - The where array query to execute for the filter. Uses - **group**: string - (optional) The dropdown module can group together any items with the same group name.
$allowedSorts The sorts that are accessible via GET. Each sort corresponds with an order by clause. Each sort in the array has the following properties: - **key**: string - The key name of the sort. Appears in the query string, should be url-friendly. - **name**: string - The display name of the sort. - **orderBy**: string - An array indicating order by fields and their directions in the format: ['field1' => 'direction', 'field2' => 'direction']
$filters The filter keys of the wheres we apply in the query.
$sort The sort key of the order by we apply in the query.

Public Methods

Method Description
__construct ( ) Class constructor. Defines the related database table name.
addArchiveWhere ( object $Sql = null ) Add SQL Where to account for archive date.
addDenormalizedViews ( Gdn_DataSet | stdClass &$Discussions ) Add denormalized views to discussions.
addDiscussionColumns ( object $Data ) Modifies discussion data before it is returned.
addFieldPrefix ( string $fieldName, string $prefix = 'd' ) : string Adds a prefix to the field name if the field doesn't already have one.
addFilter ( string $key, string $name, array $wheres, string $group = '', string $setKey = 'filter' ) Add a filter to the allowed filters array.
addFilterSet ( string $setKey, string $setName = '', array $categoryIDs = [] ) Adds a filter set to the allowed filters array.
addSort ( string $key, string $name, string | array $orderBy, array $categoryIDs = [] ) Add a sort to the allowed sorts array.
addView ( integer $DiscussionID ) Increments view count for the specified discussion.
allowedSortFields ( ) We don't use this functionality anymore. Previously, you had to register any sorting field before sorting with it.
bookmark ( integer $DiscussionID, integer $UserID, boolean | null $Bookmarked = null ) : boolean Bookmarks (or unbookmarks) a discussion for the specified user.
bookmarkCount ( integer $DiscussionID ) : integer Gets number of bookmarks specified discussion has (all users).
bookmarkDiscussion ( integer $DiscussionID, integer $UserID, &$Discussion = null ) : boolean Bookmarks (or unbookmarks) a discussion for specified user.
calculate ( &$Discussion )
canEdit ( object | array $discussion, &$timeLeft ) : boolean Determines whether or not the current user can edit a discussion.
canView ( object | array | integer $discussion, integer $userID ) : boolean Tests whether a user has permission to view a specific discussion.
categoryPermissions ( boolean $Escape = false ) : array Identify current user's category permissions and set as local array.
checkPermission ( object | array | integer $discussion, string $permission, integer $userID ) : boolean Tests whether a user has permission for a discussion by checking category-specific permissions.
clearSorts ( ) If you don't want to use any of the default sorts, use this little buddy.
counts ( $Column, $From = false, $To = false, $Max = false )
delete ( $where = [], $options = [] )
deleteID ( integer $discussionID, array $options = [] ) : boolean Delete a discussion. Update and/or delete all related data.
discussionSummaryQuery ( array $AdditionalFields = [], $Join = true ) Builds base SQL query for discussion data.
discussionTypes ( ) : array Get the allowed discussion types.
dismissAnnouncement ( integer $DiscussionID, integer $UserID ) Marks the specified announcement as dismissed by the specified user.
editContentTimeout ( object | array $discussion, integer &$timeLeft ) : boolean Checks whether the time frame when a discussion can be edited has passed.
fetchPageInfo ( $Url, $ThrowError = false )
get ( integer $Offset = '0', integer $Limit = '', array $Wheres = '', array $AdditionalFields = null ) : Gdn_DataSet Gets the data for multiple discussions based on the given criteria.
getAllowedFilters ( ) : array Get the registered filters.
getAllowedSorts ( ) : array
getAnnouncementCacheKey ( integer $CategoryID ) : string
getAnnouncements ( array $Wheres = '', integer $Offset, integer $Limit = false ) : object Gets announced discussions.
getBookmarkUsers ( integer $DiscussionID ) : object Gets all users who have bookmarked the specified discussion.
getByUser ( integer $UserID, integer $Limit, integer $Offset, integer $LastDiscussionID = false, integer $WatchUserID = false ) : Gdn_DataSet Get discussions for a user.
getCount ( array $Wheres = '', boolean $ForceNoAnnouncements = false ) : integer Count how many discussions match the given criteria.
getCountForCategory ( integer | array $categoryID ) : integer Get the count of discussions for an individual category.
getDefaultOrderBy ( ) : array Returns an array of field => direction for the order by clause on the Discussion table.
getDefaultSortKey ( ) : string
getFilters ( ) : array
getForeignID ( integer $ForeignID, string $Type = '' ) : stdClass Get data for a single discussion by ForeignID.
getID ( integer $DiscussionID, string $DataSetType = DATASET_TYPE_OBJECT, array $Options = [] ) : object Get data for a single discussion by ID.
getIn ( array $DiscussionIDs ) : Gdn_DataSet Get discussions that have IDs in the provided array.
getParticipatedUsers ( integer $DiscussionID ) : Gdn_DataSet Get all the users that have participated in the discussion.
getSort ( ) : string
getSortField ( ) : string Get discussions sort order based on config and optional user preference.
getSortFilterQueryString ( string $selectedSort, array $selectedFilters, string $sortKeyToSet = '', array $filterKeysToSet = [] ) : string Get the current sort/filter query string.
getUnread ( integer $Offset = '0', integer $Limit = '', array $Wheres = '', array $AdditionalFields = null ) : Gdn_DataSet Gets the data for multiple unread discussions based on the given criteria.
getUnreadCount ( array $Wheres = '' ) : integer Count how many discussions match the given criteria.
getUserScore ( integer $DiscussionID, integer $UserID ) : integer Gets the discussion score for specified user.
getViewsFallback ( integer $DiscussionID ) : mixed | null
getWhere ( array | false $Where = false, string $OrderFields = '', string $OrderDirection = '', integer | false $Limit = false, integer | false $Offset = false ) : Gdn_DataSet Get a list of discussions.
getWhereRecent ( array | false $Where = [], boolean | false | integer $Limit = false, integer | false $Offset = false ) : Gdn_DataSet Get a list of the most recent discussions.
incrementNewDiscussion ( integer | array | stdClass $Discussion )
notifyNewDiscussion ( integer | array | stdClass $Discussion, ActivityModel $ActivityModel, array $Activity )
removeAnnouncements ( object $Data ) Removes undismissed announcements from the data.
removeFilter ( array $filterKeys ) Removes a filters from the allowed filter array with the passed filter key/values.
removeFilterSet ( string $setKey ) Removes a filter set from the allowed filter array with the passed set key.
removeSort ( string $key ) Removes a sort from the allowed sort array with the passed key.
save ( array $FormPostValues, array $Settings = false ) : integer Inserts or updates the discussion via form values.
setField ( integer $RowID, string $Property, mixed $Value = false ) An event firing wrapper for Gdn_Model::setField().
setFilters ( array $filters ) Will only set the filters property if the passed filters exist in the allowed filters array.
setProperty ( integer $DiscussionID, string $Property, mixed $ForceValue = null ) : mixed Updates a discussion field.
setSort ( string | array $sort ) Set the discussion sort.
setUserBookmarkCount ( integer $UserID ) : integer Update and get bookmark count for the specified user.
setUserScore ( integer $DiscussionID, integer $UserID, integer $Score ) : integer Sets the discussion score for specified user.
updateDiscussionCount ( integer $CategoryID, array | false $Discussion = false ) Update the CountDiscussions value on the category based on the CategoryID being saved.
updateUserDiscussionCount ( integer $UserID, boolean $Inc = false ) Update a user's discussion count.
userBookmarkCount ( integer $UserID ) : integer Gets number of bookmarks specified user has.

Protected Methods

Method Description
addClearFilter ( string $setKey, string $setName = '' ) Adds an option to a filter set filters array to clear any existing filters on the data.
combineWheres ( array $newWheres, array $wheres ) : array Combines two arrays of where clauses.
getFiltersFromArray ( array $array ) : array Retrieves valid set key and filter keys pairs from an array, and returns the setKey => filterKey values.
getFiltersFromKeys ( array $filterKeyValues ) : array Takes an array of filter key/values [setKey => filterKey] and returns a collection of filters.
getKeysFromFilters ( array $filters ) : array Takes a collection of filters and returns the corresponding filter key/value array [setKey => filterKey].
getOrderBy ( ) : array Returns an array in the format [field => direction]. You can safely use return values from this function in the orderBy() SQL function.
getSortFromArray ( array $array ) : string Retrieves the sort key from an array and if the value is valid, returns it.
getSortFromKey ( string $sortKey ) : array
getSortFromString ( string $string ) : string Checks the allowed sorts array for the string and it is valid, returns it the string.
getWheres ( array $categoryIDs = [] ) : array Checks for any set filters and if they exist, returns the where clauses from the filters.

Private Methods

Method Description
formatTags ( string $Tags ) : string Convert tags from stored format to user-presentable format.

Method Details

__construct() public method

Class constructor. Defines the related database table name.
Since: 2.0.0
public __construct ( )

addArchiveWhere() public method

Add SQL Where to account for archive date.
Since: 2.0.0
public addArchiveWhere ( object $Sql = null )
$Sql object Gdn_SQLDriver

addClearFilter() protected static method

Adds an option to a filter set filters array to clear any existing filters on the data.
protected static addClearFilter ( string $setKey, string $setName = '' )
$setKey string The key name of the filter set to add the option to.
$setName string The display name of the option. Usually the human-readable set name.

addDenormalizedViews() public method

Add denormalized views to discussions.
public addDenormalizedViews ( Gdn_DataSet | stdClass &$Discussions )
$Discussions Gdn_DataSet | stdClass

addDiscussionColumns() public method

Takes archiving into account and fixes inaccurate comment counts.
Since: 2.0.0
public addDiscussionColumns ( object $Data )
$Data object SQL result.

addFieldPrefix() public method

Adds a prefix to the field name if the field doesn't already have one.
public addFieldPrefix ( string $fieldName, string $prefix = 'd' ) : string
$fieldName string The name of the field.
$prefix string
return string The fieldname with the prefix if one does not exist.

addFilter() public static method

Add a filter to the allowed filters array.
public static addFilter ( string $key, string $name, array $wheres, string $group = '', string $setKey = 'filter' )
$key string The key name of the filter. Appears in the query string, should be url-friendly.
$name string The display name of the filter. Usually appears as an option in the UI.
$wheres array The where array query to execute for the filter. Uses
$group string (optional) The nav module will group together any items with the same group name.
$setKey string The key name of the filter set.

addFilterSet() public static method

Adds a filter set to the allowed filters array.
public static addFilterSet ( string $setKey, string $setName = '', array $categoryIDs = [] )
$setKey string The key name of the filter set.
$setName string The name of the filter set. Appears in the UI.
$categoryIDs array The IDs of the categories that this filter will work on. If empty, filter is global.

addSort() public static method

Add a sort to the allowed sorts array.
public static addSort ( string $key, string $name, string | array $orderBy, array $categoryIDs = [] )
$key string The key name of the sort. Appears in the query string, should be url-friendly.
$name string The display name of the sort.
$orderBy string | array An array indicating order by fields and their directions in the format: array('field1' => 'direction', 'field2' => 'direction')
$categoryIDs array The IDs of the categories that this sort will work on. If empty, sort is global.

addView() public method

Increments view count for the specified discussion.
public addView ( integer $DiscussionID )
$DiscussionID integer Unique ID of discussion to get +1 view.

allowedSortFields() public static method

We don't use this functionality anymore. Previously, you had to register any sorting field before sorting with it.
Deprecation:
public static allowedSortFields ( )

bookmark() public method

Bookmarks (or unbookmarks) a discussion for the specified user.
public bookmark ( integer $DiscussionID, integer $UserID, boolean | null $Bookmarked = null ) : boolean
$DiscussionID integer The unique id of the discussion.
$UserID integer The unique id of the user.
$Bookmarked boolean | null Whether or not to bookmark or unbookmark. Pass null to toggle the bookmark.
return boolean The new value of bookmarked.

bookmarkCount() public method

Gets number of bookmarks specified discussion has (all users).
public bookmarkCount ( integer $DiscussionID ) : integer
$DiscussionID integer Unique ID of discussion for which to tally bookmarks.
return integer Total number of bookmarks.

bookmarkDiscussion() public method

Events: AfterBookmarkDiscussion.
public bookmarkDiscussion ( integer $DiscussionID, integer $UserID, &$Discussion = null ) : boolean
$DiscussionID integer Unique ID of discussion to (un)bookmark.
$UserID integer Unique ID of user doing the (un)bookmarking.
return boolean Current state of the bookmark (TRUE for bookmarked, FALSE for unbookmarked).

calculate() public method

public calculate ( &$Discussion )

canEdit() public static method

Determines whether or not the current user can edit a discussion.
public static canEdit ( object | array $discussion, &$timeLeft ) : boolean
$discussion object | array The discussion to examine.
return boolean Returns true if the user can edit or false otherwise.

canView() public method

Tests whether a user has permission to view a specific discussion.
public canView ( object | array | integer $discussion, integer $userID ) : boolean
$discussion object | array | integer The discussion ID or the discussion to test.
$userID integer The ID of the user to test permission for. If empty, it defaults to Session user.
return boolean Whether the user can view the discussion.

categoryPermissions() public static method

Identify current user's category permissions and set as local array.
Since: 2.0.0
public static categoryPermissions ( boolean $Escape = false ) : array
$Escape boolean Prepends category IDs with @
return array Protected local _CategoryPermissions

checkPermission() public method

Fires an event that can override the calculated permission.
public checkPermission ( object | array | integer $discussion, string $permission, integer $userID ) : boolean
$discussion object | array | integer The discussion ID or the discussion to test.
$permission string The category permission to test against the user.
$userID integer The ID of the user to test permission for. If empty, it defaults to Session user.
return boolean Whether the user has the specified permission privileges to the discussion.

clearSorts() public static method

If you don't want to use any of the default sorts, use this little buddy.
public static clearSorts ( )

combineWheres() protected method

Combines two arrays of where clauses.
protected combineWheres ( array $newWheres, array $wheres ) : array
$newWheres array The clauses we're adding.
$wheres array The where clauses to add new clauses to.
return array A set of where clauses, array form.

counts() public method

public counts ( $Column, $From = false, $To = false, $Max = false )

delete() public method

public delete ( $where = [], $options = [] )

deleteID() public method

Events: DeleteDiscussion.
public deleteID ( integer $discussionID, array $options = [] ) : boolean
$discussionID integer Unique ID of discussion to delete.
$options array Additional options to control the delete behavior. Not used for discussions.
return boolean Always returns **true**.

discussionSummaryQuery() public method

Events: AfterDiscussionSummaryQuery.
Since: 2.0.0
public discussionSummaryQuery ( array $AdditionalFields = [], $Join = true )
$AdditionalFields array Allows selection of additional fields as Alias=>Table.Fieldname.

discussionTypes() public static method

Get the allowed discussion types.
public static discussionTypes ( ) : array
return array Returns an array of discussion type definitions.

dismissAnnouncement() public method

Marks the specified announcement as dismissed by the specified user.
public dismissAnnouncement ( integer $DiscussionID, integer $UserID )
$DiscussionID integer Unique ID of discussion being affected.
$UserID integer Unique ID of the user being affected.

editContentTimeout() public static method

Checks whether the time frame when a discussion can be edited has passed.
public static editContentTimeout ( object | array $discussion, integer &$timeLeft ) : boolean
$discussion object | array The discussion to examine.
$timeLeft integer Sets the time left to edit or 0 if not applicable.
return boolean Whether the time to edit the discussion has passed.

fetchPageInfo() public method

public fetchPageInfo ( $Url, $ThrowError = false )

get() public method

Sorts results based on config options Vanilla.Discussions.SortField and Vanilla.Discussions.SortDirection. Events: BeforeGet, AfterAddColumns.
Since: 2.0.0
public get ( integer $Offset = '0', integer $Limit = '', array $Wheres = '', array $AdditionalFields = null ) : Gdn_DataSet
$Offset integer Number of discussions to skip.
$Limit integer Max number of discussions to return.
$Wheres array SQL conditions.
$AdditionalFields array Allows selection of additional fields as Alias=>Table.Fieldname.
return Gdn_DataSet SQL result.

getAllowedFilters() public static method

This method must never be called before plugins initialisation.
public static getAllowedFilters ( ) : array
return array The current filter array.

getAllowedSorts() public static method

public static getAllowedSorts ( ) : array
return array The current sort array.

getAnnouncementCacheKey() public method

public getAnnouncementCacheKey ( integer $CategoryID ) : string
$CategoryID integer Category ID,
return string $Key CacheKey name to be used for cache.

getAnnouncements() public method

Gets announced discussions.
Since: 2.0.0
public getAnnouncements ( array $Wheres = '', integer $Offset, integer $Limit = false ) : object
$Wheres array SQL conditions.
$Offset integer The number of records to skip.
$Limit integer The number of records to limit the query to.
return object SQL result.

getBookmarkUsers() public method

Gets all users who have bookmarked the specified discussion.
Since: 2.0.0
public getBookmarkUsers ( integer $DiscussionID ) : object
$DiscussionID integer Unique ID to find bookmarks for.
return object SQL result.

getByUser() public method

Events: BeforeGetByUser
Since: 2.1
public getByUser ( integer $UserID, integer $Limit, integer $Offset, integer $LastDiscussionID = false, integer $WatchUserID = false ) : Gdn_DataSet
$UserID integer Which user to get discussions for.
$Limit integer Max number to get.
$Offset integer Number to skip.
$LastDiscussionID integer A hint for quicker paging.
$WatchUserID integer User to use for read/unread data.
return Gdn_DataSet SQL results.

getCount() public method

Count how many discussions match the given criteria.
Since: 2.0.0
public getCount ( array $Wheres = '', boolean $ForceNoAnnouncements = false ) : integer
$Wheres array SQL conditions.
$ForceNoAnnouncements boolean Not used.
return integer Number of discussions.

getCountForCategory() public method

Get the count of discussions for an individual category.
public getCountForCategory ( integer | array $categoryID ) : integer
$categoryID integer | array The category to get the count of or an array of category IDs to get the count of.
return integer Returns the count of discussions.

getDefaultOrderBy() public static method

Attempts to get ordering fields from the config before settling on DEFAULT_ORDER_BY_FIELD.
public static getDefaultOrderBy ( ) : array
return array The default order by fields

getDefaultSortKey() public static method

public static getDefaultSortKey ( ) : string
return string

getFilters() public method

public getFilters ( ) : array
return array

getFiltersFromArray() protected method

Works real well with unfiltered request arguments. (i.e., Gdn::request()->get()) Will only return safe set key and filter key pairs from the filters array or an empty array if not found.
protected getFiltersFromArray ( array $array ) : array
$array array The array to get the filters from.
return array The valid filters from the passed array or an empty array.

getFiltersFromKeys() protected method

Takes an array of filter key/values [setKey => filterKey] and returns a collection of filters.
protected getFiltersFromKeys ( array $filterKeyValues ) : array
$filterKeyValues array The filters key array to get the filter for.
return array An array of filters.

getForeignID() public method

Get data for a single discussion by ForeignID.
Since: 2.0.18
public getForeignID ( integer $ForeignID, string $Type = '' ) : stdClass
$ForeignID integer Foreign ID of discussion to get.
$Type string The record type or an empty string for any record type.
return stdClass SQL result.

getID() public method

Get data for a single discussion by ID.
public getID ( integer $DiscussionID, string $DataSetType = DATASET_TYPE_OBJECT, array $Options = [] ) : object
$DiscussionID integer Unique ID of discussion to get.
$DataSetType string One of the **DATASET_TYPE_*** constants.
$Options array An array of extra options for the query.
return object SQL result.

getIn() public method

Get discussions that have IDs in the provided array.
Since: 2.0.18
public getIn ( array $DiscussionIDs ) : Gdn_DataSet
$DiscussionIDs array Array of DiscussionIDs to get.
return Gdn_DataSet SQL result.

getKeysFromFilters() protected method

Takes a collection of filters and returns the corresponding filter key/value array [setKey => filterKey].
protected getKeysFromFilters ( array $filters ) : array
$filters array The filters to get the keys for.
return array The filter key array.

getOrderBy() protected method

Returns an array in the format [field => direction]. You can safely use return values from this function in the orderBy() SQL function.
Since: 2.3
protected getOrderBy ( ) : array
return array An array of field => direction values.

getParticipatedUsers() public method

Get all the users that have participated in the discussion.
public getParticipatedUsers ( integer $DiscussionID ) : Gdn_DataSet
$DiscussionID integer
return Gdn_DataSet

getSort() public method

public getSort ( ) : string
return string

getSortField() public static method

Get discussions sort order based on config and optional user preference.
public static getSortField ( ) : string
return string Column name.

getSortFilterQueryString() public static method

You can pass no parameters or pass either a new filter key or sort key to build a new query string, leaving the other properties intact.
public static getSortFilterQueryString ( string $selectedSort, array $selectedFilters, string $sortKeyToSet = '', array $filterKeysToSet = [] ) : string
$selectedSort string
$selectedFilters array
$sortKeyToSet string The key name of the sort in the sorts array.
$filterKeysToSet array An array of filters, where the key is the key of the filterSet in the filters array and the value is the key of the filter.
return string The current or amended query string for sort and filter.

getSortFromArray() protected method

Works real well with unfiltered request arguments. (i.e., Gdn::request()->get()) Will only return a safe sort key from the sort array or an empty string if not found.
protected getSortFromArray ( array $array ) : string
$array array The array to get the sort from.
return string The valid sort from the passed array or an empty string.

getSortFromKey() protected method

protected getSortFromKey ( string $sortKey ) : array
$sortKey string
return array

getSortFromString() protected method

If not, returns an empty string. Will only return a safe sort key from the sort array or an empty string if not found.
protected getSortFromString ( string $string ) : string
$string string The string to get the sort from.
return string A valid sort key or an empty string.

getUnread() public method

Sorts results based on config options Vanilla.Discussions.SortField and Vanilla.Discussions.SortDirection. Events: BeforeGet, AfterAddColumns.
Since: 2.0.0
public getUnread ( integer $Offset = '0', integer $Limit = '', array $Wheres = '', array $AdditionalFields = null ) : Gdn_DataSet
$Offset integer Number of discussions to skip.
$Limit integer Max number of discussions to return.
$Wheres array SQL conditions.
$AdditionalFields array Allows selection of additional fields as Alias=>Table.Fieldname.
return Gdn_DataSet SQL result.

getUnreadCount() public method

Count how many discussions match the given criteria.
Deprecation: since 2.3
Since: 2.0.0
public getUnreadCount ( array $Wheres = '' ) : integer
$Wheres array SQL conditions.
return integer Number of discussions.

getUserScore() public method

Gets the discussion score for specified user.
public getUserScore ( integer $DiscussionID, integer $UserID ) : integer
$DiscussionID integer Unique ID of discussion getting score for.
$UserID integer Unique ID of user whose score we're getting.
return integer Total score.

getViewsFallback() public static method

public static getViewsFallback ( integer $DiscussionID ) : mixed | null
$DiscussionID integer
return mixed | null

getWhere() public method

This method call will remove announcements and may not return exactly {@link $Limit} records for optimization. You can set $Where['d.Announce'] = 'all' to return announcements.
public getWhere ( array | false $Where = false, string $OrderFields = '', string $OrderDirection = '', integer | false $Limit = false, integer | false $Offset = false ) : Gdn_DataSet
$Where array | false The where condition of the get.
$OrderFields string The field to order the discussions by.
$OrderDirection string The order, either **asc** or **desc**.
$Limit integer | false The number of discussion to return.
$Offset integer | false The offset within the total set.
return Gdn_DataSet Returns a {@link Gdn_DataSet} of discussions.

getWhereRecent() public method

Get a list of the most recent discussions.
public getWhereRecent ( array | false $Where = [], boolean | false | integer $Limit = false, integer | false $Offset = false ) : Gdn_DataSet
$Where array | false The where condition of the get.
$Limit boolean | false | integer The number of discussion to return.
$Offset integer | false The offset within the total set.
return Gdn_DataSet Returns a Gdn_DataSet of discussions. of discussions.

getWheres() protected method

Checks for any set filters and if they exist, returns the where clauses from the filters.
protected getWheres ( array $categoryIDs = [] ) : array
$categoryIDs array The category IDs from the where clause.
return array The where clauses from the filters.

incrementNewDiscussion() public method

public incrementNewDiscussion ( integer | array | stdClass $Discussion )
$Discussion integer | array | stdClass The discussion ID or discussion.

notifyNewDiscussion() public method

public notifyNewDiscussion ( integer | array | stdClass $Discussion, ActivityModel $ActivityModel, array $Activity )
$Discussion integer | array | stdClass
$ActivityModel ActivityModel
$Activity array

removeAnnouncements() public method

Removes undismissed announcements from the data.
Since: 2.0.0
public removeAnnouncements ( object $Data )
$Data object SQL result.

removeFilter() public static method

Removes a filters from the allowed filter array with the passed filter key/values.
public static removeFilter ( array $filterKeys )
$filterKeys array The key/value pairs of the filters to remove.

removeFilterSet() public static method

Removes a filter set from the allowed filter array with the passed set key.
public static removeFilterSet ( string $setKey )
$setKey string The key of the filter to remove.

removeSort() public static method

Removes a sort from the allowed sort array with the passed key.
public static removeSort ( string $key )
$key string The key of the sort to remove.

save() public method

Events: BeforeSaveDiscussion, AfterValidateDiscussion, AfterSaveDiscussion.
public save ( array $FormPostValues, array $Settings = false ) : integer
$FormPostValues array Data sent from the form model.
$Settings array Currently unused.
return integer $DiscussionID Unique ID of the discussion.

setField() public method

An event firing wrapper for Gdn_Model::setField().
public setField ( integer $RowID, string $Property, mixed $Value = false )
$RowID integer
$Property string
$Value mixed

setFilters() public method

Will only set the filters property if the passed filters exist in the allowed filters array.
public setFilters ( array $filters )
$filters array The prospective filters to set.

setProperty() public method

By default, this toggles the specified between '1' and '0'. If $ForceValue is provided, the field is set to this value instead. An example use is announcing and unannouncing a discussion.
public setProperty ( integer $DiscussionID, string $Property, mixed $ForceValue = null ) : mixed
$DiscussionID integer Unique ID of discussion being updated.
$Property string Name of field to be updated.
$ForceValue mixed If set, overrides toggle behavior with this value.
return mixed Value that was ultimately set for the field.

setSort() public method

This setter also accepts an array and checks if the sort key exists on the array. Will only set the sort property if it exists in the allowed sorts array.
public setSort ( string | array $sort )
$sort string | array The prospective sort to set.

setUserBookmarkCount() public method

Update and get bookmark count for the specified user.
public setUserBookmarkCount ( integer $UserID ) : integer
$UserID integer Unique ID of user to update.
return integer Total number of bookmarks user has.

setUserScore() public method

Sets the discussion score for specified user.
public setUserScore ( integer $DiscussionID, integer $UserID, integer $Score ) : integer
$DiscussionID integer Unique ID of discussion to update.
$UserID integer Unique ID of user setting score.
$Score integer New score for discussion.
return integer Total score.

updateDiscussionCount() public method

Update the CountDiscussions value on the category based on the CategoryID being saved.
public updateDiscussionCount ( integer $CategoryID, array | false $Discussion = false )
$CategoryID integer Unique ID of category we are updating.
$Discussion array | false The discussion to update the count for or **false** for all of them.

updateUserDiscussionCount() public method

Update a user's discussion count.
public updateUserDiscussionCount ( integer $UserID, boolean $Inc = false )
$UserID integer The user to calculate.
$Inc boolean Whether to increment of recalculate from scratch.

userBookmarkCount() public method

Gets number of bookmarks specified user has.
public userBookmarkCount ( integer $UserID ) : integer
$UserID integer Unique ID of user for which to tally bookmarks.
return integer Total number of bookmarks.

Property Details

$Watching public_oe property

public bool $Watching
return boolean

$allowedFilters protected_oe static_oe property

The filters that are accessible via GET. Each filter corresponds with a where clause. You can have multiple filter sets. Every filter must be added to a filter set. Each filter set has the following properties: - **key**: string - The key name of the filter set. Appears in the query string, should be url-friendly. - **name**: string - The display name of the filter set. Usually appears in the UI. - **filters**: array - The filters in the set. Each filter in the array has the following properties: - **key**: string - The key name of the filter. Appears in the query string, should be url-friendly. - **setKey**: string - The key name of the filter set. - **name**: string - The display name of the filter. Usually appears as an option in the UI. - **where**: string - The where array query to execute for the filter. Uses - **group**: string - (optional) The dropdown module can group together any items with the same group name.
protected static $allowedFilters

$allowedSorts protected_oe static_oe property

The sorts that are accessible via GET. Each sort corresponds with an order by clause. Each sort in the array has the following properties: - **key**: string - The key name of the sort. Appears in the query string, should be url-friendly. - **name**: string - The display name of the sort. - **orderBy**: string - An array indicating order by fields and their directions in the format: ['field1' => 'direction', 'field2' => 'direction']
protected static $allowedSorts

$filters protected_oe property

The filter keys of the wheres we apply in the query.
protected $filters

$sort protected_oe property

The sort key of the order by we apply in the query.
protected $sort