diff --git a/phpxpress/examples/card.php b/phpxpress/examples/card.php index a561c35..7e3c853 100644 --- a/phpxpress/examples/card.php +++ b/phpxpress/examples/card.php @@ -49,9 +49,18 @@ $card2->addElementToList("of various sentences"); $card2->addLink("Link1", "#"); $card2->addLink("Link2", "#"); + + $card2->onFieldDisplaying("onFieldDisplaying"); + $card2->draw(); Card::endCardGroupLayout(); + + function onFieldDisplaying(&$field , &$value){ + if($field == "Inhabitants"){ + $value .= " (census 2019)"; + } + } ?> \ No newline at end of file diff --git a/phpxpress/phpxpress/card.php b/phpxpress/phpxpress/card.php index eb01deb..7f0b615 100644 --- a/phpxpress/phpxpress/card.php +++ b/phpxpress/phpxpress/card.php @@ -2,6 +2,8 @@ include "include.php"; class Card{ + + // Structure private $imageSource; private $title; private $subtitle; @@ -12,6 +14,11 @@ private $list; private $linksArray; private $button; + + // Events + private $onFieldDisplayingFunctionName; + + // Layout private $borderColor; private $cardColor; private $textColor; @@ -140,10 +147,14 @@ echo '
'; echo '
'. $this->title .'
'; // title echo '
'. $this->subtitle .'
'; // subtitle - echo '

'. $this->innerText . '

'; // text + echo '

'. $this->innerText . '

'; // innertext - if(isset($this->fieldsArray)){ // fields + // fields + if(isset($this->fieldsArray)){ foreach($this->fieldsArray as $field => $value){ + if(isset($this->onFieldDisplayingFunctionName)){ + call_user_func_array($this -> onFieldDisplayingFunctionName , array(&$field, &$value)); + } echo '

' . $field . ': ' . $value . '

'; } } @@ -174,6 +185,23 @@ echo '
'; } + /* + ** The Event "onFieldDisplaying" gets fired just before the displaying of a field within + ** a card, so you can display your own value. + ** The function you have to provide must have this signature: + ** + ** function myFunction(&$field , &$value){...} + ** + ** You can change "field" snd "value" to whichever name you want. + ** + */ + function onFieldDisplaying($functionName){ + if(!is_callable($functionName)) + throw new InvalidArgumentException("Couldn't call $functionName. You must provide the name of a function."); + + $this -> onFieldDisplayingFunctionName = $functionName; + } + /* ** Using this overrides the card's width (known error from Bootstrap), so you should specify a width. ** It always has to be closed with endCardGroupLayout() diff --git a/phpxpress/phpxpress/table.php b/phpxpress/phpxpress/table.php index 9521836..b3eb223 100644 --- a/phpxpress/phpxpress/table.php +++ b/phpxpress/phpxpress/table.php @@ -2,6 +2,7 @@ include "include.php"; class Table{ + // Structure private $dataSource; private $columnCaptions; @@ -57,17 +58,21 @@ } + /* + ** Datasource can be either an array of object(s) or + ** an array of array(s). + */ function setDataSource(Array $dataSource){ if(empty($dataSource)) throw new InvalidArgumentException('Parameter cannot be empty.'); $this->dataSource = $dataSource; - // if array of objects provided + // Set captions when array of objects provided if(is_object($dataSource[0])) $this->columnCaptions = array_keys(get_object_vars($this->dataSource[0])); - // if array of arrays provided + // Set captione when array of arrays provided else if(is_array($dataSource[0])) $this->columnCaptions = array_keys($this->dataSource[0]); } @@ -107,12 +112,12 @@ /* ** The Event "onValueDisplaying" gets fired just before the displaying of a value within - ** a table body, so you can display your own value if you want to. + ** a table body, so you can display your own value. ** The function you have to provide must have this signature: ** ** function myFunction($caption, &$value, $row){...} ** - ** You can change "caption" and "value" to whichever name you want. + ** You can change "caption", "value" and "row" to whichever name you want. ** ** caption: the ACTUAL fieldname of the dataSource whose value belongs to ** value: the value you want to display.