X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fcriteria%2Fdataset%2Fclass_DataSetCriteria.php;fp=inc%2Fclasses%2Fmain%2Fcriteria%2Fdataset%2Fclass_DataSetCriteria.php;h=f342606e89de681a876c35553d509fa7c219e5f0;hp=0000000000000000000000000000000000000000;hb=08b1d39fa38b86cca6a0a6c968162d30ca171ae5;hpb=81d28b14f65e35ece6524eee9ae0b74d6c6117d8 diff --git a/inc/classes/main/criteria/dataset/class_DataSetCriteria.php b/inc/classes/main/criteria/dataset/class_DataSetCriteria.php new file mode 100644 index 00000000..f342606e --- /dev/null +++ b/inc/classes/main/criteria/dataset/class_DataSetCriteria.php @@ -0,0 +1,183 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software + * @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 DataSetCriteria extends BaseCriteria implements StoreableCriteria { + /** + * Table name + */ + private $tableName = ""; + + /** + * Table columns (criteria) to store + */ + private $tableColumns = array(); + + /** + * Unique key + */ + private $uniqueKey = ""; + + /** + * Primary key + */ + private $primaryKey = ""; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct() { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this criteria + * + * @param $tableName Name of the table + * @return $criteriaInstance An instance of this criteria + */ + public final static function createDataSetCriteria ($tableName) { + // Get a new instance + $criteriaInstance = new DataSetCriteria(); + + // Set table name + $criteriaInstance->setTableName($tableName); + + // Return the instance + return $criteriaInstance; + } + + /** + * Add criteria + * + * @param $criteriaKey Criteria key + * @param $criteriaValue Criteria value + * @return void + */ + public function addCriteria ($criteriaKey, $criteriaValue) { + $this->tableColumns[(string) $criteriaKey] = $criteriaValue; + } + + /** + * Add configured criteria + * + * @param $criteriaKey Criteria key + * @param $configEntry Configuration entry + * @return void + */ + public function addConfiguredCriteria ($criteriaKey, $configEntry) { + // Add configuration entry as criteria + $value = $this->getConfigInstance()->readConfig($configEntry); + $this->addCriteria($criteriaKey, $value); + } + + /** + * Setter for table name + * + * @param $tableName Name of the table to set + * @return void + */ + public final function setTableName ($tableName) { + $this->tableName = (string) $tableName; + } + + /** + * Getter for table name + * + * @return $tableName Name of the table to set + */ + public final function getTableName () { + return $this->tableName; + } + + /** + * Setter for unique key + * + * @param $uniqueKey Column to use as unique key + * @return void + */ + public final function setUniqueKey ($uniqueKey) { + $this->uniqueKey = (string) $uniqueKey; + } + + /** + * Getter for unique key + * + * @return $uniqueKey Column to use as unique key + */ + public final function getUniqueKey () { + return $this->uniqueKey; + } + + /** + * Getter for unique key value + * + * @return $uniqueValue Value of the unique key + */ + public final function getUniqueValue () { + return $this->tableColumns[$this->getUniqueKey()]; + } + + /** + * Getter for criteria array + * + * @return $tableColumns + */ + public final function getCriteriaArray () { + return $this->tableColumns; + } + + /** + * Getter for primary key or unique key if not set + * + * @return $primaryKey Primary key or unique key if not set + */ + public final function getPrimaryKey () { + // Get primary key by default + $primaryKey = $this->primaryKey; + + if (empty($primaryKey)) { + // Get uniqueKey + $primaryKey = $this->getUniqueKey(); + } // END - if + + // Return it + return $primaryKey; + } + + /** + * Setter for primary key + * + * @param $primaryKey Primary key to set + * @return void + */ + public final function setPrimaryKey ($primaryKey) { + $this->primaryKey = (string) $primaryKey; + } +} + +// [EOF] +?>