From 11972639df8315753123ebccdadee1f596807ad0 Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Tue, 16 Sep 2014 08:03:29 +0000 Subject: Integrated new EasyGiant Library --- h-source/Library/Helper/Array.php | 2 +- h-source/Library/Helper/Html.php | 2 +- h-source/Library/Helper/List.php | 243 ++++++++++++++++++++++++++++++++++---- h-source/Library/Helper/Menu.php | 40 ++++++- h-source/Library/Helper/Pages.php | 15 ++- h-source/Library/Helper/Popup.php | 44 ++++--- 6 files changed, 295 insertions(+), 51 deletions(-) (limited to 'h-source/Library/Helper') diff --git a/h-source/Library/Helper/Array.php b/h-source/Library/Helper/Array.php index 329463f..dbdda4f 100755 --- a/h-source/Library/Helper/Array.php +++ b/h-source/Library/Helper/Array.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Helper/Html.php b/h-source/Library/Helper/Html.php index 81a9bdd..9e25bb4 100755 --- a/h-source/Library/Helper/Html.php +++ b/h-source/Library/Helper/Html.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Helper/List.php b/h-source/Library/Helper/List.php index 7f8fb77..81b5345 100755 --- a/h-source/Library/Helper/List.php +++ b/h-source/Library/Helper/List.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -25,6 +25,9 @@ if (!defined('EG')) die('Direct access not allowed!'); //class to create the HTML of a list of records class Helper_List extends Helper_Html { + //table attributes + static public $tableAttributes = array('class'=>'listTable','cellspacing'=>'0'); + private $__rowArray = array(); //the current associative array representing the database record protected $_itemsList = array(); //2-dimensional associative array containing the list items @@ -34,7 +37,7 @@ 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','ledit','link','text'); //type of items allowed + protected $_allowedItems = array('simpleLink','simpleText','delForm','editForm','associateForm','moveupForm','movedownForm','Form','ledit','link','text','checkbox','input'); //type of items allowed //it can be: both, top, bottom, none protected $_boundaries = 'none'; @@ -42,6 +45,12 @@ class Helper_List extends Helper_Html { //array of filters protected $_filters = array(); + //array of bulk actions + protected $_bulkActions = array(); + + //set to false if you don't want that the filters are created inside the table + public $showFilters = true; + //set if the submit buttons have to be images or not (it can be yse or not) public $submitImageType = 'yes'; @@ -54,9 +63,6 @@ class Helper_List extends Helper_Html { //properties of columns public $colProperties = array(); - //table attributes - public $tableAttributes = array('class'=>'listTable','cellspacing'=>'0'); - //$position: array. First element: page number, second element: number of pages public $position = array(); @@ -68,12 +74,15 @@ class Helper_List extends Helper_Html { 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 + //if the filter forms have to be aggregated in a unique form or if they have to be left separated + public $aggregateFilters = false; + 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/'; + $baseUrl = Url::getRoot().'Public/Img/Icons/elementary_2_5/'; //set the files of the images $this->submitImages = array( @@ -147,17 +156,39 @@ class Helper_List extends Helper_Html { //set the filters //$filters: array whose elements are the viewArgs to be used for the filters forms + //or null public function setFilters($filters) { $this->_filters = $filters; } + + //set $this->aggregateFilters equal to true + public function aggregateFilters() + { + $this->aggregateFilters = true; + } + + //set the bulk actions + //$bulkActions: associative array. + //key: class of the inputs whose elements have to be selected and serialized by javascript in the following way: data-primary-key:value_attribute|data-primary-key:value_attribute|data-primary-key:value_attribute|... + //value: array with two elements whose first element is the bulk action to be sent as a key of $_POST, second element is the human readable name of the action, third element can be the string "confirm" (if the user has to confirm the action) or undefined + //example: + // $bulkActions = array( + // "input_category_id_order" => array("sortAction","Sort elements"), + // "checkbox_category_id" => array("deleteAction","Delete elements","confirm"), + // ); + public function setBulkActions($bulkActions) + { + $this->_bulkActions = $bulkActions; + } //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; + $key = !is_array($field) ? $field : $field[0]; + if (!array_key_exists($key,$this->viewArgs) and strcmp($key,null) !== 0) return false; } return true; } @@ -228,8 +259,8 @@ class Helper_List extends Helper_Html { } //wrap the column with the tag td - public function wrapColumn($string, $className = null) { - return wrap($string,array('td'=>$className)); + public function wrapColumn($string, $className = null, $tag = "td") { + return wrap($string,array($tag=>$className)); } //wrap the row with the tag tr @@ -238,7 +269,7 @@ class Helper_List extends Helper_Html { } public function wrapList($string) { - return wrap($string,array('table'=>$this->tableAttributes)); + return wrap($string,array('table'=>self::$tableAttributes)); } //method to create the HTML of the head of the table @@ -249,13 +280,18 @@ class Helper_List extends Helper_Html { foreach ($this->_head as $item) { $temp = $item['action']; + if (preg_match('/\[\[bulkselect:(.*?)\]\]/',$temp,$matches)) + { + $temp = Html_Form::checkbox("bulkselect_".$matches[1],"","BS","bulk_select_checkbox",null,"data-class='".$matches[1]."'"); + } + $prop = $item['type']; if (isset($this->colProperties[$count])) { $prop = $this->colProperties[$count]; } - $htmlHead .= $this->wrapColumn($temp,$prop); + $htmlHead .= $this->wrapColumn($temp, $prop, "th"); $count++; } @@ -263,7 +299,27 @@ class Helper_List extends Helper_Html { return $htmlHead; } - //method to create the HTML of the head of the table + //return an array with all the filters in a 1-dimensional array + public function getFiltersList() + { + $filterList = array(); + + foreach ($this->_filters as $f) + { + if (is_array($f)) + { + $filterList[] = $f[0]; + } + else + { + $filterList[] = $f; + } + } + + return $filterList; + } + + //method to create the HTML of the filters input public function createFilters() { $htmlFilters = null; @@ -283,18 +339,91 @@ class Helper_List extends Helper_Html { $html = ' '; if (isset($this->_filters[$count])) { - $html = $this->filterForm($this->_filters[$count]); + if (!is_array($this->_filters[$count])) + { + $html = $this->filterForm($this->_filters[$count]); + } + else + { + $html = call_user_func_array(array($this,"filterForm"),$this->_filters[$count]); +// $html = $this->filterForm($this->_filters[$count][0],$this->_filters[$count][1]); + } } - $htmlFilters .= $this->wrapColumn($html,$prop); - + + //wrap single cell if filters doesn't have to be aggregate + if (!$this->aggregateFilters) + { + $htmlFilters .= !$this->showFilters ? $html : $this->wrapColumn($html,$prop); + } + else + { + $htmlFilters .= $html; + } + $count++; } + + //wrap an aggregate cell if filters have to be aggregate + if ($this->aggregateFilters) + { + $colspan = count($this->_itemsList); + $formTop = "
\n"; + $imgSrc = Url::getRoot('Public/Img/Icons/elementary_2_5/find.png'); + + $formBottom = ""; + $emptyFilterStatusArray = array(); + $filtersList = $this->getFiltersList(); + foreach ($this->viewArgs as $k => $v) + { + if (!in_array($k,$filtersList)) + { + $emptyFilterStatusArray[] = "$k=$v"; + $formBottom .= ""; + } + } + $emptyFilterStatus = implode("&",$emptyFilterStatusArray); + + $formBottom .= ""; + + $formBottom .= "\n"; + + $formBottom .= "
"; + + $htmlFilters = !$this->showFilters ? $formTop.$htmlFilters.$formBottom : $this->wrapColumn($formTop.$htmlFilters.$formBottom,array("class"=>"aggregate_filters_td","colspan"=>$colspan)); + + } } } return $htmlFilters; } + //create the HTML of the select of the bulk actions + public function createBulkActionsSelect() + { + $htmlBulkSelect = null; + $colspan = count($this->_itemsList); + + if (count($this->_bulkActions) > 0) + { + $htmlBulkSelect .= "".$this->strings->gtext('Actions').": "; + $htmlBulkSelect = $this->wrapColumn($htmlBulkSelect,array("class"=>"bulk_actions_td","colspan"=>$colspan)); + } + + return $htmlBulkSelect; + } + //create the HTML of a single row (values taken from the associative array $rowArray) public function getRowList($rowArray) { $htmlList = null; @@ -353,16 +482,32 @@ class Helper_List extends Helper_Html { $this->_recordNumber = count($queryResult); $htmlList = null; //create the HTML of the head of the record list - $htmlList .= $this->wrapRow($this->createHead(),'listHead'); + $htmlList .= "\n".$this->wrapRow($this->createHead(),'listHead')."\n"; //create the HTML of the filters - $htmlList .= $this->wrapRow($this->createFilters(),'listFilters'); + $htmlList .= "\n"; + + $bulkActionsHtml = $this->createBulkActionsSelect(); + if (isset($bulkActionsHtml)) + { + $htmlList .= $this->wrapRow($bulkActionsHtml,'bulk_actions_tr'); + } + + if ($this->showFilters) + { + $filtersHtml = $this->createFilters(); + if (isset($filtersHtml)) + { + $htmlList .= $this->wrapRow($filtersHtml,'listFilters'); + } + } + for ($i = 0; $i < count($queryResult); $i++) { $this->ifInBoundaries($i); $temp = $this->getRowList($queryResult[$i]); $htmlList .= $this->wrapRow($temp,'listRow'); } - return $this->wrapList($htmlList); + return $this->wrapList($htmlList."\n"); } public function generalForm($itemArray, $submitName, $submitValue) @@ -459,8 +604,20 @@ class Helper_List extends Helper_Html { return $string; } + //create the HTML of a checkbox + public function checkbox($itemArray) + { + return Html_Form::checkbox($itemArray['action'],$itemArray['field'],$itemArray['name'],"checkbox_".encode($itemArray['action']),null,"data-primary-key='".$itemArray['value']."'"); + } + + //create the HTML of an input text + public function input($itemArray) + { + return Html_Form::input($itemArray['action'],$itemArray['field'],"input_".encode($itemArray['action']),null,"data-primary-key='".$itemArray['name']."'"); + } + //create the HTML of the filter - public function filterForm($viewArgsName) + public function filterForm($viewArgsName, $filterString = null, $filterValues = null) { $cleanName = str_replace('n!',null,$viewArgsName); $cleanName = str_replace('-',null,$cleanName); @@ -475,8 +632,11 @@ class Helper_List extends Helper_Html { if (Params::$nullQueryValue) { $this->viewArgs[$viewArgsName] = Params::$nullQueryValue; - $viewStatus = Url::createUrl(array_values($this->viewArgs)); - if (strcmp($value,Params::$nullQueryValue) === 0) $value = ''; + $viewStatus = Url::createUrl($this->viewArgs); + if (strcmp($value,Params::$nullQueryValue) === 0 and !isset($filterValues)) + { + $value = ''; + } } else { @@ -489,11 +649,42 @@ class Helper_List extends Helper_Html { $title = $this->strings->gtext('filter'); $clearLinkTitle = $this->strings->gtext('clear the filter'); - $html = "
\n"; - $html .= ""; - $html .= ""; - $html .= "\n"; - $html .= "
\n"; + $html = null; + + if (!$this->aggregateFilters) + { + $html .= "
\n"; + } + + $html .= isset($filterString) ? " ".$filterString." " : null; + + if (!isset($filterValues)) + { + $html .= ""; + } + else + { + $filterValues = array_merge(array(Params::$nullQueryValue => $this->strings->gtext('All')),$filterValues); + $html .= Html_Form::select($viewArgsName,$value,$filterValues,"list_filter_input list_filter_input_$cleanName",null,"yes"); + } + + if (!$this->aggregateFilters) + { + $html .= ""; + $html .= "\n"; + + if (!Params::$rewriteStatusVariables) + { + foreach ($this->viewArgs as $k => $v) + { + if (strcmp($k,"$viewArgsName") !== 0) + { + $html .= ""; + } + } + } + $html .= "
\n"; + } return $html; } diff --git a/h-source/Library/Helper/Menu.php b/h-source/Library/Helper/Menu.php index 8fd4bf4..4b33261 100755 --- a/h-source/Library/Helper/Menu.php +++ b/h-source/Library/Helper/Menu.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -25,7 +25,8 @@ if (!defined('EG')) die('Direct access not allowed!'); //class to write the top menĂ¹ of the view files class Helper_Menu extends Helper_Html { - + public static $htmlLinks = array(); + public $panelController; //panel controller public $controller; @@ -49,6 +50,7 @@ class Helper_Menu extends Helper_Html 'text' => $this->strings->gtext('Back'), 'url' => 'main', 'icon' => $baseUrl."left.png", + 'queryString' => null, ), 'add' => array( @@ -57,6 +59,7 @@ class Helper_Menu extends Helper_Html 'text' => $this->strings->gtext('Add'), 'url' => 'form/insert', 'icon' => $baseUrl."add.png", + 'queryString' => null, ), 'panel' => array( @@ -65,9 +68,25 @@ class Helper_Menu extends Helper_Html 'text' => $this->strings->gtext('Panel'), 'url' => 'main', 'icon' => $baseUrl."panel.png", + 'queryString' => null, ) ); + + foreach (self::$htmlLinks as $k => $v) + { + if (!array_key_exists($k, $this->links)) + { + $this->links[$k] = $v; + } + else + { + foreach ($v as $subK => $subV) + { + $this->links[$k][$subK] = $subV; + } + } + } } public function build($controller = null, $panelController = null) @@ -89,8 +108,11 @@ class Helper_Menu extends Helper_Html //check that the text and the ure are defined if (isset($this->links[$linkName]['text']) and isset($this->links[$linkName]['url'])) { - $title = isset($this->links[$linkName]['title']) ? "title='".$this->links[$linkName]['title']."'" : null; + $title = isset($this->links[$linkName]['title']) ? "title=\"".$this->links[$linkName]['title']."\"" : null; + $class = isset($this->links[$linkName]['class']) ? "class='".$this->links[$linkName]['class']."'" : null; + $class = isset(self::$htmlLinks[$linkName]["class"]) ? "class='".self::$htmlLinks[$linkName]["class"]."'" : $class; + $icon = isset($this->links[$linkName]['icon']) ? " " : null; //choose the controller (current or panel) @@ -98,8 +120,18 @@ class Helper_Menu extends Helper_Html $viewStatus = (strcmp($linkName,'panel') === 0) ? null : $this->viewStatus; $href = Url::getRoot($controller.$this->links[$linkName]['url'].$viewStatus); + + if (isset($this->links[$linkName]['queryString'])) + { + $href .= $this->links[$linkName]['queryString']; + } + $text = $this->links[$linkName]['text']; - $menu .= "
$icon $text
\n"; + $htmlBefore = isset($this->links[$linkName]["htmlBefore"]) ? $this->links[$linkName]["htmlBefore"] : "
$icon "; + $htmlAfter = isset($this->links[$linkName]["htmlAfter"]) ? $this->links[$linkName]["htmlAfter"] : "
"; + $attributes = isset($this->links[$linkName]["attributes"]) ? $this->links[$linkName]["attributes"] : null; + + $menu .= "$htmlBefore$text$htmlAfter\n"; } } } diff --git a/h-source/Library/Helper/Pages.php b/h-source/Library/Helper/Pages.php index d8ac856..3826469 100755 --- a/h-source/Library/Helper/Pages.php +++ b/h-source/Library/Helper/Pages.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -109,9 +109,16 @@ class Helper_Pages extends Helper_Html public function html($pageNumber,$string = null) { if (isset($string)) { $strNumber = $string; - $strClass = "class='itemListPage'"; + if (strcmp($pageNumber,"1") === 0) + { + $strClass = "class='itemListPage previous_page'"; + } + else + { + $strClass = "class='itemListPage next_page'"; + } } else { - if ($pageNumber === $this->_currentPage) + if (strcmp($pageNumber,$this->_currentPage) === 0) { $strNumber = $pageNumber; $strClass = "class='currentPage'"; @@ -123,7 +130,7 @@ class Helper_Pages extends Helper_Html } } $this->viewArgs[$this->_variableArg] = $pageNumber; - $viewStatus = Url::createUrl(array_values($this->viewArgs)); + $viewStatus = Url::createUrl($this->viewArgs); $href= Url::getRoot(null) . $this->_urlViewAction .$viewStatus; return $this->getATag($href,$strNumber,$strClass); } diff --git a/h-source/Library/Helper/Popup.php b/h-source/Library/Helper/Popup.php index 4f67a5c..f3e6058 100755 --- a/h-source/Library/Helper/Popup.php +++ b/h-source/Library/Helper/Popup.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -25,6 +25,15 @@ if (!defined('EG')) die('Direct access not allowed!'); //class to create the popup menu class Helper_Popup extends Helper_Html { + //the HTML of the popup + public static $popupHtml = array( + "before_loop" => "", + "top" => "
\n", + "bottom" => "
", + "after_loop" => "", + ); + public $popupArray = array(); //array of popup objects (see popup.php) public $url = null; //the url (controller/action) to link by means of the popup menĂ¹ // public $fieldArg = null; //the key of the viewArgs array to set to the field in the where clause @@ -85,9 +94,17 @@ class Helper_Popup extends Helper_Html { } } + public function replacePlaceholders($string, $field, $name) + { + $string = str_replace("[[field]]",$field,$string); + $string = str_replace("[[name]]",$name,$string); + + return $string; + } + //create the HTML of the popup public function render() { - $returnString = null; + $returnString = self::$popupHtml["before_loop"]; if ($this->checkViewArgs()) { if (isset($this->viewArgs[$this->pageArg])) @@ -104,11 +121,12 @@ class Helper_Popup extends Helper_Html { $tempArg = $this->viewArgs[$field]; $this->legend[$field] = $tempArg; - $returnString .= "\n"; + $returnString .= self::$popupHtml["middle"]; $this->viewArgs[$field] = $tempArg; - } - if ($this->printLegend) - { - $returnString .= "\n"; - } - if (count($this->popupArray)>0) { - $returnString .= "\n"; + + $returnString .= self::$popupHtml["bottom"]; } } + $returnString .= self::$popupHtml["after_loop"]; return $returnString; } -- cgit v1.2.3