Improve category completion
[infodrom.org/service.infodrom.org] / class / accounttable.class.php
1 <?php
2
3 abstract class AccountTable extends DatabaseTable {
4   protected $valuecolumn;
5
6   public function __construct($table, $id)
7   {
8     parent::__construct($table, $id);
9   }
10
11   public function sum($blzkto)
12   {
13     $sql = sprintf("SELECT sum(%s) FROM %s WHERE blz_kto = %s",
14                    $this->valuecolumn,
15                    $this->table,
16                    $this->db->quote($blzkto));
17     return $this->db->fetchValue($sql);
18   }
19
20   public function distinctYears($blzkto)
21   {
22     $sql = sprintf("SELECT DISTINCT substr(datum::text,0,5) AS year FROM %s ".
23                    "WHERE blz_kto = %s ORDER BY year DESC",
24                    $this->table, $this->db->quote($blzkto));
25     return $this->db->fetchObjectList($sql);
26   }
27
28   public function distinctCategories($blzkto)
29   {
30     $sql = sprintf("SELECT DISTINCT category FROM %s WHERE blz_kto = %s ORDER BY category",
31                    $this->table, $this->db->quote($blzkto));
32     return $this->db->fetchObjectList($sql);
33   }
34
35   public function distinctFromTo($blzkto, $period=false)
36   {
37     $sql = sprintf("SELECT DISTINCT from_to FROM %s WHERE blz_kto = %s%s ORDER BY from_to",
38                    $this->table, $this->db->quote($blzkto),
39                    $period === false ? '' : ' AND ' . $period);
40     return $this->db->fetchObjectList($sql);
41   }
42
43   public function distinctStatements($blzkto)
44   {
45     $sql = sprintf("SELECT DISTINCT statement FROM %s WHERE blz_kto = %s ORDER BY statement DESC",
46                    $this->table, $this->db->quote($blzkto));
47     return $this->db->fetchObjectList($sql);
48   }
49
50 }
51
52 ?>