[Fusionforge-commits] r12267 - trunk/src/common/docman

Franck VILLAUME nerville at libremir.placard.fr.eu.org
Fri Feb 11 13:11:10 CET 2011


Author: nerville
Date: 2011-02-11 13:11:10 +0100 (Fri, 11 Feb 2011)
New Revision: 12267

Modified:
   trunk/src/common/docman/Document.class.php
Log:
create a generic setter to prepare new trash implementation

Modified: trunk/src/common/docman/Document.class.php
===================================================================
--- trunk/src/common/docman/Document.class.php	2011-02-11 10:35:36 UTC (rev 12266)
+++ trunk/src/common/docman/Document.class.php	2011-02-11 12:11:10 UTC (rev 12267)
@@ -571,33 +571,31 @@
 	 * setState - set the stateid of the document.
 	 *
 	 * @param	int	The state id of the doc_states table.
-	 * @return	boolean	success.
+	 * @return	boolean	success or not.
 	 */
 	function setState($stateid) {
-		$res = db_query_params('UPDATE doc_data SET
-					stateid=$1
-					WHERE group_id=$2
-					AND docid=$3',
-					array($stateid,
-						$this->Group->getID(),
-						$this->getID())
-					);
-		if (!$res || db_affected_rows($res) < 1) {
-			$this->setOnUpdateError(db_error());
-			return false;
-		}
-		$this->sendNotice(false);
-		return true;
+		return $this->__setValueinDB('stateid', $stateid);
 	}
 
+
 	/**
-	 * setLock - set the locking status of the document
+	 * setDocGroupID - set the doc_group of the document.
 	 *
-	 * @param	int	The status of the lock
-	 * @param	int	The userid who set the lock
-	 * @param	time	the epoch time
-	 * @return	boolean	success
+	 * @param	int	The group_id of this document.
+	 * @return	boolean	success or not.
 	 */
+	function setDocGroupID($newdocgroupid) {
+		return $this->__setValueinDB('doc_group', $newdocgroupid);
+	}
+
+	/**
+	 * setLock - set the locking status of the document.
+	 *
+	 * @param	int	The status of the lock.
+	 * @param	int	The userid who set the lock.
+	 * @param	time	the epoch time.
+	 * @return	boolean	success or not.
+	 */
 	function setLock($stateLock, $userid = NULL, $thistime = 0) {
 		$res = db_query_params('UPDATE doc_data SET
 					locked=$1,
@@ -867,7 +865,7 @@
 	 *
 	 * @param	boolean	true = new document (default value)
 	 */
-	function sendNotice ($new=true) {
+	function sendNotice($new=true) {
 		$BCC = $this->Group->getDocEmailAddress();
 		if ($this->isMonitoredBy('ALL')) {
 			$BCC .= $this->getMonitoredUserEmailAddress();
@@ -929,6 +927,42 @@
 		//$this->sendNotice(false);
 		return true;
 	}
+
+	/**
+	 * __setValueinDB - private function to update columns in db
+	 *
+	 * @param	string	the column to update
+	 * @param	int	the value to store
+	 * @return	boolean	success or not
+	 * @access	private
+	 */
+	private function __setValueinDB($column, $value) {
+		switch ($column) {
+			case "stateid":
+			case "doc_group": {
+				$qpa = db_construct_qpa();
+				$qpa = db_construct_qpa($qpa, 'UPDATE doc_data SET ');
+				$qpa = db_construct_qpa($qpa, $column);
+				$qpa = db_construct_qpa($qpa, '=$1
+								WHERE group_id=$2
+								AND docid=$3',
+								array($value,
+									$this->Group->getID(),
+									$this->getID()));
+				$res = db_query_qpa($qpa);
+				if (!$res || db_affected_rows($res) < 1) {
+					$this->setOnUpdateError(db_error().print_r($res));
+					return false;
+				}
+				break;
+			}
+			default:
+				$this->setOnUpdateError(_('wrong column name'));
+				return false;
+		}
+		$this->sendNotice(false);
+		return true;
+	}
 }
 
 // Local Variables:




More information about the Fusionforge-commits mailing list