Data

Examples

Initialize class

When you call something from database then you should allways loop data with bellow.

$obj = new \app\entity\data($obj);

Usage

echo $obj->DATABASE_COLUMN()->FUNCTION(ARGUMENTS);

Example - page templates

Read from database.

Read content as text

echo $obj->content;

Read content as html

echo $obj->content()->decode();

Add excerpt to content

echo $obj->content()->excerpt(40, "...");

Multiple methods.

echo $obj->content()->strObj()->decode()->excerpt(20)->get();

Add multiple format to object

@round(DECIMALS)->number_format(DECIMALS, DEC_POINT, THOUSANDS_SEP)

echo $obj->sum()->m()->round(2)->number_format(2, ",", ",")->string(); // at the end convert obj to: string, float, int

Read image/videos

echo $obj->upload()->media("IMAGE_KEY")->puff("puff-class");

Read image only

echo $obj->upload()->media("IMAGE_KEY")->image("image-class");

Create video player

echo $obj->upload()->media("IMAGE_KEY")->video("video-class");

Read file (PDF,WORD)

%s is the file name.

echo $obj->upload()->media("IMAGE_KEY")->link("Download: %s", "button-class");

Create audio player

echo $obj->upload()->media("IMAGE_KEY")->audio("audio-class");

Read all file types

Will auto create HTML that are applicable for the file type.

echo $obj->upload()->media("IMAGE_KEY")->get("get-class");

Format date

You access date class with "datetime" method.

echo $obj->date()->datetime()->format("Y-m-d");

You can do much more with datetime than this, click here to read more.

Working with json.

Some fields is saved as json-data within the database columns.

echo $obj->extra()->json("header");

If you want to do more advanced formating or fetching as array you can instead do.

foreach($obj->extra()->jsonObj()->custom()->fetch() as $obj) {
	echo $obj->content()->decode();
}

Complete function list

Change row content with callable
@param callable $call function($row) { return "{$row->firstname} {$row->lastname}"; }
@return self
set($call)
Add image/video/file
If you want to add image/video/file you need tto first call @media
@example $obj->upload()->media('image')->attr(["rel" => "lightbox"])->image()
@param string $k The media key in database json string
@return media instance
media($k = false, $ratioKey = array(), $indexKey = array())
Format date
@example $obj->date()->dateTime()->format("Y-m-d");
@return string
dateTime()
Get date as timestamp
@example $obj->date()->time();
@return string
time()
Get data from json. If you want to extract data fomr json or database fields extra[test] then you use this function
@example echo $obj->extra()->json("test");
@param boolean/key $k If $k is false then you will get all data.
@return string/null
json($k = false)
Get data from json custom field (loops)
@example
echo $obj->extra()->custom("custom-fields", function($obj) {
echo "{$obj->header}";
echo "{$obj->content}";
});
@param boolean/key $k If $k is false then you will get all data.
@return string/null
custom($key, $call, &$count = 0)
Make all characters uppercase
@return string
uppercase()
Make all characters lowercase
@return string
lowercase()
Make all characters lowercase
@return string
leadingZero()
Make all characters lowercase
@return string
rowToArr()
Uppercase first character
@return string
ucfirst()
Excerpt string
@param integer $length string length
@param string $ending string ending
@return string
excerpt($length = 40, $ending = "...", &$triggered = false)
Excerpt string
@param integer $length string length
@param string $ending string ending
@return string
stripTags($tags = NULL)
Excerpt string
@param integer $length string length
@param string $ending string ending
@return string
strlen($tags = NULL)
Return name initials only
@example $obj->name()->initials() // Will make Daniel Von Ronkainen into DVR
@return string
initials()
Will use the database column value to find in specified argument array set,
@example IF database column "status" is 1 and:
$row->status()->findSet([0 => "Hidden", 1 => "Visible"]) // Will return "Visible"
@param [type] $arr [description]
@return [type] [description]
findSet(array $setArr)
Will use the database column value to find in specified argument array set,
@example IF database column "status" is 1 and:
$row->status()->findSet([0 => "Hidden", 1 => "Visible"]) // Will return "Visible"
@param [type] $arr [description]
@return [type] [description]
findStrSet(array $setArr)
Round data
@return float
round(int $decimal = 2)
Number format data
@return float
number_format(int $decimal = 2, string $decPoint = ".", string $thousandSep = ",")
DEPRECATED: Get as int
int()
DEPRECATED: Get as float
float()
DEPRECATED: Get as string
string()
DEPRECATED: Shortcut -> decode
d()
Get all media types - auto add image, video or file (link)
@example $obj->upload()->media('video')->get()
@param boolean $class add class to img, video or a tag
@return html
get($class = false, $dk = 0)
Get only images and videos
@example $obj->upload()->media('video')->puff()
@param boolean $class add class to html tag
@return html
puff($class = false, $dk = 0)
Get image only
@param boolean $class add class to img tag
@return html
image($class = NULL)
Get image only
@param boolean $class add class to img tag
@return html
Get image only
@param boolean $class add class to img tag
@return html
img($class = NULL)
Get video only
@param boolean $class add class to video tag
@return html
video($class = NULL)
Get video only
@param boolean $class add class to video tag
@return html
audio($class = NULL)
Get link
@param string $text add a title to the a tag example. "Download" or "Download %s".
IF you add "%s" then it will write out the file name.
@param boolean $class add class to a tag
@return html
link($text = "%s", $class = NULL)
Join set from a other uploaded file
@param self $obj app\entity\media
@return self
joinSet(self $obj)
Choose witch set you want to add to image
@param array $indexArr array with indexes in order (0-3+)
@return self
sets(array $indexArr)
Check if media is right file type
@example $obj->upload()->media('video')->isMedia('video')
@param boolean/string $type (image, video, file)
@return boolean
isMedia($type = false)
Check if media exists
@return boolean
isFile()
Get all attributes
@return string
getAttr()
STRICT: Add attr can only be added once, values cannot be empty or 0
@param string $key attr key/name
@param string $val attr value
@return self
addAttr($key, $val, $overwrite = false)
Add attributes to html tag
If you for example want to add rel="lightbox" to File.
@example $obj->upload()->media('image')->attr(["rel" => "lightbox"])->image()
@param array $arr ["rel" => "lightbox"]
@return self
attr(array $arr)
Remove attribute (can be used also to remove default att)
@example $obj->upload()->media('image')->unset(["width", "height"])->image()
@param array $arr attr keys
@return self
unsetAttr(array $arr)
Get the full URL file path
@return string
file()
Get the full URL file path
@return string
org()
Get the full URL file path
@return string
name()
Get the full URL original path
@return string
originalFile()
Get the full directory file path
@return string
fileDIR()
Get the full URL path
@return string
path(string $add = "")
Get the full URL path
@return string
url()
Get the full directory path
@return string
dir()
Get file ending
@return string
ending(&$imp = "")
Get file size in KB
@return float
kb()
Formats the bytes to appropiate ending (k,M,G,T)
@param float $size bytesum
@param integer $precision float precision (decimal count)
@return float
format()