From: Roland Haeder <roland@mxchange.org>
Date: Mon, 24 Aug 2015 21:37:55 +0000 (+0200)
Subject: Added new methods:
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ed59beaaf61598e911182425f9ff0eb6f8e7b14c;p=core.git

Added new methods:
- setPrimaryKeyCombined()
- getPrimaryKeyCombined()
- setCriteria()
- setStringGenericArrayElement()

Signed-off-by: Roland Häder <roland@mxchange.org>
---

diff --git a/inc/classes/interfaces/criteria/class_Criteria.php b/inc/classes/interfaces/criteria/class_Criteria.php
index aa929914..9609302f 100644
--- a/inc/classes/interfaces/criteria/class_Criteria.php
+++ b/inc/classes/interfaces/criteria/class_Criteria.php
@@ -103,6 +103,17 @@ interface Criteria extends FrameworkInterface {
 	 */
 	function addCriteria ($criteriaKey, $criteriaValue, $criteriaType = 'default');
 
+	/**
+	 * Sets criteria, this method converts dashes to underscores because dashes
+	 * are not valid for criteria keys.
+	 *
+	 * @param	$criteriaKey	Criteria key
+	 * @param	$criteriaValue	Criteria value
+	 * @param	$criteriaType	Type of this criteria, can be one of 'default' (default), 'choice' or 'exclude'
+	 * @return	void
+	 */
+	function setCriteria ($criteriaKey, $criteriaValue, $criteriaType = 'default');
+
 	/**
 	 * Add "choice" criteria, this method converts dashes to underscores because
 	 * dashes are not valid for criteria keys.
diff --git a/inc/classes/interfaces/criteria/extended/class_StoreableCriteria.php b/inc/classes/interfaces/criteria/extended/class_StoreableCriteria.php
index b33d7dab..faa6c89e 100644
--- a/inc/classes/interfaces/criteria/extended/class_StoreableCriteria.php
+++ b/inc/classes/interfaces/criteria/extended/class_StoreableCriteria.php
@@ -73,6 +73,21 @@ interface StoreableCriteria extends Criteria {
 	 * @return	void
 	 */
 	function setPrimaryKey ($primaryKey);
+
+	/**
+	 * Setter for primary key array
+	 *
+	 * @param	$primaryKeys	Primary key array to set
+	 * @return	void
+	 */
+	function setPrimaryKeyCombined (array $primaryKeys);
+
+	/**
+	 * Getter for primary keys
+	 *
+	 * @return	$primaryKeys	Primary key array
+	 */
+	function getPrimaryKeys ();
 }
 
 // [EOF]
diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php
index 26fa6fa2..7bee5eca 100644
--- a/inc/classes/main/class_BaseFrameworkSystem.php
+++ b/inc/classes/main/class_BaseFrameworkSystem.php
@@ -2780,10 +2780,28 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
 			$this->genericArray[$keyGroup][$subGroup][$key][$element] .= $appendGlue . (string) $value;
 		} else {
 			// Add it
-			$this->genericArray[$keyGroup][$subGroup][$key][$element] = (string) $value;
+			$this->setStringGenericArrayElement($keyGroup, $subGroup, $key, $element, $value);
 		}
 	}
 
