Browse Source

Adding document/work template see BT#6616

Julio Montoya 11 years ago
parent
commit
2ab57d4d0a
4 changed files with 58 additions and 8 deletions
  1. 6 3
      main/work/add_document.php
  2. 8 1
      main/work/upload.php
  3. 29 3
      main/work/work.lib.php
  4. 15 1
      main/work/work_list.php

+ 6 - 3
main/work/add_document.php

@@ -64,9 +64,12 @@ if (empty($docId)) {
         foreach ($documents as $doc) {
             $documentId = $doc['document_id'];
             $docData = DocumentManager::get_document_data_by_id($documentId, $courseInfo['code']);
-            $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?action=delete&id='.$workId.'&document_id='.$documentId;
-            $link = Display::url(get_lang('Delete'), $url);
-            echo $docData['title'].' '.$link.'<br />';
+            if ($docData) {
+                $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?action=delete&id='.$workId.'&document_id='.$documentId;
+                $link = Display::url(get_lang('Delete'), $url);
+                echo $docData['title'].' '.$link.'<br />';
+            }
+
         }
         echo '</div>';
     }

+ 8 - 1
main/work/upload.php

@@ -26,6 +26,7 @@ $work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
 $is_allowed_to_edit = api_is_allowed_to_edit();
 $course_id = api_get_course_int_id();
 $user_id = api_get_user_id();
+$userInfo = api_get_user_info();
 $session_id = api_get_session_id();
 $course_code = api_get_course_id();
 $course_info = api_get_course_info();
@@ -121,7 +122,7 @@ $form->addElement('header', $form_title);
 $show_progress_bar = false;
 
 if ($submitGroupWorkUrl) {
-    // For user comming from group space to publish his work
+    // For user coming from group space to publish his work
     $realUrl = str_replace($_configuration['root_sys'], api_get_path(WEB_PATH), str_replace("\\", '/', realpath($submitGroupWorkUrl)));
     $form->addElement('hidden', 'newWorkUrl', $submitGroupWorkUrl);
     $text_document = $form->addElement('text', 'document', get_lang('Document'));
@@ -162,6 +163,12 @@ if ($show_progress_bar) {
     $form->add_real_progress_bar('uploadWork', 'file');
 }
 
+$documentTemplateData = getDocumentTemplateFromWork($work_id, $course_info);
+if (!empty($documentTemplateData)) {
+    $defaults['title'] = $userInfo['complete_name'].'_'.$documentTemplateData['title'].'_'.substr(api_get_utc_datetime(), 0, 10);
+    $defaults['description'] = $documentTemplateData['file_content'];
+}
+
 $form->setDefaults($defaults);
 $error_message = null;
 $_course = api_get_course_info();

+ 29 - 3
main/work/work.lib.php

@@ -1774,7 +1774,8 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher
                 if ($work['contains_file']) {
                     $link_to_download = '<a href="download.php?id='.$item_id.'">'.Display::return_icon('save.png', get_lang('Save'),array(), ICON_SIZE_SMALL).'</a> ';
                 } else {
-                    $link_to_download = '<a href="view.php?id='.$item_id.'">'.Display::return_icon('default.png', get_lang('View'),array(), ICON_SIZE_SMALL).'</a> ';
+                    //api_get_cidreq()
+                   //$link_to_download = '<a href="view.php?id='.$item_id.'">'.Display::return_icon('default.png', get_lang('View'),array(), ICON_SIZE_SMALL).'</a> ';
                 }
 
                 $send_to = Portfolio::share('work', $work['id'],  array('style' => 'white-space:nowrap;'));
@@ -1830,7 +1831,7 @@ function get_work_user_list($start, $limit, $column, $direction, $work_id, $wher
                         $action .= Display::return_icon('edit_na.png', get_lang('Modify'),array(), ICON_SIZE_SMALL);
                     }
                     if (api_get_course_setting('student_delete_own_publication') == 1) {
-                        $action .= '<a href="'.$url.'work.php?'.api_get_cidreq().'&action=delete&amp;item_id='.$item_id.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES))."'".')) return false;" title="'.get_lang('Delete').'"  >'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
+                        $action .= ' <a href="'.$url.'work.php?'.api_get_cidreq().'&action=delete&amp;item_id='.$item_id.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES))."'".')) return false;" title="'.get_lang('Delete').'"  >'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
                     }
                 } else {
                     $action .= Display::return_icon('edit_na.png', get_lang('Modify'),array(), ICON_SIZE_SMALL);
@@ -2146,6 +2147,9 @@ function getDocumentToWork($documentId, $workId, $courseId)
 
 function getAllDocumentToWork($workId, $courseId)
 {
+    if (ADD_DOCUMENT_TO_WORK == false) {
+        return array();
+    }
     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_DOCUMENT);
     $params = array(
         'work_id = ? and c_id = ?' => array($workId, $courseId)
@@ -2220,10 +2224,15 @@ function userIsSubscribedToWork($userId, $workId, $courseId)
         return true;
     }
     $subscribedUsers = getAllUserToWork($workId, $courseId);
+
     if (empty($subscribedUsers)) {
         return true;
     } else {
-        if (in_array($userId, $subscribedUsers)) {
+        $subscribedUsersIdList = array();
+        foreach ($subscribedUsers as $item) {
+            $subscribedUsersIdList[] = $item['user_id'];
+        }
+        if (in_array($userId, $subscribedUsersIdList)) {
             return true;
         }
     }
@@ -2244,3 +2253,20 @@ function allowOnlySubscribedUser($userId, $workId, $courseId)
 
 }
 
+function getDocumentTemplateFromWork($workId, $courseInfo)
+{
+    $documents = getAllDocumentToWork($workId, $courseInfo['real_id']);
+    if (!empty($documents)) {
+        foreach ($documents as $doc) {
+            $docData = DocumentManager::get_document_data_by_id($doc['document_id'], $courseInfo['code']);
+            $fileInfo = pathinfo($docData['path']);
+            if ($fileInfo['extension'] == 'html') {
+                if (file_exists($docData['absolute_path']) && is_file($docData['absolute_path'])) {
+                    $docData['file_content'] = file_get_contents($docData['absolute_path']);
+                    return $docData;
+                }
+            }
+        }
+    }
+    return array();
+}

+ 15 - 1
main/work/work_list.php

@@ -37,7 +37,6 @@ $url_dir = api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq();
 
 allowOnlySubscribedUser(api_get_user_id(), $workId, $courseInfo['real_id']);
 
-
 if (!empty($group_id)) {
     $group_properties  = GroupManager :: get_group_properties($group_id);
     $show_work = false;
@@ -79,6 +78,21 @@ if (!empty($my_folder_data['description'])) {
     echo '<p><div><strong>'.get_lang('Description').':</strong><p>'.Security::remove_XSS($my_folder_data['description']).'</p></div></p>';
 }
 
+$documents = getAllDocumentToWork($workId, $courseInfo['real_id']);
+if (!empty($documents)) {
+    $docContent = '<ul class="nav nav-list well">';
+    $docContent .= '<li class="nav-header">'.get_lang('Documents').'</li>';
+    foreach ($documents as $doc) {
+        $docData = DocumentManager::get_document_data_by_id($doc['document_id'], $courseInfo['code']);
+        if ($docData) {
+            $docContent .= '<li><a target="_blank" href="'.$docData['url'].'">'.$docData['title'].'</a></li>';
+        }
+
+    }
+    $docContent .= '</ul><br />';
+    echo $docContent;
+}
+
 $check_qualification = intval($my_folder_data['qualification']);
 
 if (!empty($work_data['enable_qualification']) && !empty($check_qualification)) {