commit | author | age
|
175a52
|
1 |
<?php |
JK |
2 |
class ksiazki_cache { |
|
3 |
static $cache = array(); |
|
4 |
|
|
5 |
static function cache_get($kod) { |
|
6 |
$kod = (int)$kod; |
|
7 |
|
|
8 |
if(!isset(self::$cache[(int)$kod])) { |
|
9 |
self::cache_update($kod); |
|
10 |
} |
|
11 |
|
|
12 |
return self::$cache[(int)$kod]; |
|
13 |
} |
|
14 |
|
|
15 |
static function cache_add($kod, &$dane) { |
|
16 |
self::$cache[(int)$kod] = $dane; |
|
17 |
} |
|
18 |
|
|
19 |
static function cache_addarray(&$dane) { |
|
20 |
foreach($dane as &$r) { |
|
21 |
self::cache_add($r['id'], $r); |
|
22 |
} |
|
23 |
} |
|
24 |
|
|
25 |
static function cache_clear($id=NULL) { |
|
26 |
if(is_null($id)) { |
|
27 |
self::$cache = array(); |
|
28 |
} |
|
29 |
else |
|
30 |
{ |
|
31 |
unset(self::$cache[(int)$id]); |
|
32 |
} |
|
33 |
} |
|
34 |
|
|
35 |
static function cache_update($kod) { |
381239
|
36 |
$dane = db2::escape_data(sql::fetchone(sql::query('SELECT `ksiazki`.*, `pozycz`.`od`, `pozycz`.`kto` FROM `ksiazki` LEFT OUTER JOIN `pozycz` ON `pozycz`.`id`=`ksiazki`.`id` WHERE `ksiazki`.`id`='.sql::escape($kod)))); |
175a52
|
37 |
self::cache_add($kod, $dane); |
JK |
38 |
} |
|
39 |
} |
|
40 |
|
|
41 |
class ksiazki extends ksiazki_cache { |
|
42 |
static function okladka($KOD, $ISBN) { |
|
43 |
return okladki::znajdz($KOD, $ISBN, 'covers'); |
|
44 |
} |
|
45 |
|
|
46 |
static function okladka_big($KOD, $ISBN) { |
|
47 |
return okladki::znajdz($KOD, $ISBN, 'covers_big'); |
|
48 |
} |
|
49 |
|
|
50 |
static function exists($kod) { |
|
51 |
$info = self::cache_get($kod); |
|
52 |
if(isset($info['id'])) { |
|
53 |
return TRUE; |
|
54 |
} |
|
55 |
else |
|
56 |
{ |
|
57 |
return FALSE; |
|
58 |
} |
|
59 |
} |
|
60 |
|
|
61 |
static function szukaj_KOD($kod) { |
|
62 |
validate::KOD($kod, TRUE); |
|
63 |
|
|
64 |
return self::cache_get($kod); |
|
65 |
} |
|
66 |
|
|
67 |
static function szukaj_ISBN($ISBN) { |
|
68 |
validate::EAN($ISBN); |
|
69 |
|
|
70 |
return db2::get('ksiazki', '*', array('ISBN' => $ISBN), NULL, 10); |
|
71 |
} |
|
72 |
|
|
73 |
static function szukaj_ISSN($ISSN) { |
|
74 |
validate::EAN($ISSN); |
|
75 |
|
|
76 |
return db2::get('ksiazki', '*', array('ISSN' => $ISSN), NULL, 10); |
|
77 |
} |
|
78 |
|
|
79 |
static function szukaj_info($dane, $order=NULL, $start=NULL, $limit=30) { |
|
80 |
$allow = array('id', 'tytul', 'autor', 'wydawnictwo', 'miejsce', 'rok', 'wydanie', 'wycofana'); |
|
81 |
$replace = array('tytul' => 'tytul~~', 'autor' => 'autor~~', 'wydawnictwo' => 'wydawnictwo~~'); |
|
82 |
|
|
83 |
$where = array(); |
|
84 |
|
|
85 |
foreach($dane as $key => $value) { |
|
86 |
if(!in_array($key, $allow) OR $value==='') { |
|
87 |
continue; |
|
88 |
} |
|
89 |
|
|
90 |
if($replace[$key]) { |
|
91 |
$key = $replace[$key]; |
|
92 |
} |
|
93 |
|
|
94 |
$where[$key] = $value; |
|
95 |
} |
|
96 |
|
|
97 |
if($where['id']) { |
|
98 |
validate::$kod = TRUE; |
|
99 |
switch(validate::type($where['id'])) { |
|
100 |
case 'ISBN': |
|
101 |
$where['ISBN'] = $where['id']; |
|
102 |
unset($where['id']); |
|
103 |
break; |
|
104 |
case 'ISSN': |
|
105 |
$where['ISSN'] = $where['id']; |
|
106 |
unset($where['id']); |
|
107 |
break; |
|
108 |
case 'MSC': |
|
109 |
$where['regal'] = $where['id']; |
|
110 |
if($dane['polka']) { |
|
111 |
$where['polka'] = $dane['polka']; |
|
112 |
} |
|
113 |
if($dane['rzad']) { |
|
114 |
$where['rzad'] = $dane['rzad']; |
|
115 |
} |
|
116 |
unset($where['id']); |
|
117 |
break; |
|
118 |
} |
|
119 |
validate::$kod = FALSE; |
|
120 |
} |
|
121 |
|
|
122 |
if(!$where['regal']) { |
|
123 |
unset($where['polka']); |
|
124 |
unset($where['rzad']); |
|
125 |
} |
|
126 |
|
|
127 |
if($where['id']) { |
|
128 |
$ret[] = self::szukaj_KOD($where['id']); |
|
129 |
$num = count($ret); |
|
130 |
} |
|
131 |
else |
|
132 |
{ |
|
133 |
if($dane['do']) { |
381239
|
134 |
$num = db2::num('pozycz', 'id'); |
JK |
135 |
if($num == 0) { |
175a52
|
136 |
$ret = array(); |
JK |
137 |
} |
|
138 |
else |
|
139 |
{ |
381239
|
140 |
$ret = db2::get(array('pozycz', array('J', 'ksiazki', 'USING', 'id')), '*', NULL, $order, $start, $limit); |
175a52
|
141 |
} |
JK |
142 |
} |
|
143 |
else |
|
144 |
{ |
|
145 |
$num = db2::num('ksiazki', 'id', $where); |
381239
|
146 |
if($num == 0) { |
175a52
|
147 |
$ret = array(); |
JK |
148 |
} |
|
149 |
else |
|
150 |
{ |
|
151 |
$where = db2::__combine_where($where, TRUE); |
f84915
|
152 |
$ret = db2::escape_data(sql::fetch(sql::query('SELECT `ksiazki`.*, `pozycz`.`od`, `pozycz`.`kto`'.(db2::revelance() ? ', '.db2::$revelance : '').' FROM `ksiazki` LEFT OUTER JOIN `pozycz` ON `pozycz`.`id`=`ksiazki`.`id` '.$where.db2::__combine_order($order, TRUE).db2::__combine_limit($start, $limit)))); |
175a52
|
153 |
} |
JK |
154 |
} |
|
155 |
|
|
156 |
self::cache_addarray($ret); |
|
157 |
} |
|
158 |
|
|
159 |
return array($num, $ret, db2::revelance()); |
|
160 |
} |
|
161 |
} |
532779
|
162 |
?> |