[Fusionforge-commits] r15020 - in trunk/src: common/docman common/docman/include common/docman/views db

Franck VILLAUME nerville at fusionforge.org
Sat Dec 17 15:11:49 CET 2011


Author: nerville
Date: 2011-12-17 15:11:48 +0100 (Sat, 17 Dec 2011)
New Revision: 15020

Added:
   trunk/src/db/20111214-docman-doc_groups-created_by.sql
Modified:
   trunk/src/common/docman/Document.class.php
   trunk/src/common/docman/DocumentGroup.class.php
   trunk/src/common/docman/DocumentManager.class.php
   trunk/src/common/docman/include/webdav.php
   trunk/src/common/docman/views/listfile.php
Log:
add support for createdate, updatedate, created_by in doc_groups, prepare webdav

Modified: trunk/src/common/docman/Document.class.php
===================================================================
--- trunk/src/common/docman/Document.class.php	2011-12-17 14:05:25 UTC (rev 15019)
+++ trunk/src/common/docman/Document.class.php	2011-12-17 14:11:48 UTC (rev 15020)
@@ -29,7 +29,9 @@
 require_once $gfcommon.'include/Error.class.php';
 require_once $gfcommon.'docman/Parsedata.class.php';
 require_once $gfcommon.'docman/DocumentManager.class.php';
+require_once $gfcommon.'docman/DocumentGroup.class.php';
 
+
 class Document extends Error {
 
 	/**
@@ -208,6 +210,13 @@
 			db_rollback();
 			return false;
 		}
+
+		$localDg = new DocumentGroup($this->Group, $doc_group);
+		if (!$localDg->update($localDg->getName(), $localDg->getParentID(), 1)) {
+			$this->setError(_('Error updating document group:').$localDg->getErrorMessage());
+			db_rollback();
+			return false;
+		}
 		$this->sendNotice(true);
 		db_commit();
 		return true;

Modified: trunk/src/common/docman/DocumentGroup.class.php
===================================================================
--- trunk/src/common/docman/DocumentGroup.class.php	2011-12-17 14:05:25 UTC (rev 15019)
+++ trunk/src/common/docman/DocumentGroup.class.php	2011-12-17 14:11:48 UTC (rev 15020)
@@ -134,12 +134,14 @@
 			return false;
 		}
 
-		$result = db_query_params('INSERT INTO doc_groups (group_id,groupname,parent_doc_group,stateid,createdate) VALUES ($1, $2, $3, $4, $5)',
+		$user_id = ((session_loggedin()) ? user_getid() : 100);
+		$result = db_query_params('INSERT INTO doc_groups (group_id, groupname, parent_doc_group, stateid, createdate, created_by) VALUES ($1, $2, $3, $4, $5, $6)',
 						array ($this->Group->getID(),
 							htmlspecialchars($name),
 							$parent_doc_group,
 							'1',
-							time())
+							time(),
+							$user_id)
 						);
 		if ($result && db_affected_rows($result) > 0) {
 			$this->clearError();
@@ -155,6 +157,12 @@
 			return false;
 		}
 
+		if ($parent_doc_group) {
+			/* update the parent */
+			$parentDg = new DocumentGroup($this->Group, $parent_doc_group);
+			$parentDg->update($parentDg->getName(), $parentDg->getParentID(), 1, 0);
+		}
+
 		return true;
 	}
 
@@ -182,6 +190,13 @@
 
 		db_commit();
 
+		if (!$result) {
+			return false;
+		}
+
+		/* update the parent */
+		$parentDg = new DocumentGroup($this->Group, $this->getParentID());
+		$parentDg->update($parentDg->getName(), $parentDg->getParentID(), 1, 1);
 		/* is there any subdir ? */
 		$subdir = db_query_params('select doc_group from doc_groups where parent_doc_group = $1 and group_id = $2',
 					array($doc_groupid, $project_group_id));
