From a93461b231fb94f3a6a9df09a30557732201ddcc Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Mon, 14 Oct 2013 16:06:56 +0000 Subject: added new EasyGiant Library --- h-source/Library/Helper/List.php | 45 ++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 20 deletions(-) (limited to 'h-source/Library/Helper/List.php') diff --git a/h-source/Library/Helper/List.php b/h-source/Library/Helper/List.php index ba59643..7f8fb77 100755 --- a/h-source/Library/Helper/List.php +++ b/h-source/Library/Helper/List.php @@ -172,47 +172,48 @@ class Helper_List extends Helper_Html { public function replaceFields($string,$rowArray) { $this->__rowArray = $rowArray; //used by the replaceField method - $string = preg_replace_callback('/(\;)(.*?)(\;)/', 'Helper_List::replaceField' ,$string); + $string = preg_replace_callback('/(\;)(.*?)(\;)/', array($this, 'replaceField') ,$string); return $string; } + //get : or . as char used to separate table and field + public function getChar($string) + { + return strstr($string,':') ? ':' : '.'; + } + //replace a single string wrapped by ; with its correspondent value taken by the $recordArray associative array (a row of the select query) public function replaceField($match) { $string = $match[2]; - if (strstr($string,':') or strstr($string,'.')) { - if (strstr($string,':')) - { - $char = ':'; - } - else - { - $char = '.'; - } - //check if a function has been indicated - if (strstr($string,'|')) + //check if a function has been indicated + if (strstr($string,'|')) + { + //get the function + $firstArray = explode('|',$string); + if (strstr($firstArray[1],':') or strstr($firstArray[1],'.')) { - //get the function - $firstArray = explode('|',$string); $func = $firstArray[0]; //replace the fields + $char = $this->getChar($firstArray[1]); $temp = explode($char,$firstArray[1]); $string = $this->__rowArray[$temp[0]][$temp[1]]; - if (!function_exists($func)) { - throw new Exception('Error in '.__METHOD__.': function '.$func.' does not exists..'); - } - //apply the function - $string = call_user_func($func,$string); + $string = callFunction($func,$string,__METHOD__); } - else + } + else + { + if (strstr($string,':') or strstr($string,'.')) { + $char = $this->getChar($string); $temp = explode($char,$string); $string = $this->__rowArray[$temp[0]][$temp[1]]; } } + return $string; } @@ -477,6 +478,10 @@ class Helper_List extends Helper_Html { $viewStatus = Url::createUrl(array_values($this->viewArgs)); if (strcmp($value,Params::$nullQueryValue) === 0) $value = ''; } + else + { + $viewStatus = $this->viewStatus; + } $this->viewArgs[$viewArgsName] = $temp; $action = Url::getRoot($this->url).$viewStatus; -- cgit v1.2.3