From: Roland Haeder Date: Mon, 24 Aug 2015 21:15:09 +0000 (+0200) Subject: Added a public methods to interface + some logger messages. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ddbfa7f3adf7db4bdc370d1f45c9f499d3bdb65c;p=core.git Added a public methods to interface + some logger messages. Signed-off-by: Roland Häder --- diff --git a/inc/classes/interfaces/criteria/extended/class_StoreableCriteria.php b/inc/classes/interfaces/criteria/extended/class_StoreableCriteria.php index 5c3f9fb0..b33d7dab 100644 --- a/inc/classes/interfaces/criteria/extended/class_StoreableCriteria.php +++ b/inc/classes/interfaces/criteria/extended/class_StoreableCriteria.php @@ -22,6 +22,57 @@ * along with this program. If not, see . */ interface StoreableCriteria extends Criteria { + /** + * Setter for table name + * + * @param $tableName Name of the table to set + * @return void + */ + function setTableName ($tableName); + + /** + * Getter for table name + * + * @return $tableName Name of the table to set + */ + function getTableName (); + + /** + * Setter for unique key + * + * @param $uniqueKey Column to use as unique key + * @return void + */ + function setUniqueKey ($uniqueKey); + + /** + * Getter for unique key + * + * @return $uniqueKey Column to use as unique key + */ + function getUniqueKey (); + + /** + * Getter for unique key value + * + * @return $uniqueValue Value of the unique key + */ + function getUniqueValue (); + + /** + * Getter for primary key or unique key if not set + * + * @return $primaryKey Primary key or unique key if not set + */ + function getPrimaryKey (); + + /** + * Setter for primary key + * + * @param $primaryKey Primary key to set + * @return void + */ + function setPrimaryKey ($primaryKey); } // [EOF] diff --git a/inc/classes/main/criteria/class_BaseCriteria.php b/inc/classes/main/criteria/class_BaseCriteria.php index 400ed06c..1abb7afe 100644 --- a/inc/classes/main/criteria/class_BaseCriteria.php +++ b/inc/classes/main/criteria/class_BaseCriteria.php @@ -161,6 +161,9 @@ class BaseCriteria extends BaseFrameworkSystem implements Criteria { * @return void */ public final function addCriteria ($criteriaKey, $criteriaValue, $criteriaType = 'default') { + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($criteriaType) . '-CRITERIA[' . __METHOD__ . ':' . __LINE__ . ']: criteriaKey=' . $criteriaKey . ',criteriaValue=' . $criteriaValue . ',criteriaType=' . $criteriaType . ' - CALLED!'); + // Make sure no 'my-' or 'my_' passes this point assert((strpos($criteriaKey, 'my-') === FALSE) && (strpos($criteriaKey, 'my_') === FALSE) && (!is_bool($criteriaValue))); @@ -168,7 +171,7 @@ class BaseCriteria extends BaseFrameworkSystem implements Criteria { $criteriaKey = self::convertDashesToUnderscores($criteriaKey); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($criteriaType) . '(' . $this->__toString() . ')-CRITERIA[' . __METHOD__ . ':' . __LINE__ . ']: criteriaKey=' . $criteriaKey . ',criteriaValue=' . $criteriaValue); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($criteriaType) . '(' . $this->__toString() . ')-CRITERIA[' . __METHOD__ . ':' . __LINE__ . ']: criteriaKey=' . $criteriaKey); // Append it $this->appendStringToGenericArrayElement('criteria', $criteriaType, 'entries', $criteriaKey, $criteriaValue); @@ -228,6 +231,9 @@ class BaseCriteria extends BaseFrameworkSystem implements Criteria { * @return $value Whether the value of the critera or FALSE */ public function getCriteriaElemnent ($criteriaKey, $criteriaType = 'default') { + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($criteriaType) . '-CRITERIA[' . __METHOD__ . ':' . __LINE__ . ']: criteriaKey=' . $criteriaKey . ',criteriaType=' . $criteriaType . ' - CALLED!'); + // Make sure no 'my-' or 'my_' passes this point assert((strpos($criteriaKey, 'my-') === FALSE) && (strpos($criteriaKey, 'my_') === FALSE)); @@ -235,7 +241,7 @@ class BaseCriteria extends BaseFrameworkSystem implements Criteria { $criteriaKey = self::convertDashesToUnderscores($criteriaKey); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($criteriaType) . '-CRITERIA[' . __METHOD__ . ':' . __LINE__ . ']: criteriaKey=' . $criteriaKey . ',criteria()=' . $this->countGenericArrayGroup('criteria', $criteriaType))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($criteriaType) . '-CRITERIA[' . __METHOD__ . ':' . __LINE__ . ']: criteriaKey=' . $criteriaKey . ',criteria()=' . $this->countGenericArrayGroup('criteria', $criteriaType)); // Default is not found $value = FALSE; @@ -246,6 +252,9 @@ class BaseCriteria extends BaseFrameworkSystem implements Criteria { $value = $this->getGenericArrayElement('criteria', $criteriaType, 'entries', $criteriaKey); } // END - if + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($criteriaType) . '-CRITERIA[' . __METHOD__ . ':' . __LINE__ . ']: value=' . $value . ' - EXIT!'); + // Return the value return $value; } diff --git a/inc/classes/main/criteria/dataset/class_DataSetCriteria.php b/inc/classes/main/criteria/dataset/class_DataSetCriteria.php index 1c03be5d..323a893d 100644 --- a/inc/classes/main/criteria/dataset/class_DataSetCriteria.php +++ b/inc/classes/main/criteria/dataset/class_DataSetCriteria.php @@ -108,7 +108,38 @@ class DataSetCriteria extends BaseCriteria implements StoreableCriteria { * @return $uniqueValue Value of the unique key */ public final function getUniqueValue () { - return $this->getCriteriaElemnent($this->getUniqueKey()); + // Get primary key first + $primaryKey = trim($this->getCriteriaElemnent($this->getPrimaryKey())); + + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: tableName=' . $this->getTableName() . ',primaryKey=' . $primaryKey); + + /* + * If this is not set, this could mean a badly written frontend as + * tables should always have a primary key. + */ + if (empty($primaryKey)) { + // @TODO Issue a warning + self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: Primary key not set for table ' . $this->getTableName() . ', please fix your table. Falling back to unique key ...'); + + // Get unique key + $uniqueKey = trim($this->getCriteriaElemnent($this->getUniqueKey())); + + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: tableName=' . $this->getTableName() . ',uniqueKey=' . $uniqueKey); + + // Is it empty, too? + if (empty($uniqueKey)) { + // Bad news, nothing is "unique" by design for this table + ApplicationEntryPoint::app_exit('Table ' . $this->getTableName() . ' has both no primary and unique key, but ' . __METHOD__ . ' was called. Please fix your table.'); + } else { + // Return unique key + return $uniqueKey; + } + } else { + // Return primary key + return $primaryKey; + } } /**