aboutsummaryrefslogtreecommitdiff
path: root/h-source/Library/Helper/List.php
diff options
context:
space:
mode:
authorYuchen Pei <me@ypei.me>2021-07-29 14:17:20 +1000
committerYuchen Pei <me@ypei.me>2021-07-29 14:17:20 +1000
commit3ff03dc4f0a72432b34c00da620272cf011e4ddd (patch)
tree5746711ba17a91aed56c6529ea8cceb06c3ad16a /h-source/Library/Helper/List.php
parentcd4534aa10ba3b122963992741721289fa50d0ab (diff)
Publishing h-node.org code.
- this is the h-node.org code, except - removed a js file (3x copies at three different locations) without license / copyright headers - /Js/linkToForm.js - /Public/Js/linkToForm.js - /admin/Public/Js/linkToForm.js - removed config files containing credentials - /Application/Include/params.php - /Config/Config.php - /admin/Application/Include/params.php - /admin/Config/Config.php - added license and copyright header to one php file - /admin/Library/ErrorReporting.php (almost identical to /Library/ErrorReporting.php which has the headers)
Diffstat (limited to 'h-source/Library/Helper/List.php')
-rwxr-xr-xh-source/Library/Helper/List.php288
1 files changed, 46 insertions, 242 deletions
diff --git a/h-source/Library/Helper/List.php b/h-source/Library/Helper/List.php
index 81b5345..ba59643 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 - 2014 Antonio Gallo (info@laboratoriolibero.com)
+// Copyright (C) 2009 - 2011 Antonio Gallo
// See COPYRIGHT.txt and LICENSE.txt.
//
// This file is part of EasyGiant
@@ -25,9 +25,6 @@ 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
@@ -37,7 +34,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','checkbox','input'); //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';
@@ -45,12 +42,6 @@ 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';
@@ -63,6 +54,9 @@ 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();
@@ -74,15 +68,12 @@ 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 = Url::getRoot().'Public/Img/Icons/elementary_2_5/';
+ $baseUrl = 'http://'.DOMAIN_NAME.'/Public/Img/Icons/elementary_2_5/';
//set the files of the images
$this->submitImages = array(
@@ -156,39 +147,17 @@ 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)
{
- $key = !is_array($field) ? $field : $field[0];
- if (!array_key_exists($key,$this->viewArgs) and strcmp($key,null) !== 0) return false;
+ if (!array_key_exists($field,$this->viewArgs) and strcmp($field,null) !== 0) return false;
}
return true;
}
@@ -203,48 +172,47 @@ class Helper_List extends Helper_Html {
public function replaceFields($string,$rowArray) {
$this->__rowArray = $rowArray; //used by the replaceField method
- $string = preg_replace_callback('/(\;)(.*?)(\;)/', array($this, 'replaceField') ,$string);
+ $string = preg_replace_callback('/(\;)(.*?)(\;)/', 'Helper_List::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];
- //check if a function has been indicated
- if (strstr($string,'|'))
- {
- //get the function
- $firstArray = explode('|',$string);
- if (strstr($firstArray[1],':') or strstr($firstArray[1],'.'))
+ 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
- $char = $this->getChar($firstArray[1]);
$temp = explode($char,$firstArray[1]);
$string = $this->__rowArray[$temp[0]][$temp[1]];
- $string = callFunction($func,$string,__METHOD__);
+ 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
- {
- if (strstr($string,':') or strstr($string,'.'))
+ else
{
- $char = $this->getChar($string);
$temp = explode($char,$string);
$string = $this->__rowArray[$temp[0]][$temp[1]];
}
}
-
return $string;
}
@@ -259,8 +227,8 @@ class Helper_List extends Helper_Html {
}
//wrap the column with the tag td
- public function wrapColumn($string, $className = null, $tag = "td") {
- return wrap($string,array($tag=>$className));
+ public function wrapColumn($string, $className = null) {
+ return wrap($string,array('td'=>$className));
}
//wrap the row with the tag tr
@@ -269,7 +237,7 @@ class Helper_List extends Helper_Html {
}
public function wrapList($string) {
- return wrap($string,array('table'=>self::$tableAttributes));
+ return wrap($string,array('table'=>$this->tableAttributes));
}
//method to create the HTML of the head of the table
@@ -280,18 +248,13 @@ 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, "th");
+ $htmlHead .= $this->wrapColumn($temp,$prop);
$count++;
}
@@ -299,27 +262,7 @@ class Helper_List extends Helper_Html {
return $htmlHead;
}
- //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
+ //method to create the HTML of the head of the table
public function createFilters() {
$htmlFilters = null;
@@ -339,91 +282,18 @@ class Helper_List extends Helper_Html {
$html = '&nbsp';
if (isset($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]);
- }
- }
-
- //wrap single cell if filters doesn't have to be aggregate
- if (!$this->aggregateFilters)
- {
- $htmlFilters .= !$this->showFilters ? $html : $this->wrapColumn($html,$prop);
+ $html = $this->filterForm($this->_filters[$count]);
}
- else
- {
- $htmlFilters .= $html;
- }
-
+ $htmlFilters .= $this->wrapColumn($html,$prop);
+
$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;
@@ -482,32 +352,16 @@ class Helper_List extends Helper_Html {
$this->_recordNumber = count($queryResult);
$htmlList = null;
//create the HTML of the head of the record list
- $htmlList .= "<thead>\n".$this->wrapRow($this->createHead(),'listHead')."</thead>\n";
+ $htmlList .= $this->wrapRow($this->createHead(),'listHead');
//create the HTML of the filters
- $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');
- }
- }
-
+ $htmlList .= $this->wrapRow($this->createFilters(),'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."</tbody>\n");
+ return $this->wrapList($htmlList);
}
public function generalForm($itemArray, $submitName, $submitValue)
@@ -604,20 +458,8 @@ 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, $filterString = null, $filterValues = null)
+ public function filterForm($viewArgsName)
{
$cleanName = str_replace('n!',null,$viewArgsName);
$cleanName = str_replace('-',null,$cleanName);
@@ -632,15 +474,8 @@ class Helper_List extends Helper_Html {
if (Params::$nullQueryValue)
{
$this->viewArgs[$viewArgsName] = Params::$nullQueryValue;
- $viewStatus = Url::createUrl($this->viewArgs);
- if (strcmp($value,Params::$nullQueryValue) === 0 and !isset($filterValues))
- {
- $value = '';
- }
- }
- else
- {
- $viewStatus = $this->viewStatus;
+ $viewStatus = Url::createUrl(array_values($this->viewArgs));
+ if (strcmp($value,Params::$nullQueryValue) === 0) $value = '';
}
$this->viewArgs[$viewArgsName] = $temp;
@@ -649,42 +484,11 @@ class Helper_List extends Helper_Html {
$title = $this->strings->gtext('filter');
$clearLinkTitle = $this->strings->gtext('clear the filter');
- $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";
- }
+ $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;
}