ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilPaymentVendors.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4
14{
15 private static $_instance;
16
20 public $db = null;
21
22 public $vendors = array();
23
24
25 public static function getInstance()
26 {
27 if(!isset(self::$_instance))
28 {
29 self::$_instance = new ilPaymentVendors();
30 }
31
32 return self::$_instance;
33 }
34
39 private function __construct()
40 {
41 global $ilDB;
42
43 $this->db = $ilDB;
44
45 $this->__read();
46 }
47
48 public function getVendors()
49 {
50 return $this->vendors;
51 }
52
53 public function isAssigned($a_usr_id)
54 {
55 return isset($this->vendors[$a_usr_id]);
56 }
57
58 public function add($a_usr_id)
59 {
60 if(isset($this->vendors[$a_usr_id]))
61 {
62 die("class.ilPaymentVendors::add() Vendor already exists");
63 }
64
65 $this->db->insert('payment_vendors',
66 array(
67 'vendor_id' => array('integer', $a_usr_id),
68 'cost_center' => array('text', 'IL_INST_ID_' . $a_usr_id)
69 ));
70
71 $this->__read();
72
73 return true;
74 }
75
76 public function update($a_usr_id, $a_cost_center)
77 {
78 $this->db->update('payment_vendors',
79 array('cost_center' => array('text', $a_cost_center)),
80 array('vendor_id' => array('integer', $a_usr_id)));
81
82 $this->__read();
83
84 return true;
85 }
86
87 public function delete($a_usr_id)
88 {
89 if(!isset($this->vendors[$a_usr_id]))
90 {
91 die("class.ilPaymentVendors::delete() Vendor does not exist");
92 }
93
94 $this->db->manipulateF('
95 DELETE FROM payment_vendors WHERE vendor_id = %s',
96 array('integer'),
97 array($a_usr_id));
98
99 // deleting of trustees is done by gui as a next step
100
101 $this->__read();
102
103 return true;
104 }
105
106 // PRIVATE
107 private function __read()
108 {
109 $this->vendors = array();
110
111 $res = $this->db->query('SELECT * FROM payment_vendors');
112
113
114 while($row = $this->db->fetchObject($res))
115 {
116 $this->vendors[$row->vendor_id]['vendor_id'] = $row->vendor_id;
117 $this->vendors[$row->vendor_id]['cost_center'] = $row->cost_center;
118 }
119 return true;
120 }
121
122 // STATIC
123 public static function _isVendor($a_usr_id)
124 {
128 global $ilDB;
129
130 $res = $ilDB->queryf('
131 SELECT * FROM payment_vendors WHERE vendor_id = %s',
132 array('integer'), array($a_usr_id));
133
134 return $ilDB->numRows($res) ? true : false;
135 }
136
137 public static function _getCostCenter($a_usr_id)
138 {
142 global $ilDB;
143
144 $res = $ilDB->queryf('
145 SELECT * FROM payment_vendors WHERE vendor_id = %s',
146 array('integer'), array($a_usr_id));
147
148 while($row = $ilDB->fetchObject($res))
149 {
150 return $row->cost_center;
151 }
152 return -1;
153 }
154
155} // END class.ilPaymentVendors
156?>
__construct()
Constructor @access private.
update($a_usr_id, $a_cost_center)
global $ilDB