Browse Source

Adding api_get_item_property_info() function + removing detail date in the document tool

Julio Montoya 14 years ago
parent
commit
ce9288395c
3 changed files with 40 additions and 10 deletions
  1. 2 1
      main/document/document.php
  2. 14 8
      main/document/edit_document.php
  3. 24 1
      main/inc/lib/main_api.lib.php

+ 2 - 1
main/document/document.php

@@ -882,7 +882,8 @@ if (isset($docs_and_folders) && is_array($docs_and_folders)) {
         // Last edit date
         $last_edit_date = $id['lastedit_date'];
         $last_edit_date = api_get_local_time($last_edit_date, null, date_default_timezone_get());
-        $display_date = date_to_str_ago($last_edit_date).'<br /><span class="dropbox_date">'.api_format_date($last_edit_date).'</span>';
+        //$display_date = date_to_str_ago($last_edit_date).'<br /><span class="dropbox_date">'.api_format_date($last_edit_date).'</span>';
+        $display_date = date_to_str_ago($last_edit_date);
         $row[] = $invisibility_span_open.$display_date.$invisibility_span_close;
         // Admins get an edit column
         if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder($_user['user_id'], $curdirpath, $current_session_id)) {

+ 14 - 8
main/document/edit_document.php

@@ -143,7 +143,7 @@ $html_editor_config = array(
 	'BaseHref' =>  api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$dir
 );
 
-$is_allowed_to_edit = is_allowed_to_edit(null, true) || $_SESSION['group_member_with_upload_rights']|| is_my_shared_folder($_user['user_id'], $dir, $current_session_id);
+$is_allowed_to_edit = is_allowed_to_edit(null, true) || $_SESSION['group_member_with_upload_rights']|| is_my_shared_folder(api_get_user_id(), $dir, $current_session_id);
 
 $use_document_title = api_get_setting('use_document_title') == 'true';
 $noPHP_SELF = true;
@@ -318,8 +318,8 @@ if ($is_allowed_to_edit) {
 						if (!is_dir($filepath.'css')) {
 							mkdir($filepath.'css', api_get_permissions_for_new_directories());
 							$doc_id = add_document($_course, $dir.'css', 'folder', 0, 'css');
-							api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id'], null, null, null, null, $current_session_id);
-							api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id'], null, null, null, null, $current_session_id);
+							api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', api_get_user_id(), null, null, null, null, $current_session_id);
+							api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', api_get_user_id(), null, null, null, null, $current_session_id);
 						}
 
 						if (!is_file($filepath.'css/frames.css')) {
@@ -428,11 +428,9 @@ $readonly = Database::result($rs, 0, 'readonly');
 $doc_id = Database::result($rs, 0, 'id');
 
 // Owner
-$sql = 'SELECT insert_user_id FROM '.Database::get_course_table(TABLE_ITEM_PROPERTY).'
-		WHERE tool LIKE "document"
-		AND ref='.intval($doc_id);
-$rs = Database::query($sql);
-$owner_id = Database::result($rs, 0, 'insert_user_id');
+$document_info  = api_get_item_property_info(api_get_course_int_id(),'document', $doc_id);
+$owner_id       = $document_info['insert_user_id'];
+$last_edit_date = $document_info['lastedit_date'];
 
 
 if ($owner_id == $_user['user_id'] || api_is_platform_admin() || $is_allowed_to_edit || GroupManager :: is_user_in_group($_user['user_id'], $_SESSION['_gid'] )) {
@@ -482,7 +480,15 @@ if ($owner_id == $_user['user_id'] || api_is_platform_admin() || $is_allowed_to_
 
 	if (!$group_document && !is_my_shared_folder($_user['user_id'], $my_cur_dir_path, $current_session_id)) {
 		$metadata_link = '<a href="../metadata/index.php?eid='.urlencode('Document.'.$docId).'">'.get_lang('AddMetadata').'</a>';
+
+		//Updated on field
+		$last_edit_date = api_get_local_time($last_edit_date, null, date_default_timezone_get());
+        $display_date = date_to_str_ago($last_edit_date).'<br /><span class="dropbox_date">'.api_format_date($last_edit_date).'</span>';
+        
 		$form->addElement('static', null, get_lang('Metadata'), $metadata_link);
+		
+        
+		$form->addElement('static', null, get_lang('UpdatedOn'), $display_date);
 	}
 
 	$form->addElement('textarea', 'newComment', get_lang('Comment'), 'rows="3" style="width:300px;"');

+ 24 - 1
main/inc/lib/main_api.lib.php

@@ -2567,7 +2567,7 @@ function api_item_property_update($_course, $tool, $item_id, $lastedit_type, $us
  * @param string    tool name, linked to 'rubrique' of the course tool_list (Warning: language sensitive !!)
  * @param int       id of the item itself, linked to key of every tool ('id', ...), "*" = all items of the tool
  */
-function api_get_item_property_id ($course_code, $tool, $ref) {
+function api_get_item_property_id($course_code, $tool, $ref) {
 
     $course_info    = api_get_course_info($course_code);
     $tool           = Database::escape_string($tool);
@@ -2585,6 +2585,29 @@ function api_get_item_property_id ($course_code, $tool, $ref) {
     return $item_property_id;
 }
 
+/**
+ * Gets item property data from tool of a course id
+ * @param int    	course id
+ * @param string    tool name, linked to 'rubrique' of the course tool_list (Warning: language sensitive !!)
+ * @param int       id of the item itself, linked to key of every tool ('id', ...), "*" = all items of the tool
+ */
+function api_get_item_property_info($course_id, $tool, $ref) {
+
+    $course_info    = api_get_course_info_by_id($course_id);
+    $tool           = Database::escape_string($tool);
+    $ref            = intval($ref);
+
+    // Definition of tables.
+    $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
+    $sql = "SELECT * FROM $TABLE_ITEMPROPERTY WHERE tool = '$tool' AND ref = $ref ";
+    $rs  = Database::query($sql);    
+    $row = array();
+    if (Database::num_rows($rs) > 0) {
+        $row = Database::fetch_array($rs,'ASSOC');   
+    }
+    return $row;
+}
+
 
 /* Language Dropdown */