PHP Class LogModel, vanilla

Inheritance: extends Model
Afficher le fichier Open project: vanilla/vanilla Class Usage Examples

Méthodes publiques

Méthode 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

Méthode 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 méthode

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 }.
Résultat array | null A 2D array the format {[count] => [id1, id2]}

beginTransaction() public static méthode

Begin a log transaction.
public static beginTransaction ( )

delete() public méthode

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

endTransaction() public static méthode

End a log transaction.
public static endTransaction ( )

formatConfiguration() public méthode

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

formatContent() public méthode

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

formatDiff() public méthode

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**.
Résultat string | array Returns the diff formatted according to {@link $Method}.

formatKey() public méthode

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.
Résultat string Returns the formatted entry.

formatRecord() public méthode

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.
Résultat string Returns the formatted record.

getCountWhere() public méthode

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

getIDs() public méthode

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

getOperationCount() public méthode

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.
Résultat integer Returns a count.

getWhere() public méthode

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.
Résultat array Returns a data set.

insert() public static méthode

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.
Résultat integer | false The log ID or **false** if there was a problem.

logChange() public static méthode

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 méthode

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

restore() public méthode

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.