@@ -190,9 +205,6 @@
 			$this->delete($arr['doc_group'], $project_group_id);
 		}
 
-		if (!$result) {
-			return false;
-		}
 		return true;
 	}
 
@@ -303,14 +315,62 @@
 	}
 
 	/**
+	 * getCreatedate - get the creation date.
+	 *
+	 * @return	integer	The creation date.
+	 * @access	public
+	 */
+	function getCreatedate() {
+		return $this->data_array['createdate'];
+	}
+
+	/**
+	 * getUpdatedate - get the update date.
+	 *
+	 * @return	integer	The update date.
+	 * @access	public
+	 */
+	function getUpdatedate() {
+		return $this->data_array['updatedate'];
+	}
+
+	/**
+	 * getLastModifyDate - get the bigger value between update date and creation date.
+	 *
+	 * @return	integer	The last modified date.
+	 * @access	public
+	 */
+	function getLastModifyDate() {
+		if($this->data_array['updatedate']) {
+			return $this->data_array['updatedate'];
+		} else {
+			return $this->data_array['createdate'];
+		}
+
+	}
+
+
+
+	/**
+	 * getCreated_by - get the creator (user) id.
+	 *
+	 * @return	integer	The User id.
+	 * @access	public
+	 */
+	function getCreated_by() {
+		return $this->data_array['created_by'];
+	}
+
+	/**
 	 * update - update a DocumentGroup.
 	 *
 	 * @param	string	Name of the category.
 	 * @param	integer	the doc_group id of the parent. default = 0
+	 * @param	integer	update only the metadata : created_by, updatedate
 	 * @return	boolean	success or not
 	 * @access	public
 	 */
