continued :)
[phpgitweb.git] / htdocs / pages / projects.class.php
diff --git a/htdocs/pages/projects.class.php b/htdocs/pages/projects.class.php
new file mode 100644 (file)
index 0000000..ade8eb6
--- /dev/null
@@ -0,0 +1,109 @@
+<?php
+/* projects.class.php - phpgitweb
+ * Copyright (C) 2011-2012  Philipp Kreil (pk910)
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. 
+ */
+
+class page_projects {
+    private $page, $phpgitweb;
+       
+    public function main($phpgitweb, $project) {
+               $this->phpgitweb = $phpgitweb;
+               $this->page = new ContentProvider('projects', 'main');
+               
+               $project_loader = $phpgitweb->get_project_loader();
+               $project_counter = 0;
+               $project_list = $project_loader->getProjectList();
+               
+               foreach($project_list as $projectid => &$project) {
+                       //load some additional information
+                       $project['last_change'] = $project_loader->getLastChange($project);
+               }
+               unset($project);
+               
+               if(array_key_exists('o', $_GET))
+                       $order = $_GET['o'];
+               else
+                       $order = 'project';
+               
+               $this->page->set('header_project',     new ContentProvider('projects', ($order == 'project' ? 'head_order_active' : 'head_order_link'), array('name' => "Project",     'tag' => "project")));
+               $this->page->set('header_description', new ContentProvider('projects', ($order == 'descr'   ? 'head_order_active' : 'head_order_link'), array('name' => "Description", 'tag' => "descr")));
+               $this->page->set('header_owner',       new ContentProvider('projects', ($order == 'owner'   ? 'head_order_active' : 'head_order_link'), array('name' => "Owner",       'tag' => "owner")));
+               $this->page->set('header_age',         new ContentProvider('projects', ($order == 'age'     ? 'head_order_active' : 'head_order_link'), array('name' => "Last Change", 'tag' => "age")));
+               
+               switch($order) {
+               case 'project':
+                       usort($project_list, array($this, "sort_by_project"));
+                       break;
+               case 'descr':
+                       usort($project_list, array($this, "sort_by_description"));
+                       break;
+               case 'owner':
+                       usort($project_list, array($this, "sort_by_owner"));
+                       break;
+               case 'age':
+                       usort($project_list, array($this, "sort_by_age"));
+                       break;
+               }
+               
+               foreach($project_list as $projectid => $project) {
+                       $project_counter++;
+                       $project_entry = $this->project(($project_counter % 2 ? 'dark' : 'light'), $project);
+                       $this->page->append('projects', $project_entry);
+               }
+               
+               return $this->page;
+       }
+       
+       private function sort_by_project($a, $b) {
+               return strcmp($a['name'], $b['name']);
+       }
+       private function sort_by_description($a, $b) {
+               $ret = strcmp($a['description'], $b['description']);
+               if($ret == 0)
+                       $ret = strcmp($a['name'], $b['name']);
+               return $ret;
+       }
+       private function sort_by_owner($a, $b) {
+               $ret = strcmp($a['owner'], $b['owner']);
+               if($ret == 0)
+                       $ret = strcmp($a['name'], $b['name']);
+               return $ret;
+       }
+       private function sort_by_age($a, $b) {
+               $ret = $a['last_change'] - $b['last_change'];
+               if($ret == 0)
+                       $ret = strcmp($a['name'], $b['name']);
+               return $ret;
+       }
+    
+       private function project($class, $project) {
+               $entry = new ContentProvider('projects', 'project');
+               $entry->set('class', $class);
+               $entry->set('project', $project['name']);
+               $entry->set('name', htmlentities($project['name']));
+               $entry->set('description', htmlentities($project['description']));
+               $entry->set('owner', htmlentities($project['owner']));
+               
+               $age = Tools::age_calculate($project['last_change']);
+               
+               $entry->set('ageclass', $age['age_class']);
+               $entry->set('age', $age['age_str']);
+               return $entry;
+       }
+       
+}
+
+?>
\ No newline at end of file