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.

The fastest way to extract json data from the database column is:

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

Chaining json methods

But if you want to extract json data and at the same time want to call som functionality.

echo $obj->extra()->jsonObj()->content()->decode()->get();

Grouped json fields

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

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

Check if grouped json field has both name and content filled in.

if($inst = $obj->extra()->jsonObj()->custom()->hasFetch(["name", "content"])) {
	foreach($inst->fetch() as $row) {
		echo "<h3>{$row->name}</h3>";
		echo $row->name()->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()
Access json DTP
@param boolean $k
@return jsonObj
jsonObj($k = false)
Access product DTO
@return product
productObj()
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)
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 = ",")
Explode string
@return array
exp()
Get last array item
@return mixed
end()
Chunck out
@param array $data
@param int $offset
@return array
static chunkOut(array $data, int $offset)
DEPRECATED METHODS -->
m()
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 only picture tag
@example $obj->upload()->media('image')->picture()
@param boolean $class add class to html tag
@return html
picture($class = NULL)
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 (IMG TAG)
@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)
Unset attribute
@param string $key attr key/name
@return self
deleteAttr($key)
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(?int $key = NULL)
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()