<?php
/*
* Copyright 2008 Blandware (http://www.blandware.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Contains some grid utilities.
*
* @package AtleapLite
* @author Roman Puchkovskiy
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
*/
/**
* Clears all filters, resets sort state and page number.
*/
function clearFilters()
{
unset($_SESSION['grids']);
$_SESSION['sortDir'] = 'asc';
unset($_SESSION[PAGE_ID_VAR]);
}
/**
* If a parameter is in GET, takes it from there and puts to session. If
* Nothing wak taken and nothing was in session for this parameter, then, if
* <b>leaveUntouched</b> is false, default value is put into session.
*
* @param string $gridName name of grid
* @param string $paramName name of parameter
* @param mixed $defaultValue default value to set if nothing is in
* GET, session and <b>leaveUntouched</b> is false
* @param bool $leaveUntouched optional whether default value should be ignored
* if nothing is in GET and session
* @return bool true if something was put into session (value from GET or
* default value)
*/
function processGridParam($gridName, $paramName, $defaultValue, $leaveUntouched = false)
{
if (isset($_GET[$paramName])) {
$_SESSION['grids'][$gridName][$paramName] = $_GET[$paramName];
$result = true;
} else {
$result = false;
}
if (!isset($_SESSION['grids'][$gridName][$paramName]) && !$leaveUntouched) {
$_SESSION['grids'][$gridName][$paramName] = $defaultValue;
$result = true;
}
return $result;
}
/**
* Processes default grid params that control filtering and sorting.
*
* @param string $gridName name of grid
* @param array $filtersValue default value
*/
function processGridParams($gridName, $filtersValue = array()) {
processGridParam($gridName, 'sortColon', null, true);
processGridParam($gridName, 'sortDir', 'asc');
processGridParam($gridName, 'filters', $filtersValue);
}
?>