\Alddesign\Crudkit\ClassesDataProcessor

Holds a set of usefull methods.

In most cases the static methods are all you need. An instance of this Object is only needed by CRUDKit itself. Thats a little bit messy but its ok for now.

Summary

Methods
Properties
Constants
__construct()
preProcess()
postProcess()
formatRecords()
text()
getTexts()
noop()
e()
ex()
crudkitException()
xout()
getCrudkitDbConfig()
swap()
appendToArray()
formatSeconds()
fastArrayMerge()
start()
end()
getAjaxErrorResult()
getAjaxResult()
binaryStringToBase64Png()
getPrimaryKeyValuesFromRequest()
getFiltersFromRequest()
getFiltersFromUrl()
getPrimaryKeyValuesFromUrl()
getParamsFromUrl()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
addData()
setEmpty()
setNull()
setData()
formatBoolean()
formatDecimal()
processBinaryData()
formatBytes()
formatDateAndTime()
getUploadFileData()
No private properties found
N/A

Methods

__construct()

__construct(\Alddesign\Crudkit\Classes\TableDescriptor  $table) 

An instance is needed when dealing with data (pre/postprocessing).

Parameters

\Alddesign\Crudkit\Classes\TableDescriptor $table

Table for later pre/postprocessing

preProcess()

preProcess(array  $requestData, \Alddesign\Crudkit\Classes\bool  $insert) : array

Processing data from request before INSERT, UPDATE it to the database

Considering the four important things: -Request data for field exists -Request data for field has value or is NULL -Field has SQL default value in Databse -Field is set as NOT NULL in Database

Parameters

array $requestData
\Alddesign\Crudkit\Classes\bool $insert

Returns

array —

$recordData

postProcess()

postProcess(  $records, boolean  $singleRecord = false, \Alddesign\Crudkit\Classes\bool  $formatDateAndTime = true,   $formatBool = true,   $formatDec = true,   $formatBinary = true) : array

Processing data after SELECTing it from the database, before sending it to the view.

Parameters

$records
boolean $singleRecord
\Alddesign\Crudkit\Classes\bool $formatDateAndTime
$formatBool
$formatDec
$formatBinary

Returns

array —

$records

formatRecords()

formatRecords(  $records, \Alddesign\Crudkit\Classes\bool  $singleRecord = false, \Alddesign\Crudkit\Classes\bool  $formaDateAndTime = true,   $formatBool = true,   $formatDec = true,   $formatBinary = true) 

Parameters

$records
\Alddesign\Crudkit\Classes\bool $singleRecord
\Alddesign\Crudkit\Classes\bool $formaDateAndTime
$formatBool
$formatDec
$formatBinary

text()

text(string  $name, string  $language = '') : string

Gets a single text constant for the specified language form the config (crudkit-texts.php)

Parameters

string $name

The name of the test constant.

string $language

The language code. If not set, the default language is used.

Returns

string

getTexts()

getTexts(string  $language = '') : string

Gets all text constants for the specified language form the config (crudkit-texts.php)

Parameters

string $language

The language code. If not set, the default language is used.

Returns

string

noop()

noop() 

e()

e(mixed  $var) : boolean

A better implementation of PHP function empty(); - See code itself for details.

Parameters

mixed $var

The variable to check

Returns

boolean

ex()

ex(string  $message, mixed  $p1 = '', mixed  $p2 = '', mixed  $p3 = '', mixed  $p4 = '', mixed  $p5 = '', mixed  $p6 = '', mixed  $p7 = '', mixed  $p8 = '') 

Shorthand call of throw new Exception(); with up to 8 placeholders

//Example usage:
DataProcessor::ex("%d errors while trying to delete user '%s'.", 4, "admin");

Parameters

string $message

The Exception message to show

mixed $p1

(optional) placeholder

mixed $p2

(optional) placeholder

mixed $p3

(optional) placeholder

mixed $p4

(optional) placeholder

mixed $p5

(optional) placeholder

mixed $p6

(optional) placeholder

mixed $p7

(optional) placeholder

mixed $p8

(optional) placeholder

crudkitException()

