/** * Detects current controller action. * * @param string $actionFieldName $_REQUEST action field name if form submit. * @param string $defaultAction Default action if no action detected. * * @return string Action name. */ public function getAction($actionFieldName = 'action', $defaultAction = 'list') { $action = Request::getFieldValue($actionFieldName); if (empty($action)) { if (!empty($this->action)) { return $this->action; } else { return $defaultAction; } } return $action; }
/** * Validate if localised field value is not empty. * * @param string $fieldName Name of the field. * * @return bool */ public static function validateNotEmpty($fieldName) { $fieldValue = Request::getFieldValue($fieldName); if (is_array($fieldValue)) { foreach ($fieldValue as $value) { $value = trim($value); if (empty($value)) { Errors::saveErrorFor($fieldName, \__ERRORS::EMPTY_FIELD); return false; } } } else { return validateNotEmpty($fieldName); } return true; }
/** * Validates if some value is in array. * * @param string $fieldName Field name. * @param array $range Array with values. * * @return bool */ public static function validateRange($fieldName, $range) { $fieldValue = Request::getFieldValue($fieldName); if (!in_array($fieldValue, $range)) { Errors::saveErrorFor($fieldName, \__ERRORS::INCORRECT_VALUE); return false; } return true; }
<?php /** * UI data filters functionality. * * @category Asymptix PHP Framework * @author Dmytro Zarezenko <*****@*****.**> * @copyright (c) 2009 - 2015, Dmytro Zarezenko * * @git https://github.com/Asymptix/Framework * @license http://opensource.org/licenses/MIT */ use Asymptix\web\Request; // Set and Reset filter submit fields names may be changed. $setFilter = (bool) Request::getFieldValue('setFilter'); $resetFilter = (bool) Request::getFieldValue('resetFilter'); if (isset($_SESSION['_filter'])) { $_FILTER = unserialize($_SESSION['_filter']); } else { $_FILTER = array(); } if ($setFilter) { $_FILTER = array_merge($_FILTER, $_REQUEST); unset($_FILTER['setFilter']); } if ($resetFilter) { $_FILTER = array(); } $_SESSION['_filter'] = serialize($_FILTER);