PHP Class LogModel, vanilla

Inheritance: extends Model
Datei anzeigen Open project: vanilla/vanilla Class Usage Examples

Public Methods

Method Description
arrayFlipAndCombine ( array $array ) : array | null Takes an array and returns a flip, making values the keys and making the keys values.
beginTransaction ( ) Begin a log transaction.
delete ( int[] | string $LogIDs ) Purge entries from the log.
endTransaction ( ) End a log transaction.
formatConfiguration ( array $Data ) : string Format a configuration subtree.
formatContent ( array $Log ) : string Format the content of a log file.
formatDiff ( string $Old, string $New, string $Method = 'html' ) : string | array Format a diff of an edit.
formatKey ( string $Key, array $Data ) : string Format a specific column from the log.
formatRecord ( string[] $Keys, array $Data ) : string Format a record that the log points to.
getCountWhere ( array $Where ) : integer Get the count of log entries matching a query.
getIDs ( int[] | string $IDs ) : array Get the log rows by array of IDs.
getOperationCount ( string $Operation ) : integer A wrapper for GetCountWhere that takes care of caching specific operation counts.
getWhere ( array | false $Where = false, string $OrderFields = '', string $OrderDirection = 'asc', boolean $Offset = false, boolean $Limit = false ) : array Get log rows by a query.
insert ( string $Operation, string $RecordType, array $Data, array $Options = [] ) : integer | false Log an operation into the log table.
logChange ( string $Operation, string $RecordType, array $NewData, array | null $OldData = null ) Log a record edit.
recalculate ( ) Recalculate a record after a log operation.
restore ( array | integer $Log, boolean $DeleteLog = true ) Restore an entry from the log.

Private Methods

Method Description
instance ( ) : LogModel Returns the shared instance of this class.
logValue ( array $Data, string $LogKey, string $BakKey1 = '', string $BakKey2 = '' ) : mixed Get a value from a log entry.
restoreOne ( array $Log, boolean $DeleteLog = true ) Restores a single entry from the log.

Method Details

arrayFlipAndCombine() public method

In case of multiple values with the several occurrences, this reserves all original keys by pushing them onto an array.
public arrayFlipAndCombine ( array $array ) : array | null
$array array An array in the format {[id1] => count, [id2] => count }.
return array | null A 2D array the format {[count] => [id1, id2]}

beginTransaction() public static method

Begin a log transaction.
public static beginTransaction ( )

delete() public method

Purge entries from the log.
public delete ( int[] | string $LogIDs )
$LogIDs int[] | string An array or CSV of log IDs.

endTransaction() public static method

End a log transaction.
public static endTransaction ( )

formatConfiguration() public method

Format a configuration subtree.
public formatConfiguration ( array $Data ) : string
$Data array The data to format.
return string Returns the formatted entry.

formatContent() public method

Format the content of a log file.
public formatContent ( array $Log ) : string
$Log array The log entry to format.
return string Returns the formatted log entry.

formatDiff() public method

Format a diff of an edit.
public formatDiff ( string $Old, string $New, string $Method = 'html' ) : string | array
$Old string The record before the edit.
$New string The record after the edit.
$Method string Either **normal**, **html**, or **mixed**.
return string | array Returns the diff formatted according to {@link $Method}.

formatKey() public method

Format a specific column from the log.
public formatKey ( string $Key, array $Data ) : string
$Key string The key in the log row to format.
$Data array The log row.
return string Returns the formatted entry.

formatRecord() public method

Format a record that the log points to.
public formatRecord ( string[] $Keys, array $Data ) : string
$Keys string[] The keys to use from the record.
$Data array The log row.
return string Returns the formatted record.

getCountWhere() public method

Get the count of log entries matching a query.
public getCountWhere ( array $Where ) : integer
$Where array The filter.
return integer Returns the count.

getIDs() public method

Get the log rows by array of IDs.
public getIDs ( int[] | string $IDs ) : array
$IDs int[] | string And array or CSV of IDs.
return array Returns an array of log rows.

getOperationCount() public method

A wrapper for GetCountWhere that takes care of caching specific operation counts.
public getOperationCount ( string $Operation ) : integer
$Operation string Comma-delimited list of operation types to get (sum of) counts for.
return integer Returns a count.

getWhere() public method

Get log rows by a query.
public getWhere ( array | false $Where = false, string $OrderFields = '', string $OrderDirection = 'asc', boolean $Offset = false, boolean $Limit = false ) : array
$Where array | false The where filter.
$OrderFields string The fields to order by.
$OrderDirection string The order direction.
$Offset boolean The database offset.
$Limit boolean The database limit.
return array Returns a data set.

insert() public static method

Log an operation into the log table.
public static insert ( string $Operation, string $RecordType, array $Data, array $Options = [] ) : integer | false
$Operation string The operation being performed. This is usually one of: - Delete: The record has been deleted. - Edit: The record has been edited. - Spam: The record has been marked spam. - Moderate: The record requires moderation. - Pending: The record needs pre-moderation.
$RecordType string The type of record being logged. This usually correspond to the tablename of the record.
$Data array The record data. - If you are logging just one row then pass the row as an array. - You can pass an additional _New element to tell the logger what the new data is.
$Options array Additional options to affect the insert.
return integer | false The log ID or **false** if there was a problem.

logChange() public static method

Log a record edit.
public static logChange ( string $Operation, string $RecordType, array $NewData, array | null $OldData = null )
$Operation string The specific operation being logged.
$RecordType string The type of record. This matches the name of the record's table.
$NewData array The record after the edit.
$OldData array | null The record before the edit.

recalculate() public method

Recalculate a record after a log operation.
public recalculate ( )

restore() public method

Restore an entry from the log.
public restore ( array | integer $Log, boolean $DeleteLog = true )
$Log array | integer The log row or the ID of the log row.
$DeleteLog boolean Whether or not to delete the log row after restoring.