-	function update($name, $parent_doc_group = 0) {
+	function update($name, $parent_doc_group = 0, $metadata = 0) {
 		$perm =& $this->Group->getPermission();
 		if (!$perm || !$perm->isDocEditor()) {
 			$this->setPermissionDeniedError();
@@ -333,24 +393,33 @@
 			}
 		}
 
-		$res=db_query_params('SELECT * FROM doc_groups WHERE groupname=$1 AND parent_doc_group=$2 AND group_id=$3',
-					array($name,
-						$parent_doc_group,
-						$this->Group->getID())
-					);
-		if ($res && db_numrows($res) > 0) {
-			$this->setError(_('Documents Folder name already exists'));
-			return false;
+		if (!$metadata) {
+			$res = db_query_params('SELECT * FROM doc_groups WHERE groupname=$1 AND parent_doc_group=$2 AND group_id=$3',
+						array($name,
+							$parent_doc_group,
+							$this->Group->getID())
+						);
+			if ($res && db_numrows($res) > 0) {
+				$this->setError(_('Documents Folder name already exists'));
+				return false;
+			}
 		}
 
-		$result = db_query_params('UPDATE doc_groups SET groupname=$1, parent_doc_group=$2 WHERE doc_group=$3 AND group_id=$4',
+		$user_id = ((session_loggedin()) ? user_getid() : 100);
+		$result = db_query_params('UPDATE doc_groups SET groupname=$1, parent_doc_group=$2, updatedate=$3, created_by=$4 WHERE doc_group=$5 AND group_id=$6',
 						array(htmlspecialchars($name),
 							$parent_doc_group,
+							time(),
+							$user_id,
 							$this->getID(),
 							$this->Group->getID())
 					);
 		if ($result && db_affected_rows($result) > 0) {
-			$this->fetchData($this->getID()) ;
+			$parentDg = new DocumentGroup($this->Group, $parent_doc_group);
+			if ($parentDg->getParentID())
+				$parentDg->update($parentDg->getName(), $parentDg->getParentID(), 1);
+
+			$this->fetchData($this->getID());
 			return true;
 		} else {
 			$this->setOnUpdateError(_('Error') . _(': ') .db_error());

Modified: trunk/src/common/docman/DocumentManager.class.php
===================================================================
--- trunk/src/common/docman/DocumentManager.class.php	2011-12-17 14:05:25 UTC (rev 15019)
+++ trunk/src/common/docman/DocumentManager.class.php	2011-12-17 14:11:48 UTC (rev 15020)
@@ -22,6 +22,7 @@
  */
 
 require_once $gfcommon.'include/Error.class.php';
+require_once $gfcommon.'include/User.class.php';
 require_once $gfcommon.'docman/DocumentGroup.class.php';
 
 class DocumentManager extends Error {
@@ -177,7 +178,9 @@
 				if (isset($nbDocsTrashed)) {
 					$nbDocsLabel = '<span class="tabtitle-nw" title="'._('Number of deleted documents in this folder').'" >('.$nbDocsTrashed.')</span>';
 				}
-				echo '<li id="leaf-'.$subGroupIdValue.'" class="'.$liclass.'">'.util_make_link($link, $localDg->getName()).$nbDocsLabel;
+				$user = user_get_object($localDg->getCreated_by());
+				$lititle = _('Created_by:').$user->getRealName()._('; Last modified:').date(_('Y-m-d H:i'), $localDg->getLastModifyDate());
+				echo '<li id="leaf-'.$subGroupIdValue.'" class="'.$liclass.'">'.util_make_link($link, $localDg->getName(), array('class'=>'tabtitle-nw', 'title'=>$lititle)).$nbDocsLabel;
 				if ($dg->getSubgroup($subGroupIdValue, $stateId)) {
 					echo '<ul>';
 					$this->getTree($selecteddir, $linkmenu, $subGroupIdValue);

Modified: trunk/src/common/docman/include/webdav.php
===================================================================
--- trunk/src/common/docman/include/webdav.php	2011-12-17 14:05:25 UTC (rev 15019)
+++ trunk/src/common/docman/include/webdav.php	2011-12-17 14:11:48 UTC (rev 15020)
@@ -135,12 +135,17 @@
 				return false;
 
 			$arr = db_fetch_array($res);
+			if ($arr['updatedate']) {
+				$lastmodifieddate = $arr['updatedate'];
+			} else {
+				$lastmodifieddate = $arr['createdate'];
+			}
 			$files["files"][$i] = array();
 			$files["files"][$i]["path"] = $path;
 			$files["files"][$i]["props"] = array();
 			$files["files"][$i]["props"][] = $this->mkprop("displayname", $arr['groupname']);
 			$files["files"][$i]["props"][] = $this->mkprop("creationdate", $arr['createdate']);
-			$files["files"][$i]["props"][] = $this->mkprop("getlastmodified", $arr['updatedate']);
+			$files["files"][$i]["props"][] = $this->mkprop("getlastmodified", $lastmodifieddate);
 			$files["files"][$i]["props"][] = $this->mkprop("lastaccessed", '');
 			$files["files"][$i]["props"][] = $this->mkprop("ishidden", false);
 			$files["files"][$i]["props"][] = $this->mkprop("resourcetype", "collection");
@@ -152,12 +157,17 @@
 
 			while ($arr = db_fetch_array($res)) {
 				$i++;
+				if ($arr['updatedate']) {
+					$lastmodifieddate = $arr['updatedate'];
+				} else {
+					$lastmodifieddate = $arr['createdate'];
+				}
 				$files["files"][$i] = array();
 				$files["files"][$i]["path"]  = $path.'/'.$arr['groupname'];
 				$files["files"][$i]["props"] = array();
 				$files["files"][$i]["props"][] = $this->mkprop("displayname", $arr['groupname']);
 				$files["files"][$i]["props"][] = $this->mkprop("creationdate", $arr['createdate']);
-				$files["files"][$i]["props"][] = $this->mkprop("getlastmodified", $arr['updatedate']);
+				$files["files"][$i]["props"][] = $this->mkprop("getlastmodified", $lastmodifieddate);
 				$files["files"][$i]["props"][] = $this->mkprop("lastaccessed", '');
 				$files["files"][$i]["props"][] = $this->mkprop("ishidden", false);
 				$files["files"][$i]["props"][] = $this->mkprop("resourcetype","collection");
@@ -170,12 +180,17 @@
 
 			while ($arr = db_fetch_array($res)) {
 				$i++;
+				if ($arr['updatedate']) {
+					$lastmodifieddate = $arr['updatedate'];
+				} else {
+					$lastmodifieddate = $arr['createdate'];
+				}
 				$files["files"][$i] = array();
 				$files["files"][$i]["path"] = $path.'/'.$arr['filename'];
 				$files["files"][$i]["props"] = array();
 				$files["files"][$i]["props"][] = $this->mkprop("displayname", $arr['filename']);
 				$files["files"][$i]["props"][] = $this->mkprop("creationdate", $arr['createdate']);
-				$files["files"][$i]["props"][] = $this->mkprop("getlastmodified", $arr['updatedate']);
+				$files["files"][$i]["props"][] = $this->mkprop("getlastmodified", $lastmodifieddate);
 				$files["files"][$i]["props"][] = $this->mkprop("lastaccessed", '');
 				$files["files"][$i]["props"][] = $this->mkprop("ishidden", false);
 				$files["files"][$i]["props"][] = $this->mkprop("getcontentlength", $arr['filesize']);

Modified: trunk/src/common/docman/views/listfile.php
===================================================================
--- trunk/src/common/docman/views/listfile.php	2011-12-17 14:05:25 UTC (rev 15019)
+++ trunk/src/common/docman/views/listfile.php	2011-12-17 14:11:48 UTC (rev 15020)
@@ -289,15 +289,15 @@
 			if ($d->getLocked()) {
 				if ($d->getLockedBy() == $u->getID()) {
 					$d->setLock(0);
-					/* if you change the 60000 value above, please update here too */
+				/* if you change the 60000 value above, please update here too */
 				} elseif ((time() - $d->getLockdate()) > 600) {
 					$d->setLock(0);
 				}
 			}
 			if (!$d->getLocked() && !$d->getReserved()) {
 				echo '<a class="tabtitle-ne" href="'.$actionlistfileurl.'&action=trashfile&fileid='.$d->getID().'" title="'. _('Move this document to trash') .'" >'.html_image('docman/trash-empty.png',22,22,array('alt'=>_('Move to trash this document'))). '</a>';
+				echo '<a class="tabtitle-ne" href="#" onclick="javascript:controllerListFile.toggleEditFileView(\''.$d->getID().'\')" title="'. _('Edit this document') .'" >'.html_image('docman/edit-file.png',22,22,array('alt'=>_('Edit this document'))). '</a>';
 				if (session_loggedin()) {
-					echo '<a class="tabtitle-ne" href="#" onclick="javascript:controllerListFile.toggleEditFileView(\''.$d->getID().'\')" title="'. _('Edit this document') .'" >'.html_image('docman/edit-file.png',22,22,array('alt'=>_('Edit this document'))). '</a>';
 					echo '<a class="tabtitle-ne" href="'.$actionlistfileurl.'&action=reservefile&fileid='.$d->getID().'" title="'. _('Reserve this document for later edition') .'" >'.html_image('docman/reserve-document.png',22,22,array('alt'=>_('Reserve this document'))). '</a>';
 				}
 			} else {

Added: trunk/src/db/20111214-docman-doc_groups-created_by.sql
===================================================================
--- trunk/src/db/20111214-docman-doc_groups-created_by.sql	                        (rev 0)
+++ trunk/src/db/20111214-docman-doc_groups-created_by.sql	2011-12-17 14:11:48 UTC (rev 15020)
@@ -0,0 +1,2 @@
+alter table doc_groups add column created_by integer DEFAULT 0 NOT NULL;
+update doc_groups set created_by = 100;




More information about the Fusionforge-commits mailing list