remove long dead svn magic lines
[plewww.git] / planetlab / includes / plc_visibletags2.php
1 <?php
2
3     // utility function for displaying extra columns based on tags and categories
4   // expected type is e.g. 'node'
5
6 class VisibleTags {
7   var $api;
8   var $type;
9
10   function __construct ($api, $type) {
11     $this->api=$api;
12     $this->type=$type;
13     $this->columns=NULL;
14   }
15
16   // returns an ordered set of columns - compute only once
17   function columns () {
18     # if cached
19     if ($this->columns != NULL)
20       return $this->columns;
21
22     // scan tag types to find relevant additional columns
23     $tag_types = $this->api->GetTagTypes(array('category'=>"$this->type*/ui*"));
24
25     $columns = array();
26     foreach ($tag_types as $tag_type) {
27       $tagname=$tag_type['tagname'];
28       $column=array();
29       $column['tagname']=$tagname;
30       // defaults
31       $column['header']=$tagname;
32       $column['rank']=$tagname;
33       $column['type']='string';
34       $column['description']=$tag_type['description'];
35       // split category and parse any setting
36       $category_tokens=explode('/',$tag_type['category']);
37       foreach ($category_tokens as $token) {
38               $assign=explode('=',$token);
39               if (count($assign)==2)
40                 $column[$assign[0]]=$assign[1];
41       }
42       $columns []= $column;
43     }
44
45     // sort upon 'rank'
46     usort ($columns, function($col1, $col2) { return strcmp($col1["header"],$col2["header"]); });
47
48     # cache for next time
49     $this->columns=$columns;
50
51     //plc_debug('columns',$columns);
52     return $columns;
53   }
54
55   // extract tagname
56   function column_names () {
57     return array_map(function($tt) {return $tt["tagname"];},
58                      $this->columns());
59   }
60
61   // to add with array_merge to the headers part of the Plekit Table
62   function headers () {
63     $headers=array();
64     $columns=$this->columns();
65     foreach ($columns as $column)
66         {
67         if ($column['header'] == 'f')
68                 continue;
69
70             //panos: needed a few more fields in the header array
71         $headerId = $column['header'];
72         if ($column['headerId'] != "")
73                 $headerId = $column['headerId'];
74
75         $headers[$headerId]=array('header'=>$column['header'],'headerId'=>$headerId, 'type'=>$column['type'],'tagname'=>$column['tagname'],'title'=>$column['description']);
76         }
77     /*
78       if ($column['header'] == $column['tagname'])
79         $headers[$column['header']]=$column['type'];
80       else
81         $headers[$column['header']]=array('type'=>$column['type'],'title'=>$column['description']);
82      */
83     return $headers;
84   }
85
86   // to add with array_merge to the notes part of the Plekit Table
87   function notes () {
88     $notes=array();
89     $columns=$this->columns();
90     foreach ($columns as $column)
91       if ($column['header'] != $column['tagname'])
92         $notes []= strtoupper($column['header']) . ' = ' . $column['description'];
93     return $notes;
94   }
95
96 }
97 ?>