+	/**
+	 * Sets a string in a given generic array element
+	 *
+	 * @param	$keyGroup	Main group for the key
+	 * @param	$subGroup	Sub group for the key
+	 * @param	$key		Key to unset
+	 * @param	$element	Element to check
+	 * @param	$value		Value to add/append
+	 * @return	void
+	 */
+	protected final function setStringGenericArrayElement ($keyGroup, $subGroup, $key, $element, $value, $appendGlue = '') {
+		// Debug message
+		//* NOISY-DEBUG: */ if (!is_object($value)) $this->outputLine('[' . __METHOD__ . ':' . __LINE__ . '] keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ',value[' . gettype($value) . ']=' . print_r($value, TRUE) . ',appendGlue=' . $appendGlue);
+
+		// Set it
+		$this->genericArray[$keyGroup][$subGroup][$key][$element] = (string) $value;
+	}
+
 	/**
 	 * Initializes given generic array group
 	 *
diff --git a/inc/classes/main/criteria/class_BaseCriteria.php b/inc/classes/main/criteria/class_BaseCriteria.php
index 1abb7afe..6c3e7d05 100644
--- a/inc/classes/main/criteria/class_BaseCriteria.php
+++ b/inc/classes/main/criteria/class_BaseCriteria.php
@@ -177,6 +177,32 @@ class BaseCriteria extends BaseFrameworkSystem implements Criteria {
 		$this->appendStringToGenericArrayElement('criteria', $criteriaType, 'entries', $criteriaKey, $criteriaValue);
 	}
 
+	/**
+	 * Set criteria, this method converts dashes to underscores because dashes
+	 * are not valid for criteria keys.
+	 *
+	 * @param	$criteriaKey	Criteria key
+	 * @param	$criteriaValue	Criteria value
+	 * @param	$criteriaType	Type of this criteria, can be one of 'default' (default), 'choice' or 'exclude'
+	 * @return	void
+	 */
+	public final function setCriteria ($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)));
+
+		// Convert dashes to underscore
+		$criteriaKey = self::convertDashesToUnderscores($criteriaKey);
+
+		// Debug message
+		//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($criteriaType) . '(' . $this->__toString() . ')-CRITERIA[' . __METHOD__ . ':' . __LINE__ . ']: criteriaKey=' . $criteriaKey);
+
+		// Set it
+		$this->setStringGenericArrayElement('criteria', $criteriaType, 'entries', $criteriaKey, $criteriaValue);
+	}
+
 	/**
 	 * Add "choice" criteria, this method converts dashes to underscores because
 	 * dashes are not valid for criteria keys.
diff --git a/inc/classes/main/criteria/dataset/class_DataSetCriteria.php b/inc/classes/main/criteria/dataset/class_DataSetCriteria.php
index 323a893d..bb5d43b4 100644
--- a/inc/classes/main/criteria/dataset/class_DataSetCriteria.php
+++ b/inc/classes/main/criteria/dataset/class_DataSetCriteria.php
@@ -108,17 +108,40 @@ class DataSetCriteria extends BaseCriteria implements StoreableCriteria {
 	 * @return	$uniqueValue	Value of the unique key
 	 */
 	public final function getUniqueValue () {
-		// Get primary key first
-		$primaryKey = trim($this->getCriteriaElemnent($this->getPrimaryKey()));
+		// Get primary key(s) first
+		$primaryKey  = trim($this->getCriteriaElemnent($this->getPrimaryKey()));
+		$primaryKeys = $this->getPrimaryKeys();
 
 		// Debug message
-		//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: tableName=' . $this->getTableName() . ',primaryKey=' . $primaryKey);
+		//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: tableName=' . $this->getTableName() . ',primaryKey=' . $primaryKey . ',primaryKeys()=' . count($primaryKeys));
 
 		/*
 		 * If this is not set, this could mean a badly written frontend as
 		 * tables should always have a primary key.
 		 */
-		if (empty($primaryKey)) {
+		if (count($primaryKeys) > 0) {
+			/*
+			 * Init return value, this can be put all together without any
+			 * separator as it only aids as a "unique value" for generating the
+			 * "row file name".
+			 */
+			$return = '';
+
+			// Combination set, so get all
+			foreach ($primaryKeys as $primaryKey) {
+				// Add it
+				$return .= trim($this->getCriteriaElemnent($primaryKey));
+			} // END - foreach
+
+			// Debug message
+			//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: tableName=' . $this->getTableName() . ',return=' . $return . ' - EXIT!');
+
+			// Return it
+			return $return;
+		} elseif (!empty($primaryKey)) {
+			// Return primary key
+			return $primaryKey;
+		} else {
 			// @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 ...');
 
@@ -136,9 +159,6 @@ class DataSetCriteria extends BaseCriteria implements StoreableCriteria {
 				// Return unique key
 				return $uniqueKey;
 			}
-		} else {
-			// Return primary key
-			return $primaryKey;
 		}
 	}
 
@@ -169,6 +189,26 @@ class DataSetCriteria extends BaseCriteria implements StoreableCriteria {
 	public final function setPrimaryKey ($primaryKey) {
 		$this->primaryKey = (string) $primaryKey;
 	}
+
+	/**
+	 * Setter for primary key array
+	 *
+	 * @param	$primaryKeys	Primary key array to set
+	 * @return	void
+	 */
+	public function setPrimaryKeyCombined (array $primaryKeys) {
+		$this->primaryKeys = $primaryKeys;
+	}
+
+	/**
+	 * Getter for primary keys
+	 *
+	 * @return	$primaryKeys	Primary key array
+	 */
+	public final function getPrimaryKeys () {
+		// Return it
+		return $this->primaryKeys;
+	}
 }
 
 // [EOF]