2 /* projects.class.php - phpgitweb
3 * Copyright (C) 2011-2012 Philipp Kreil (pk910)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 private $page, $phpgitweb;
22 public function main($phpgitweb, $project) {
23 $this->phpgitweb = $phpgitweb;
24 $this->page = new ContentProvider('projects', 'main');
26 $project_loader = $phpgitweb->get_project_loader();
28 $project_list = $project_loader->getProjectList();
30 foreach($project_list as $projectid => &$project) {
31 //load some additional information
32 $project['last_change'] = $project_loader->getLastChange($project);
36 if(array_key_exists('o', $_GET))
41 $this->page->set('header_project', new ContentProvider('projects', ($order == 'project' ? 'head_order_active' : 'head_order_link'), array('name' => "Project", 'tag' => "project")));
42 $this->page->set('header_description', new ContentProvider('projects', ($order == 'descr' ? 'head_order_active' : 'head_order_link'), array('name' => "Description", 'tag' => "descr")));
43 $this->page->set('header_owner', new ContentProvider('projects', ($order == 'owner' ? 'head_order_active' : 'head_order_link'), array('name' => "Owner", 'tag' => "owner")));
44 $this->page->set('header_age', new ContentProvider('projects', ($order == 'age' ? 'head_order_active' : 'head_order_link'), array('name' => "Last Change", 'tag' => "age")));
48 usort($project_list, array($this, "sort_by_project"));
51 usort($project_list, array($this, "sort_by_description"));
54 usort($project_list, array($this, "sort_by_owner"));
57 usort($project_list, array($this, "sort_by_age"));
61 foreach($project_list as $projectid => $project) {
63 $project_entry = $this->project(($project_counter % 2 ? 'dark' : 'light'), $project);
64 $this->page->append('projects', $project_entry);
70 private function sort_by_project($a, $b) {
71 return strcmp($a['name'], $b['name']);
73 private function sort_by_description($a, $b) {
74 $ret = strcmp($a['description'], $b['description']);
76 $ret = strcmp($a['name'], $b['name']);
79 private function sort_by_owner($a, $b) {
80 $ret = strcmp($a['owner'], $b['owner']);
82 $ret = strcmp($a['name'], $b['name']);
85 private function sort_by_age($a, $b) {
86 $ret = $a['last_change'] - $b['last_change'];
88 $ret = strcmp($a['name'], $b['name']);
92 private function project($class, $project) {
93 $entry = new ContentProvider('projects', 'project');
94 $entry->set('class', $class);
95 $entry->set('project', $project['name']);
96 $entry->set('name', htmlentities($project['name']));
97 $entry->set('description', htmlentities($project['description']));
98 $entry->set('owner', htmlentities($project['owner']));
100 $age = Tools::age_calculate($project['last_change']);
102 $entry->set('ageclass', $age['age_class']);
103 $entry->set('age', $age['age_str']);