crudkitException(string  $message, string  $classOrFilename, string  $methodOrFunctionName, mixed  $p1 = '', mixed  $p2 = '', mixed  $p3 = '', mixed  $p4 = '', mixed  $p5 = '', mixed  $p6 = '', mixed  $p7 = '', mixed  $p8 = '') 

Shorthand call of throw new Exception(); with up to 8 placeholders, plus classname and method.

//Example usage:
DataProcessor::crudkitException("%d errors while trying to delete user '%s'.", __CLASS__, __FUNCTION__ 4, "admin");

Parameters

string $message

The Exception message to show

string $classOrFilename

Classname or Filename

string $methodOrFunctionName

Method or Function name

mixed $p1

(optional) placeholder

mixed $p2

(optional) placeholder

mixed $p3

(optional) placeholder

mixed $p4

(optional) placeholder

mixed $p5

(optional) placeholder

mixed $p6

(optional) placeholder

mixed $p7

(optional) placeholder

mixed $p8

(optional) placeholder

xout()

xout(mixed  $value, boolean  $dontDie = false, \Alddesign\Crudkit\Classes\bool  $initCall = true) 

A better implementation of PHP function var_dump();

Provides syntax-highlighted insight even into nested objects,arrays, etc.

//Example usage:
DataProcessor::xout(['cars' => ['audi','bmw'], 'nothing' => (object)['name' => 'Mario', 'age' => 34]]);

Parameters

mixed $value

The variable to print out

boolean $dontDie

Default = false. If set to true the script will not be aborted after execution of this function.

\Alddesign\Crudkit\Classes\bool $initCall

getCrudkitDbConfig()

getCrudkitDbConfig() 

swap()

swap(  $var1,   $var2) 

Swaps the values of two variables.

Parameters

$var1
$var2

appendToArray()

appendToArray(mixed  $value, array  $array, boolean  $appendIfEmpty = true) : void

Parameters

mixed $value

The value to append

array $array

The array (as reference)

boolean $appendIfEmpty

formatSeconds()

formatSeconds(integer  $seconds) : string

Formats 3620 seconds into 1h 0m 20s

Parameters

integer $seconds

Returns

string

fastArrayMerge()

fastArrayMerge(array  $array, array  $intoArray) : void

This is upt to 2000 times faster than array_merge().

Parameters

array $array

the array which will be merged into $intoArray

array $intoArray

the new "result" array (this one will be modified)

start()

start(integer  $index) : void

Handy method for measuring execution time. Use DataProcessor::start() and DataProcessor::end()

Parameters

integer $index

Use different indexes if there are multiple DataProcessor::start() points, befor there is and DataProcessor::end().

end()

end(integer  $index) : float

Retruns the time in seconds betweetn DataProcessor::start() and DataProcessor::end()

Parameters

integer $index

The index for the corresponding DataProcessor::start()

Returns

float

getAjaxErrorResult()

getAjaxErrorResult(mixed  $data, string  $message = '', string  $p1 = '',   $p2 = '',   $p3 = '',   $p4 = '',   $p5 = '',   $p6 = '',   $p7 = '',   $p8 = '') : string

Gets a JSON string which can be used for CRUDKit custom ajax error results.

Parameters

mixed $data

which will be logged by the JS console on the client: console.log(data);

string $message

A simple message for the user

string $p1

p1 to p8 are placeholders for the message

$p2
$p3
$p4
$p5
$p6
$p7
$p8

Returns

string —

JSON string you can return to the client

getAjaxResult()

getAjaxResult(array  $data) : string

Gets a JSON string which can be used for CRUDKit custom ajax results.

Parameters

array $data

is an array of objects:

//Example
$data =
[
        (object)['id' => 1, 'text' => 'john doe', 'img' => 'data:image/png;base64,R0lG...'],
        (object)['id' => 2, 'text' => 'jane doe', 'img' => 'data:image/png;base64,R0ax...']
];

Returns

string —

JSON string

binaryStringToBase64Png()

binaryStringToBase64Png(string  $data, integer  $scaleWidthTo = -1) : string

Parameters

string $data

The binary image data as string (mostly it comes like this from the DB)

integer $scaleWidthTo

If you want to scale the image width

Returns

string —

The base64 encoded image as a string (PNG format)

