/** * 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; }
/** * Return parent folder * * @param void * @return object */ function getParent() { if (is_null($this->parent)) { $this->parent = ProjectFolders::findById($this->getParentId()); if ($this->parent instanceof ProjectFolder && $this->parent->getProjectId() != $this->getProjectId()) { $this->parent = null; } // if } // if return $this->parent; }
/** * This function will return paginated result. Result is an array where first element is * array of returned object and second populated pagination object that can be used for * obtaining and rendering pagination data using various helpers. * * Items and pagination array vars are indexed with 0 for items and 1 for pagination * because you can't use associative indexing with list() construct * * @access public * @param array $arguments Query argumens (@see find()) Limit and offset are ignored! * @param integer $items_per_page Number of items per page * @param integer $current_page Current page number * @return array */ function paginate($arguments = null, $items_per_page = 10, $current_page = 1) { if (isset($this) && instance_of($this, 'ProjectFolders')) { return parent::paginate($arguments, $items_per_page, $current_page); } else { return ProjectFolders::instance()->paginate($arguments, $items_per_page, $current_page); //$instance =& ProjectFolders::instance(); //return $instance->paginate($arguments, $items_per_page, $current_page); } // if }
function getFolders() { if (is_null($this->folders)) { $this->folders = ProjectFolders::getProjectFolders($this); } // if return $this->folders; }
/** * Add file * * @access public * @param void * @return null */ function add_file() { if (!ProjectFile::canAdd(logged_user(), active_project())) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('files')); } // if $file = new ProjectFile(); $file_data = array_var($_POST, 'file'); if (!is_array($file_data)) { $file_data = array('is_private' => config_option('default_private', false)); // array } // if $folder = null; $folder_id = get_id('folder_id'); if ($folder_id) { $folder = ProjectFolders::findById($folder_id); } // if if ($folder instanceof ProjectFolder) { if (!is_array($file_data)) { $file_data = array('folder_id' => $folder->getId(), 'is_private' => config_option('default_private', false)); // array } else { $file_data['is_private'] = config_option('default_private', false); } } // if tpl_assign('file', $file); tpl_assign('file_data', $file_data); if (is_array(array_var($_POST, 'file'))) { try { DB::beginWork(); $uploaded_file = array_var($_FILES, 'file_file'); $file->setFromAttributes($file_data); if (!logged_user()->isMemberOfOwnerCompany()) { $file->setIsPrivate(false); $file->setIsImportant(false); $file->setCommentsEnabled(true); $file->setAnonymousCommentsEnabled(false); } // if $file->setFilename(array_var($uploaded_file, 'name')); $file->setProjectId(active_project()->getId()); $file->setIsVisible(true); $file->save(); if (plugin_active('tags')) { $file->setTagsFromCSV(array_var($file_data, 'tags')); } $revision = $file->handleUploadedFile($uploaded_file, true); // handle uploaded file ApplicationLogs::createLog($file, active_project(), ApplicationLogs::ACTION_ADD); DB::commit(); flash_success(lang('success add file', $file->getFilename())); $this->redirectToUrl($file->getDetailsUrl()); } catch (Exception $e) { DB::rollback(); tpl_assign('error', $e); tpl_assign('file', new ProjectFile()); // reset file // If we uploaded the file remove it from repository if (isset($revision) && $revision instanceof ProjectFileRevision && FileRepository::isInRepository($revision->getRepositoryId())) { FileRepository::deleteFile($revision->getRepositoryId()); } // if } // try } // if }
/** * Return manager instance * * @access protected * @param void * @return ProjectFolders */ function manager() { if (!$this->manager instanceof ProjectFolders) { $this->manager = ProjectFolders::instance(); } return $this->manager; }
function getFolders() { if(!plugin_active('files')) { return null; } if (is_null($this->folders)) { $this->folders = ProjectFolders::getProjectFolders($this); } // if return $this->folders; } // getFolders
/** * Render folder tree * * @param string $name Control name * @param Project $project * @param integer $selected ID of selected folder * @param array $attributes Select box attributes * @return string */ function render_folder_tree($folder, $depth = 0, $project = null, $selected = null, $attributes = null) { if ($depth > 5) { return; } if (is_null($project)) { $project = active_project(); } // if if (!$project instanceof Project) { throw new InvalidInstanceError('$project', $project, 'Project'); } // if if (is_array($attributes)) { if (!isset($attributes['class'])) { $attributes['class'] = 'select_folder'; } } else { $attributes = array('class' => 'select_folder'); } // if $options = array(option_tag(lang('none'), 0)); $html = ''; if ($folder instanceof ProjectFolder) { $folders = ProjectFolders::getProjectFolderTree($project, $folder->getId()); } else { $folders = ProjectFolders::getProjectFolderTree($project); } if (is_array($folders)) { $html .= '<ul>'; foreach ($folders as $folder) { $class = $folder->getId() == $selected ? $class = 'class="selected"' : ''; //$html .= '<li>' . $folder->getName() . render_folder_tree( $folder, $depth, $project, $selected, $attributes ) . '</li>'; $html .= '<li><a href="' . $folder->getBrowseUrl() . '" ' . $class . '>' . clean($folder->getName()) . '</a>'; if ($folder->canEdit(logged_user())) { $html .= ' <a href="' . $folder->getEditUrl() . '" class="blank" title="' . lang('edit folder') . '"><img src="' . icon_url('edit.gif') . '" alt="" /></a>'; } // if if ($folder->canDelete(logged_user())) { $html .= ' <a href="' . $folder->getDeleteUrl() . '" class="blank" title="' . lang('delete folder') . '"><img src="' . icon_url('cancel_gray.gif') . '" alt="" /></a>'; } // if $html .= render_folder_tree($folder, $depth + 1, $project, $selected, $attributes); $html .= '</li>'; } // foreach $html .= '</ul>'; } // if return $html; }
/** * Show file details * * @param void * @return null */ function file_details() { $this->addHelper('textile'); $file = ProjectFiles::findById(get_id()); if (!($file instanceof ProjectFile)) { flash_error(lang('file dnx')); $this->redirectToReferer(get_url('files')); } // if if (!$file->canView(logged_user())) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('files')); } // if $revisions = $file->getRevisions(); if (!count($revisions)) { flash_error(lang('no file revisions in file')); $this->redirectToReferer(get_url('files')); } // if $this->canGoOn(); tpl_assign('file', $file); tpl_assign('folder', $file->getFolder()); tpl_assign('last_revision', $file->getLastRevision()); tpl_assign('revisions', $revisions); // This variables are required for the sidebar tpl_assign('current_folder', $file->getFolder()); tpl_assign('order', null); tpl_assign('page', null); tpl_assign('folders', active_project()->getFolders()); tpl_assign('folder_tree', ProjectFolders::getProjectFolderTree(active_project())); tpl_assign('important_files', active_project()->getImportantFiles()); $this->setSidebar(get_template_path('index_sidebar', 'files')); } // file_details
/** * Add file * * @access public * @param void * @return null */ function add_file() { if (!ProjectFile::canAdd(logged_user(), active_project())) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('files')); } // if $file = new ProjectFile(); $file_data = array_var($_POST, 'file'); if (!is_array($file_data)) { $file_data = array('is_private' => config_option('default_private', false)); // array } // if $folder = null; $folder_id = get_id('folder_id'); if ($folder_id) { $folder = ProjectFolders::findById($folder_id); } // if if ($folder instanceof ProjectFolder) { if (!is_array($file_data)) { $file_data = array('folder_id' => $folder->getId(), 'is_private' => config_option('default_private', false)); // array } else { $file_data['is_private'] = config_option('default_private', false); } } // if tpl_assign('file', $file); tpl_assign('file_data', $file_data); if (is_array(array_var($_POST, 'file'))) { try { DB::beginWork(); $uploaded_file = array_var($_FILES, 'file_file'); // move uploaded file to folder where I can read and write move_uploaded_file($uploaded_file['tmp_name'], ROOT . '/tmp/' . $uploaded_file['name']); $uploaded_file['tmp_name'] = ROOT . '/tmp/' . $uploaded_file['name']; $file->setFromAttributes($file_data); if (!logged_user()->isMemberOfOwnerCompany()) { $file->setIsPrivate(false); $file->setIsImportant(false); $file->setCommentsEnabled(true); $file->setAnonymousCommentsEnabled(false); } // if $file->setFilename(array_var($uploaded_file, 'name')); $file->setProjectId(active_project()->getId()); $file->setIsVisible(true); $file->save(); if (plugin_active('tags')) { $file->setTagsFromCSV(array_var($file_data, 'tags')); } $revision = $file->handleUploadedFile($uploaded_file, true); // handle uploaded file ApplicationLogs::createLog($file, active_project(), ApplicationLogs::ACTION_ADD); DB::commit(); // Try to send notifications but don't break submission in case of an error // define all the users to be notified - here all project users, from all companies. // Restrictions if comment is private is taken into account in newOtherComment() try { $notify_people = array(); $project_companies = active_project()->getCompanies(); foreach ($project_companies as $project_company) { $company_users = $project_company->getUsersOnProject(active_project()); if (is_array($company_users)) { foreach ($company_users as $company_user) { if (array_var($file_data, 'notify_company_' . $project_company->getId()) == 'checked' || array_var($file_data, 'notify_user_' . $company_user->getId())) { $notify_people[] = $company_user; } // if } // if } // if } // if Notifier::newFile($file, $notify_people); // send notification email... } catch (Exception $e) { Logger::log("Error: Notification failed, " . $e->getMessage(), Logger::ERROR); } // try flash_success(lang('success add file', $file->getFilename())); $this->redirectToUrl($file->getDetailsUrl()); } catch (Exception $e) { DB::rollback(); tpl_assign('error', $e); tpl_assign('file', new ProjectFile()); // reset file // If we uploaded the file remove it from repository if (isset($revision) && $revision instanceof ProjectFileRevision && FileRepository::isInRepository($revision->getRepositoryId())) { FileRepository::deleteFile($revision->getRepositoryId()); } // if } // try } // if }