class_SearchCriteria.php

Go to the documentation of this file.
00001 <?php
00026 class SearchCriteria extends BaseFrameworkSystem implements LocalSearchCriteria {
00030         private $searchCriteria = array();
00031 
00035         private $limit = 0;
00036 
00040         private $skip = 0;
00041 
00047         protected function __construct () {
00048                 // Call parent constructor
00049                 parent::__construct(__CLASS__);
00050 
00051                 // Clean up a little
00052                 $this->removeNumberFormaters();
00053                 $this->removeSystemArray();
00054         }
00055 
00061         public final static function createSearchCriteria () {
00062                 // Get a new instance
00063                 $criteriaInstance = new SearchCriteria();
00064 
00065                 // Return this instance
00066                 return $criteriaInstance;
00067         }
00068 
00076         public final function addCriteria ($criteriaKey, $criteriaValue) {
00077                 $this->searchCriteria[(string)$criteriaKey] = (string)$criteriaValue;
00078         }
00079 
00087         public final function addConfiguredCriteria ($criteriaKey, $configEntry) {
00088                 // Add the configuration entry as a criteria
00089                 $value = $this->getConfigInstance()->readConfig($configEntry);
00090                 $this->addCriteria($criteriaKey, $value);
00091         }
00092 
00100         public final function setLimit ($limit) {
00101                 $this->limit = $limit;
00102         }
00103 
00109         public final function getLimit () {
00110                 return $this->limit;
00111         }
00112 
00120         public final function setSkip ($skip) {
00121                 $this->skip = $skip;
00122         }
00123 
00129         public final function getSkip () {
00130                 return $this->skip;
00131         }
00132 
00138         public function getCacheKey () {
00139                 // Initialize the key
00140                 $cacheKey = "";
00141 
00142                 // Now walk through all criterias
00143                 foreach ($this->searchCriteria as $criteriaKey => $criteriaValue) {
00144                         // Add the value URL encoded to avoid any trouble with special characters
00145                         $cacheKey .= sprintf("%s=%s;",
00146                                 $criteriaKey,
00147                                 urlencode($criteriaValue)
00148                         );
00149                 }
00150 
00151                 // Add limit and skip values
00152                 $cacheKey .= sprintf("%%limit%%=%s;%%skip%%=%s",
00153                         $this->limit,
00154                         $this->skip
00155                 );
00156 
00157                 // Return the cache key
00158                 return $cacheKey;
00159         }
00160 
00167         public function getCriteriaElemnent ($criteria) {
00168                 // Default is not found
00169                 $value = null;
00170 
00171                 // Is the criteria there?
00172                 if (isset($this->searchCriteria[$criteria])) {
00173                         // Then use it
00174                         $value = $this->searchCriteria[$criteria];
00175                 }
00176 
00177                 // Return the value
00178                 return $value;
00179         }
00180 
00187         public function ifEntryMatches (array $entryArray) {
00188                 // First nothing matches and nothing is counted
00189                 $matches = false;
00190                 $counted = 0;
00191 
00192                 // Walk through all entries
00193                 foreach ($entryArray as $key => $entry) {
00194                         // Then walk through all search criteria
00195                         foreach ($this->searchCriteria as $criteriaKey => $criteriaValue) {
00196                                 // Is the element found and does it match?
00197                                 if (($key == $criteriaKey) && ($criteriaValue == $entry)) {
00198                                         // Then count this one up
00199                                         $counted++;
00200                                 } // END - if
00201                         } // END - foreach
00202                 } // END - foreach
00203 
00204                 // Now check if expected criteria counts match
00205                 $matches = ($counted == count($this->searchCriteria));
00206 
00207                 // Return the result
00208                 return $matches;
00209         }
00210 }
00211 
00212 // [EOF]
00213 ?>

Generated on Mon Dec 8 01:06:45 2008 for Ship-Simulator by  doxygen 1.5.6