* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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]
* @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)));
$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);
* @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));
$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;
$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;
}
* @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;
+ }
}
/**