From e7b3717614621f14695ab6ca6dda6dd17ba3d65c Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Thu, 28 Jul 2011 20:27:23 +0000 Subject: added new easygiant library --- h-source/Library/Helper/List.php | 78 +++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 13 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 ce811e2..61b3e7b 100755 --- a/h-source/Library/Helper/List.php +++ b/h-source/Library/Helper/List.php @@ -30,11 +30,11 @@ class Helper_List extends Helper_Html { protected $_recordNumber = null; //number of records from the table - protected $_allowedItems = array('simpleLink','simpleText','delForm','editForm','associateForm','moveupForm','movedownForm'); //type of items allowed + protected $_allowedItems = array('simpleLink','simpleText','delForm','editForm','associateForm','moveupForm','movedownForm','Form'); //type of items allowed //set if the submit buttons have to be images or not (it can be yse or not) public $submitImageType = 'no'; - + //set the files of the images public $submitImages = array( 'edit' => null, @@ -53,6 +53,9 @@ class Helper_List extends Helper_Html { 'link' => 'associate the record' ); + //properties of each column + public $colProperties = array(); + //$position: array. First element: page number, second element: number of pages public $position = array(); @@ -70,7 +73,7 @@ class Helper_List extends Helper_Html { } //add a list Item. $type: the type of the item, $field: the table.field to exctract (use colon to separate the table and the field),$action: controller/action,$value=if type == link->the value of the link - public function addItem($type, $action = '', $field = '', $name = '') { + public function addItem($type, $action = '', $field = '', $name = '', $value = '', $title = '') { if (!in_array($type,$this->_allowedItems)) { throw new Exception('"'.$type. '" argument not allowed in '.__METHOD__.' method'); } @@ -79,6 +82,8 @@ class Helper_List extends Helper_Html { $temp['action'] = $action; $temp['field'] = $field; $temp['name'] = $name; + $temp['value'] = $value; + $temp['title'] = $title; $this->_itemsList[] = $temp; //set the $this->_head array @@ -117,7 +122,15 @@ class Helper_List extends Helper_Html { public function replaceFields($string,$rowArray) { $stringArray = explode(';',$string); for ($i = 0; $i < count($stringArray); $i++) { - if (strstr($stringArray[$i],':')) { + if (strstr($stringArray[$i],':') or strstr($stringArray[$i],'.')) { + if (strstr($stringArray[$i],':')) + { + $char = ':'; + } + else + { + $char = '.'; + } //check if a function has been indicated if (strstr($stringArray[$i],'|')) { @@ -125,7 +138,7 @@ class Helper_List extends Helper_Html { $firstArray = explode('|',$stringArray[$i]); $func = $firstArray[0]; //replace the fields - $temp = explode(':',$firstArray[1]); + $temp = explode($char,$firstArray[1]); $stringArray[$i] = $rowArray[$temp[0]][$temp[1]]; if (!function_exists($func)) { @@ -136,7 +149,7 @@ class Helper_List extends Helper_Html { } else { - $temp = explode(':',$stringArray[$i]); + $temp = explode($char,$stringArray[$i]); $stringArray[$i] = $rowArray[$temp[0]][$temp[1]]; } } @@ -149,6 +162,8 @@ class Helper_List extends Helper_Html { $item['action'] = $this->replaceFields($item['action'],$rowArray); $item['field'] = $this->replaceFields($item['field'],$rowArray); $item['name'] = $this->replaceFields($item['name'],$rowArray); + $item['value'] = $this->replaceFields($item['value'],$rowArray); + $item['title'] = $this->replaceFields($item['title'],$rowArray); return $item; } @@ -169,9 +184,20 @@ class Helper_List extends Helper_Html { //method to create the HTML of the head of the table public function createHead() { $htmlHead = null; + + $count = 0; foreach ($this->_head as $item) { $temp = $item['action']; - $htmlHead .= $this->wrapColumn($temp,$item['type']); + + $prop = $item['type']; + if (isset($this->colProperties[$count])) + { + $prop = $this->colProperties[$count]; + } + + $htmlHead .= $this->wrapColumn($temp,$prop); + + $count++; } return $htmlHead; } @@ -179,18 +205,27 @@ class Helper_List extends Helper_Html { //create the HTML of a single row (values taken from the associative array $rowArray) public function getRowList($rowArray) { $htmlList = null; + + $count = 0; foreach ($this->_itemsList as $item) { $item = $this->replaceAll($item,$rowArray); + $prop = $item['type']; + if (isset($this->colProperties[$count])) + { + $prop = $this->colProperties[$count]; + } + if (($this->_boundaries === 'top' and $item['type'] === 'moveupForm') or ($this->_boundaries === 'bottom' and $item['type'] === 'movedownForm') or ($this->_boundaries === 'both' and ($item['type'] === 'moveupForm' or $item['type'] === 'movedownForm'))) { - $htmlList .= $this->wrapColumn(' ',$item['type']); + $htmlList .= $this->wrapColumn(' ',$prop); } else { $temp = call_user_func_array(array($this,$item['type']),array($item)); - $htmlList .= $this->wrapColumn($temp,$item['type']); + $htmlList .= $this->wrapColumn($temp,$prop); } + $count++; } return $htmlList; } @@ -239,15 +274,27 @@ class Helper_List extends Helper_Html { { $string = "
viewStatus."' method='POST'>\n"; $name = (strcmp($itemArray['name'],'') !== 0) ? $itemArray['name'] : $submitName; + $value = (strcmp($itemArray['value'],'') !== 0) ? $itemArray['value'] : $submitValue; + + if (strcmp($itemArray['title'],'') !== 0) + { + $title = "title='".$itemArray['title']."'"; + } + else + { + $title = isset($this->submitTitles[$value]) ? "title='".$this->submitTitles[$value]."'" : null; + } - if (strcmp($this->submitImageType,'yes') === 0) + if (strcmp($this->submitImageType,'yes') === 0 and isset($this->submitImages[$value])) { - $string .= "\n"; - $string .= "\n"; + $imgSrc = $this->submitImages[$value]; + + $string .= "\n"; + $string .= "\n"; } else { - $string .= "\n"; + $string .= "\n"; } $string .= "\n"; @@ -255,6 +302,11 @@ class Helper_List extends Helper_Html { return $string; } + public function Form($itemArray) + { + return $this->generalForm($itemArray, 'name_missing', 'value_missing'); + } + public function moveupForm($itemArray) { return $this->generalForm($itemArray, 'moveupAction', 'up'); -- cgit v1.2.3