From 37933349d84945b09079ea0ac2220b4d0d3e6232 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Mon, 17 Oct 2016 17:14:23 +0800 Subject: [PATCH] * finish task #2674. --- module/doc/control.php | 32 +++++++++++++++++++-- module/doc/css/showfiles.css | 2 ++ module/doc/lang/zh-cn.php | 2 ++ module/doc/model.php | 45 +++++++++++++++++++++++++++-- module/doc/view/alllibs.html.php | 4 +++ module/doc/view/index.html.php | 17 ++++++++++- module/doc/view/showfiles.html.php | 46 ++++++++++++++++++++++++++++++ module/doc/view/showlibs.html.php | 4 +++ 8 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 module/doc/css/showfiles.css create mode 100644 module/doc/view/showfiles.html.php diff --git a/module/doc/control.php b/module/doc/control.php index fb762789e1..d81014ace0 100644 --- a/module/doc/control.php +++ b/module/doc/control.php @@ -519,7 +519,7 @@ class doc extends control * @access public * @return void */ - public function allLibs($type, $extra = '', $recTotal = 0, $recPerPage = 20, $pageID = 1) + public function allLibs($type, $extra = '', $recTotal = 0, $recPerPage = 21, $pageID = 1) { $libName = isset($this->lang->doc->systemLibs[$type]) ? $this->lang->doc->systemLibs[$type] : $this->lang->doc->custom; $this->doc->setMenu(array($libName), 0, $type); @@ -533,7 +533,7 @@ class doc extends control $libs = $this->doc->getAllLibs($type, $pager, $extra); $subLibs = array(); - if($type == 'product' or $type == 'project') $subLibs = $this->doc->getSubLibGroups($type, array_keys($libs), $limit = 0); + if($type == 'product' or $type == 'project') $subLibs = $this->doc->getSubLibGroups($type, array_keys($libs)); $this->view->type = $type; $this->view->libs = $libs; @@ -564,4 +564,32 @@ class doc extends control $this->view->libs = $this->doc->getLibsByObject($type, $objectID); $this->display(); } + + /** + * Show files for product or project. + * + * @param int $type + * @param int $objectID + * @access public + * @return void + */ + public function showFiles($type, $objectID) + { + $uri = $this->app->getURI(true); + $this->app->session->set('taskList', $uri); + $this->app->session->set('storyList', $uri); + $this->app->session->set('docList', $uri); + + $table = $type == 'product' ? TABLE_PRODUCT : TABLE_PROJECT; + $object = $this->dao->select('id,name')->from($table)->where('id')->eq($objectID)->fetch(); + $this->doc->setMenu(array($this->lang->doclib->files), 0, $type); + + $this->view->title = $object->name; + $this->view->position[] = $object->name; + + $this->view->type = $type; + $this->view->object = $object; + $this->view->files = $this->doc->getLibFiles($type, $objectID); + $this->display(); + } } diff --git a/module/doc/css/showfiles.css b/module/doc/css/showfiles.css new file mode 100644 index 0000000000..b3c502c919 --- /dev/null +++ b/module/doc/css/showfiles.css @@ -0,0 +1,2 @@ +.card a.file{display:block; text-align:center;} +.card a.file i.icon{display:block; font-size:61px; margin:10px} diff --git a/module/doc/lang/zh-cn.php b/module/doc/lang/zh-cn.php index 13ead53a0c..6c39847923 100644 --- a/module/doc/lang/zh-cn.php +++ b/module/doc/lang/zh-cn.php @@ -30,6 +30,7 @@ $lang->doc->editedBy = '由谁编辑'; $lang->doc->editedDate = '编辑时间'; $lang->doc->basicInfo = '基本信息'; $lang->doc->deleted = '已删除'; +$lang->doc->fileObject = '所属对象'; $lang->doc->moduleDoc = '按模块浏览'; $lang->doc->searchDoc = '搜索'; @@ -82,3 +83,4 @@ $lang->doclib->name = '文档库名称'; $lang->doclib->acl = '文档库权限'; $lang->doclib->group = '分组'; $lang->doclib->user = '用户'; +$lang->doclib->files = '附件库'; diff --git a/module/doc/model.php b/module/doc/model.php index 8cb92e3bce..6f879a8b0f 100644 --- a/module/doc/model.php +++ b/module/doc/model.php @@ -560,7 +560,8 @@ class docModel extends model $buildGroups = array(); foreach($libGroups as $objectID => $libs) { - $i = 1; + $i = common::hasPriv('doc', 'showFiles') ? 2 : 1; + if($type == 'product' and isset($hasProject[$objectID]) and common::hasPriv('doc', 'allLibs')) $i += 1; foreach($libs as $lib) { if($limit and $i > $limit) break; @@ -570,7 +571,8 @@ class docModel extends model $i++; } } - if($type == 'product' and isset($hasProject[$objectID])) $buildGroups[$objectID]['project'] = $this->lang->doc->systemLibs['project']; + if($type == 'product' and isset($hasProject[$objectID]) and common::hasPriv('doc', 'allLibs')) $buildGroups[$objectID]['project'] = $this->lang->doc->systemLibs['project']; + if(common::hasPriv('doc', 'showFiles')) $buildGroups[$objectID]['files'] = $this->lang->doclib->files; } return $buildGroups; @@ -600,8 +602,45 @@ class docModel extends model { if($this->checkPriv($lib)) $libs[$lib->id] = $lib->name; } - if($type == 'product' and isset($hasProject[$objectID])) $libs['project'] = $this->lang->doc->systemLibs['project']; + if($type == 'product' and isset($hasProject[$objectID]) and common::hasPriv('doc', 'allLibs')) $libs['project'] = $this->lang->doc->systemLibs['project']; + if(common::hasPriv('doc', 'showFiles')) $libs['files'] = $this->lang->doclib->files; return $libs; } + + /** + * Get lib files. + * + * @param string $type + * @param int $objectID + * @access public + * @return array + */ + public function getLibFiles($type, $objectID) + { + $this->loadModel('file'); + $joinTable = $type == 'project' ? TABLE_TASK : TABLE_STORY; + $objectType = $type == 'project' ? 'task' : 'story'; + $files = $this->dao->select('t1.*')->from(TABLE_FILE)->alias('t1') + ->leftJoin($joinTable)->alias('t2')->on('t1.objectID=t2.id') + ->where("t2.$type")->eq($objectID) + ->andWhere('t1.objectType')->eq($objectType) + ->andWhere('t2.deleted')->eq(0) + ->fetchAll('id'); + + $docFiles = $this->dao->select('t1.*')->from(TABLE_FILE)->alias('t1') + ->leftJoin(TABLE_DOC)->alias('t2')->on('t1.objectID=t2.id') + ->where("t2.$type")->eq($objectID) + ->andWhere('t1.objectType')->eq('doc') + ->andWhere('t2.deleted')->eq(0) + ->fetchAll('id'); + foreach($docFiles as $fileID => $file) $files[$fileID] = $file; + foreach($files as $fileID => $file) + { + $file->realPath = $this->file->savePath . $file->pathname; + $file->webPath = $this->file->webPath . $file->pathname; + } + + return $files; + } } diff --git a/module/doc/view/alllibs.html.php b/module/doc/view/alllibs.html.php index 663a868e75..07833fca79 100644 --- a/module/doc/view/alllibs.html.php +++ b/module/doc/view/alllibs.html.php @@ -34,6 +34,10 @@ { echo html::a(inlink('allLibs', "type=project&extra=product=$lib->id"), $subLibName); } + elseif($subLibID == 'files') + { + echo html::a(inlink('showFiles', "type=$type&objectID=$lib->id"), $subLibName); + } else { echo html::a(inlink('browse', "libID=$subLibID"), $subLibName); diff --git a/module/doc/view/index.html.php b/module/doc/view/index.html.php index a6735e1120..d2c389c883 100644 --- a/module/doc/view/index.html.php +++ b/module/doc/view/index.html.php @@ -34,6 +34,10 @@ { echo html::a(inlink('allLibs', "type=project&extra=product=$product->id"), $libName); } + elseif($libID == 'files') + { + echo html::a(inlink('showFiles', "type=product&objectID=$product->id"), $libName); + } else { echo html::a(inlink('browse', "libID=$libID"), $libName); @@ -66,7 +70,18 @@ id])):?> id] as $libID => $libName):?>
-
+
+ id"), $libName); + } + else + { + echo html::a(inlink('browse', "libID=$libID"), $libName); + } + ?> +
diff --git a/module/doc/view/showfiles.html.php b/module/doc/view/showfiles.html.php new file mode 100644 index 0000000000..f70ae4321e --- /dev/null +++ b/module/doc/view/showfiles.html.php @@ -0,0 +1,46 @@ + + * @package doc + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +
+
+ name?> +
+
+ +
+
extension?>'> + createLink('file', 'download', "fileID=$file->id&mouse=left"); + if(in_array($file->extension, $config->file->imageExtensions)) + { + echo html::a($downloadLink, "", '_blank', "class='file'"); + } + else + { + $iconClass = 'icon-file'; + if(strpos('zip,tar,gz,bz2,rar', $file->extension) !== false) $iconClass = 'icon-file-archive'; + if(strpos('csv,xls,xlsx', $file->extension) !== false) $iconClass = 'icon-file-excel'; + if(strpos('doc,docx', $file->extension) !== false) $iconClass = 'icon-file-word'; + if(strpos('ppt,pptx', $file->extension) !== false) $iconClass = 'icon-file-powerpoint'; + if(strpos('pdf', $file->extension) !== false) $iconClass = 'icon-file-pdf'; + echo html::a($downloadLink, "", '_blank', "class='file'"); + } + ?> +
createLink($file->objectType, 'view', "objectID=$file->objectID"), $lang->doc->fileObject . ' ' . strtoupper($file->objectType) . ' #' . $file->objectID)?>
+
+
+ +
+
+ + diff --git a/module/doc/view/showlibs.html.php b/module/doc/view/showlibs.html.php index c7e04a35dc..c8f03def6d 100644 --- a/module/doc/view/showlibs.html.php +++ b/module/doc/view/showlibs.html.php @@ -24,6 +24,10 @@ { echo html::a(inlink('allLibs', "type=project&extra=product=$object->id"), $libName); } + elseif($libID == 'files') + { + echo html::a(inlink('showFiles', "type=$type&objectID=$object->id"), $libName); + } else { echo html::a(inlink('browse', "libID=$libID"), $libName);