aboutsummaryrefslogtreecommitdiff
path: root/h-source/Library/Helper/List.php
diff options
context:
space:
mode:
authorAntonio Gallo <tonicucoz@gmail.com>2014-09-16 08:03:29 +0000
committerAntonio Gallo <tonicucoz@gmail.com>2014-09-16 08:03:29 +0000
commit11972639df8315753123ebccdadee1f596807ad0 (patch)
tree7c932d7e2f0d66afa55e603960f86cef7b00c5ff /h-source/Library/Helper/List.php
parent6209923d6cfb2418ee926cccdc62a9383e14bd97 (diff)
Integrated new EasyGiant Library
Diffstat (limited to 'h-source/Library/Helper/List.php')
-rwxr-xr-xh-source/Library/Helper/List.php243
1 files changed, 217 insertions, 26 deletions
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 = '&nbsp';
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 = "<form class='list_filter_form' action='".Url::getRoot($this->url)."' method='GET'>\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 .= "<input type='hidden' name='".$k."' value='$v' />";
+ }
+ }
+ $emptyFilterStatus = implode("&",$emptyFilterStatusArray);
+
+ $formBottom .= "<a class='list_filter_clear_link' title='".$this->strings->gtext('clear the filter')."' href='".Url::getRoot($this->url)."?".$emptyFilterStatus."'><img src='".Url::getRoot()."/Public/Img/Icons/elementary_2_5/clear_filter.png' /></a>";
+
+ $formBottom .= "<input class='list_filter_submit' type='image' title='".$this->strings->gtext('filter')."' src='".$imgSrc."' value='trova'>\n";
+
+ $formBottom .= "</form>";
+
+ $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 .= "<span class='bulk_actions_select_label'>".$this->strings->gtext('Actions')."</span>: <select data-url='".Url::getRoot(null).$this->url.$this->viewStatus."' class='bulk_actions_select' name='bulk_select'>";
+
+ $htmlBulkSelect .= "<option data-class='0' value='0'>".$this->strings->gtext('-- Select bulk action --')."</option>";
+
+ foreach ($this->_bulkActions as $class => $action)
+ {
+ $class = str_replace("+","",$class);
+ $confirm = isset($action[2]) ? "data-confirm='Y'" : "data-confirm='N'";
+ $htmlBulkSelect .= "<option $confirm data-class='$class' value='".$action[0]."'>".$action[1]."</option>";
+ }
+
+ $htmlBulkSelect .= "</select>";
+ $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 .= "<thead>\n".$this->wrapRow($this->createHead(),'listHead')."</thead>\n";
//create the HTML of the filters
- $htmlList .= $this->wrapRow($this->createFilters(),'listFilters');
+ $htmlList .= "<tbody>\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."</tbody>\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 = "<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";
+ $html = null;
+
+ if (!$this->aggregateFilters)
+ {
+ $html .= "<form class='list_filter_form list_filter_form_$cleanName' action='".$action."' method='GET'>\n";
+ }
+
+ $html .= isset($filterString) ? " <span class='list_filter_span list_filter_span_$cleanName'>".$filterString."</span> " : null;
+
+ if (!isset($filterValues))
+ {
+ $html .= "<input class='list_filter_input list_filter_input_$cleanName' type='text' name='$viewArgsName' value='".$value."'>";
+ }
+ 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 .= "<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";
+
+ if (!Params::$rewriteStatusVariables)
+ {
+ foreach ($this->viewArgs as $k => $v)
+ {
+ if (strcmp($k,"$viewArgsName") !== 0)
+ {
+ $html .= "<input type='hidden' name='".$k."' value='$v' />";
+ }
+ }
+ }
+ $html .= "</form>\n";
+ }
return $html;
}