-
Notifications
You must be signed in to change notification settings - Fork 2
/
projectstree.inc.php
105 lines (90 loc) · 4.35 KB
/
projectstree.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**************************************************************************
* This file is part of the WebIssues Server program
* Copyright (C) 2006 Michał Męciński
* Copyright (C) 2007-2017 WebIssues Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
if ( !defined( 'WI_VERSION' ) ) die( -1 );
class Client_ProjectsTree extends System_Web_Component
{
protected function __construct()
{
parent::__construct();
}
protected function execute()
{
$projectManager = new System_Api_ProjectManager();
$typeId = (int)$this->request->getQueryString( 'type' );
if ( !$typeId ) {
$issueId = (int)$this->request->getQueryString( 'issue' );
if ( $issueId ) {
$issueManager = new System_Api_IssueManager();
$issue = $issueManager->getIssue( $issueId );
$folderId = $issue[ 'folder_id' ];
$projectId = $issue[ 'project_id' ];
} else {
$folderId = (int)$this->request->getQueryString( 'folder' );
if ( $folderId ) {
$folder = $projectManager->getFolder( $folderId );
$projectId = $folder[ 'project_id' ];
} else {
$projectId = (int)$this->request->getQueryString( 'project' );
}
}
}
$preferencesManager = new System_Api_PreferencesManager();
$pageSize = $preferencesManager->getPreferenceOrSetting( 'project_page_size' );
$this->grid = new System_Web_Grid();
$this->grid->setPageSize( $pageSize );
$this->grid->setParameters( 'ppg', 'po', 'ps' );
if ( $typeId )
$this->grid->setSelection( $typeId, 'T' );
else
$this->grid->setSelection( $folderId, $projectId );
$this->grid->setColumns( $projectManager->getProjectsColumns() );
$this->grid->setDefaultSort( 'name', System_Web_Grid::Ascending );
$this->grid->setRowsCount( $projectManager->getProjectsCount() );
$projects = $projectManager->getProjectsPage( $this->grid->getOrderBy(), $this->grid->getPageSize(), $this->grid->getOffset() );
$folders = $projectManager->getFoldersForProjects( $projects );
$this->projects = array();
foreach ( $projects as $project ) {
$project[ 'folders' ] = array();
$this->projects[ $project[ 'project_id' ] ] = $project;
}
foreach ( $folders as $folder )
$this->projects[ $folder[ 'project_id' ] ][ 'folders' ][ $folder[ 'folder_id' ] ] = $folder;
$emptyProjects = array();
$anyProjectAdmin = false;
foreach ( $this->projects as $id => $project ) {
if ( empty( $project[ 'folders' ] ) )
$emptyProjects[] = $id;
if ( $project[ 'project_access' ] == System_Const::AdministratorAccess )
$anyProjectAdmin = true;
}
$this->grid->removeExpandCookieIds( 'wi_projects', $emptyProjects );
$typeManager = new System_Api_TypeManager();
$types = $typeManager->getAvailableIssueTypes();
$this->types = array();
foreach ( $types as $type )
$this->types[ $type[ 'type_id' ] ] = $type;
$javaScript = new System_Web_JavaScript( $this->view );
$javaScript->registerExpandCookie( 'wi_projects' );
$this->toolBar = new System_Web_ToolBar();
$this->toolBar->setFilterParameters( array() );
if ( System_Api_Principal::getCurrent()->isAdministrator() || $anyProjectAdmin )
$this->toolBar->addFixedCommand( '/client/projects/index.php', '/common/images/project-admin-16.png', $this->tr( 'Manage Projects' ) );
}
}