From a96b03814abb7bcfa3e22becd602114921262092 Mon Sep 17 00:00:00 2001 From: wangchunsheng Date: Fri, 19 Nov 2010 08:00:37 +0000 Subject: [PATCH] * rewrite the comments of file module. --- module/file/control.php | 59 ++++++++++++++++++++++++----- module/file/model.php | 82 +++++++++++++++++++++++++++++++++++------ 2 files changed, 120 insertions(+), 21 deletions(-) diff --git a/module/file/control.php b/module/file/control.php index e29fa8b17d..293b409a7d 100644 --- a/module/file/control.php +++ b/module/file/control.php @@ -11,7 +11,14 @@ */ class file extends control { - /* 生成文件上传的表单。*/ + /** + * Build the upload form. + * + * @param int $fileCount + * @param float $percent + * @access public + * @return void + */ public function buildForm($fileCount = 2, $percent = 0.9) { $this->view->fileCount = $fileCount; @@ -19,7 +26,12 @@ class file extends control $this->display(); } - /* ajax接口,用于接收编辑器附件上传。*/ + /** + * AJAX: get upload request from the web editor. + * + * @access public + * @return void + */ public function ajaxUpload() { $file = $this->file->getUpload('imgFile'); @@ -38,17 +50,24 @@ class file extends control } } - /* 下载一个文件。*/ + /** + * Down a file. + * + * @param int $fileID + * @param string $mouse + * @access public + * @return void + */ public function download($fileID, $mouse = '') { $file = $this->file->getById($fileID); - /* 判断是下载还是打开。*/ + /* Judge the mode, down or open. */ $mode = 'down'; $fileTypes = 'txt|jpg|jpeg|gif|png|bmp|xml|html'; if(strpos($fileTypes, $file->extension) !== false and $mouse == 'left') $mode = 'open'; - /* 模式为open,直接在浏览器打开。*/ + /* If the mode is open, locate directly. */ if($mode == 'open') { if(file_exists($file->realPath))$this->locate($file->webPath); @@ -56,7 +75,7 @@ class file extends control } else { - /* 下载文件。*/ + /* Down the file. */ if(file_exists($file->realPath)) { $fileName = $file->title . '.' . $file->extension; @@ -71,13 +90,19 @@ class file extends control } } - /* 导出csv格式的文件。*/ + /** + * Export as csv format. + * + * @param string $agent + * @access public + * @return void + */ public function export2csv($agent) { $fileName = $this->post->fileName; $csvData = stripslashes($this->post->csvData); - /* 如果是中文,尝试将编码转为gbk. */ + /* If the language is zh-cn, convert to gbk. */ $clientLang = $this->app->getClientLang(); if($clientLang == 'zh-cn') { @@ -101,7 +126,14 @@ class file extends control die(); } - /* 删除一个文件。*/ + /** + * Delete a file. + * + * @param int $fileID + * @param string $confirm yes|no + * @access public + * @return void + */ public function delete($fileID, $confirm = 'no') { if($confirm == 'no') @@ -118,7 +150,14 @@ class file extends control } } - /* 显示下载及删除链接。*/ + /** + * Print files. + * + * @param array $files + * @param string $fieldset + * @access public + * @return void + */ public function printFiles($files, $fieldset) { $this->view->files = $files; diff --git a/module/file/model.php b/module/file/model.php index 405f44d353..543fe3dfe2 100644 --- a/module/file/model.php +++ b/module/file/model.php @@ -17,7 +17,12 @@ class fileModel extends model public $webPath = ''; public $now = 0; - /* 构造函数。*/ + /** + * Construct function. + * + * @access public + * @return void + */ public function __construct() { parent::__construct(); @@ -26,13 +31,26 @@ class fileModel extends model $this->setWebPath(); } - /* 通过对象类型获取文件列表。*/ + /** + * Get files of an object. + * + * @param string $objectType + * @param string $objectID + * @access public + * @return array + */ public function getByObject($objectType, $objectID) { return $this->dao->select('*')->from(TABLE_FILE)->where('objectType')->eq($objectType)->andWhere('objectID')->eq((int)$objectID)->orderBy('id')->fetchAll(); } - /* 获得某一个文件的信息。*/ + /** + * Get info of a file. + * + * @param int $fileID + * @access public + * @return object + */ public function getById($fileID) { $file = $this->dao->findById($fileID)->from(TABLE_FILE)->fetch(); @@ -41,7 +59,15 @@ class fileModel extends model return $file; } - /* 保存上传的文件。*/ + /** + * Save upload. + * + * @param string $objectType + * @param string $objectID + * @param string $extra + * @access public + * @return array + */ public function saveUpload($objectType = '', $objectID = '', $extra = '') { $fileTitles = array(); @@ -63,19 +89,30 @@ class fileModel extends model return $fileTitles; } - /* 获得文件数量。*/ + /** + * Get counts of uploaded files. + * + * @access public + * @return int + */ public function getCount() { return count($this->getUpload()); } - /* 获取上传的文件信息。*/ + /** + * Get info of uploaded files. + * + * @param string $htmlTagName + * @access public + * @return array + */ public function getUpload($htmlTagName = 'files') { $files = array(); if(!isset($_FILES[$htmlTagName])) return $files; - /* 表单定义中的变量名是数组。*/ + /* If the file var name is an array. */ if(is_array($_FILES[$htmlTagName]['name'])) { extract($_FILES[$htmlTagName]); @@ -104,7 +141,13 @@ class fileModel extends model return $files; } - /* 获取文件扩展名。*/ + /** + * Get extension of a file. + * + * @param string $filename + * @access private + * @return string + */ private function getExtension($filename) { $extension = pathinfo($filename, PATHINFO_EXTENSION); @@ -113,7 +156,14 @@ class fileModel extends model return $extension; } - /* 设置要存储的文件名。*/ + /** + * Set path name of the uploaded file to be saved. + * + * @param int $fileID + * @param string $extension + * @access private + * @return string + */ private function setPathName($fileID, $extension) { $sessionID = session_id(); @@ -121,7 +171,12 @@ class fileModel extends model return date('Ym/dHis', $this->now) . $fileID . mt_rand(0, 10000) . $randString . '.' . $extension; } - /* 设置存储路径。*/ + /** + * Set save path. + * + * @access private + * @return void + */ private function setSavePath() { $savePath = $this->app->getAppRoot() . "www/data/upload/{$this->app->company->id}/" . date('Ym/', $this->now); @@ -129,7 +184,12 @@ class fileModel extends model $this->savePath = dirname($savePath) . '/'; } - /* 设置web访问路径。*/ + /** + * Set the web path of upload files. + * + * @access public + * @return void + */ public function setWebPath() { $this->webPath = $this->app->getWebRoot() . "data/upload/{$this->app->company->id}/";