DTO
Examples
The DTO will be automatically active for template partials files.
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()->excerpt(20)->uppercase();
Get as string (the above utilze toString magick method)
Make sure whats return is a string.
echo $obj->content()->excerpt(20)->uppercase()->get();
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
@param callable $call function($row) { return "{$row->firstname} {$row->lastname}"; }
@return self
set($call)
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())
@example $obj->date()->dateTime()->format("Y-m-d");
@return string
dateTime()
@example $obj->date()->time();
@return string
time()
@param boolean $k
@return jsonObj
jsonObj($k = false)
productObj()
@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)
@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)
@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)
@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(int $decimal = 2)
number_format(int $decimal = 2, string $decPoint = ".", string $thousandSep = ",")
exp()
end()
@param array $data
@param int $offset
@return array
static chunkOut(array $data, int $offset)
@example $obj->email()->valid()->email();
@return valid
valid()
decode()
nl2br()
boldColonText()
@param integer $length string length
@param string $ending string ending
@param bool $triggered string ending
@return string
excerpt($length = 40, $ending = "...", &$triggered = false)
uppercase()
lowercase()
ucfirst()
encrypt()
decrypt()
metaTitle()
@return [type] [description]
metaDesc()
@example $obj->name()->initials() // Will make Daniel Von Ronkainen into DVR
@return self
initials()
@param string|null $tags Tag whitelist
@return self
stripTags($tags = NULL)
cleanLineBreaks(string $replace = "")
strlen()
float()
int()
string()
get()
leadingZero()
Media DTO
@example $obj->upload()->media('video')->get()
@param boolean $class add class to img, video or a tag
@return html
get($class = false, $dk = 0)
@example $obj->upload()->media('video')->puff()
@param boolean $class add class to html tag
@return html
puff($class = false, $dk = 0)
@example $obj->upload()->media('image')->picture()
@param boolean $class add class to html tag
@return html
picture($class = NULL)
@param boolean $class add class to img tag
@return html
image($class = NULL)
@param boolean $class add class to img tag
@return html
@param boolean $class add class to img tag
@return html
img($class = NULL)
@param boolean $class add class to video tag
@return html
video($class = NULL)
@param boolean $class add class to video tag
@return html
audio($class = NULL)
@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)
@param self $obj app\entity\media
@return self
joinSet(self $obj)
@param array $indexArr array with indexes in order (0-3+)
@return self
sets(array $indexArr)
@example $obj->upload()->media('video')->isMedia('video')
@param boolean/string $type (image, video, file)
@return boolean
isMedia($type = false)
isFile()
getAttr()
@param string $key attr key/name
@param string $val attr value
@return self
addAttr($key, $val, $overwrite = false)
@param string $key attr key/name
@return self
deleteAttr($key)
If you for example want to add rel="lightbox" to
.
@example $obj->upload()->media('image')->attr(["rel" => "lightbox"])->image()
@param array $arr ["rel" => "lightbox"]
@return self
attr(array $arr)
@example $obj->upload()->media('image')->unset(["width", "height"])->image()
@param array $arr attr keys
@return self
unsetAttr(array $arr)
file(?int $key = NULL)
org()
name()
originalFile()
fileDIR()
path(string $add = "")
url()
dir()
ending(&$imp = "")
kb()
@param float $size bytesum
@param integer $precision float precision (decimal count)
@return float
format()
Product DTO
@param int $int
@return void
static _decimals(int $int)
https://en.wikipedia.org/wiki/List_of_circulating_currencies
@param string $currencyIso expects a valid 3 characters iso currency code
@return void
static _currency(string $currencyIso)
https://fbdevwiki.com/wiki/Locales
@param string $formatStrCode
@return void
static _currencyFormat(string $formatStrCode)
inWeb()
inStore()
shippingType()
shippingStore()
orderType()
@param \DateTime $time
@return bool|string If not specified then false else return week day
hasStockRefillDate(\DateTime $time)
@param int|integer $qty Multiply the price
@return self
thePrice(int $qty = 1)
quantity()
theQty()
hasQty()
vatPrice(int $qty = 1)
@param int|integer $dec decimals
@return self
round(int $dec = 0)
@param int $dec decimals
@return self
modifyPriceRound(int $dec)
isSale()
money()
excludeVat()
gateFormat()
get()