5 * Generated on Tue, 04 Jul 2006 06:46:08 +0200 by DataObject generation tool
7 * @http://www.projectpier.org/
9 class ProjectFolder
extends BaseProjectFolder
{
12 * Cached array of all folder files
19 * Cached array of folder files filtered by user permissions
26 * Return all project files
31 function getAllFiles() {
32 if(is_null($this->all_files
)) {
33 $this->all_files
= ProjectFiles
::getByFolder($this, true);
35 return $this->all_files
;
45 if(is_null($this->files
)) {
46 $this->files
= ProjectFiles
::getByFolder($this, logged_user()->isMemberOfOwnerCompany());
51 // ---------------------------------------------------
53 // ---------------------------------------------------
58 * @param string $order_by
59 * @param integer $page
62 function getBrowseUrl($order_by = null, $page = null) {
64 // If page and order are not set use defaults
65 if(($order_by <> ProjectFiles
::ORDER_BY_NAME
) && ($order_by <> ProjectFiles
::ORDER_BY_POSTTIME
)) {
66 $order_by = ProjectFiles
::ORDER_BY_POSTTIME
;
69 // #PAGE# is reserved as a placeholder
70 if($page <> '#PAGE#') {
71 $page = (integer) $page > 0 ?
(integer) $page : 1;
74 return get_url('files', 'browse_folder', array(
75 'id' => $this->getId(),
76 'active_project' => $this->getProjectId(),
88 function getAddFileUrl() {
89 return get_url('files', 'add_file', array(
90 'folder_id' => $this->getId(),
91 'active_project' => $this->getProjectId()
96 * Return edit folder URL
101 function getEditUrl() {
102 return get_url('files', 'edit_folder', array('id' => $this->getId(), 'active_project' => $this->getProjectId()));
106 * Return delete folder URL
111 function getDeleteUrl() {
112 return get_url('files', 'delete_folder', array('id' => $this->getId(), 'active_project' => $this->getProjectId()));
115 // ---------------------------------------------------
117 // ---------------------------------------------------
120 * Check CAN_MANAGE_MESSAGES permission
126 function canManage(User
$user) {
127 if(!$user->isProjectUser($this->getProject())) return false;
128 return $user->getProjectPermission($this->getProject(), ProjectUsers
::CAN_MANAGE_FILES
);
132 * Empty implementation of abstract method. Message determins if user have view access
137 function canView(User
$user) {
138 return $user->isProjectUser($this->getProject());
142 * Empty implementation of abstract methods. Messages determine does user have
143 * permissions to add comment
148 function canAdd(User
$user, Project
$project) {
149 if(!$user->isProjectUser($project)) return false;
150 return $user->getProjectPermission($project, ProjectUsers
::CAN_MANAGE_FILES
);
154 * Check if specific user can edit this file
160 function canEdit(User
$user) {
161 if(!$user->isProjectUser($this->getProject())) return false;
162 return $user->isAdministrator() ||
$this->canManage($user);
166 * Check if specific user can delete this comment
172 function canDelete(User
$user) {
173 if(!$user->isProjectUser($this->getProject())) return false;
174 return $user->isAdministrator() ||
$this->canManage($user);
177 // ---------------------------------------------------
179 // ---------------------------------------------------
182 * Validate before save
184 * @param array $errors
187 function validate(&$errors) {
188 if($this->validatePresenceOf('name')) {
189 if(!$this->validateUniquenessOf('name', 'project_id')) $errors[] = lang('folder name unique');
191 $errors[] = lang('folder name required');
202 $files = $this->getAllFiles();
203 if(is_array($files)) {
204 foreach($files as $file) $file->delete();
206 return parent
::delete();
209 // ---------------------------------------------------
210 // ApplicationDataObject implementation
211 // ---------------------------------------------------
220 function getObjectName() {
221 return $this->getName();
225 * Return object type name
230 function getObjectTypeName() {
231 return lang('folder');
232 } // getObjectTypeName
241 function getObjectUrl() {
242 return $this->getBrowseUrl();