* @version 0.0.0 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ class SearchCriteria extends BaseCriteria implements LocalSearchCriteria { /** * Criteria to handle */ private $criteria = array(); /** * Limitation for the search */ private $limit = 0; /** * Skip these entries before using them */ private $skip = 0; /** * Protected constructor * * @return void */ protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); } /** * Create an instance of this class * * @return $criteriaInstance An instance of this criteria */ public static final function createSearchCriteria () { // Get a new instance $criteriaInstance = new SearchCriteria(); // Return this instance return $criteriaInstance; } /** * Setter for limit * * @param $limit Search limit * @return void * @todo Find a nice casting here. (int) allows until and including 32766. */ public final function setLimit ($limit) { $this->limit = $limit; } /** * "Setter" for limit from a configuration entry * * @param $configEntry The configuration entry which hold a number as limit * @return void */ public final function setConfiguredLimit ($configEntry) { // Get the limit from config entry and set it $limit = $this->getConfigInstance()->getConfigEntry($configEntry); $this->setLimit($limit); } /** * Getter for limit * * @return $limit Search limit */ public final function getLimit () { return $this->limit; } /** * Setter for skip * * @param $skip Search skip * @return void * @todo Find a nice casting here. (int) allows until and including 32766. */ public final function setSkip ($skip) { $this->skip = $skip; } /** * Getter for skip * * @return $skip Search skip */ public final function getSkip () { return $this->skip; } /** * Checks whether the given key/value pair is matching with 'default' and one of 'choice' and * never with in 'exclude'. * * @param $key Key element to check * @param $value Value to check * @return $isMatching Whether the key/value is matching or excluded */ public function isCriteriaMatching ($key, $value) { // Get 'default' search value $search = $this->getCriteriaElemnent($key); // 'default' check $isMatching = ((!is_null($search)) && ($search == $value)); // Get 'choice' search value (can be NULL or comma-separated string) $search = $this->getCriteriaChoiceElemnent($key); // 'choice' check $isMatching = (($isMatching === TRUE) && ((is_null($search)) || (in_array($value, explode(',', $search))))); // Get 'exclude' search value $search = $this->getCriteriaExcludeElemnent($key); // 'exclude' check $isMatching = (($isMatching === TRUE) && ((is_null($search)) || ($search != $value))); // Return result return $isMatching; } } // [EOF] ?>