getPrimaryKeyValuesFromRequest()

getPrimaryKeyValuesFromRequest(\Illuminate\Http\Request  $request) : array

Gets an array of CRUDKit primary keys from the CRUDKit request

Parameters

\Illuminate\Http\Request $request

Returns

array

getFiltersFromRequest()

getFiltersFromRequest(\Illuminate\Http\Request  $request) : array<mixed,\Alddesign\Crudkit\Classes\Filter>

Gets an array of filters from the CRUDKit request

Parameters

\Illuminate\Http\Request $request

Returns

array<mixed,\Alddesign\Crudkit\Classes\Filter>

getFiltersFromUrl()

getFiltersFromUrl(string  $url) : array<mixed,\Alddesign\Crudkit\Classes\Filter>

Gets an array of filters from a given CRUDKit URL

Parameters

string $url

Returns

array<mixed,\Alddesign\Crudkit\Classes\Filter>

getPrimaryKeyValuesFromUrl()

getPrimaryKeyValuesFromUrl(string  $url) : array

Gets an array with primary key values from a given CRUDKit URL

Parameters

string $url

Returns

array

getParamsFromUrl()

getParamsFromUrl(string  $url) : array

Gets an array of the URL params $key => $value

Parameters

string $url

Returns

array

addData()

addData(array  $recordData,   $columnName,   $data, \Alddesign\Crudkit\Classes\bool  $deleteBlob, \Alddesign\Crudkit\Classes\bool  $insert, \Alddesign\Crudkit\Classes\bool  $i, \Alddesign\Crudkit\Classes\bool  $u) 

In the Update From there is the special "delete" checkbox for blob/image fields.

If the user doesnt check this checkbox, doesnt provide a file, and there is already data in the DB, we have to ensure not to delete the existing data. This will bypass the above maxtrix with all the logic of null,empty,value...

Parameters

array $recordData
$columnName
$data
\Alddesign\Crudkit\Classes\bool $deleteBlob
\Alddesign\Crudkit\Classes\bool $insert
\Alddesign\Crudkit\Classes\bool $i
\Alddesign\Crudkit\Classes\bool $u

setEmpty()

setEmpty(  $fieldValue, \Alddesign\Crudkit\Classes\string  $fieldDatatype, \Alddesign\Crudkit\Classes\string  $columnName = '') 

Setting the empty or lets say database specific value for each datatype

Parameters

$fieldValue
\Alddesign\Crudkit\Classes\string $fieldDatatype
\Alddesign\Crudkit\Classes\string $columnName

setNull()

setNull(  $fieldValue, \Alddesign\Crudkit\Classes\string  $fieldDatatype, \Alddesign\Crudkit\Classes\string  $columnName = '') 

Parameters

$fieldValue
\Alddesign\Crudkit\Classes\string $fieldDatatype
\Alddesign\Crudkit\Classes\string $columnName

setData()

setData(  $fieldValue, \Alddesign\Crudkit\Classes\string  $fieldDatatype, \Alddesign\Crudkit\Classes\string  $columnName = '') 

Parameters

$fieldValue
\Alddesign\Crudkit\Classes\string $fieldDatatype
\Alddesign\Crudkit\Classes\string $columnName

formatBoolean()

formatBoolean(  $columnName,   $columnValue) 

Parameters

$columnName
$columnValue

formatDecimal()

formatDecimal(  $columnName,   $columnValue) 

Parameters

$columnName
$columnValue

processBinaryData()

processBinaryData(  $columnName,   $columnValue,   $singleRecord) 

Parameters

$columnName
$columnValue
$singleRecord

formatBytes()

formatBytes(  $bytes, \Alddesign\Crudkit\Classes\int  $precision = 2) 

Parameters

$bytes
\Alddesign\Crudkit\Classes\int $precision

formatDateAndTime()

formatDateAndTime(  $columnName,   $columnValue) 

Parameters

$columnName
$columnValue

getUploadFileData()

getUploadFileData(\Illuminate\Http\UploadedFile  $uploadedFile) : mixed

Gets the binary data from an uploaded file.

Parameters

\Illuminate\Http\UploadedFile $uploadedFile

Returns

mixed