📄 projectfile.class.php
字号:
<?php /** * ProjectFile class * Generated on Tue, 04 Jul 2006 06:46:08 +0200 by DataObject generation tool * * @http://www.projectpier.org/ */ class ProjectFile extends BaseProjectFile { /** * This project object is taggable * * @var boolean */ protected $is_taggable = true; /** * Message comments are searchable * * @var boolean */ protected $is_searchable = true; /** * Array of searchable columns * * @var array */ protected $searchable_columns = array('filename', 'filecontent', 'description'); /** * Project file is commentable object * * @var boolean */ protected $is_commentable = true; /** * Cached parent folder object * * @var ProjectFolder */ private $folder; /** * Cached file type object * * @var FileType */ private $file_type; /** * Last revision instance * * @var ProjectFileRevision */ private $last_revision; /** * Contruct the object * * @param void * @return null */ function __construct() { $this->addProtectedAttribute('system_filename', 'filename', 'type_string', 'filesize'); parent::__construct(); } // __construct /** * Return parent folder instance * * @param void * @return ProjectFolder */ function getFolder() { if (is_null($this->folder)) { $this->folder = ProjectFolders::findById($this->getFolderId()); if (($this->folder instanceof ProjectFolder) && ($this->folder->getProjectId() <> $this->getProjectId())) { $this->folder = null; } // if } // if return $this->folder; } // getFolder /** * Return parent project instance * * @param void * @return Project */ function getProject() { if (is_null($this->project)) { $this->project = Projects::findById($this->getProjectId()); } // if return $this->project; } // getProject /** * Return all file revisions * * @param void * @return array */ function getRevisions($exclude_last = false) { if ($exclude_last) { $last_revision = $this->getLastRevision(); if ($last_revision instanceof ProjectFileRevision) { $conditions = DB::prepareString('`id` <> ? AND `file_id` = ?', array($last_revision->getId(), $this->getId())); } } // if if (!isset($conditions)) { $conditions = DB::prepareString('`file_id` = ?', array($this->getId())); } return ProjectFileRevisions::find(array( 'conditions' => $conditions, 'order' => '`created_on` DESC' )); // find } // getRevisions /** * Return the number of file revisions * * @param void * @return integer */ function countRevisions() { return ProjectFileRevisions::count(array( '`file_id` = ?', $this->getId() )); // count } // countRevisions /** * Return revision number of last revision. If there is no revisions return 0 * * @param void * @return integer */ function getRevisionNumber() { $last_revision = $this->getLastRevision(); return $last_revision instanceof ProjectFileRevision ? $last_revision->getRevisionNumber() : 0; } // getRevisionNumber /** * Return last revision of this file * * @param void * @return ProjectFileRevision */ function getLastRevision() { if (is_null($this->last_revision)) { $this->last_revision = ProjectFileRevisions::findOne(array( 'conditions' => array('`file_id` = ?', $this->getId()), 'order' => '`created_on` DESC', 'limit' => 1, )); // findOne } // if return $this->last_revision; } // getLastRevision /** * Return file type object * * @param void * @return FileType */ function getFileType() { $revision = $this->getLastRevision(); return $revision instanceof ProjectFileRevision ? $revision->getFileType() : null; } // getFileType /** * Return URL of file type icon * * @access public * @param void * @return string */ function getTypeIconUrl() { $last_revision = $this->getLastRevision(); return $last_revision instanceof ProjectFileRevision ? $last_revision->getTypeIconUrl() : ''; } // getTypeIconUrl // --------------------------------------------------- // Revision interface // --------------------------------------------------- /** * Return file type ID * * @param void * @return integer */ function getFileTypeId() { $revision = $this->getLastRevision(); return $revision instanceof ProjectFileRevision ? $revision->getFileTypeId() : null; } // getFileTypeId /** * Return type string. We need to know mime type when forwarding file * to the client * * @param void * @return string */ function getTypeString() { $revision = $this->getLastRevision(); return $revision instanceof ProjectFileRevision ? $revision->getTypeString() : null; } // getTypeString /** * Return file size in bytes * * @param void * @return integer */ function getFileSize() { $revision = $this->getLastRevision(); return $revision instanceof ProjectFileRevision ? $revision->getFileSize() : null; } // getFileSize /** * Return file content * * @param void * @return string */ function getFileContent() { $revision = $this->getLastRevision(); return $revision instanceof ProjectFileRevision ? $revision->getFileContent() : null; } // getFileContent // --------------------------------------------------- // Util functions // --------------------------------------------------- /** * This function will process uploaded file * * @param array $uploaded_file * @param boolean $create_revision Create new revision or update last one * @param string $revision_comment Revision comment, if any * @return ProjectFileRevision */ function handleUploadedFile($uploaded_file, $create_revision = true, $revision_comment = '') { $revision = null; if (!$create_revision) { $revision = $this->getLastRevision(); } // if if (!($revision instanceof ProjectFileRevision)) { $revision = new ProjectFileRevision(); $revision->setFileId($this->getId()); $revision->setRevisionNumber($this->getNextRevisionNumber()); if ((trim($revision_comment) == '') && ($this->countRevisions() < 1)) { $revision_comment = lang('initial versions'); } // if } // if $revision->deleteThumb(false); // remove thumb // We have a file to handle! if (!is_array($uploaded_file) || !isset($uploaded_file['name']) || !isset($uploaded_file['size']) || !isset($uploaded_file['type']) || !isset($uploaded_file['tmp_name']) || !is_readable($uploaded_file['tmp_name'])) { throw new InvalidUploadError($uploaded_file); } // if if (isset($uploaded_file['error']) && ($uploaded_file['error'] > UPLOAD_ERR_OK)) { throw new InvalidUploadError($uploaded_file); } // if $repository_id = FileRepository::addFile($uploaded_file['tmp_name'], array('name' => $uploaded_file['name'], 'type' => $uploaded_file['type'], 'size' => $uploaded_file['size'])); $revision->setRepositoryId($repository_id); $revision->deleteThumb(false); $revision->setFilesize($uploaded_file['size']); $revision->setTypeString($uploaded_file['type']); $extension = get_file_extension(basename($uploaded_file['name'])); if (trim($extension)) { $file_type = FileTypes::getByExtension($extension); if ($file_type instanceof Filetype) { $revision->setFileTypeId($file_type->getId()); } // if } // if $revision->setComment($revision_comment); $revision->save(); $this->last_revision = $revision; // update last revision return $revision; } // handleUploadedFile /** * Return next revision number * * @param void * @return integer */ protected function getNextRevisionNumber() { $last_revision = $this->getLastRevision(); return $last_revision instanceof ProjectFileRevision ? $last_revision->getRevisionNumber() + 1 : 1; } // getNextRevisionNumber // --------------------------------------------------- // URLs // ---------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -