aboutsummaryrefslogtreecommitdiff
path: root/h-source/Library/Helper
diff options
context:
space:
mode:
authorAntonio Gallo <tonicucoz@gmail.com>2012-02-18 00:07:50 +0000
committerAntonio Gallo <tonicucoz@gmail.com>2012-02-18 00:07:50 +0000
commit14691cd854be3e9ee272c9619a6368c83d72267b (patch)
tree89215d53db8d6f01bb24a5c1d30d9dd4c8d7a5b9 /h-source/Library/Helper
parenta2c0b2c4f80463a94e2dd87b59f193ab3aa925eb (diff)
upload new EasyGiant library and added added a new filter for the model name (part 2)
Diffstat (limited to 'h-source/Library/Helper')
-rwxr-xr-xh-source/Library/Helper/List.php259
-rwxr-xr-xh-source/Library/Helper/Menu.php61
-rwxr-xr-xh-source/Library/Helper/Pages.php21
-rwxr-xr-xh-source/Library/Helper/Popup.php40
4 files changed, 293 insertions, 88 deletions
diff --git a/h-source/Library/Helper/List.php b/h-source/Library/Helper/List.php
index 51ed09c..ba59643 100755
--- a/h-source/Library/Helper/List.php
+++ b/h-source/Library/Helper/List.php
@@ -22,9 +22,11 @@
if (!defined('EG')) die('Direct access not allowed!');
-//class to create the HTML for the view action
+//class to create the HTML of a list of records
class Helper_List extends Helper_Html {
+ private $__rowArray = array(); //the current associative array representing the database record
+
protected $_itemsList = array(); //2-dimensional associative array containing the list items
//keys: type,table:field,controller/action,value
protected $_head = array(); //2-dimensional array containing the head of the table
@@ -32,28 +34,22 @@ 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','Form'); //type of items allowed
+ protected $_allowedItems = array('simpleLink','simpleText','delForm','editForm','associateForm','moveupForm','movedownForm','Form','ledit','link','text'); //type of items allowed
+
+ //it can be: both, top, bottom, none
+ protected $_boundaries = 'none';
+ //array of filters
+ protected $_filters = array();
+
//set if the submit buttons have to be images or not (it can be yse or not)
- public $submitImageType = 'no';
+ public $submitImageType = 'yes';
//set the files of the images
- public $submitImages = array(
- 'edit' => null,
- 'del' => null,
- 'up' => null,
- 'down' => null,
- 'link' => null
- );
+ public $submitImages = array();
//set the titles of the input:submit
- public $submitTitles = array(
- 'edit' => 'edit the record',
- 'del' => 'delete the record',
- 'up' => 'move up the record',
- 'down' => 'move down the record',
- 'link' => 'associate the record'
- );
+ public $submitTitles = array();
//properties of columns
public $colProperties = array();
@@ -63,13 +59,46 @@ class Helper_List extends Helper_Html {
//$position: array. First element: page number, second element: number of pages
public $position = array();
+
+ //instance of Lang_{language}_Generic
+ public $strings = null;
+
+ //the url (controller/action) of the current page
+ public $url = null;
+
+ public $pageArg = null; //the key of the viewArgs array representing the page number. $this->viewArgs[$this->pageArg] is set to 1 if $this->pageArg !== null
- //it can be: both, top, bottom, none
- protected $_boundaries = 'none';
+ public function __construct() {
+
+ //get the generic language class
+ $this->strings = Factory_Strings::generic(Params::$language);
+
+ $baseUrl = 'http://'.DOMAIN_NAME.'/Public/Img/Icons/elementary_2_5/';
+
+ //set the files of the images
+ $this->submitImages = array(
+ 'up' => $baseUrl.'up.png',
+ 'down' => $baseUrl.'down.png',
+ 'edit' => $baseUrl.'edit.png',
+ 'del' => $baseUrl.'delete.png',
+ 'link' => $baseUrl.'link.png',
+ );
+
+ $this->submitTitles = array(
+ 'edit' => $this->strings->gtext('edit'),
+ 'del' => $this->strings->gtext('delete'),
+ 'up' => $this->strings->gtext('move up'),
+ 'down' => $this->strings->gtext('move down'),
+ 'link' => $this->strings->gtext('associate')
+ );
- public function build($identifierName = 'identifier')
+ }
+
+ public function build($identifierName = 'identifier', $url = null, $pageArg = null)
{
$this->_identifierName = $identifierName;
+ $this->url = $url;
+ $this->pageArg = $pageArg;
}
public function setIdentifierName($identifierName)
@@ -116,8 +145,24 @@ class Helper_List extends Helper_Html {
}
}
+ //set the filters
+ //$filters: array whose elements are the viewArgs to be used for the filters forms
+ public function setFilters($filters)
+ {
+ $this->_filters = $filters;
+ }
- //$method to extract the field name from the $action string (;table:field;)
+ //check that the ViewArgs array is complete
+ public function checkViewArgs()
+ {
+ foreach ($this->_filters as $field)
+ {
+ if (!array_key_exists($field,$this->viewArgs) and strcmp($field,null) !== 0) return false;
+ }
+ return true;
+ }
+
+ //$method to extract the field name from the $action string (;table:field;). Used for the head
public function extractFieldName($string) {
$string = str_replace(';','',$string);
return $string;
@@ -125,41 +170,50 @@ class Helper_List extends Helper_Html {
//replace the strings wrapped by ; with their correspondent value taken by the $recordArray associative array (a row of the select query)
public function replaceFields($string,$rowArray) {
- $stringArray = explode(';',$string);
- for ($i = 0; $i < count($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],'|'))
- {
- //get the function
- $firstArray = explode('|',$stringArray[$i]);
- $func = $firstArray[0];
- //replace the fields
- $temp = explode($char,$firstArray[1]);
- $stringArray[$i] = $rowArray[$temp[0]][$temp[1]];
-
- if (!function_exists($func)) {
- throw new Exception('Error in <b>'.__METHOD__.'</b>: function <b>'.$func.'</b> does not exists..');
- }
- //apply the function
- $stringArray[$i] = call_user_func($func,$stringArray[$i]);
- }
- else
- {
- $temp = explode($char,$stringArray[$i]);
- $stringArray[$i] = $rowArray[$temp[0]][$temp[1]];
+ $this->__rowArray = $rowArray; //used by the replaceField method
+
+ $string = preg_replace_callback('/(\;)(.*?)(\;)/', 'Helper_List::replaceField' ,$string);
+
+ return $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,'|'))
+ {
+ //get the function
+ $firstArray = explode('|',$string);
+ $func = $firstArray[0];
+ //replace the fields
+ $temp = explode($char,$firstArray[1]);
+ $string = $this->__rowArray[$temp[0]][$temp[1]];
+
+ if (!function_exists($func)) {
+ throw new Exception('Error in <b>'.__METHOD__.'</b>: function <b>'.$func.'</b> does not exists..');
}
+ //apply the function
+ $string = call_user_func($func,$string);
+ }
+ else
+ {
+ $temp = explode($char,$string);
+ $string = $this->__rowArray[$temp[0]][$temp[1]];
}
}
- return implode('',$stringArray);
+ return $string;
}
//call the method replaceFields upon the $items array using the associative array $rowArray
@@ -204,9 +258,42 @@ class Helper_List extends Helper_Html {
$count++;
}
+
return $htmlHead;
}
+ //method to create the HTML of the head of the table
+ public function createFilters() {
+ $htmlFilters = null;
+
+ if (count($this->_filters) > 0)
+ {
+ if ($this->checkViewArgs())
+ {
+ $count = 0;
+ foreach ($this->_head as $item) {
+
+ $prop = $item['type'];
+ if (isset($this->colProperties[$count]))
+ {
+ $prop = $this->colProperties[$count];
+ }
+
+ $html = '&nbsp';
+ if (isset($this->_filters[$count]))
+ {
+ $html = $this->filterForm($this->_filters[$count]);
+ }
+ $htmlFilters .= $this->wrapColumn($html,$prop);
+
+ $count++;
+ }
+ }
+ }
+
+ return $htmlFilters;
+ }
+
//create the HTML of a single row (values taken from the associative array $rowArray)
public function getRowList($rowArray) {
$htmlList = null;
@@ -266,6 +353,8 @@ class Helper_List extends Helper_Html {
$htmlList = null;
//create the HTML of the head of the record list
$htmlList .= $this->wrapRow($this->createHead(),'listHead');
+ //create the HTML of the filters
+ $htmlList .= $this->wrapRow($this->createFilters(),'listFilters');
for ($i = 0; $i < count($queryResult); $i++)
{
$this->ifInBoundaries($i);
@@ -281,18 +370,21 @@ class Helper_List extends Helper_Html {
$name = (strcmp($itemArray['name'],'') !== 0) ? $itemArray['name'] : $submitName;
$value = (strcmp($itemArray['value'],'') !== 0) ? $itemArray['value'] : $submitValue;
+ $oldValue = $value;
+ $value = $this->strings->gtext($value);
+
if (strcmp($itemArray['title'],'') !== 0)
{
$title = "title='".$itemArray['title']."'";
}
else
{
- $title = isset($this->submitTitles[$value]) ? "title='".$this->submitTitles[$value]."'" : null;
+ $title = isset($this->submitTitles[$oldValue]) ? "title='".$this->submitTitles[$oldValue]."'" : null;
}
- if (strcmp($this->submitImageType,'yes') === 0 and isset($this->submitImages[$value]))
+ if (strcmp($this->submitImageType,'yes') === 0 and isset($this->submitImages[$oldValue]))
{
- $imgSrc = $this->submitImages[$value];
+ $imgSrc = $this->submitImages[$oldValue];
$string .= "<input type='image' $title src='".$imgSrc."' value='$value'>\n";
$string .= "<input type='hidden' name='".$name."' value='$value'>\n";
@@ -343,9 +435,62 @@ class Helper_List extends Helper_Html {
return $string;
}
+ public function text($itemArray)
+ {
+ return $this->simpleText($itemArray);
+ }
+
public function simpleLink($itemArray) {
- $string = "<a class='linkItem' href='".Url::getRoot(null).$itemArray['action'].$this->viewStatus."'>".$itemArray['name']."</a>\n";
+ $string = "<a title='".$itemArray['field']."' class='linkItem' href='".Url::getRoot(null).$itemArray['action'].$this->viewStatus."'>".$itemArray['name']."</a>\n";
+ return $string;
+ }
+
+ public function link($itemArray)
+ {
+ return $this->simpleLink($itemArray);
+ }
+
+ public function ledit($itemArray)
+ {
+ $text = isset($this->submitImages['edit']) ? "<img src='".$this->submitImages['edit']."'>" : $itemArray['name'];
+ $title = isset($this->submitTitles['edit']) ? $this->submitTitles['edit'] : $itemArray['field'];
+ $string = "<a title='".$title."' class='linkItem' href='".Url::getRoot(null).$itemArray['action'].$this->viewStatus."'>$text</a>\n";
return $string;
}
+
+ //create the HTML of the filter
+ public function filterForm($viewArgsName)
+ {
+ $cleanName = str_replace('n!',null,$viewArgsName);
+ $cleanName = str_replace('-',null,$cleanName);
+
+ if (isset($this->viewArgs[$this->pageArg]))
+ {
+ $this->viewArgs[$this->pageArg] = 1;
+ }
+
+ $temp = $value = $this->viewArgs[$viewArgsName];
+ //set the viewArg to the null query value
+ if (Params::$nullQueryValue)
+ {
+ $this->viewArgs[$viewArgsName] = Params::$nullQueryValue;
+ $viewStatus = Url::createUrl(array_values($this->viewArgs));
+ if (strcmp($value,Params::$nullQueryValue) === 0) $value = '';
+ }
+ $this->viewArgs[$viewArgsName] = $temp;
+
+ $action = Url::getRoot($this->url).$viewStatus;
+ $imgSrc = Url::getRoot('Public/Img/Icons/elementary_2_5/find.png');
+ $title = $this->strings->gtext('filter');
+ $clearLinkTitle = $this->strings->gtext('clear the filter');
+
+ $html = "<form class='list_filter_form list_filter_form_$cleanName' action='".$action."' method='GET'>\n";
+ $html .= "<input class='list_filter_input list_filter_input_$cleanName' type='text' name='$viewArgsName' value='".$value."'>";
+ $html .= "<a class='list_filter_clear_link list_filter_clear_link_$cleanName' title='$clearLinkTitle' href='$action'><img src='".Url::getRoot()."/Public/Img/Icons/elementary_2_5/clear_filter.png' /></a>";
+ $html .= "<input class='list_filter_submit list_filter_submit_$cleanName' type='image' title='$title' src='".$imgSrc."' value='trova'>\n";
+ $html .= "</form>\n";
+
+ return $html;
+ }
} \ No newline at end of file
diff --git a/h-source/Library/Helper/Menu.php b/h-source/Library/Helper/Menu.php
index 608795f..8fd4bf4 100755
--- a/h-source/Library/Helper/Menu.php
+++ b/h-source/Library/Helper/Menu.php
@@ -29,30 +29,46 @@ class Helper_Menu extends Helper_Html
public $panelController; //panel controller
public $controller;
- public $links = array(
+ public $links = array();
+
+ //instance of Lang_{language}_Generic
+ public $strings = null;
- 'back' => array(
- 'title' => 'back',
- 'class' => 'mainMenuItem',
- 'text' => 'Back',
- 'url' => 'main'
- ),
-
- 'add' => array(
- 'title' => 'add a new record',
- 'class' => 'mainMenuItem',
- 'text' => 'Add',
- 'url' => 'form/insert'
- ),
+ public function __construct()
+ {
+ $baseUrl = "http://".DOMAIN_NAME.'/Public/Img/Icons/elementary_2_5/';
- 'panel' => array(
- 'title' => 'back to the Panel',
- 'class' => 'mainMenuItem',
- 'text' => 'Panel',
- 'url' => 'main'
- )
+ //get the generic language class
+ $this->strings = Factory_Strings::generic(Params::$language);
- );
+ $this->links = array(
+
+ 'back' => array(
+ 'title' => $this->strings->gtext('back'),
+ 'class' => 'mainMenuItem',
+ 'text' => $this->strings->gtext('Back'),
+ 'url' => 'main',
+ 'icon' => $baseUrl."left.png",
+ ),
+
+ 'add' => array(
+ 'title' => $this->strings->gtext('add a new record'),
+ 'class' => 'mainMenuItem',
+ 'text' => $this->strings->gtext('Add'),
+ 'url' => 'form/insert',
+ 'icon' => $baseUrl."add.png",
+ ),
+
+ 'panel' => array(
+ 'title' => $this->strings->gtext('back to the Panel'),
+ 'class' => 'mainMenuItem',
+ 'text' => $this->strings->gtext('Panel'),
+ 'url' => 'main',
+ 'icon' => $baseUrl."panel.png",
+ )
+
+ );
+ }
public function build($controller = null, $panelController = null)
{
@@ -75,6 +91,7 @@ class Helper_Menu extends Helper_Html
{
$title = isset($this->links[$linkName]['title']) ? "title='".$this->links[$linkName]['title']."'" : null;
$class = isset($this->links[$linkName]['class']) ? "class='".$this->links[$linkName]['class']."'" : null;
+ $icon = isset($this->links[$linkName]['icon']) ? "<img class='top_menu_icon' src='".$this->links[$linkName]['icon']."'> " : null;
//choose the controller (current or panel)
$controller = (strcmp($linkName,'panel') === 0) ? $this->panelController.'/' : $this->controller.'/';
@@ -82,7 +99,7 @@ class Helper_Menu extends Helper_Html
$href = Url::getRoot($controller.$this->links[$linkName]['url'].$viewStatus);
$text = $this->links[$linkName]['text'];
- $menu .= "<div $class><a $title href='$href'>$text</a></div>\n";
+ $menu .= "<div $class>$icon <a $title href='$href'>$text</a></div>\n";
}
}
}
diff --git a/h-source/Library/Helper/Pages.php b/h-source/Library/Helper/Pages.php
index a6e3287..64e2649 100755
--- a/h-source/Library/Helper/Pages.php
+++ b/h-source/Library/Helper/Pages.php
@@ -22,7 +22,7 @@
if (!defined('EG')) die('Direct access not allowed!');
-//Helper class to create the HTML of the page division list
+//Helper class to create the HTML of the page list
class Helper_Pages extends Helper_Html
{
@@ -31,17 +31,24 @@ class Helper_Pages extends Helper_Html
protected $_numbOfPages; //number of pages
protected $_variableArg = ''; //value of the $viewArgs key that has to be modified
- public $previousString; //string of the link to the previous page
- public $nextString; //string of the link to the next page
+ public $previousString = null; //string of the link to the previous page
+ public $nextString = null; //string of the link to the next page
+
+ //instance of Lang_{language}_Generic
+ public $strings = null;
+
+ public function __construct()
+ {
+ //get the generic language class
+ $this->strings = Factory_Strings::generic(Params::$language);
+ }
public function build($urlViewAction = '' , $variableArg = 'page', $previousString = 'previous', $nextString = 'next')
{
-
$this->_variableArg = $variableArg;
$this->_urlViewAction =$urlViewAction; //url of the controller and (/) main action
- $this->previousString = $previousString;
- $this->nextString = $nextString;
-
+ $this->previousString = $this->strings->gtext($previousString);
+ $this->nextString = $this->strings->gtext($nextString);
}
//return the number of pages
diff --git a/h-source/Library/Helper/Popup.php b/h-source/Library/Helper/Popup.php
index 017e873..18bb00d 100755
--- a/h-source/Library/Helper/Popup.php
+++ b/h-source/Library/Helper/Popup.php
@@ -34,16 +34,31 @@ class Helper_Popup extends Helper_Html {
//the type of the popup. If type !=exclusive, than each voice selected is added to the where clause. If type=exclusive, the selection of a popup voice causes the unselection of the other voices
public $type = null;
- public $allString = 'All';
+ public $allString = null;
//list of popup names
public $popupItems = array();
+
+ //if it has to print the filter legend
+ public $printLegend = false;
+
+ //popup legend
+ public $legend = array();
+
+ public function __construct()
+ {
+ //get the generic language class
+ $this->strings = Factory_Strings::generic(Params::$language);
+
+ $this->allString = $this->strings->gtext('All');
+ }
- public function build($url, $popupArray = null, $type = 'exclusive', $pageArg = null) {
+ public function build($url, $popupArray = null, $type = 'exclusive', $pageArg = null, $printLegend = false) {
$this->url = $url;
$this->popupArray = $popupArray;
$this->pageArg = $pageArg;
$this->type = $type;
+ $this->printLegend = $printLegend;
foreach ($this->popupArray as $field => $popup)
{
@@ -70,6 +85,7 @@ class Helper_Popup extends Helper_Html {
}
}
+ //create the HTML of the popup
public function render() {
$returnString = null;
if ($this->checkViewArgs())
@@ -80,15 +96,26 @@ class Helper_Popup extends Helper_Html {
}
foreach ($this->popupArray as $field => $popup)
{
+ //default legend
+ $this->legend[$field] = Params::$nullQueryValue;
+
if ($this->type === 'exclusive') $this->unselect($field);
//save the value of the current ViewArg
$tempArg = $this->viewArgs[$field];
+ $this->legend[$field] = $tempArg;
+
$returnString .= "<ul onMouseOver='DisplayTag(this,\"block\");' onMouseOut='DisplayTag(this,\"none\");' id='menuBlock'><li class='innerItem'>".$popup->name."<ul class='innerList'>\n";
for ($i = 0; $i < count($popup->itemsValue); $i++)
{
$this->viewArgs[$field] = $popup->itemsValue[$i];
$viewStatus = Url::createUrl(array_values($this->viewArgs));
$returnString .= "<li><a href='".Url::getRoot($this->url).$viewStatus."'>".$popup->itemsName[$i]."</a></li>\n";
+
+ //set the legend
+ if (strcmp($popup->itemsValue[$i],$this->legend[$field]) === 0)
+ {
+ $this->legend[$field] = $popup->itemsName[$i];
+ }
}
$this->viewArgs[$field] = Params::$nullQueryValue;
$viewStatus = Url::createUrl(array_values($this->viewArgs));
@@ -96,6 +123,15 @@ class Helper_Popup extends Helper_Html {
$returnString .= "</ul>\n</li>\n</ul>\n";
$this->viewArgs[$field] = $tempArg;
}
+ if ($this->printLegend)
+ {
+ $returnString .= "<div class='popup_legend'>\n";
+ foreach ($this->popupArray as $field => $popup)
+ {
+ $returnString .= "<div class='popup_legend_item'>".$this->legend[$field]."</div>";
+ }
+ $returnString .= "</div>\n";
+ }
if (count($this->popupArray)>0) {
$returnString .= "<script type=\"text/javascript\" src=\"http://".DOMAIN_NAME."/Public/Js/DisplayTag.js\"></script>\n";
}