first import
[projectpier.git] / application / models / project_folders / ProjectFolder.class.php
blob081391314059633e7762461d0d0234f96569e048
1 <?php
3 /**
4 * ProjectFolder class
5 * Generated on Tue, 04 Jul 2006 06:46:08 +0200 by DataObject generation tool
7 * @http://www.projectpier.org/
8 */
9 class ProjectFolder extends BaseProjectFolder {
11 /**
12 * Cached array of all folder files
14 * @var array
16 private $all_files;
18 /**
19 * Cached array of folder files filtered by user permissions
21 * @var array
23 private $files;
25 /**
26 * Return all project files
28 * @param void
29 * @return array
31 function getAllFiles() {
32 if(is_null($this->all_files)) {
33 $this->all_files = ProjectFiles::getByFolder($this, true);
34 } // if
35 return $this->all_files;
36 } // getAllFiles
38 /**
39 * Return files
41 * @param void
42 * @return array
44 function getFiles() {
45 if(is_null($this->files)) {
46 $this->files = ProjectFiles::getByFolder($this, logged_user()->isMemberOfOwnerCompany());
47 } // if
48 return $this->files;
49 } // getFiles
51 // ---------------------------------------------------
52 // URLs
53 // ---------------------------------------------------
55 /**
56 * Return browse URL
58 * @param string $order_by
59 * @param integer $page
60 * @return string
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;
67 } // if
69 // #PAGE# is reserved as a placeholder
70 if($page <> '#PAGE#') {
71 $page = (integer) $page > 0 ? (integer) $page : 1;
72 } // if
74 return get_url('files', 'browse_folder', array(
75 'id' => $this->getId(),
76 'active_project' => $this->getProjectId(),
77 'order' => $order_by,
78 'page' => $page
79 )); // array
80 } // getBrowseUrl
82 /**
83 * Return add file URL
85 * @param void
86 * @return string
88 function getAddFileUrl() {
89 return get_url('files', 'add_file', array(
90 'folder_id' => $this->getId(),
91 'active_project' => $this->getProjectId()
92 )); // array
93 } // getAddFileUrl
95 /**
96 * Return edit folder URL
98 * @param void
99 * @return string
101 function getEditUrl() {
102 return get_url('files', 'edit_folder', array('id' => $this->getId(), 'active_project' => $this->getProjectId()));
103 } // getEditUrl
106 * Return delete folder URL
108 * @param void
109 * @return string
111 function getDeleteUrl() {
112 return get_url('files', 'delete_folder', array('id' => $this->getId(), 'active_project' => $this->getProjectId()));
113 } // getDeleteUrl
115 // ---------------------------------------------------
116 // Permissions
117 // ---------------------------------------------------
120 * Check CAN_MANAGE_MESSAGES permission
122 * @access public
123 * @param User $user
124 * @return boolean
126 function canManage(User $user) {
127 if(!$user->isProjectUser($this->getProject())) return false;
128 return $user->getProjectPermission($this->getProject(), ProjectUsers::CAN_MANAGE_FILES);
129 } // canManage
132 * Empty implementation of abstract method. Message determins if user have view access
134 * @param void
135 * @return boolean
137 function canView(User $user) {
138 return $user->isProjectUser($this->getProject());
139 } // canView
142 * Empty implementation of abstract methods. Messages determine does user have
143 * permissions to add comment
145 * @param void
146 * @return null
148 function canAdd(User $user, Project $project) {
149 if(!$user->isProjectUser($project)) return false;
150 return $user->getProjectPermission($project, ProjectUsers::CAN_MANAGE_FILES);
151 } // canAdd
154 * Check if specific user can edit this file
156 * @access public
157 * @param User $user
158 * @return boolean
160 function canEdit(User $user) {
161 if(!$user->isProjectUser($this->getProject())) return false;
162 return $user->isAdministrator() || $this->canManage($user);
163 } // canEdit
166 * Check if specific user can delete this comment
168 * @access public
169 * @param User $user
170 * @return boolean
172 function canDelete(User $user) {
173 if(!$user->isProjectUser($this->getProject())) return false;
174 return $user->isAdministrator() || $this->canManage($user);
175 } // canDelete
177 // ---------------------------------------------------
178 // System
179 // ---------------------------------------------------
182 * Validate before save
184 * @param array $errors
185 * @return null
187 function validate(&$errors) {
188 if($this->validatePresenceOf('name')) {
189 if(!$this->validateUniquenessOf('name', 'project_id')) $errors[] = lang('folder name unique');
190 } else {
191 $errors[] = lang('folder name required');
192 } // if
193 } // validate
196 * Delete this folder
198 * @param void
199 * @return boolean
201 function delete() {
202 $files = $this->getAllFiles();
203 if(is_array($files)) {
204 foreach($files as $file) $file->delete();
205 } // if
206 return parent::delete();
207 } // delete
209 // ---------------------------------------------------
210 // ApplicationDataObject implementation
211 // ---------------------------------------------------
214 * Return object name
216 * @access public
217 * @param void
218 * @return string
220 function getObjectName() {
221 return $this->getName();
222 } // getObjectName
225 * Return object type name
227 * @param void
228 * @return string
230 function getObjectTypeName() {
231 return lang('folder');
232 } // getObjectTypeName
235 * Return object URl
237 * @access public
238 * @param void
239 * @return string
241 function getObjectUrl() {
242 return $this->getBrowseUrl();
243 } // getObjectUrl
245 } // ProjectFolder