<?php
|
class ksiazki_cache {
|
static $cache = array();
|
|
static function cache_get($kod) {
|
$kod = (int)$kod;
|
|
if(!isset(self::$cache[(int)$kod])) {
|
self::cache_update($kod);
|
}
|
|
return self::$cache[(int)$kod];
|
}
|
|
static function cache_add($kod, &$dane) {
|
self::$cache[(int)$kod] = $dane;
|
}
|
|
static function cache_addarray(&$dane) {
|
foreach($dane as &$r) {
|
self::cache_add($r['id'], $r);
|
}
|
}
|
|
static function cache_clear($id=NULL) {
|
if(is_null($id)) {
|
self::$cache = array();
|
}
|
else
|
{
|
unset(self::$cache[(int)$id]);
|
}
|
}
|
|
static function cache_update($kod) {
|
$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))));
|
self::cache_add($kod, $dane);
|
}
|
}
|
|
class ksiazki extends ksiazki_cache {
|
static function okladka($KOD, $ISBN) {
|
return okladki::znajdz($KOD, $ISBN, 'covers');
|
}
|
|
static function okladka_big($KOD, $ISBN) {
|
return okladki::znajdz($KOD, $ISBN, 'covers_big');
|
}
|
|
static function exists($kod) {
|
$info = self::cache_get($kod);
|
if(isset($info['id'])) {
|
return TRUE;
|
}
|
else
|
{
|
return FALSE;
|
}
|
}
|
|
static function szukaj_KOD($kod) {
|
validate::KOD($kod, TRUE);
|
|
return self::cache_get($kod);
|
}
|
|
static function szukaj_ISBN($ISBN) {
|
validate::EAN($ISBN);
|
|
return db2::get('ksiazki', '*', array('ISBN' => $ISBN), NULL, 10);
|
}
|
|
static function szukaj_ISSN($ISSN) {
|
validate::EAN($ISSN);
|
|
return db2::get('ksiazki', '*', array('ISSN' => $ISSN), NULL, 10);
|
}
|
|
static function szukaj_info($dane, $order=NULL, $start=NULL, $limit=30) {
|
$allow = array('id', 'tytul', 'autor', 'wydawnictwo', 'miejsce', 'rok', 'wydanie', 'wycofana');
|
$replace = array('tytul' => 'tytul~~', 'autor' => 'autor~~', 'wydawnictwo' => 'wydawnictwo~~');
|
|
$where = array();
|
|
foreach($dane as $key => $value) {
|
if(!in_array($key, $allow) OR $value==='') {
|
continue;
|
}
|
|
if($replace[$key]) {
|
$key = $replace[$key];
|
}
|
|
$where[$key] = $value;
|
}
|
|
if($where['id']) {
|
validate::$kod = TRUE;
|
switch(validate::type($where['id'])) {
|
case 'ISBN':
|
$where['ISBN'] = $where['id'];
|
unset($where['id']);
|
break;
|
case 'ISSN':
|
$where['ISSN'] = $where['id'];
|
unset($where['id']);
|
break;
|
case 'MSC':
|
$where['regal'] = $where['id'];
|
if($dane['polka']) {
|
$where['polka'] = $dane['polka'];
|
}
|
if($dane['rzad']) {
|
$where['rzad'] = $dane['rzad'];
|
}
|
unset($where['id']);
|
break;
|
}
|
validate::$kod = FALSE;
|
}
|
|
if(!$where['regal']) {
|
unset($where['polka']);
|
unset($where['rzad']);
|
}
|
|
if($where['id']) {
|
$ret[] = self::szukaj_KOD($where['id']);
|
$num = count($ret);
|
}
|
else
|
{
|
if($dane['do']) {
|
$num = db2::num('pozycz', 'id');
|
if($num == 0) {
|
$ret = array();
|
}
|
else
|
{
|
$ret = db2::get(array('pozycz', array('J', 'ksiazki', 'USING', 'id')), '*', NULL, $order, $start, $limit);
|
}
|
}
|
else
|
{
|
$num = db2::num('ksiazki', 'id', $where);
|
if($num == 0) {
|
$ret = array();
|
}
|
else
|
{
|
$where = db2::__combine_where($where, TRUE);
|
$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))));
|
}
|
}
|
|
self::cache_addarray($ret);
|
}
|
|
return array($num, $ret, db2::revelance());
|
}
|
}
|
?>
|