*/
function getWrapperConfigEntry ();
+ /**
+ * Checks whether given key is set
+ *
+ * @param $criteriaType Type of this criteria, can be one of 'default' (default), 'choice' or 'exclude'
+ * @param $criteriaKey Criteria key
+ * @return $isSet Whether key is set
+ */
+ function isKeySet ($criteriaType, $criteriaKey);
+
+ /**
+ * Checks whether given key is set for 'choice' type
+ *
+ * @param $criteriaKey Criteria key
+ * @return $isSet Whether key is set
+ */
+ function isChoiceKeySet ($criteriaKey);
+
+ /**
+ * Checks whether given key is set for 'exclude' type
+ *
+ * @param $criteriaKey Criteria key
+ * @return $isSet Whether key is set
+ */
+ function isExcludeKeySet ($criteriaKey);
+
/**
* Getter for criteria array
*
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
interface LocalSearchCriteria extends Criteria {
+ /**
+ * Setter for limit
+ *
+ * @param $limit Search limit
+ * @return void
+ * @todo Find a nice casting here. (int) allows until and including 32766.
+ */
+ function setLimit ($limit);
+
+ /**
+ * "Setter" for limit from a configuration entry
+ *
+ * @param $configEntry The configuration entry which hold a number as limit
+ * @return void
+ */
+ function setConfiguredLimit ($configEntry);
+
+ /**
+ * Getter for limit
+ *
+ * @return $limit Search limit
+ */
+ function getLimit ();
+
+ /**
+ * Setter for skip
+ *
+ * @param $skip Search skip
+ * @return void
+ * @todo Find a nice casting here. (int) allows until and including 32766.
+ */
+ function setSkip ($skip);
+
+ /**
+ * Getter for skip
+ *
+ * @return $skip Search skip
+ */
+ function getSkip ();
+
+ /**
+ * 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
+ */
+ function isCriteriaMatching ($key, $value);
}
// [EOF]
parent::__construct($className);
}
+ /**
+ * Checks whether given key is set
+ *
+ * @param $criteriaType Type of this criteria, can be one of 'default' (default), 'choice' or 'exclude'
+ * @param $criteriaKey Criteria key
+ * @return $isSet Whether key is set
+ */
+ public function isKeySet ($criteriaType, $criteriaKey) {
+ // Determine it
+ $isSet = isset($this->criteria[$criteriaType][$criteriaKey]);
+
+ // Return it
+ return $isSet;
+ }
+
+ /**
+ * Checks whether given key is set for 'choice' type
+ *
+ * @param $criteriaKey Criteria key
+ * @return $isSet Whether key is set
+ */
+ public function isChoiceKeySet ($criteriaKey) {
+ // Call inner method
+ return $this->isKeySet('choice', $criteriaKey);
+ }
+
+ /**
+ * Checks whether given key is set for 'exclude' type
+ *
+ * @param $criteriaKey Criteria key
+ * @return $isSet Whether key is set
+ */
+ public function isExcludeKeySet ($criteriaKey) {
+ // Call inner method
+ return $this->isKeySet('exclude', $criteriaKey);
+ }
+
/**
* Setter for wrapper class name
*
$criteriaKey = $this->convertDashesToUnderscores($criteriaKey);
// Is it already there?
- if (isset($this->criteria[$criteriaType][$criteriaKey])) {
+ if ($this->isKeySet($criteriaType, $criteriaKey)) {
// Append it
$this->criteria[$criteriaType][$criteriaKey] .= ',' . $criteriaValue;
} else {
$value = NULL;
// Is the criteria there?
- if (isset($this->criteria[$criteriaType][$criteriaKey])) {
+ if ($this->isKeySet($criteriaType, $criteriaKey)) {
// Then use it
$value = $this->criteria[$criteriaType][$criteriaKey];
} // END - if
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]
* Starts a SELECT query on the database by given return type, table name
* and search criteria
*
- * @param $tableName Name of the database table
- * @param $criteria Local search criteria class
- * @return $resultData Result data of the query
+ * @param $tableName Name of the database table
+ * @param $searchInstance Local search criteria class
+ * @return $resultData Result data of the query
* @throws UnsupportedCriteriaException If the criteria is unsupported
* @throws SqlException If an 'SQL error' occurs
*/
- public function querySelect ($tableName, LocalSearchCriteria $criteriaInstance) {
+ public function querySelect ($tableName, LocalSearchCriteria $searchInstance) {
// The result is null by any errors
$resultData = NULL;
$idx = 1;
// Read the directory with some exceptions
- while (($dataFile = $directoryInstance->readDirectoryExcept(array('.', '..', '.htaccess', '.svn', 'info.' . $this->getFileExtension()))) && (($limitFound < $criteriaInstance->getLimit()) || ($criteriaInstance->getLimit() == 0))) {
+ while (($dataFile = $directoryInstance->readDirectoryExcept(array('.', '..', '.htaccess', '.svn', 'info.' . $this->getFileExtension()))) && (($limitFound < $searchInstance->getLimit()) || ($searchInstance->getLimit() == 0))) {
// Does the extension match?
if (substr($dataFile, -(strlen($this->getFileExtension()))) !== $this->getFileExtension()) {
// Skip this file!
if (is_array($dataArray)) {
// Search in the criteria with FMFW (First Matches, First Wins)
foreach ($dataArray as $key => $value) {
- // Get criteria element
- $criteria = $criteriaInstance->getCriteriaElemnent($key);
-
// Is the criteria met or none set?
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: criteria[' . gettype($criteria) . ']=' . $criteria . ';()=' . strlen($criteria) . ',criteriaInstance()=' . $criteriaInstance->count() . ',value(' . strlen($value) . ')=' . $value);
- if (((!is_null($criteria)) && ($criteria == $value)) || ($criteriaInstance->count() == 0)) {
+ if ($searchInstance->isCriteriaMatching($key, $value)) {
// Shall we skip this entry?
- if ($criteriaInstance->getSkip() > 0) {
+ if ($searchInstance->getSkip() > 0) {
// We shall skip some entries
- if ($skipFound < $criteriaInstance->getSkip()) {
+ if ($skipFound < $searchInstance->getSkip()) {
// Skip this entry
$skipFound++;
break;
$skipFound = 0;
// Get the criteria array from the dataset
- $criteriaArray = $dataSetInstance->getCriteriaArray();
+ $searchArray = $dataSetInstance->getCriteriaArray();
// Get search criteria
$searchInstance = $dataSetInstance->getSearchInstance();
if (is_array($dataArray)) {
// Search in the criteria with FMFW (First Matches, First Wins)
foreach ($dataArray as $key => $value) {
- // Get criteria element
- $criteria = $searchInstance->getCriteriaElemnent($key);
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: dataFile=' . $dataFile . ',key=' . $key . ',criteria=' . $criteria);
-
// Is the criteria met?
- if (((!is_null($criteria)) && ($criteria == $value)) || ($searchInstance->count() == 0)) {
+ if ($searchInstance->isCriteriaMatching($key, $value)) {
// Shall we skip this entry?
if ($searchInstance->getSkip() > 0) {
// We shall skip some entries
} // END - if
// Entry found, so update it
- foreach ($criteriaArray as $criteriaKey => $criteriaValue) {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: criteriaKey=' . $criteriaKey . ',criteriaValue=' . $criteriaValue);
- $dataArray[$criteriaKey] = $criteriaValue;
+ foreach ($searchArray as $searchKey => $searchValue) {
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: criteriaKey=' . $searchKey . ',criteriaValue=' . $searchValue);
+ $dataArray[$searchKey] = $searchValue;
} // END - foreach
// Write the data to a local file